|
@@ -201,7 +201,7 @@ void getSensorInfo(Webs *wp){
|
|
|
int HighNRThresh;
|
|
|
int SensorAccessibleFlags;
|
|
|
struct sensor_data *pSensorBuff = NULL;
|
|
|
- long int reading,lownr,lowct,lownc,highnc,highct,highnr = 0;
|
|
|
+ char reading[10], lownr[10],lowct[10],lownc[10],highnc[10],highct[10],highnr[10];
|
|
|
unsigned char *pStartBuff = NULL;
|
|
|
IPMI20_UDS_SESSION_T UDSSession;
|
|
|
|
|
@@ -250,7 +250,7 @@ void getSensorInfo(Webs *wp){
|
|
|
else
|
|
|
{
|
|
|
|
|
|
- cchar *pStr;
|
|
|
+ char *pStr;
|
|
|
int code = 200;
|
|
|
cJSON * root = cJSON_CreateObject();
|
|
|
cJSON *pJsonArry,*pJsonsub;
|
|
@@ -258,34 +258,62 @@ void getSensorInfo(Webs *wp){
|
|
|
logmsg(2, "-----------------------sensor----------------------");
|
|
|
while(nSensors)
|
|
|
{
|
|
|
- reading = pSensorBuff->sensor_reading * 1000;
|
|
|
- lownr = pSensorBuff->low_non_recov_thresh * 1000;
|
|
|
- lowct = pSensorBuff->low_crit_thresh * 1000;
|
|
|
- lownc = pSensorBuff->low_non_crit_thresh * 1000;
|
|
|
- highnc = pSensorBuff->high_non_crit_thresh * 1000;
|
|
|
- highct = pSensorBuff->high_crit_thresh * 1000;
|
|
|
- highnr = pSensorBuff->high_non_recov_thresh * 1000;
|
|
|
+ sprintf(reading, "%.3f", pSensorBuff->sensor_reading);
|
|
|
+ sprintf(lownr, "%.3f", pSensorBuff->low_non_recov_thresh);
|
|
|
+ sprintf(lowct, "%.3f", pSensorBuff->low_crit_thresh);
|
|
|
+ sprintf(lownc, "%.3f", pSensorBuff->low_non_crit_thresh);
|
|
|
+ sprintf(highnc, "%.3f", pSensorBuff->high_non_crit_thresh);
|
|
|
+ sprintf(highct, "%.3f", pSensorBuff->high_crit_thresh);
|
|
|
+ sprintf(highnr, "%.3f", pSensorBuff->high_non_recov_thresh);
|
|
|
+
|
|
|
cJSON_AddItemToArray(pJsonArry,pJsonsub=cJSON_CreateObject()); /* 给创建的数组增加对对象*/
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "sensorNum", pSensorBuff->sensor_num);
|
|
|
+ //cJSON_AddNumberToObject(pJsonsub, "sensorNum", pSensorBuff->sensor_num);
|
|
|
cJSON_AddStringToObject(pJsonsub, "sensorName", pSensorBuff->sensor_name);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "ownerId", pSensorBuff->owner_id);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "ownerNun", pSensorBuff->owner_lun);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "sensorType", pSensorBuff->sensor_type);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "sensorUnits1", pSensorBuff->sensor_units[0]);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "sensorUnits2", pSensorBuff->sensor_units[1]);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "sensorUnits3", pSensorBuff->sensor_units[2]);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "rawReading", pSensorBuff->raw_reading);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "sensorState", pSensorBuff->sensor_state);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "discreteState", pSensorBuff->discrete_state);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "sensorAccessibleFlags", pSensorBuff->SensorAccessibleFlags);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "reading", reading); /* 给对象增加内容 */
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "lownr", lownr);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "lowct", lowct);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "lownc", lownc);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "highnc", highnc);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "highct", highct);
|
|
|
- cJSON_AddNumberToObject(pJsonsub, "highnr", highnr);
|
|
|
|
|
|
+ //cJSON_AddNumberToObject(pJsonsub, "ownerId", pSensorBuff->owner_id);
|
|
|
+ //cJSON_AddNumberToObject(pJsonsub, "ownerNun", pSensorBuff->owner_lun);
|
|
|
+ //cJSON_AddNumberToObject(pJsonsub, "sensorType", pSensorBuff->sensor_type);
|
|
|
+ // cJSON_AddNumberToObject(pJsonsub, "sensorUnits1", pSensorBuff->sensor_units[0]);
|
|
|
+ // cJSON_AddNumberToObject(pJsonsub, "sensorUnits2", pSensorBuff->sensor_units[1]);
|
|
|
+ // cJSON_AddNumberToObject(pJsonsub, "sensorUnits3", pSensorBuff->sensor_units[2]);
|
|
|
+
|
|
|
+ //cJSON_AddNumberToObject(pJsonsub, "rawReading", pSensorBuff->raw_reading);
|
|
|
+ //cJSON_AddNumberToObject(pJsonsub, "sensorState", pSensorBuff->sensor_state);
|
|
|
+ //cJSON_AddNumberToObject(pJsonsub, "discreteState", pSensorBuff->discrete_state);
|
|
|
+ //cJSON_AddNumberToObject(pJsonsub, "SensorAccessibleFlags", pSensorBuff->SensorAccessibleFlags);
|
|
|
+ cJSON_AddStringToObject(pJsonsub, "reading", reading); /* 给对象增加内容 */
|
|
|
+ cJSON_AddStringToObject(pJsonsub, "lownr", lownr);
|
|
|
+ cJSON_AddStringToObject(pJsonsub, "lowct", lowct);
|
|
|
+ cJSON_AddStringToObject(pJsonsub, "highnc", highnc);
|
|
|
+ cJSON_AddStringToObject(pJsonsub, "highct", highct);
|
|
|
+ cJSON_AddStringToObject(pJsonsub, "highnr", highnr);
|
|
|
+
|
|
|
+ switch(pSensorBuff->sensor_units[1]) //sensorUinits2
|
|
|
+ {
|
|
|
+ case 0: cJSON_AddStringToObject(pJsonsub, "Unit", "unspecified"); break;
|
|
|
+ case 1: cJSON_AddStringToObject(pJsonsub, "Unit", "degree C"); break;
|
|
|
+ case 2: cJSON_AddStringToObject(pJsonsub, "Unit", "degree F"); break;
|
|
|
+ case 3: cJSON_AddStringToObject(pJsonsub, "Unit", "degree K"); break;
|
|
|
+ case 4: cJSON_AddStringToObject(pJsonsub, "Unit", "Volts"); break;
|
|
|
+ case 5: cJSON_AddStringToObject(pJsonsub, "Unit", "Amps"); break;
|
|
|
+ case 6: cJSON_AddStringToObject(pJsonsub, "Unit", "Watts"); break;
|
|
|
+ case 18: cJSON_AddStringToObject(pJsonsub, "Unit", "RPM"); break;
|
|
|
+ default: cJSON_AddStringToObject(pJsonsub, "Unit", "unknown"); break;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch(pSensorBuff->sensor_state)
|
|
|
+ {
|
|
|
+ case 0x1: cJSON_AddStringToObject(pJsonsub, "State", "ok"); break;
|
|
|
+ case 0x2: cJSON_AddStringToObject(pJsonsub, "State", "Upper Non-Critical"); break;
|
|
|
+ case 0x4: cJSON_AddStringToObject(pJsonsub, "State", "Upper Critical Threshold"); break;
|
|
|
+ case 0x8: cJSON_AddStringToObject(pJsonsub, "State", "Lower Non-Critical"); break;
|
|
|
+ case 0x10: cJSON_AddStringToObject(pJsonsub, "State", "Lower Critical"); break;
|
|
|
+ case 0x20: cJSON_AddStringToObject(pJsonsub, "State", "Access failed"); break;
|
|
|
+ case 0x40: cJSON_AddStringToObject(pJsonsub, "State", "Upper Non-Recoverable"); break;
|
|
|
+ case 0x80: cJSON_AddStringToObject(pJsonsub, "State", "Lower Non-Recoverable"); break;
|
|
|
+ default: cJSON_AddNumberToObject(pJsonsub, "State", pSensorBuff->sensor_state); break;
|
|
|
+ }
|
|
|
+
|
|
|
pSensorBuff++;
|
|
|
nSensors--;
|
|
|
}
|
|
@@ -296,6 +324,7 @@ void getSensorInfo(Webs *wp){
|
|
|
// pStr = cJSON_Print(pJsonArry);
|
|
|
cJSON_AddItemToObject(root, "data", pJsonArry);
|
|
|
pStr = cJSON_PrintUnformatted(root);
|
|
|
+ printf("---> pStr %d: %s\n", strlen(pStr), pStr);
|
|
|
|
|
|
websSetStatus(wp, 200);
|
|
|
websWriteHeaders(wp, -1, 0);
|
|
@@ -305,6 +334,9 @@ void getSensorInfo(Webs *wp){
|
|
|
//websWrite(wp, "]");
|
|
|
//websFlush(wp, 0);
|
|
|
websDone(wp);
|
|
|
+
|
|
|
+ if(root)
|
|
|
+ cJSON_Delete(root);
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -312,7 +344,6 @@ void getSensorInfo(Webs *wp){
|
|
|
error_out:
|
|
|
if(pStartBuff)
|
|
|
free(pStartBuff);
|
|
|
-
|
|
|
|
|
|
}
|
|
|
|
|
@@ -333,6 +364,11 @@ void buy(Webs *wp)
|
|
|
websWrite(wp, "age %s", age);
|
|
|
websFlush(wp, 0);
|
|
|
websDone(wp);
|
|
|
+
|
|
|
+ if(name)
|
|
|
+ wfree(name);
|
|
|
+ if(age)
|
|
|
+ wfree(age);
|
|
|
}
|
|
|
|
|
|
|