|
@@ -0,0 +1,133 @@
|
|
|
+#include "goahead.h"
|
|
|
+#include "libipmi_IPM.h"
|
|
|
+#include "com_IPMIDefs.h"
|
|
|
+#include "ResultUtils.h"
|
|
|
+#include "cJSON.h"
|
|
|
+#include "libipmi_storlead_OEM.h"
|
|
|
+#include "libsensor.h"
|
|
|
+#include "libipmi_sdr.h"
|
|
|
+#include "libipmi_sensor.h"
|
|
|
+#include "com_BMCCfg.h"
|
|
|
+#include <stdio.h>
|
|
|
+#include <sys/socket.h>
|
|
|
+#include <sys/un.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <string.h>
|
|
|
+#include <stdlib.h>
|
|
|
+
|
|
|
+void getAllFanInfo(Webs *wp){
|
|
|
+ FanInfo_T fanInfo[FAN_NUMBERS];
|
|
|
+ uint16_t wRet = LIBIPMI_E_SUCCESS;
|
|
|
+ IPMI20_UDS_SESSION_T UDSSession;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ //Create session
|
|
|
+ LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
|
|
|
+
|
|
|
+ wRet = LIBIPMI_HL_GetFanInfo( &UDSSession, fanInfo, DEFAULT_TIMEOUT);
|
|
|
+ if(wRet != 0)
|
|
|
+ {
|
|
|
+ websError(wp, 404, "getAllFanInfo error!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //Close session
|
|
|
+ LIBIPMI_CloseSession(&UDSSession );
|
|
|
+
|
|
|
+ char *pStr;
|
|
|
+ cJSON * root = cJSON_CreateObject();
|
|
|
+ cJSON * pJsonArry=cJSON_CreateArray(); /*创建数组*/
|
|
|
+ cJSON * pJsonsub;
|
|
|
+ cJSON_AddItemToObject(root, "data", pJsonArry);//根节点下添加
|
|
|
+ cJSON_AddStringToObject(root, "msg", "");
|
|
|
+ cJSON_AddNumberToObject(root, "code", 200);
|
|
|
+
|
|
|
+ for(i=0;i<FAN_NUMBERS;i++)
|
|
|
+ {
|
|
|
+ cJSON_AddItemToArray(pJsonArry,pJsonsub=cJSON_CreateObject()); /* 给创建的数组增加对对象*/
|
|
|
+ cJSON_AddNumberToObject(pJsonsub, "index", fanInfo[i].index);
|
|
|
+ cJSON_AddStringToObject(pJsonsub, "name", fanInfo[i].name);
|
|
|
+ cJSON_AddNumberToObject(pJsonsub, "mode", fanInfo[i].mode); //0: 自动, 1:手动
|
|
|
+ cJSON_AddNumberToObject(pJsonsub, "level", fanInfo[i].level);
|
|
|
+ cJSON_AddNumberToObject(pJsonsub, "speed", fanInfo[i].speed);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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 setFanInfo(Webs *wp){
|
|
|
+ uint16_t wRet = LIBIPMI_E_SUCCESS;
|
|
|
+ IPMI20_UDS_SESSION_T UDSSession;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ char *strIndex = websGetVar(wp, "index", NULL);
|
|
|
+ char *strMode = websGetVar(wp, "mode", NULL);
|
|
|
+ char *strLevel = websGetVar(wp, "level", NULL);
|
|
|
+
|
|
|
+ uint8_t index = atoi(strIndex);
|
|
|
+ uint8_t mode = atoi(strMode);
|
|
|
+ uint8_t level = atoi(strLevel);
|
|
|
+
|
|
|
+ if(index >= FAN_NUMBERS)
|
|
|
+ {
|
|
|
+ websError(wp, 404, "Invalid index!");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(mode > 1)
|
|
|
+ {
|
|
|
+ websError(wp, 404, "Invalid mode!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(level > 100)
|
|
|
+ level = 100;
|
|
|
+
|
|
|
+ //Create session
|
|
|
+ LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
|
|
|
+
|
|
|
+ wRet = LIBIPMI_HL_SetFanInfo( &UDSSession, index, mode, level, DEFAULT_TIMEOUT);
|
|
|
+ if(wRet != 0)
|
|
|
+ {
|
|
|
+ websError(wp, 404, "getAllFanInfo error!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //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);
|
|
|
+}
|