diff --git a/applications/core.c b/applications/core.c index 1f4615f..a7bff66 100644 --- a/applications/core.c +++ b/applications/core.c @@ -428,6 +428,7 @@ static void upSendFile_thread_entry(void *parameter) rt_mutex_take(okTosend, RT_WAITING_FOREVER); static rt_uint8_t d[BUFFER_ROW][200] = { };//need static? static rt_uint8_t s[BUFFER_ROW] = { }; + memset(s,0,BUFFER_ROW); if (!getFileSize(f->fname)) { LOG_W("file '%s' is empty.",f->fname); clearFileToSend(f->fname); @@ -444,13 +445,13 @@ static void upSendFile_thread_entry(void *parameter) LOG_D("ready to send '%s---%d'",f->fname,f->index); uint8_t len = pack_File(f->fname, 0, d, s); for (size_t i = 0; i < len; i++) { - LOG_HEX("msg",27,d[i],s[i]); +// LOG_HEX("msg",27,d[i],s[i]); } // list_thread(); if (len) { LOG_D("%d pack(s) to send", f->index ? 1 : len); - for (rt_uint8_t var = 0; var < len; var++) + for (size_t var = 0; (var < len && s[var]!=0); var++) { if (!f->index || (var+1) == f->index) { //index=0 全发,或者仅发index @@ -483,7 +484,7 @@ void upSendFile(const char *f, int index) info.index = index; /* 创建 serial 线程 */ - rt_thread_t thread = rt_thread_create("SendFile", upSendFile_thread_entry, (void *) &info, 1024 * 5, 27, 10); + rt_thread_t thread = rt_thread_create("SendFile", upSendFile_thread_entry, (void *) &info, 1024 * 10, 27, 10); /* 创建成功则启动线程 */ if (thread != RT_NULL) { @@ -561,7 +562,7 @@ static void chkAndSendFile_thread_entry() { // int e; LOG_I("ready and waiting",scfg.sendInterval); - if (!isTCPok() || rt_event_recv(&chkSta, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, + if (rt_event_recv(&chkSta, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, RT_NULL) == RT_EOK) //条件1满足 { LOG_I("等待TT就绪"); @@ -582,8 +583,9 @@ static void chkAndSendFile_thread_entry() if (rst == RT_EOK) //条件2满足 { LOG_I("TT准备就绪"); + sendACK(); //当前固件底层未缓存待发数据,导致前几包数据可能丢失,暂时用延时规避 - rt_thread_mdelay(1*60*1000); +// rt_thread_mdelay(1*60*1000); getAndSendFile(); break; } @@ -607,7 +609,7 @@ static void chkAndSendFile_thread_entry() break; } } -// LOG_W("--------one mission DONE--------"); +// LOG_W("--------one loop DONE--------"); } } @@ -693,6 +695,7 @@ void initTT_thread_entry() recTT(); repGetTT(); reportLoc(); + fileIsReady(); // resetTM();//启动超时,激活后开启 } } diff --git a/applications/ttmsg/ttmsg.c b/applications/ttmsg/ttmsg.c index 4cb634d..ca78d71 100644 --- a/applications/ttmsg/ttmsg.c +++ b/applications/ttmsg/ttmsg.c @@ -256,7 +256,7 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[ size_t file_size = 0; rt_uint8_t len = 0; // rt_uint8_t *buffer = RT_NULL; - static size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX + size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX // rt_uint8_t len = 0; fd_in = open(fin, O_RDONLY, 0); @@ -275,14 +275,14 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[ // 粗略调整每包大小 if (file_size > (size_t) FRAME_DATA_LEN_MAX) { - while (file_size % flen < flen / 1.2 && flen < FRAME_DATA_LEN_MAX) // 阈值约83% + while ((file_size % flen) < (flen / 1.2) && flen < FRAME_DATA_LEN_MAX) // 阈值约83% { flen += 1; } - if (file_size % flen < flen / 1.2) + if ((file_size % flen) < (flen / 1.2)) { // 到达限制仍不符合要求 flen = 150; - while (file_size % flen < flen / 2.5 && flen < FRAME_DATA_LEN_MAX) // 调整阈值为40% + while ((file_size % flen) < (flen / 2.5) && flen < FRAME_DATA_LEN_MAX) // 调整阈值为40% { flen += 1; } @@ -292,12 +292,12 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[ { flen = file_size; } - + LOG_E("p=%d",flen); //更新算法,改用特定大小依次读取文件,弃用一次性全部读入文件 // static uint8_t row =0; uint8_t row = (file_size / flen) + (file_size % flen > 0 ? 1 : 0); cfg.fallpiece[0] = row; - + LOG_E("--------row=%d,%d",row,cfg.fallpiece[0]); uint8_t block_size = 0; rt_uint8_t *buffer = RT_NULL; buffer = (rt_uint8_t *) rt_malloc(flen); @@ -348,6 +348,7 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[ } // return row; + LOG_E("row=%d,%d",row,cfg.fallpiece[0]); return cfg.fallpiece[0]; } @@ -499,3 +500,48 @@ void updateTargetAddr(uint8_t *din, uint8_t *addr) { memcpy(din+13,addr,4); } +void cmdCCID(uint8_t ccid) +{ + uint8_t dout[200]; + static MSG cfg; + rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间 + char fin[30]; + time2Str(fin); + strcat(fin,".bin"); + packInit(&cfg, fin, 0); //写入配置 + cfg.fcurpiece[0] = 1; + cfg.fallpiece[0] = 1; + uint8_t ack[]={0x37}; + + size_t rst = packMsg(&cfg, ack, sizeof(ack), dout);//packMsgs +// memcpy() + sendMsg(dout, rst); +} +/** + * 手动发送心跳 + */ +void sendACK(void) +{ + uint8_t dout[200]; + static MSG cfg; + rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间 + char fin[30]; + time2Str(fin); + strcat(fin,".bin"); + packInit(&cfg, fin, 0); //写入配置 + cfg.fcurpiece[0] = 1; + cfg.fallpiece[0] = 1; + uint8_t ack[]={0x37}; + + size_t rst = packMsg(&cfg, ack, sizeof(ack), dout);//packMsgs + + if (rst) + { + uint8_t addr[]={0x39,0x39,0x39,0x39}; + updateTargetAddr(dout, addr); + if (sendMsg(dout, rst) == RT_EOK) + { +// LOG_I("send %d bytes to TT Done.",rst); + } + } +}