Parcourir la source

add getEraseStatus

zhangbo il y a 4 ans
Parent
commit
3f4cb69ede

+ 31 - 16
app/UpdateFirmware/main.c

@@ -30,7 +30,7 @@ int main()
 	uint8_t rate = 0;
 
 	buf = malloc(64*1024);
-	chkBuf = malloc(64*1024);
+//	chkBuf = malloc(64*1024);
 
 	fp = fopen("/var/www/goahead/tmp/tmp.uImage", "rb");
 	if(NULL == fp)
@@ -45,21 +45,37 @@ int main()
 	fseek(fp, 0, SEEK_SET);
 	printf("Image size: %d\n", totalSize);
 
-//用来保存更新的进度
-		fprogress = fopen("/var/www/goahead/tmp/UpdateProgress.log", "w");
-		if(NULL == fp)
-		{
-			printf("Create UpdateProgress.log file fail!\n");
-			//return -1;
-		}
-		sprintf(progressStr, "%d", rate);
-		fputs(progressStr, fprogress);	
-		fclose(fprogress);	
+	//开始擦除
+	fprogress = fopen("/var/www/goahead/tmp/Erase.log", "w");
+	if(NULL == fprogress)
+	{
+		printf("Create Erase.log file fail!\n");
+	}
+	fputs(progressStr, "Erasing");	
+	fclose(fprogress);	
 
 	printf("Chip erase ...\n");
 	sf_chip_erase(5);
 	printf("Chip erase finished!\n");
 
+	fprogress = fopen("/var/www/goahead/tmp/Erase.log", "w");
+	if(NULL == fprogress)
+	{
+		printf("Create Erase.log file fail!\n");
+	}
+	fputs(progressStr, "Erase OK");	
+	fclose(fprogress);	
+
+	//用来保存更新的进度
+	fprogress = fopen("/var/www/goahead/tmp/UpdateProgress.log", "w");
+	if(NULL == fprogress)
+	{
+		printf("Create UpdateProgress.log file fail!\n");
+		//return -1;
+	}
+	fputs(progressStr, "0");	
+	fclose(fprogress);	
+
 	do{
 		len = fread(buf, 1, 64*1024, fp);
 		if(len <= 0)
@@ -86,7 +102,7 @@ int main()
 
 		//用来保存更新的进度
 		fprogress = fopen("/var/www/goahead/tmp/UpdateProgress.log", "w");
-		if(NULL == fp)
+		if(NULL == fprogress)
 		{
 			printf("Create UpdateProgress.log file fail!\n");
 			//return -1;
@@ -104,17 +120,16 @@ int main()
 	printf("Verigy successful.\n");
 	//用来保存校验结果
 	fprogress = fopen("/var/www/goahead/tmp/Verify.log", "w");
-	if(NULL == fp)
+	if(NULL == fprogress)
 	{
 		printf("Create UpdateProgress.log file fail!\n");
 	}
-	sprintf(progressStr, "Verify OK");
-	fputs(progressStr, fprogress);
+	fputs(progressStr, "Verify OK");
 	fclose(fprogress);
 
 	fclose(fp);
 
 	free(buf);
-	free(chkBuf);
+//	free(chkBuf);
 	return 0;
 }

BIN
app/UpdateFirmware/updateFW_app


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

@@ -218,6 +218,7 @@ websDefineAction("updateFlash", updateFlash);
 websDefineAction("getUpdateProgress", getUpdateProgress);
 websDefineAction("getVerifyStatus", getVerifyStatus);
 websDefineAction("resetBmc", resetBmc);
+websDefineAction("getEraseStatus", getEraseStatus);
 
 
 //server_health

+ 1 - 0
app/goahead-3.6.5/src/web_interface/inc/fw_update.h

@@ -21,5 +21,6 @@ void updateFlash(Webs *wp);
 void getUpdateProgress(Webs *wp);
 void getVerifyStatus(Webs *wp);
 void resetBmc(Webs *wp);
+void getEraseStatus(Webs *wp);
 
 #endif /* __FW_UPDATE_H__ */

+ 74 - 5
app/goahead-3.6.5/src/web_interface/src/fw_update.c

@@ -228,6 +228,67 @@ void getUpdateProgress(Webs *wp)
         cJSON_Delete(root);
 }
 
+void getEraseStatus(Webs *wp)
+{
+    uint8_t EraseStr[13] = {0};
+    FILE *fp;
+
+//    wp->index = TEST_INDEX;
+    target_addr = gIPMBAddr[wp->index];
+    if(target_addr == 0x20)
+    {
+        //TODO:
+        fp = fopen("/var/www/goahead/tmp/Erase.log", "r");
+        if(NULL == fp)
+        {
+            printf("Open Erase.log failed!\n");
+            websError(wp, 200, "Open Erase.log failed!");
+            return;
+        }
+
+        if(NULL == fgets(EraseStr, 13, fp))
+        {
+            printf("Read Erase.log failed!\n");
+            websError(wp, 200, "Read Erase.log failed!");
+            fclose(fp);
+            return;
+        }
+        
+        printf("Erase: %s\n", EraseStr);
+    }
+    else
+    {
+        sprintf(EraseStr, "Erase OK");
+    }
+
+
+    
+    cJSON * root =  cJSON_CreateObject();
+    if(strcmp(EraseStr, "Erase OK") == 0)
+    {
+        cJSON_AddNumberToObject(root, "Erase", 1);
+    }
+    else
+    {
+        cJSON_AddNumberToObject(root, "Erase", 0);   
+    }
+    cJSON_AddNumberToObject(root, "code", 200);
+    
+    char *pStr;
+    pStr = cJSON_PrintUnformatted(root);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteEndHeaders(wp);
+    websWrite(wp, "%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+    printf("cJSON:%s\n", pStr);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+}
 
 /*
     获取Flash的校验结果
@@ -237,7 +298,7 @@ void getUpdateProgress(Webs *wp)
 */
 void getVerifyStatus(Webs *wp)
 {
-    uint8_t verigyStr[13] = {0};
+    uint8_t verifyStr[13] = {0};
     FILE *fp;
 
 //    wp->index = TEST_INDEX;
@@ -253,7 +314,7 @@ void getVerifyStatus(Webs *wp)
             return;
         }
 
-        if(NULL == fgets(verigyStr, 13, fp))
+        if(NULL == fgets(verifyStr, 13, fp))
         {
             printf("Read Verify.log failed!\n");
             websError(wp, 200, "Read Verify.log failed!");
@@ -261,17 +322,25 @@ void getVerifyStatus(Webs *wp)
             return;
         }
         
-        printf("Update Firmware: %s\n", verigyStr);
+        printf("Update Firmware: %s\n", verifyStr);
     }
     else
     {
-        sprintf(verigyStr, "Verify OK");
+        sprintf(verifyStr, "Verify OK");
     }
 
 
     
     cJSON * root =  cJSON_CreateObject();
-    cJSON_AddStringToObject(root, "verify", verigyStr);
+    if(strcmp(verifyStr,"Verify OK") == 0)
+    {
+        cJSON_AddNumberToObject(root, "verify", 1);
+    }
+    else
+    {
+        cJSON_AddNumberToObject(root, "verify", 0);   
+    }
+
     cJSON_AddNumberToObject(root, "code", 200);
     
     char *pStr;

+ 121 - 110
app/goahead-3.6.5/src/web_interface/src/server_health.c

@@ -135,130 +135,141 @@ void webGetSensorHistory(Webs *wp)
     IPMI20_UDS_SESSION_T    UDSSession;
     int         i = 0,j=0;
     int         wRet = 0;
-    sensor_history_st *pSensorHistory = (sensor_history_st *)walloc(sizeof(sensor_history_st));
-    char        tmpBuf[10];
-    char        *historyBuf = walloc(5000);
+    //sensor_history_st *pSensorHistory = (sensor_history_st *)walloc(sizeof(sensor_history_st));
+//    char        tmpBuf[10];
+//    char        *historyBuf = walloc(500);
     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;
     float       tmpValue;
-    uint8_t     Req[20];
-    uint8_t     Res[256];
     uint32_t    dwResLen;
 
     char *strSensorNumber = websGetVar(wp, "SensorNumber", NULL);
     int   SensorNumber = atoi(strSensorNumber);
+
+    //memset(pSensorHistory->sensor_history, 0, 480);
     
-    //Create session
-    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
+    // //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);
 
-    //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);
-    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;
-        }
-    }
     
-    //Close session
-    LIBIPMI_CloseSession(&UDSSession );
+    // 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;
+    //     }
+    // }
     
-    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;
-        }
-        tmpBuf[j] = ',';    //replace '\0' by ','
-        j++;        //point to next empty
-        sprintf(strBuf, "%s", tmpBuf);
-        strBuf += j;
-    }
-    strBuf--;
-    *strBuf = '\0';
+    // //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';
 
     cJSON * root =  cJSON_CreateObject();
-    cJSON_AddNumberToObject(root, "SensorNum", pSensorHistory->sensor_num);
-    cJSON_AddStringToObject(root, "SensorName", pSensorHistory->sensor_name);
-    cJSON_AddStringToObject(root, "history", historyBuf);
+    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);
-    websSetStatus(wp, 200);
-    websWriteHeaders(wp, -1, 0);
-    websWriteEndHeaders(wp); 
-    websWrite(wp, pStr);
+    websWrite(wp, "%s", pStr);
     websFlush(wp, 0);
     websDone(wp);
     printf("cJSON:%s\n", pStr);
@@ -268,10 +279,10 @@ void webGetSensorHistory(Webs *wp)
     if(root)
         cJSON_Delete(root);
 
-    if(historyBuf)
-        wfree(historyBuf);
-    if(pSensorHistory)
-        wfree(pSensorHistory);
+    // if(historyBuf)
+    //     wfree(historyBuf);
+    // if(pSensorHistory)
+    //     wfree(pSensorHistory);
 }