增加本地文件更新功能

This commit is contained in:
Peng
2025-04-18 18:39:33 +08:00
parent 4e1b376b6a
commit d7e2243a86
14 changed files with 994 additions and 877 deletions

View File

@@ -1,2 +1,2 @@
set remotetimeout 20
shell start /B C:\Users\ooo\Desktop\MiCoder/OpenOCD/Win32/openocd_mico.exe -s ./ -f ./mico-os/makefiles/OpenOCD/interface/jlink_swd.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx_gdb_jtag.cfg -l ./build/openocd_log.txt
shell start /B F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/Win32/openocd_mico.exe -s ./ -f ./mico-os/makefiles/OpenOCD/interface/jlink_swd.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx_gdb_jtag.cfg -l ./build/openocd_log.txt

View File

@@ -1,3 +1,3 @@
source [find C:\Users\ooo\Desktop\MiCoder/OpenOCD/jlink_swd.cfg]
source [find C:\Users\ooo\Desktop\MiCoder/OpenOCD/mw3xx.cfg]
source [find C:\Users\ooo\Desktop\MiCoder/OpenOCD/mw3xx_gdb_jtag.cfg]
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/jlink_swd.cfg]
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/mw3xx.cfg]
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/mw3xx_gdb_jtag.cfg]

1
.version Normal file
View File

@@ -0,0 +1 @@
v1.0.79

View File

@@ -257,55 +257,90 @@ static int HttpSetButtonEvent(httpd_request_t *req) {
return err;
}
#define OTA_BUF_SIZE 1024
#define OTA_BUF_SIZE 5120
static int HttpSetOTAFile(httpd_request_t *req)
{
tc1_log("[OTA] hdr_parsed=%d, remaining=%d, body_nbytes=%d, req.chunked=%d",
req->hdr_parsed, req->remaining_bytes, req->body_nbytes, req->chunked);
OSStatus err = kNoErr;
uint8_t *buffer = malloc(OTA_BUF_SIZE);
if (!buffer) return kNoMemoryErr;
tc1_log("[OTA] hdr_parsed=%d, remaining=%d, body_nbytes=%d",
req->hdr_parsed, req->remaining_bytes, req->body_nbytes);
int total = 0;
int ret = 0;
// req->chunked = 1;
int total1 = req->remaining_bytes;
char *buffer = malloc(OTA_BUF_SIZE);
if (!buffer) return kNoMemoryErr;
uint32_t offset = 0;
mico_logic_partition_t* ota_partition = MicoFlashGetInfo(MICO_PARTITION_OTA_TEMP);
MicoFlashErase(MICO_PARTITION_OTA_TEMP, 0x0, ota_partition->partition_length);
CRC16_Context crc_context;
CRC16_Init(&crc_context);
uint32_t offset = 0;
int total = 0;
// 尝试读取全部 POST 数据
while (1) {
int ret = httpd_get_data(req, buffer, OTA_BUF_SIZE);
if (ret == 0) break;
if (ret < 0) {
tc1_log("[OTA] 读取失败 ret=%d", ret);
err = kConnectionErr;
goto exit;
ret = httpd_get_data2(req, buffer,OTA_BUF_SIZE);
// ret = httpd_recv(req->sock, buffer, 128, 0);
total += ret;
// req->remaining_bytes -= ret;
if (ret > 0) {
CRC16_Update(&crc_context, buffer, ret);
err = MicoFlashWrite(MICO_PARTITION_OTA_TEMP, &offset, (uint8_t *)buffer, ret);
require_noerr_quiet(err, exit);
tc1_log("[OTA] 本次读取 %d 字节,累计 %d 字节", ret, total);
}
CRC16_Update(&crc_context, buffer, ret);
err = MicoFlashWrite(MICO_PARTITION_OTA_TEMP, &offset, buffer, ret);
require_noerr_quiet(err, exit);
if (ret == 0 || req->remaining_bytes <= 0) {
// 读取完毕
tc1_log("[OTA] 数据读取完成, 总计 %d 字节", total);
break;
} else if (ret < 0) {
tc1_log("[OTA] 数据读取失败, ret=%d", ret);
err = kConnectionErr;
break;
}
total += ret;
mico_rtos_thread_msleep(100);
// tc1_log("[OTA] %x", buffer);
// tc1_log("[OTA] hdr_parsed=%d, remaining=%d, body_nbytes=%d",
// req->hdr_parsed, req->remaining_bytes, req->body_nbytes);
}
// if (buffer) free(buffer);
uint16_t crc16;
CRC16_Final(&crc_context, &crc16);
err = mico_ota_switch_to_new_fw(total, crc16);
tc1_log("[OTA] mico_ota_switch_to_new_fw err=%d", err);
require_noerr(err, exit);
char resp[64];
snprintf(resp, sizeof(resp), "OK, total: %d bytes", total);
char resp[128];
snprintf(resp, sizeof(resp), "OK, total: %d bytes, req %d %d", total, req->body_nbytes, total1);
send_http(resp, strlen(resp), exit, &err);
mico_system_power_perform(mico_system_context_get(), eState_Software_Reset);
exit:
if (buffer) free(buffer);
tc1_log("[OTA] buffer");
tc1_log("[OTA] bbbbbbbbbbbbbbbbbbbb");
return err;
// ota_file_req = req;
// OSStatus err = kNoErr;
// err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "OtaFileThread", OtaFileThread, 0x1000, 0);
// char buf[16] = {0};
// sprintf(buf, "%d", sizeof(ota_file_req));
// send_http(buf, strlen(buf), exit, &err);
// exit:
// if (buf) free(buf);
// return err;
}
static int HttpSetDeviceName(httpd_request_t *req) {

View File

@@ -975,6 +975,7 @@
BTN_OPERATIONS.push("重新配网");
BTN_OPERATIONS.push("重置系统");
BTN_OPERATIONS.push("切换童锁");
BTN_OPERATIONS.push("重启网页");
$('#btn_action_selector').append(
$('<li>')

File diff suppressed because it is too large Load Diff

View File

@@ -187,8 +187,8 @@ int application_start(void) {
}
KeyInit();
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
err = UserMqttInit();
require_noerr(err, exit);
err = UserMqttInit();
require_noerr(err, exit);
}
err = UserRtcInit();
require_noerr(err, exit);
@@ -199,12 +199,12 @@ int application_start(void) {
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "p_count",
(mico_thread_function_t) schedule_p_count_task,
0x1000, 0);
0x800, 0);
require_noerr_string(err, exit, "ERROR: Unable to start the p_count thread.");
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mqtt_power_report",
(mico_thread_function_t) reportMqttPowerInfoThread,
0x1000, 0);
0x800, 0);
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt_power_report thread.");
@@ -214,6 +214,7 @@ int application_start(void) {
ProcessTask();
}
if (now % 10 == 5) system_log("Free memory %d bytes", MicoGetMemoryInfo()->free_memory);
mico_thread_msleep(1000);
}

View File

@@ -16,7 +16,7 @@
#define wifi_log(M, ...) custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__);
#define power_log(M, ...) custom_log("POWER", M, ##__VA_ARGS__); web_log("POWER", M, ##__VA_ARGS__);
#define VERSION "v2.1.8"
#define VERSION "v2.2.4"
#define TYPE 1
#define TYPE_NAME "TC1"

View File

@@ -67,7 +67,7 @@ OSStatus UserRtcInit(void)
/* start rtc client */
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "rtc",
(mico_thread_function_t) RtcThread,
0x1000, 0);
0x800, 0);
require_noerr_string(err, exit, "ERROR: Unable to start the rtc thread.");
if (kNoErr != err) rtc_log("ERROR1, app thread exit err: %d kNoErr[%d]", err, kNoErr);

View File

@@ -46,6 +46,8 @@ char* get_func_name(char func_code) {
return "Toggle LED";
case REBOOT_SYSTEM:
return "Reboot";
case REBOOT_HTTP:
return "REBOOT_HTTP";
case CONFIG_WIFI:
return "WiFi Config";
case RESET_SYSTEM:
@@ -226,6 +228,13 @@ static void KeyEventHandler(int num, boolean longPress) {
break;
MicoSystemReboot();
break;
case REBOOT_HTTP:
if (childLockEnabled)
break;
AppHttpdStop();
mico_rtos_thread_sleep(1);
AppHttpdStart();
break;
case CONFIG_WIFI:
if (childLockEnabled)
break;

View File

@@ -17,6 +17,7 @@
#define CONFIG_WIFI 9
#define RESET_SYSTEM 10
#define SWITCH_CHILD_LOCK_ENABLE 11
#define REBOOT_HTTP 12
extern char socket_status[32];

0
git版本.txt Normal file
View File

View File

@@ -50,7 +50,8 @@ httpd_state_t httpd_state;
static mico_thread_t httpd_main_thread;
#define http_server_thread_stack_size 0x5000
// 0x8000 不行
#define http_server_thread_stack_size 0x6000
/* Why HTTPD_MAX_MESSAGE + 2?
* Handlers are allowed to use HTTPD_MAX_MESSAGE bytes of this buffer.

View File

@@ -543,6 +543,52 @@ out:
return req->remaining_bytes;
}
int httpd_get_data2(httpd_request_t *req, char *content, int length)
{
int ret;
char *buf;
// /* Is this condition required? */
// if (req->body_nbytes >= HTTPD_MAX_MESSAGE - 2)
// return -kInProgressErr;
if (!req->hdr_parsed) {
buf = malloc(HTTPD_MAX_MESSAGE);
if (!buf) {
system_log("Failed to allocate memory for buffer");
return -kInProgressErr;
}
ret = httpd_parse_hdr_tags(req, req->sock, buf,
HTTPD_MAX_MESSAGE);
if (ret != kNoErr) {
system_log("Unable to parse header tags");
goto out;
} else {
system_log("Headers parsed successfully\r\n");
req->hdr_parsed = 1;
}
free(buf);
}
/* handle here */
ret = httpd_recv(req->sock, content,
length, 0);
if (ret == -1) {
system_log("Failed to read POST data");
goto out;
}
/* scratch will now have the JSON data */
// content[ret] = '\0';
req->remaining_bytes -= ret;
system_log("Read %d bytes and remaining %d bytes",
ret, req->remaining_bytes);
out:
return ret;
}
static int get_matching_chars(const char *s1, const char *s2)
{
int match = 0;