|
@@ -135,11 +135,11 @@ void webGetSensorHistory(Webs *wp)
|
|
IPMI20_UDS_SESSION_T UDSSession;
|
|
IPMI20_UDS_SESSION_T UDSSession;
|
|
int i = 0,j=0;
|
|
int i = 0,j=0;
|
|
int wRet = 0;
|
|
int wRet = 0;
|
|
- //sensor_history_st *pSensorHistory = (sensor_history_st *)walloc(sizeof(sensor_history_st));
|
|
|
|
-// char tmpBuf[10];
|
|
|
|
-// char *historyBuf = walloc(500);
|
|
|
|
|
|
+ sensor_history_st *pSensorHistory = (sensor_history_st *)walloc(sizeof(sensor_history_st));
|
|
|
|
+ char tmpBuf[10];
|
|
|
|
+ char *historyBuf = walloc(500);
|
|
uint8_t target_addr;
|
|
uint8_t target_addr;
|
|
- // FullSensorRec_T *sdr_record = (FullSensorRec_T*) walloc(100);
|
|
|
|
|
|
+ FullSensorRec_T *sdr_record = (FullSensorRec_T*) walloc(100);
|
|
uint32_t sdr_buff_size = 0;
|
|
uint32_t sdr_buff_size = 0;
|
|
float tmpValue;
|
|
float tmpValue;
|
|
uint32_t dwResLen;
|
|
uint32_t dwResLen;
|
|
@@ -147,142 +147,122 @@ void webGetSensorHistory(Webs *wp)
|
|
char *strSensorNumber = websGetVar(wp, "SensorNumber", NULL);
|
|
char *strSensorNumber = websGetVar(wp, "SensorNumber", NULL);
|
|
int SensorNumber = atoi(strSensorNumber);
|
|
int SensorNumber = atoi(strSensorNumber);
|
|
|
|
|
|
- //memset(pSensorHistory->sensor_history, 0, 480);
|
|
|
|
|
|
+ memset(pSensorHistory->sensor_history, 0, HISTORY_DATA_SIZE);
|
|
|
|
|
|
- // //Create session
|
|
|
|
- // LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
|
|
|
|
-
|
|
|
|
- // //wp->index = 1;
|
|
|
|
- // target_addr = gIPMBAddr[wp->index];
|
|
|
|
- // //get factors
|
|
|
|
- // if(target_addr == 0x20)
|
|
|
|
- // {
|
|
|
|
- // wRet = LIBIPMI_HL_GetSpecificSDR( &UDSSession, (uint8_t*)sdr_record, &sdr_buff_size, SensorNumber, DEFAULT_TIMEOUT );
|
|
|
|
- // }
|
|
|
|
- // else
|
|
|
|
- // {
|
|
|
|
- // wRet = IPMC_GetSpecificSDR(&UDSSession, target_addr, (uint8_t*)sdr_record, &sdr_buff_size, SensorNumber, DEFAULT_TIMEOUT);
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // if(wRet != 0)
|
|
|
|
- // {
|
|
|
|
- // websError(wp, 404, "GetSpecificSDR error!");
|
|
|
|
- // wfree(pSensorHistory);
|
|
|
|
- // wfree(historyBuf);
|
|
|
|
- // wfree(sdr_record);
|
|
|
|
- // return;
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // pSensorHistory->sensor_num = SensorNumber;
|
|
|
|
- // strcpy(pSensorHistory->sensor_name, sdr_record->IDStr);
|
|
|
|
|
|
+ //Create session
|
|
|
|
+ LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
|
|
|
|
|
|
|
|
+ target_addr = gIPMBAddr[wp->index];
|
|
|
|
+ //get factors
|
|
|
|
+ if(target_addr == 0x20)
|
|
|
|
+ {
|
|
|
|
+ wRet = LIBIPMI_HL_GetSpecificSDR( &UDSSession, (uint8_t*)sdr_record, &sdr_buff_size, SensorNumber, DEFAULT_TIMEOUT );
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ wRet = IPMC_GetSpecificSDR(&UDSSession, target_addr, (uint8_t*)sdr_record, &sdr_buff_size, SensorNumber, DEFAULT_TIMEOUT);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ if(wRet != 0)
|
|
|
|
+ {
|
|
|
|
+ websError(wp, 404, "GetSpecificSDR error!");
|
|
|
|
+ wfree(pSensorHistory);
|
|
|
|
+ wfree(historyBuf);
|
|
|
|
+ wfree(sdr_record);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ pSensorHistory->sensor_num = SensorNumber;
|
|
|
|
+ strcpy(pSensorHistory->sensor_name, sdr_record->IDStr);
|
|
|
|
|
|
- // if(target_addr == 0x20)
|
|
|
|
- // {
|
|
|
|
- // wRet = IPMI_GetSensorHistory(&UDSSession, SensorNumber, (uint8_t*)historyBuf, DEFAULT_TIMEOUT);
|
|
|
|
- // if(wRet != 0)
|
|
|
|
- // {
|
|
|
|
- // websError(wp, 404, "IPMI_GetSensorHistory error!");
|
|
|
|
- // wfree(pSensorHistory);
|
|
|
|
- // wfree(historyBuf);
|
|
|
|
- // wfree(sdr_record);
|
|
|
|
- // return;
|
|
|
|
- // }
|
|
|
|
- // for(i=0;i<MAX_HISTORY_LEN;i++)
|
|
|
|
- // {
|
|
|
|
- // ipmi_convert_reading( (uint8_t*)sdr_record, (uint8_t)historyBuf[3+i], &tmpValue ); //remove ccode, returnlen_lsb/msb
|
|
|
|
- // pSensorHistory->sensor_history[i] = tmpValue;
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // else
|
|
|
|
- // {
|
|
|
|
- // //获取前240字节
|
|
|
|
- // wRet = IPMC_GetSensorHistory(&UDSSession, target_addr, SensorNumber, 0, 240, (uint8_t*)historyBuf, DEFAULT_TIMEOUT);
|
|
|
|
- // if(wRet != 0)
|
|
|
|
- // {
|
|
|
|
- // websError(wp, 404, "IPMC_GetSensorHistory error!");
|
|
|
|
- // wfree(pSensorHistory);
|
|
|
|
- // wfree(historyBuf);
|
|
|
|
- // wfree(sdr_record);
|
|
|
|
- // return;
|
|
|
|
- // }
|
|
|
|
- // for(i=0;i<240;i++)
|
|
|
|
- // {
|
|
|
|
- // ipmi_convert_reading( (uint8_t*)sdr_record, historyBuf[9+i], &tmpValue ); //remove ipmb header and ccode,returnlen_lsb/msb
|
|
|
|
- // pSensorHistory->sensor_history[i] = tmpValue;
|
|
|
|
- // }
|
|
|
|
- // //获取后240字节
|
|
|
|
- // wRet = IPMC_GetSensorHistory(&UDSSession, target_addr, SensorNumber, 240, 240, (uint8_t*)historyBuf, DEFAULT_TIMEOUT);
|
|
|
|
- // if(wRet != 0)
|
|
|
|
- // {
|
|
|
|
- // websError(wp, 404, "IPMC_GetSensorHistory error!");
|
|
|
|
- // wfree(pSensorHistory);
|
|
|
|
- // wfree(historyBuf);
|
|
|
|
- // wfree(sdr_record);
|
|
|
|
- // return;
|
|
|
|
- // }
|
|
|
|
- // for(i=0;i<240;i++)
|
|
|
|
- // {
|
|
|
|
- // ipmi_convert_reading( (uint8_t*)sdr_record, historyBuf[9+i], &tmpValue ); //remove ipmb header and ccode,returnlen_lsb/msb
|
|
|
|
- // pSensorHistory->sensor_history[240+i] = tmpValue;
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
|
|
+ if(target_addr == 0x20)
|
|
|
|
+ {
|
|
|
|
+ wRet = IPMI_GetSensorHistory(&UDSSession, SensorNumber, (uint8_t*)historyBuf, DEFAULT_TIMEOUT);
|
|
|
|
+ if(wRet != 0)
|
|
|
|
+ {
|
|
|
|
+ websError(wp, 404, "IPMI_GetSensorHistory error!");
|
|
|
|
+ wfree(pSensorHistory);
|
|
|
|
+ wfree(historyBuf);
|
|
|
|
+ wfree(sdr_record);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for(i=0;i<HISTORY_DATA_SIZE;i++)
|
|
|
|
+ {
|
|
|
|
+ ipmi_convert_reading( (uint8_t*)sdr_record, (uint8_t)historyBuf[3+i], &tmpValue ); //remove ccode, returnlen_lsb/msb
|
|
|
|
+ pSensorHistory->sensor_history[i] = tmpValue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //获取前240字节
|
|
|
|
+ wRet = IPMC_GetSensorHistory(&UDSSession, target_addr, SensorNumber, 0, 240, (uint8_t*)historyBuf, DEFAULT_TIMEOUT);
|
|
|
|
+ if(wRet != 0)
|
|
|
|
+ {
|
|
|
|
+ websError(wp, 404, "IPMC_GetSensorHistory error!");
|
|
|
|
+ wfree(pSensorHistory);
|
|
|
|
+ wfree(historyBuf);
|
|
|
|
+ wfree(sdr_record);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for(i=0;i<240;i++)
|
|
|
|
+ {
|
|
|
|
+ ipmi_convert_reading( (uint8_t*)sdr_record, historyBuf[9+i], &tmpValue ); //remove ipmb header and ccode,returnlen_lsb/msb
|
|
|
|
+ pSensorHistory->sensor_history[i] = tmpValue;
|
|
|
|
+ }
|
|
|
|
+ //获取后240字节
|
|
|
|
+ wRet = IPMC_GetSensorHistory(&UDSSession, target_addr, SensorNumber, 240, 240, (uint8_t*)historyBuf, DEFAULT_TIMEOUT);
|
|
|
|
+ if(wRet != 0)
|
|
|
|
+ {
|
|
|
|
+ websError(wp, 404, "IPMC_GetSensorHistory error!");
|
|
|
|
+ wfree(pSensorHistory);
|
|
|
|
+ wfree(historyBuf);
|
|
|
|
+ wfree(sdr_record);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for(i=0;i<240;i++)
|
|
|
|
+ {
|
|
|
|
+ ipmi_convert_reading( (uint8_t*)sdr_record, historyBuf[9+i], &tmpValue ); //remove ipmb header and ccode,returnlen_lsb/msb
|
|
|
|
+ pSensorHistory->sensor_history[240+i] = tmpValue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- // //Close session
|
|
|
|
- // LIBIPMI_CloseSession(&UDSSession );
|
|
|
|
|
|
+ //Close session
|
|
|
|
+ LIBIPMI_CloseSession(&UDSSession );
|
|
|
|
|
|
- // websSetStatus(wp, 200);
|
|
|
|
- // websWriteHeaders(wp, -1, 0);
|
|
|
|
- // websWriteEndHeaders(wp);
|
|
|
|
- // websWrite(wp, "{\"SensorNum\":%d,\"SensorName\":\"%s\",\"history\":\"", SensorNumber, sdr_record->IDStr);
|
|
|
|
-
|
|
|
|
- // //char *strBuf = historyBuf;
|
|
|
|
- // for(i=0;i<HISTORY_DATA_SIZE;i++)
|
|
|
|
- // {
|
|
|
|
- // sprintf(tmpBuf, "%0.2f", pSensorHistory->sensor_history[i]);
|
|
|
|
- // j = 0;
|
|
|
|
- // while(tmpBuf[j] != '\0')
|
|
|
|
- // {
|
|
|
|
- // j++;
|
|
|
|
- // if(j>=10)
|
|
|
|
- // break;
|
|
|
|
- // }
|
|
|
|
- // if(i < HISTORY_DATA_SIZE-1)
|
|
|
|
- // tmpBuf[j] = ','; //replace '\0' by ','
|
|
|
|
- // else
|
|
|
|
- // tmpBuf[j] = '"'; //最后一个串结束符用引号替换
|
|
|
|
- // j++; //point to next empty
|
|
|
|
- // websWrite(wp,"%s",tmpBuf);
|
|
|
|
- // //sprintf(strBuf, "%s", tmpBuf);
|
|
|
|
- // //strBuf += j;
|
|
|
|
- // }
|
|
|
|
- // websWrite(wp, "}");
|
|
|
|
- //strBuf--;
|
|
|
|
- //*strBuf = '\0';
|
|
|
|
|
|
+ websSetStatus(wp, 200);
|
|
|
|
+ websWriteHeaders(wp, -1, 0);
|
|
|
|
+ websWriteEndHeaders(wp);
|
|
|
|
+ websWrite(wp, "{\"SensorNum\":%d,\"SensorName\":\"%s\",\"history\":\"", SensorNumber, sdr_record->IDStr);
|
|
|
|
+
|
|
|
|
+ //char *strBuf = historyBuf;
|
|
|
|
+ for(i=0;i<HISTORY_DATA_SIZE;i++)
|
|
|
|
+ {
|
|
|
|
+ memset(tmpBuf,0, sizeof(tmpBuf));
|
|
|
|
+ sprintf(tmpBuf, "%0.2f", pSensorHistory->sensor_history[i]);
|
|
|
|
+ j = 0;
|
|
|
|
+ while(tmpBuf[j] != '\0')
|
|
|
|
+ {
|
|
|
|
+ j++;
|
|
|
|
+ if(j>=10)
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if(i < HISTORY_DATA_SIZE-1)
|
|
|
|
+ tmpBuf[j] = ','; //replace '\0' by ','
|
|
|
|
+ else
|
|
|
|
+ tmpBuf[j] = '"'; //最后一个串结束符用引号替换
|
|
|
|
+ websWrite(wp, tmpBuf);
|
|
|
|
+ }
|
|
|
|
+ websWrite(wp, "}");
|
|
|
|
|
|
- cJSON * root = cJSON_CreateObject();
|
|
|
|
- cJSON_AddNumberToObject(root, "SensorNum", 1);//pSensorHistory->sensor_num);
|
|
|
|
- cJSON_AddStringToObject(root, "SensorName", "test");//pSensorHistory->sensor_name);
|
|
|
|
- cJSON_AddStringToObject(root, "history", "");//historyBuf);
|
|
|
|
-
|
|
|
|
- char *pStr;
|
|
|
|
- pStr = cJSON_PrintUnformatted(root);
|
|
|
|
- websWrite(wp, "%s", pStr);
|
|
|
|
websFlush(wp, 0);
|
|
websFlush(wp, 0);
|
|
websDone(wp);
|
|
websDone(wp);
|
|
- //printf("cJSON:%s\n", pStr);
|
|
|
|
-
|
|
|
|
- if(pStr)
|
|
|
|
- wfree(pStr);
|
|
|
|
- if(root)
|
|
|
|
- cJSON_Delete(root);
|
|
|
|
|
|
|
|
- // if(historyBuf)
|
|
|
|
- // wfree(historyBuf);
|
|
|
|
- // if(pSensorHistory)
|
|
|
|
- // wfree(pSensorHistory);
|
|
|
|
|
|
+ if(historyBuf)
|
|
|
|
+ wfree(historyBuf);
|
|
|
|
+ if(pSensorHistory)
|
|
|
|
+ wfree(pSensorHistory);
|
|
|
|
+ if(sdr_record)
|
|
|
|
+ wfree(sdr_record);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|