Răsfoiți Sursa

New time interface

zhangbo 5 ani în urmă
părinte
comite
cf43d0b613

+ 4 - 0
app/goahead-3.6.5/src/goahead.c

@@ -199,6 +199,10 @@ websDefineAction("getFruProductInfo", getFruProductInfo);
 //sel
 websDefineAction("Web_ClearSEL", Web_ClearSEL);
 websDefineAction("GetAllSELEntriesSorted", GetAllSELEntriesSorted);
+websDefineAction("SetTime", SetTime);
+websDefineAction("GetTime", GetTime);
+websDefineAction("SetTimeUTCOffset", SetTimeUTCOffset);
+websDefineAction("GetTimeUTCOffset", GetTimeUTCOffset);
 
 //user
 websDefineAction("getAllUserInfo", getAllUserInfo);

+ 5 - 0
app/goahead-3.6.5/src/web_interface/inc/sel.h

@@ -6,4 +6,9 @@
 void Web_ClearSEL(Webs *wp);
 void GetAllSELEntriesSorted(Webs *wp);
 
+void SetTime(Webs *wp);
+void GetTime(Webs *wp);
+void SetTimeUTCOffset(Webs *wp);
+void GetTimeUTCOffset(Webs *wp);
+
 #endif /* __SEL_H__ */

+ 189 - 0
app/goahead-3.6.5/src/web_interface/src/sel.c

@@ -181,3 +181,192 @@ error_out:
 
 }
 
+
+void SetTime(Webs *wp)
+{
+	int wRet = 0;
+	IPMI20_UDS_SESSION_T    UDSSession;
+	SetSELTimeReq_T SetSELTimeReq;
+
+	char *strTime = websGetVar(wp, "time", NULL);
+
+    SetSELTimeReq.Time = atoi(strTime);
+
+    printf("Time: %s, second: %d\n", strTime, SetSELTimeReq.Time);
+  
+	//Create session
+    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
+    wRet = IPMICMD_SetSELTime(&UDSSession,	&SetSELTimeReq, DEFAULT_TIMEOUT);
+    if(wRet != 0)
+    {
+    	websError(wp, 404, "Set sel time fail!");
+    	//Close session
+    	LIBIPMI_CloseSession(&UDSSession );
+    	return;
+    }
+    //Close session
+    LIBIPMI_CloseSession(&UDSSession );
+	
+	char *pStr;
+    cJSON * root =  cJSON_CreateObject();
+    cJSON * data =  cJSON_CreateObject();
+    cJSON_AddItemToObject(root, "data", data);//根节点下添加
+    cJSON_AddStringToObject(root, "msg", "");
+    cJSON_AddNumberToObject(root, "code", 200);
+
+  
+    pStr = cJSON_PrintUnformatted(root);
+
+    printf("---> cJSON Str:\n%s\n", pStr);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteEndHeaders(wp); 
+    websWrite(wp,"%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+
+}
+
+
+void GetTime(Webs *wp)
+{
+	int wRet = 0;
+	IPMI20_UDS_SESSION_T    UDSSession;
+	GetSELTimeRes_T GetSELTimeRes;
+  
+	//Create session
+    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
+    wRet = IPMICMD_GetSELTime(&UDSSession, &GetSELTimeRes, DEFAULT_TIMEOUT);
+    if(wRet != 0)
+    {
+    	websError(wp, 404, "Get sel time fail!");
+    	//Close session
+    	LIBIPMI_CloseSession(&UDSSession );
+    	return;
+    }
+    //Close session
+    LIBIPMI_CloseSession(&UDSSession );
+	
+	char *pStr;
+    cJSON * root =  cJSON_CreateObject();
+    cJSON * data =  cJSON_CreateObject();
+    cJSON_AddItemToObject(root, "data", data);//根节点下添加
+    cJSON_AddStringToObject(root, "msg", "");
+    cJSON_AddNumberToObject(root, "code", 200);
+
+    cJSON_AddNumberToObject(data, "time", GetSELTimeRes.Time);
+
+  
+    pStr = cJSON_PrintUnformatted(root);
+
+    printf("---> cJSON Str:\n%s\n", pStr);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteEndHeaders(wp); 
+    websWrite(wp,"%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+}
+
+
+void SetTimeUTCOffset(Webs *wp)
+{
+	int wRet = 0;
+	IPMI20_UDS_SESSION_T    UDSSession;
+	SetSELTimeUTCOffsetReq_T SetSELTimeUTCOffsetReq;
+	char *strUTCOffset = websGetVar(wp, "UTCOffset", NULL);	//这里的时区单位是 分钟
+
+    SetSELTimeUTCOffsetReq.UTCOffset = atoi(strUTCOffset);	//东8区就是 8*60
+    printf("Str: %s, int: %d\n", strUTCOffset, SetSELTimeUTCOffsetReq.UTCOffset);
+  
+	//Create session
+    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
+    wRet = IPMICMD_SetSELTimeUTCOffset(&UDSSession,	&SetSELTimeUTCOffsetReq, DEFAULT_TIMEOUT);
+    if(wRet != 0)
+    {
+    	websError(wp, 404, "Set sel time UTC offset fail!");
+    	//Close session
+    	LIBIPMI_CloseSession(&UDSSession );
+    	return;
+    }
+    //Close session
+    LIBIPMI_CloseSession(&UDSSession );
+	
+	char *pStr;
+    cJSON * root =  cJSON_CreateObject();
+    cJSON * data =  cJSON_CreateObject();
+    cJSON_AddItemToObject(root, "data", data);//根节点下添加
+    cJSON_AddStringToObject(root, "msg", "");
+    cJSON_AddNumberToObject(root, "code", 200);
+
+    pStr = cJSON_PrintUnformatted(root);
+
+    printf("---> cJSON Str:\n%s\n", pStr);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteEndHeaders(wp); 
+    websWrite(wp,"%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+}
+
+
+void GetTimeUTCOffset(Webs *wp)	//这里返回的时区单位是 分钟
+{
+	int wRet = 0;
+	IPMI20_UDS_SESSION_T    UDSSession;
+	GetSELTimeUTCOffsetRes_T GetSELTimeUTCOffsetRes;
+  
+	//Create session
+    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
+    wRet = IPMICMD_GetSELTimeUTCOffset(&UDSSession,	&GetSELTimeUTCOffsetRes, DEFAULT_TIMEOUT);
+    if(wRet != 0)
+    {
+    	websError(wp, 404, "Get time UTC offset fail!");
+    	//Close session
+    	LIBIPMI_CloseSession(&UDSSession );
+    	return;
+    }
+    //Close session
+    LIBIPMI_CloseSession(&UDSSession );
+	
+	char *pStr;
+    cJSON * root =  cJSON_CreateObject();
+    cJSON * data =  cJSON_CreateObject();
+    cJSON_AddItemToObject(root, "data", data);//根节点下添加
+    cJSON_AddStringToObject(root, "msg", "");
+    cJSON_AddNumberToObject(root, "code", 200);
+
+    cJSON_AddNumberToObject(data, "UTCOffset", GetSELTimeUTCOffsetRes.UTCOffset);
+
+  
+    pStr = cJSON_PrintUnformatted(root);
+
+    printf("---> cJSON Str:\n%s\n", pStr);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteEndHeaders(wp); 
+    websWrite(wp,"%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+}