更新 getAndSendFile 中逻辑,添加 getCntOfFileToSend 功能

This commit is contained in:
CSSC-WORK\murmur 2023-09-06 11:18:11 +08:00
parent 47fe7c90ee
commit 04c090e9b2
2 changed files with 54 additions and 35 deletions

View File

@ -310,7 +310,7 @@ volatile size_t nislock=0;
static void nsetLock()
{
rt_mutex_take(isTosendOk, RT_WAITING_FOREVER);
LOG_W("------file locked------");
// LOG_W("------file locked------");
return;
// LOG_D("--%d--",nislock);
size_t cnt=10;
@ -328,7 +328,7 @@ static void nsetLock()
static void nclearLock()
{
rt_mutex_release(isTosendOk);
LOG_W("=====file unlocked=====");
// LOG_W("=====file unlocked=====");
return;
nislock=0;
LOG_W("file is unlocked.");
@ -392,12 +392,27 @@ size_t getFilesToSend(char (*kstr)[MAX_KEY_LEN], int *v)
v[len] = ini_getl(SECTION_TO_SEND, kstr[len], -1, FILE_TO_SEND);
len +=1;
if (len>5) {
break;
// break;
}
}
// nclearLock();
return len;
}
/**
*
* @return
*/
size_t getCntOfFileToSend(void)
{
size_t len=0;
char tmp[100];
for (size_t k = 0; ini_getkey(SECTION_TO_SEND, k, tmp, sizeof(tmp), FILE_TO_SEND) > 0; k++) {
len = k + 1;
}
// LOG_D("cnt=%d",len);
return len;
}
/**
*
*/
@ -415,26 +430,28 @@ int clearFileToSend(const char *k)
static void gf()
{
size_t cnt = getCntOfFileToSend();
// return;
int v[MAX_KEY_LEN];
char kstr[10][MAX_KEY_LEN];
size_t cnt = getFilesToSend(kstr, v);
char kstr[cnt][MAX_KEY_LEN];
if (!cnt) {
LOG_D("no files waiting to be sent");
}
else
{
getFilesToSend(kstr, v);
for (size_t var = 0; var < cnt; var++)
{
LOG_I("%s -- %d", kstr[var], v[var]);
}
// cnt = getFilesToSend(kstr, v);
}
}
static void add(int argc, char **argv)
{
postFileInfo(argv[1],atoi(argv[2]));
gf();
// gf();
// clearFileToSend(argv[1]);
// gf();
}

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_sem_t okTosend = RT_NULL;//可以发送后续文件
rt_mutex_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;
@ -209,7 +209,7 @@ static void updatecfg(void)
void sysSemInit()
{
okTosend = rt_sem_create("okTosend", 0, RT_IPC_FLAG_FIFO);//同一时间仅一个线程发送文件
okTosend = rt_mutex_create("okTosend", 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
@ -418,12 +418,19 @@ static void upSendFile_thread_entry(void *parameter)
static rt_uint8_t d[BUFFER_ROW][200] = { };//need static?
static rt_uint8_t s[BUFFER_ROW] = { };
if (!getFileSize(f->fname)) {
LOG_W("file '%s' is empty.",f->fname);
clearFileToSend(f->fname);
rt_mutex_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_sem_release(okTosend);
rt_mutex_release(okTosend);
return;
}
LOG_D("ready to send '%s---%d'",f->fname,f->index);
rt_uint8_t len = pack_File(f->fname, 0, d, s);
for (size_t i = 0; i < len; i++) {
@ -444,13 +451,13 @@ static void upSendFile_thread_entry(void *parameter)
}
}
LOG_I("upSendFile '%s' done.",f->fname);
clearFileToSend(f->fname);
clearFileToSend(f->fname);//由于没有准确的校核机制,此处自能认为是发送成功
// list_thread();
}
//当前文件处理完后置位
rt_sem_release(okTosend);
rt_mutex_release(okTosend);
}
/**
@ -467,7 +474,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 * 3, 27, 10);
rt_thread_t thread = rt_thread_create("SendFile", upSendFile_thread_entry, (void *) &info, 1024 * 5, 27, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
@ -500,15 +507,14 @@ void getAndSendFile()
if (getFileSize(fnow)) {//有数据才发
updateCacheFileName();
LOG_I("send latest data first");
// rt_sem_release(okTosend);//初始赋值
rt_mutex_take(okTosend, RT_WAITING_FOREVER);
upSendFile(fnow,0);
rt_thread_mdelay(10*1000);
// rt_mutex_release(okTosend);//由upSendFile释放
}
static int index[MAX_KEY_LEN];
static char f[5][MAX_KEY_LEN];
int cnt = getFilesToSend(f, index);
uint8_t cnt = (uint8_t)getCntOfFileToSend();
if(cnt)
{
LOG_I("ready to send %d file(s).",cnt);
@ -519,25 +525,21 @@ void getAndSendFile()
return;
}
rt_sem_release(okTosend);//初始赋值
while(cnt)
{
int i=0;
for (i = cnt-1; i > -1; i--)//倒序发送
{
if (rt_sem_take(okTosend, RT_WAITING_FOREVER) == RT_EOK) {
rt_thread_mdelay(1000);//thread close
upSendFile(f[i],index[i]);
}
}
rt_thread_mdelay(3000);
if (rt_sem_take(okTosend, RT_WAITING_FOREVER) == RT_EOK) {//等待上一轮最后一个文件发送完毕
cnt = getFilesToSend(f, index);
}
// 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]);
// continue;
if (rt_mutex_take(okTosend, RT_WAITING_FOREVER) == RT_EOK) {
rt_thread_mdelay(1000);//thread close
upSendFile(f[i],index[i]);
}
}
//发送完毕
// rt_sem_take(sem, timeout)
LOG_D("mission done.");
resetTM();
}
@ -547,7 +549,7 @@ static void chkAndSendFile_thread_entry()
while (1)
{
// int e;
LOG_I("等待发送条件(文件就绪或定时%d分钟超时",scfg.sendInterval);
LOG_I("ready and waiting",scfg.sendInterval);
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满足
{