更新发送缓存的逻辑为添加文件到待发列表

发送由mutex改回为sem
This commit is contained in:
CSSC-WORK\murmur 2023-09-14 17:30:01 +08:00
parent a0aa6405b7
commit f03adfa9e6
3 changed files with 47 additions and 21 deletions

View File

@ -352,7 +352,16 @@ static int setFileToSend_thread_entry(void *parameter)
// list_thread();
// return RT_EOK;
}
void manualAaddlst(char *f)
{
nsetLock();
int rst = ini_putl(SECTION_TO_SEND, f, 0, FILE_TO_SEND);
nclearLock();
if (!rst) {
LOG_E("manual add file to send error.");
}
LOG_D("add %s-0 to list.",f);
}
/**
*
* @param fin

View File

@ -34,7 +34,7 @@ static struct rt_event chkSta; //发送条件含两部分1-超时或文件
rt_sem_t TTReady= RT_NULL;//天通具备发送状态后 rt_sem_release(TTReady);
rt_sem_t cfgUpdate = RT_NULL;//配置文件更新
rt_sem_t shuntDownTT = RT_NULL;//关闭TT
rt_mutex_t okTosend = RT_NULL;//可以发送后续文件。仅一个线程,文件依次发送
rt_sem_t okTosend = RT_NULL;//可以发送后续文件。仅一个线程,文件依次发送
rt_sem_t okToreport = RT_NULL;//配置信息ACK
static rt_thread_t initThread=RT_NULL;
static rt_thread_t deinitThread=RT_NULL;
@ -211,7 +211,7 @@ static void updatecfg(void)
void sysSemInit()
{
okTosend = rt_mutex_create("okTosend", RT_IPC_FLAG_FIFO);//同一时间仅一个线程发送文件
okTosend = rt_sem_create("okTosend", 0, RT_IPC_FLAG_FIFO);//同一时间仅一个线程发送文件
cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_FIFO);//更新cfg
shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_FIFO);//关闭TT
okToreport = rt_sem_create("reportINFO", 0, RT_IPC_FLAG_FIFO);//关闭TT
@ -281,11 +281,19 @@ void fileIsReady(void)
rt_event_send(&chkSta, FILE_IS_OK);
stopTM();
}
static isTTok=0;
void TTIsReady(void)
{
isTTok=1;
rt_event_send(&chkSta, TT_IS_OK);
// resetTM();
}
void TTIsNotReady(void)
{
isTTok=0;
// rt_event_send(&chkSta, TT_IS_OK);
// resetTM();
}
@ -425,20 +433,20 @@ static void upSendFile_thread_entry(void *parameter)
{
FILE_INFO *f = RT_NULL;
f = (FILE_INFO *) parameter;
rt_mutex_take(okTosend, RT_WAITING_FOREVER);
// 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);
rt_mutex_release(okTosend);
rt_sem_release(okTosend);
return;
}
if (getFileSize(f->fname) > scfg.maxSizePerFile+200) {//部分demo数据体积>>1k
LOG_W("file '%s' is too large to send.",f->fname);
clearFileToSend(f->fname);
rt_mutex_release(okTosend);
rt_sem_release(okTosend);
return;
}
@ -451,24 +459,32 @@ static void upSendFile_thread_entry(void *parameter)
if (len)
{
LOG_D("%d pack(s) to send", f->index ? 1 : len);
uint8_t issendall=1;
for (size_t var = 0; (var < len && s[var]!=0); var++)
{
if (!f->index || (var+1) == f->index)
{ //index=0 全发或者仅发index
if (sendMsg(d[var], s[var]) == RT_EOK) {
LOG_D("send pack[%d] with %d bytes done.",var+1,s[var]);
};
}
else {
issendall=0;
break;
}
rt_thread_mdelay(3000);//发送间隔目前服务器未处理暂设为3s避免粘包
}
}
LOG_I("upSendFile '%s' done.",f->fname);
clearFileToSend(f->fname);//由于没有准确的校核机制,此处自能认为是发送成功
if (issendall) {
LOG_I("upSendFile '%s' done.",f->fname);
clearFileToSend(f->fname);//由于没有准确的校核机制,此处自能认为是发送成功
}
// list_thread();
}
//当前文件处理完后置位
rt_mutex_release(okTosend);
rt_sem_release(okTosend);
}
/**
@ -515,13 +531,9 @@ void getAndSendFile()
//优先发送未达指定大小的文件
char fnow[50];
getLstCacheFileName(fnow);
if (getFileSize(fnow)) {//有数据才发
updateCacheFileName();
LOG_I("send latest data first");
// rt_mutex_take(okTosend, RT_WAITING_FOREVER);
upSendFile(fnow,0);
// rt_mutex_release(okTosend);//由upSendFile释放
}
manualAaddlst(fnow);
updateCacheFileName();
rt_thread_mdelay(1000);
@ -536,16 +548,16 @@ void getAndSendFile()
return;
}
// rt_sem_release(okTosend);//初始赋值
rt_sem_release(okTosend);//初始赋值
static int index[MAX_KEY_LEN];
char f[cnt][MAX_KEY_LEN];
getFilesToSend(f, index);
for (int i = cnt-1; i > -1; i--)//倒序发送
{
// LOG_D("f[%d]=%s",i,f[i]);
LOG_D("f[%d]=%s",i,f[i]);
// continue;
// if (rt_mutex_take(okTosend, RT_WAITING_FOREVER) == RT_EOK)
if (rt_sem_take(okTosend, RT_WAITING_FOREVER) == RT_EOK)
{
rt_thread_mdelay(1000);//thread close
upSendFile(f[i],index[i]);
@ -585,7 +597,7 @@ static void chkAndSendFile_thread_entry()
LOG_I("TT准备就绪");
sendACK();
//当前固件底层未缓存待发数据,导致前几包数据可能丢失,暂时用延时规避
// rt_thread_mdelay(1*60*1000);
rt_thread_mdelay(15*1000);
getAndSendFile();
break;
}

View File

@ -199,6 +199,7 @@ static void rulecheck(void)
else {
okCnt = 0;
// LOG_W("不符合。");
TTIsNotReady();
return;
}
if (okCnt >= scfg.minTTPeriCnt) {
@ -219,6 +220,10 @@ static void rulecheck(void)
// }
}
size_t isTTok(void)
{
return okCnt;
}
/* 数据解析 */
static void tt_parse(rt_uint8_t *data)