|
@@ -41,6 +41,9 @@ void getDeviceInfo(Webs *wp){
|
|
|
sprintf(FwVersion, "%d.%d", DeviceID.FirmwareRevision1, DeviceID.FirmwareRevision2);
|
|
|
}
|
|
|
|
|
|
+ //Close session
|
|
|
+ LIBIPMI_CloseSession(&UDSSession );
|
|
|
+
|
|
|
// //get mac address
|
|
|
// if((sock=socket(AF_INET,SOCK_STREAM,0))<0)
|
|
|
// {
|
|
@@ -87,28 +90,33 @@ void getDeviceInfo(Webs *wp){
|
|
|
// }
|
|
|
// close(sock);
|
|
|
|
|
|
- //Close session
|
|
|
- LIBIPMI_CloseSession(&UDSSession );
|
|
|
+
|
|
|
|
|
|
printf("BuildTime: %s\n", BuildTime);
|
|
|
printf("FwVersion: %s\n", FwVersion);
|
|
|
printf("MacAddr: %s\n", MacAddr);
|
|
|
printf("IpAddr: %s\n", IpAddr);
|
|
|
|
|
|
- cchar *pStr;
|
|
|
+ char *pStr;
|
|
|
+
|
|
|
+ char *testStr;
|
|
|
+ testStr = malloc(200);
|
|
|
+ sprintf(testStr, "%s", "jimbo is very confused!");
|
|
|
+
|
|
|
int code = 200;
|
|
|
cJSON * root = cJSON_CreateObject();
|
|
|
cJSON * data = cJSON_CreateObject();
|
|
|
// cJSON * next = cJSON_CreateObject();
|
|
|
- cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
- cJSON_AddItemToObject(root, "msg", cJSON_CreateString(""));
|
|
|
- cJSON_AddItemToObject(root, "code", cJSON_CreateString("200"));
|
|
|
- cJSON_AddStringToObject(data, "buildTime", BuildTime);
|
|
|
- cJSON_AddStringToObject(data, "fwVersion", FwVersion);
|
|
|
- cJSON_AddStringToObject(data, "macAddr", MacAddr);
|
|
|
- cJSON_AddStringToObject(data, "ipAddr", IpAddr);
|
|
|
+ // cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
+ // cJSON_AddItemToObject(root, "msg", cJSON_CreateString(""));
|
|
|
+ // cJSON_AddItemToObject(root, "code", cJSON_CreateString("200"));
|
|
|
+ // cJSON_AddStringToObject(data, "buildTime", BuildTime);
|
|
|
+ // cJSON_AddStringToObject(data, "fwVersion", FwVersion);
|
|
|
+ // cJSON_AddStringToObject(data, "macAddr", MacAddr);
|
|
|
+ // cJSON_AddStringToObject(data, "ipAddr", IpAddr);
|
|
|
|
|
|
- pStr = cJSON_Print(root);
|
|
|
+ //pStr = cJSON_Print(root);
|
|
|
+ pStr = testStr;
|
|
|
|
|
|
printf("first json:\n%s\n", pStr);
|
|
|
logmsg(2, "-----------------------jso1n----------------------%s", pStr);
|
|
@@ -116,11 +124,13 @@ void getDeviceInfo(Webs *wp){
|
|
|
websSetStatus(wp, WEBS_KEEP_ALIVE);
|
|
|
websWriteHeaders(wp, -1, 0);
|
|
|
websWriteEndHeaders(wp);
|
|
|
- //websWrite(wp, "[");
|
|
|
- websWrite(wp, pStr);
|
|
|
- //websWrite(wp, "]");
|
|
|
- //websFlush(wp, 0);
|
|
|
+ websWrite(wp, "%s", pStr);
|
|
|
+ websFlush(wp, 0);
|
|
|
websDone(wp);
|
|
|
+
|
|
|
+ if(pStr)
|
|
|
+ free(pStr);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -397,24 +407,52 @@ void actionTest(Webs *wp)
|
|
|
{
|
|
|
IPMI20_UDS_SESSION_T UDSSession;
|
|
|
GetDevIDRes_T DeviceID;
|
|
|
+ char BuildTime[30] = "2020-3-17";
|
|
|
+ char FwVersion[10] = "5.555";
|
|
|
+ char MacAddr[18] = "22.22.22.22.22.22";
|
|
|
+ char IpAddr[16] = "192.168.255.255";
|
|
|
|
|
|
//Create session
|
|
|
printf("actionTest!\n");
|
|
|
- LIBIPMI_CreateSession(&UDSSession, 10);
|
|
|
- IPMICMD_GetDeviceID( &UDSSession, &DeviceID, DEFAULT_TIMEOUT);
|
|
|
+ // LIBIPMI_CreateSession(&UDSSession, 10);
|
|
|
+ // IPMICMD_GetDeviceID( &UDSSession, &DeviceID, DEFAULT_TIMEOUT);
|
|
|
+ // LIBIPMI_CloseSession(&UDSSession );
|
|
|
|
|
|
+ char *pStr;
|
|
|
|
|
|
- char name[] = "jimbo";
|
|
|
- char address[] = "shanghai";
|
|
|
- printf("name: %s, address: %s\n", name, address);
|
|
|
- websSetStatus(wp, WEBS_KEEP_ALIVE);
|
|
|
+ // char *testStr;
|
|
|
+ // testStr = malloc(200);
|
|
|
+ // sprintf(testStr, "version %d.%d, buildTime %s %s", \
|
|
|
+ // DeviceID.FirmwareRevision1, DeviceID.FirmwareRevision2, __DATE__, __TIME__);
|
|
|
+
|
|
|
+ cJSON * root = cJSON_CreateObject();
|
|
|
+ cJSON * data = cJSON_CreateObject();
|
|
|
+ cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
+ cJSON_AddItemToObject(root, "msg", cJSON_CreateString(""));
|
|
|
+ cJSON_AddItemToObject(root, "code", cJSON_CreateString("200"));
|
|
|
+ cJSON_AddStringToObject(data, "buildTime", BuildTime);
|
|
|
+ cJSON_AddStringToObject(data, "fwVersion", FwVersion);
|
|
|
+ cJSON_AddStringToObject(data, "macAddr", MacAddr);
|
|
|
+ cJSON_AddStringToObject(data, "ipAddr", IpAddr);
|
|
|
+
|
|
|
+ pStr = cJSON_Print(root); //include malloc
|
|
|
+ //pStr = testStr;
|
|
|
+
|
|
|
+
|
|
|
+ websSetStatus(wp, 200);
|
|
|
websWriteHeaders(wp, -1, 0);
|
|
|
websWriteEndHeaders(wp);
|
|
|
- websWrite(wp, "Name %s", name);
|
|
|
+ websWrite(wp,"%s", pStr);
|
|
|
websFlush(wp, 0);
|
|
|
websDone(wp);
|
|
|
|
|
|
- LIBIPMI_CloseSession(&UDSSession );
|
|
|
+ if(pStr)
|
|
|
+ free(pStr);
|
|
|
+
|
|
|
+ cJSON_Delete(root);
|
|
|
+ cJSON_Delete(data);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|