|
@@ -20,17 +20,30 @@ void prepareDevice(Webs *wp)
|
|
printf("Update Firmware: Prepare Device...\n");
|
|
printf("Update Firmware: Prepare Device...\n");
|
|
uint8_t cmd[50] = {0};
|
|
uint8_t cmd[50] = {0};
|
|
progress = 0;
|
|
progress = 0;
|
|
-
|
|
|
|
//kill bmc_app
|
|
//kill bmc_app
|
|
sprintf(cmd, "killall -9 bmc_app");
|
|
sprintf(cmd, "killall -9 bmc_app");
|
|
system(cmd);
|
|
system(cmd);
|
|
-
|
|
|
|
|
|
+ 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);
|
|
websSetStatus(wp, 200);
|
|
websWriteHeaders(wp, -1, 0);
|
|
websWriteHeaders(wp, -1, 0);
|
|
- //websWriteHeader(wp, "","prepareDevice");
|
|
|
|
- websWriteEndHeaders(wp);
|
|
|
|
- //websWrite(wp, "%s", pStr);
|
|
|
|
- //websFlush(wp, 0);
|
|
|
|
|
|
+ websWriteEndHeaders(wp);
|
|
|
|
+ websWrite(wp,"%s", pStr);
|
|
|
|
+ websFlush(wp, 0);
|
|
|
|
+ // websDone(wp);
|
|
|
|
+
|
|
|
|
+ if(pStr)
|
|
|
|
+ wfree(pStr);
|
|
|
|
+ if(root)
|
|
|
|
+ cJSON_Delete(root);
|
|
|
|
+
|
|
websDone(wp);
|
|
websDone(wp);
|
|
printf("Update Firmware: Prepare Device Ok.\n");
|
|
printf("Update Firmware: Prepare Device Ok.\n");
|
|
}
|
|
}
|
|
@@ -38,38 +51,45 @@ void prepareDevice(Webs *wp)
|
|
/*
|
|
/*
|
|
接收上传的固件
|
|
接收上传的固件
|
|
*/
|
|
*/
|
|
|
|
+
|
|
void uploadFirmware(Webs *wp)
|
|
void uploadFirmware(Webs *wp)
|
|
{
|
|
{
|
|
WebsKey *s;
|
|
WebsKey *s;
|
|
WebsUpload *up;
|
|
WebsUpload *up;
|
|
char *upfile;
|
|
char *upfile;
|
|
-
|
|
|
|
- websSetStatus(wp, 200);
|
|
|
|
- websWriteHeaders(wp, -1, 0);
|
|
|
|
- websWriteHeader(wp, "Content-Type", "text/plain");
|
|
|
|
- websWriteEndHeaders(wp);
|
|
|
|
if (scaselessmatch(wp->method, "POST")) {
|
|
if (scaselessmatch(wp->method, "POST")) {
|
|
for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
|
|
for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
|
|
up = s->content.value.symbol;
|
|
up = s->content.value.symbol;
|
|
- websWrite(wp, "FILE: %s\r\n", s->name.value.string);
|
|
|
|
- websWrite(wp, "FILENAME=%s\r\n", up->filename);
|
|
|
|
- websWrite(wp, "CLIENT=%s\r\n", up->clientFilename);
|
|
|
|
- websWrite(wp, "TYPE=%s\r\n", up->contentType);
|
|
|
|
- websWrite(wp, "SIZE=%d\r\n", up->size);
|
|
|
|
- upfile = sfmt("%s/tmp/%s", websGetDocuments(), "tmp.uImage"/*up->clientFilename*/);
|
|
|
|
- printf("upfile: %s\n", upfile);
|
|
|
|
|
|
+ upfile = sfmt("%s/tmp/%s", websGetDocuments(), "tmp.uImage");
|
|
|
|
+ printf("<<<<<<<<<<<%s>>111111>>>>>>>>\n", upfile);
|
|
if (rename(up->filename, upfile) < 0) {
|
|
if (rename(up->filename, upfile) < 0) {
|
|
error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
|
|
error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
|
|
}
|
|
}
|
|
wfree(upfile);
|
|
wfree(upfile);
|
|
}
|
|
}
|
|
- websWrite(wp, "\r\nVARS:\r\n");
|
|
|
|
- for (s = hashFirst(wp->vars); s; s = hashNext(wp->vars, s)) {
|
|
|
|
- websWrite(wp, "%s=%s\r\n", s->name.value.string, s->content.value.string);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+ 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);
|
|
|
|
+
|
|
websDone(wp);
|
|
websDone(wp);
|
|
- printf("Update Firmware: Upload Firmware oK.\n");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -86,14 +106,29 @@ void updateFlash(Webs *wp)
|
|
//Call updateFW_app
|
|
//Call updateFW_app
|
|
sprintf(cmd, "/usr/bin/updateFW_app &");
|
|
sprintf(cmd, "/usr/bin/updateFW_app &");
|
|
system(cmd);
|
|
system(cmd);
|
|
-
|
|
|
|
|
|
+ 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);
|
|
websSetStatus(wp, 200);
|
|
websWriteHeaders(wp, -1, 0);
|
|
websWriteHeaders(wp, -1, 0);
|
|
- //websWriteHeader(wp, "updateFlash");
|
|
|
|
- websWriteEndHeaders(wp);
|
|
|
|
- //websWrite(wp, "%s", pStr);
|
|
|
|
- //websFlush(wp, 0);
|
|
|
|
|
|
+ websWriteEndHeaders(wp);
|
|
|
|
+ websWrite(wp,"%s", pStr);
|
|
|
|
+ websFlush(wp, 0);
|
|
|
|
+ // websDone(wp);
|
|
|
|
+
|
|
|
|
+ if(pStr)
|
|
|
|
+ wfree(pStr);
|
|
|
|
+ if(root)
|
|
|
|
+ cJSON_Delete(root);
|
|
|
|
+
|
|
websDone(wp);
|
|
websDone(wp);
|
|
|
|
+ printf("Update Firmware: Prepare Device Ok.\n");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -141,7 +176,7 @@ void getUpdateProgress(Webs *wp)
|
|
websWrite(wp, "%s", pStr);
|
|
websWrite(wp, "%s", pStr);
|
|
websFlush(wp, 0);
|
|
websFlush(wp, 0);
|
|
websDone(wp);
|
|
websDone(wp);
|
|
-
|
|
|
|
|
|
+
|
|
if(pStr)
|
|
if(pStr)
|
|
wfree(pStr);
|
|
wfree(pStr);
|
|
if(root)
|
|
if(root)
|