更新继电器逻辑,继电器不去反

更新TT帧头数据
rulecheck屏蔽部分log避免刷屏
添加led显示
This commit is contained in:
CSSC-WORK\murmur 2023-08-15 17:10:18 +08:00
parent e9fca0787a
commit afaf81a3fc
8 changed files with 52 additions and 32 deletions

View File

@ -1,5 +1,5 @@
[config] [config]
# V1.81 # V1.82
#发送间隔M以零点为基准时刻 #发送间隔M以零点为基准时刻
sendInterval=60 sendInterval=60
# 最大文件大小,超过此大小则进入发送流程 # 最大文件大小,超过此大小则进入发送流程
@ -11,14 +11,14 @@ maxTTWaitTime=4
# TT最大重试次数 # TT最大重试次数
maxTTRetryCnt=3 maxTTRetryCnt=3
# TT最低信号值 # TT最低信号值
minTTsinal=5 minTTsinal=3
# TT状态检测周期数 # TT状态检测周期数
minTTPeriCnt=2 minTTPeriCnt=2
compressType=1 compressType=1
# 加密方式0-不加密 # 加密方式0-不加密
encrytType=1 encrytType=1
# 开窗时间UTC+8,持续时间H。以【,】为分隔符 # 开窗时间UTC+8,持续时间H。以【,】为分隔符
openWindowTime=1,2,7,8 openWindowTime=1,0,2,0,7,0,8,0
#超时时间M主动开机上报数据情况下最后一次通信后开始计时超时后关闭TT #超时时间M主动开机上报数据情况下最后一次通信后开始计时超时后关闭TT
timeout=5 timeout=5
# 工作模式1-TT2-BD # 工作模式1-TT2-BD

View File

@ -311,9 +311,14 @@ static void chkAndSendFile_thread_entry()
} }
else if (rst == -RT_ETIMEOUT)//超时则重试 else if (rst == -RT_ETIMEOUT)//超时则重试
{ {
LOG_W("第%d次尝试中TT准备失败。", var + 1); if ((var+1) < scfg.maxTTRetryCnt)
rt_thread_mdelay(1000); {
if ((var+1) == scfg.maxTTRetryCnt) { LOG_W("第%d次尝试中TT准备失败重试。", var + 1);
deInitTT();
rt_thread_mdelay(1000);
initTT();
}
else {
LOG_E("TT准备失败"); LOG_E("TT准备失败");
} }
} }
@ -378,10 +383,10 @@ void resetTM()
void d_getRemain() void d_getRemain()
{ {
LOG_D("=%d=",rt_tick_from_millisecond(10*60*1000)); LOG_D("=%d=",rt_tick_from_millisecond(10*60*1000));
rt_tick_t *arg1,*arg2; rt_tick_t arg1,arg2;
arg1=rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_GET_TIME, (void*)arg1); arg1=rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_GET_TIME, (void*)&arg1);
arg2=rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_GET_REMAIN_TIME, (void*)arg2); arg2=rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_GET_REMAIN_TIME, (void*)&arg2);
LOG_D("tm=%d-%d",&arg1,&arg2); LOG_D("tm=%d-%d",arg1,arg2);
} }
/* 定时器超时函数 */ /* 定时器超时函数 */
@ -430,6 +435,7 @@ void initTT_thread_entry()
LOG_D("TCP is ready."); LOG_D("TCP is ready.");
tcpRecMQ(); //开启tcp接收线程 tcpRecMQ(); //开启tcp接收线程
recTT(); recTT();
repGetTT();
// chkAndSendFile(); // chkAndSendFile();
} }
} }

View File

@ -239,14 +239,14 @@ void selfTest()
LOG_I("FUNC = selftest"); LOG_I("FUNC = selftest");
rt_uint8_t rst[100]={0x5A, 0xA5, ADDR_ANJI, ADDR_TT, _CMD_SELF_TEST>>8, _CMD_SELF_TEST & 0xff}; rt_uint8_t rst[100]={0x5A, 0xA5, ADDR_ANJI, ADDR_TT, _CMD_SELF_TEST>>8, _CMD_SELF_TEST & 0xff};
int p = 6; int p = 6;
rt_uint8_t sysSta=1,xh=0,jh=0,commSpeed=0; rt_uint8_t sysSta=1,commSpeed=0;
//长度 //长度
rst[p++]=0x00; rst[p++]=0x00;
rst[p++]=0x09; rst[p++]=0x09;
rst[p++] = sysSta; rst[p++] = sysSta;
rst[p++] = xh;//xh,jh rst[p++] = getXh();//xh,jh
rst[p++] = jh; rst[p++] = isTTjh();
rst[p++] = commSpeed; rst[p++] = commSpeed;
rst[p++] = getPowerLevel(); rst[p++] = getPowerLevel();
@ -943,7 +943,7 @@ void parse3SData(uint8_t *din, size_t count)
void chkACK(uint8_t *msg, size_t size) void chkACK(uint8_t *msg, size_t size)
{ {
rt_uint8_t ackgood[] = { 0x88, 0xAA, 0xBB, 0x88, 0x41, 0x43, 0x4B }; //前四字节=帧头、后三字节=ACK rt_uint8_t ackgood[] = { 0x88, 0xAA, 0xBB, 0x88, 0x41, 0x43, 0x4B }; //前四字节=帧头、后三字节=ACK
if (rt_memcmp(msg, ackgood, 4) == 0 && rt_memcmp(msg + size - 3, ackgood + 4, 3) == 0) if (rt_memcmp(msg, ackgood, 4) == 0 && rt_memcmp(msg + size - 3, ackgood + 4, 3) == 0)
{ {
LOG_I("data is ACK."); LOG_I("data is ACK.");
@ -969,10 +969,10 @@ void parseTTData(uint8_t *din, size_t len)
* | 0x88,0xAA,0xBB,0x88 | 0x00,0x01 | 0x00,0x00 | 0x70,0x21 | 0x00,0xAA | 0x00 | 0x27,0x22,0x22,0x22 | | * | 0x88,0xAA,0xBB,0x88 | 0x00,0x01 | 0x00,0x00 | 0x70,0x21 | 0x00,0xAA | 0x00 | 0x27,0x22,0x22,0x22 | |
* +---------------------+-----------+-----------+-----------+-----------+---------+---------------------+------------+ * +---------------------+-----------+-----------+-----------+-----------+---------+---------------------+------------+
*/ */
uint8_t head[]={0x88,0xAA,0xBB,0x88, 0x00,0x01, 0x00,0x00, 0x70,0x21, 0x00,0xaa, 0x00, 0x27,0x22,0x22,0x22 }; uint8_t head[]={0x88,0xAA,0xBB,0x88, 0xFF,0xFF, 0x00,0x00, 0x70,0x21, 0x00,0xaa, 0x00, 0x27,0x22,0x22,0x22 };
//fstart[4] fnum[2]  bak[2]  ftype[2]  fdlen[2]  fcrc[1] ftccid[4] //fstart[4] fnum[2]  bak[2]  ftype[2]  fdlen[2]  fcrc[1] ftccid[4]
uint8_t index[10]; uint8_t index[10];
size_t n=isInByte(din, len, head, 10, index); size_t n=isInByte(din, len, head, 4, index);//仅判断帧头因ACK不一样
uint8_t ndin[200]; uint8_t ndin[200];
if (!n) { if (!n) {
LOG_W("TTData中无匹配帧"); LOG_W("TTData中无匹配帧");

View File

@ -192,15 +192,13 @@ static void rulecheck(void)
} }
else { else {
okCnt = 0; okCnt = 0;
LOG_W("不符合。"); // LOG_W("不符合。");
return; return;
} }
if (okCnt >= scfg.minTTPeriCnt) { if (okCnt >= scfg.minTTPeriCnt) {
//TT具备发送条件 //TT具备发送条件
// TTisReady();
TTIsReady(); TTIsReady();
LOG_I("符合规则TT具备发送状态。"); // LOG_I("符合规则TT具备发送状态。");
// updateSta();
okCnt = scfg.minTTPeriCnt -1; okCnt = scfg.minTTPeriCnt -1;
} }
// if (okCnt > minTTPeriCnt) { // if (okCnt > minTTPeriCnt) {
@ -392,17 +390,25 @@ MSH_CMD_EXPORT(getTT, 获取天通信息,支持参数。 "getTT 3 1" means try
*/ */
int isTTon(void) int isTTon(void)
{ {
#ifndef RELAY
return !rt_pin_read(TT_EN); return !rt_pin_read(TT_EN);
#else
return rt_pin_read(TT_EN);
#endif
} }
/** /**
* TT是否激活 * TT是否激活
* @return 1-0- * @return 1-0-
*/ */
int isTTjh(void) uint8_t isTTjh(void)
{ {
return atoi(TTinfo->jh); return atoi(TTinfo->jh);
} }
uint8_t getXh(void)
{
return (uint8_t)atoi(TTinfo->xh);
}
void repGetTT_thread_entry(void* parameter) void repGetTT_thread_entry(void* parameter)
{ {

View File

@ -37,13 +37,15 @@ static void led_entry(void *parameter)
while (1) while (1)
{ {
/* 拉低PIN脚 */ /* 拉低PIN脚 */
rt_pin_write(pin_num, PIN_LOW); rt_pin_write(LED_HEART, PIN_LOW);
rt_pin_write(LED_HEART_DEBUG, PIN_HIGH);
/* 延时1ms省电 */ /* 延时1ms省电 */
rt_thread_mdelay(1);//去掉延时共用print替换 rt_thread_mdelay(10); //去掉延时共用print替换
// rt_kprintf("Heartbeat.\n"); // rt_kprintf("Heartbeat.\n");
/* 拉高PIN脚 */ /* 拉高PIN脚 */
rt_pin_write(pin_num, PIN_HIGH); rt_pin_write(LED_HEART, PIN_HIGH);
rt_pin_write(LED_HEART_DEBUG, PIN_LOW);
rt_thread_mdelay(1000); rt_thread_mdelay(1000);
} }
} }
@ -66,8 +68,8 @@ int led_sample(int argc, char *argv[])
tid = rt_thread_create("led", tid = rt_thread_create("led",
led_entry, led_entry,
RT_NULL, RT_NULL,
512, 256,
RT_THREAD_PRIORITY_MAX / 3, 30,
20); 20);
if (tid != RT_NULL) if (tid != RT_NULL)
{ {
@ -83,5 +85,5 @@ int led_sample(int argc, char *argv[])
/* 导出到 msh 命令列表中 */ /* 导出到 msh 命令列表中 */
//MSH_CMD_EXPORT(led_sample, led sample); //MSH_CMD_EXPORT(led_sample, led sample);
/* 导出到自动初始化 */ /* 导出到自动初始化 */
//INIT_COMPONENT_EXPORT(led_sample); INIT_COMPONENT_EXPORT(led_sample);

View File

@ -39,7 +39,7 @@ int main(void)
rt_pin_mode(ETH_RESET_PIN, PIN_MODE_OUTPUT); rt_pin_mode(ETH_RESET_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(TT_EN, PIN_MODE_OUTPUT); rt_pin_mode(TT_EN, PIN_MODE_OUTPUT);
rt_pin_write(TT_EN, PIN_HIGH); rt_pin_write(TT_EN, PIN_LOW);
// rt_pin_attach_irq(TT_EN, PIN_IRQ_MODE_FALLING, pwTT_irq_callback, RT_NULL); // 下降沿触发 // rt_pin_attach_irq(TT_EN, PIN_IRQ_MODE_FALLING, pwTT_irq_callback, RT_NULL); // 下降沿触发
// rt_pin_irq_enable(TT_EN, PIN_IRQ_ENABLE); // 使能中断 // rt_pin_irq_enable(TT_EN, PIN_IRQ_ENABLE); // 使能中断

View File

@ -359,7 +359,11 @@ void pwTT_thread_entry(void *parameter)
} }
else else
{ {
#ifndef RELAY
flag = !(rt_bool_t) atoi(parameter); flag = !(rt_bool_t) atoi(parameter);
#else
flag = (rt_bool_t) atoi(parameter);
#endif
} }
rt_pin_write(TT_EN, flag);// rt_pin_write(TT_EN, flag);//
@ -373,7 +377,7 @@ void pwTT_thread_entry(void *parameter)
// } // }
#ifndef RELAY
if (rt_pin_read(TT_EN))//检查设置后状态 if (rt_pin_read(TT_EN))//检查设置后状态
{ {
LOG_I("set TT %s", "OFF");//高电平关断 LOG_I("set TT %s", "OFF");//高电平关断
@ -384,7 +388,9 @@ void pwTT_thread_entry(void *parameter)
// add_val("swCnt");//更新统计值 // add_val("swCnt");//更新统计值
LOG_I("set TT %s", "ON");//低电平开启 LOG_I("set TT %s", "ON");//低电平开启
} }
#else
LOG_I("set TT %s", rt_pin_read(TT_EN)?"ON":"OFF");
#endif
} }
static int swTT(int argc, char **argv) static int swTT(int argc, char **argv)
@ -439,7 +445,7 @@ void recTT_thread_entry()
break; break;
} }
LOG_I("%d Bytes received from TT",msg.size); LOG_I("%d Bytes received from TT",msg.size);
LOG_HEX("TTrec", 16, msg.data, msg.size); LOG_HEX("TTrec", 27, msg.data, msg.size);
//此处调用处理函数 //此处调用处理函数
// LOG_D("try to parse data."); // LOG_D("try to parse data.");
resetTM(); resetTM();

View File

@ -52,6 +52,6 @@ typedef struct
#define ROOT_PATH_LOG "/sd/log/" #define ROOT_PATH_LOG "/sd/log/"
#define ROOT_PATH_DATA "/sd/rxdata/" #define ROOT_PATH_DATA "/sd/rxdata/"
#define RELAY
#endif /* APPLICATIONS_USRCFG_H_ */ #endif /* APPLICATIONS_USRCFG_H_ */