|
@@ -898,141 +898,186 @@ u_int8_t alarmCheck(u_int8_t starthour,u_int8_t endhour,u_int8_t startmin,u_int8
|
|
|
return workflag;
|
|
return workflag;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* 采集段结束处理:卷带电机转一圈 + 发送自动对焦指令
|
|
|
|
|
+ * 进入时先清零自锁,避免执行期间(turnlimit可能阻塞较久)新的采集段结束事件被覆盖丢失
|
|
|
|
|
+ * work_done 由工作流程线程独占清零,消除与状态检测线程的双写竞态
|
|
|
|
|
+ */
|
|
|
|
|
+static void exec_work_done(void)
|
|
|
|
|
+{
|
|
|
|
|
+ device_status.work_done = 0;
|
|
|
|
|
+ LOG_I("采集段结束, 执行转带+自动对焦");
|
|
|
|
|
+ turnlimit(); //卷带电机转一圈
|
|
|
|
|
+ rt_thread_delay(2000);
|
|
|
|
|
+ uint8_t retry_send = 0;
|
|
|
|
|
+ while(1){
|
|
|
|
|
+ char *take_start = makeJson_Warn("start", "autofocus");
|
|
|
|
|
+ if(take_start != RT_NULL) {
|
|
|
|
|
+ DTU_Write("%s",take_start);
|
|
|
|
|
+ rt_free(take_start);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ LOG_E("makeJson_Warn failed! retry:%d", retry_send);
|
|
|
|
|
+ }
|
|
|
|
|
+ rt_thread_delay(5000);
|
|
|
|
|
+ retry_send++;
|
|
|
|
|
+ if(retry_send==30||device_status.autotakepic>0){
|
|
|
|
|
+ LOG_I("send start msg done, retry=%d, autotakepic=%d", retry_send, device_status.autotakepic);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void WorkTask_BZYV2(void)
|
|
void WorkTask_BZYV2(void)
|
|
|
{
|
|
{
|
|
|
if(device_status.ds==1&&device_status.temp_status==0){
|
|
if(device_status.ds==1&&device_status.temp_status==0){
|
|
|
|
|
|
|
|
|
|
+ /* 等待设备进入工作窗口 */
|
|
|
while(device_status.work_status ==0){
|
|
while(device_status.work_status ==0){
|
|
|
- rt_thread_delay(10000);
|
|
|
|
|
- LOG_W("等待设备进入工作");
|
|
|
|
|
|
|
+ /* 待机期间若有未处理的采集段结束动作,立即补做 */
|
|
|
|
|
+ if(device_status.work_done==1){
|
|
|
|
|
+ exec_work_done();
|
|
|
|
|
+ }
|
|
|
|
|
+ rt_thread_delay(1000);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /* 处于工作窗口:按对焦状态控制路由器供电 */
|
|
|
while(device_status.work_status ==1){
|
|
while(device_status.work_status ==1){
|
|
|
if(device_status.autotakepic==0){
|
|
if(device_status.autotakepic==0){
|
|
|
- ctr_Heat(ON);
|
|
|
|
|
|
|
+ ctr_router(ON);
|
|
|
}else{
|
|
}else{
|
|
|
- ctr_Heat(OFF);
|
|
|
|
|
|
|
+ ctr_router(OFF);
|
|
|
}
|
|
}
|
|
|
if(device_status.temp_status==1){
|
|
if(device_status.temp_status==1){
|
|
|
device_status.work_status = 0;
|
|
device_status.work_status = 0;
|
|
|
- ctr_Heat(OFF);
|
|
|
|
|
|
|
+ ctr_router(OFF);
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- rt_thread_delay(10000);
|
|
|
|
|
|
|
+ /* 任一采集段窗口结束(下降沿置位 work_done)立即执行转带+对焦 */
|
|
|
|
|
+ if(device_status.work_done==1){
|
|
|
|
|
+ exec_work_done();
|
|
|
|
|
+ }
|
|
|
|
|
+ rt_thread_delay(1000);
|
|
|
}
|
|
}
|
|
|
- ctr_Heat(OFF);
|
|
|
|
|
|
|
+ ctr_router(OFF);
|
|
|
|
|
|
|
|
|
|
+ /* 退出工作循环后若有未处理的结束动作(如温控异常跳出), 补做 */
|
|
|
if(device_status.work_done==1){
|
|
if(device_status.work_done==1){
|
|
|
- turnlimit(); //卷带电机转一圈
|
|
|
|
|
- rt_thread_delay(2000);
|
|
|
|
|
- uint8_t retry_send = 0;
|
|
|
|
|
- while(1){
|
|
|
|
|
- char *take_start = makeJson_Warn("start", "autofocus");
|
|
|
|
|
- if(take_start != RT_NULL) {
|
|
|
|
|
- DTU_Write("%s",take_start);
|
|
|
|
|
- rt_free(take_start);
|
|
|
|
|
- } else {
|
|
|
|
|
- LOG_E("makeJson_Warn failed! retry:%d", retry_send);
|
|
|
|
|
- }
|
|
|
|
|
- rt_thread_delay(5000);
|
|
|
|
|
- retry_send++;
|
|
|
|
|
- if(retry_send==30||device_status.autotakepic>0){
|
|
|
|
|
- LOG_I("send start msg done, retry=%d, autotakepic=%d", retry_send, device_status.autotakepic);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- device_status.work_done = 0;
|
|
|
|
|
|
|
+ exec_work_done();
|
|
|
}
|
|
}
|
|
|
}else{
|
|
}else{
|
|
|
LOG_W("==================!!!设备已待机!!!===================");
|
|
LOG_W("==================!!!设备已待机!!!===================");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/* 入口函数-工作状态检测 */
|
|
/* 入口函数-工作状态检测 */
|
|
|
static void Work_status_thread_entry(void *parameter)
|
|
static void Work_status_thread_entry(void *parameter)
|
|
|
{
|
|
{
|
|
|
|
|
+ /* 记录上一轮各采集段的窗口状态,用于检测窗口结束(ON->OFF下降沿) */
|
|
|
|
|
+ u_int8_t last_seg_on[3] = {OFF, OFF, OFF};
|
|
|
|
|
+
|
|
|
static uint32_t takephoto_cnt = 0;
|
|
static uint32_t takephoto_cnt = 0;
|
|
|
- static uint8_t last_work_day = 0; // 记录上次递增的日期,防止一天多次递增
|
|
|
|
|
|
|
+ static uint8_t work_day_checked = 0; // 23点当天只检查一次,非23点复位
|
|
|
while(1)
|
|
while(1)
|
|
|
{
|
|
{
|
|
|
- if(device_status.ds==0||
|
|
|
|
|
- device_status.temp_status==1){
|
|
|
|
|
|
|
+ if(device_status.ds==0 || device_status.temp_status==1)
|
|
|
|
|
+ {
|
|
|
device_status.work_status = 0;
|
|
device_status.work_status = 0;
|
|
|
|
|
+ /* 设备待机时复位上一轮窗口状态,避免恢复工作后误判下降沿 */
|
|
|
|
|
+ last_seg_on[0] = OFF;
|
|
|
|
|
+ last_seg_on[1] = OFF;
|
|
|
|
|
+ last_seg_on[2] = OFF;
|
|
|
rt_thread_delay(5000);
|
|
rt_thread_delay(5000);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- while(alarmCheck(device_status.collecting_sh1,device_status.collecting_eh1,device_status.collt_min_sh1,device_status.collt_min_eh1) == ON)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- LOG_I("the alarm1 workflag was ON");
|
|
|
|
|
- device_status.work_done=1;
|
|
|
|
|
- rt_thread_delay(1000);
|
|
|
|
|
- }
|
|
|
|
|
- //如果当前时间大于collecting_eh1,开始拍照
|
|
|
|
|
|
|
+ /* 依次判断3段采集窗口,任何一段处于窗口内即为工作状态 */
|
|
|
|
|
+ u_int8_t seg_on[3];
|
|
|
|
|
+ seg_on[0] = alarmCheck(device_status.collecting_sh1, device_status.collecting_eh1,
|
|
|
|
|
+ device_status.collt_min_sh1, device_status.collt_min_eh1);
|
|
|
|
|
+ seg_on[1] = alarmCheck(device_status.collecting_sh2, device_status.collecting_eh2,
|
|
|
|
|
+ device_status.collt_min_sh2, device_status.collt_min_eh2);
|
|
|
|
|
+ seg_on[2] = alarmCheck(device_status.collecting_sh3, device_status.collecting_eh3,
|
|
|
|
|
+ device_status.collt_min_sh3, device_status.collt_min_eh3);
|
|
|
|
|
|
|
|
- while(alarmCheck(device_status.collecting_sh2,device_status.collecting_eh2,device_status.collt_min_sh2,device_status.collt_min_eh2) == ON)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.work_done=1;
|
|
|
|
|
- LOG_I("the alarm2 workflag was ON");
|
|
|
|
|
- rt_thread_delay(1000);
|
|
|
|
|
- }
|
|
|
|
|
- //如果当前时间大于collecting_eh2,开始拍照
|
|
|
|
|
|
|
+ device_status.work_status = (seg_on[0] || seg_on[1] || seg_on[2]) ? 1 : 0;
|
|
|
|
|
|
|
|
- while(alarmCheck(device_status.collecting_sh3,device_status.collecting_eh3,device_status.collt_min_sh3,device_status.collt_min_eh3) == ON)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.work_done=1;
|
|
|
|
|
- LOG_I("the alarm3 workflag was ON");
|
|
|
|
|
|
|
|
|
|
- rt_thread_delay(1000);
|
|
|
|
|
- }
|
|
|
|
|
- device_status.work_status = 0;
|
|
|
|
|
-
|
|
|
|
|
- // 检查当天所有采集阶段是否都已完成
|
|
|
|
|
- if (alarmCheck(device_status.collecting_sh1,device_status.collecting_eh1,device_status.collt_min_sh1,device_status.collt_min_eh1) == OFF &&
|
|
|
|
|
- alarmCheck(device_status.collecting_sh2,device_status.collecting_eh2,device_status.collt_min_sh2,device_status.collt_min_eh2) == OFF &&
|
|
|
|
|
- alarmCheck(device_status.collecting_sh3,device_status.collecting_eh3,device_status.collt_min_sh3,device_status.collt_min_eh3) == OFF)
|
|
|
|
|
|
|
+ /* 每段窗口结束(ON->OFF)置位一次 work_done,保证每个采集段结束后只触发一次转带+对焦 */
|
|
|
|
|
+ u_int8_t i;
|
|
|
|
|
+ for(i = 0; i < 3; i++)
|
|
|
{
|
|
{
|
|
|
- // 获取当前日期
|
|
|
|
|
- time_t now;
|
|
|
|
|
- time(&now);
|
|
|
|
|
- struct tm now_tm = *localtime(&now);
|
|
|
|
|
- uint8_t today = now_tm.tm_mday;
|
|
|
|
|
-
|
|
|
|
|
- // 如果日期变更且上次递增不是今天,则递增 worked_day
|
|
|
|
|
- if (today != last_work_day)
|
|
|
|
|
|
|
+ if(last_seg_on[i] == ON && seg_on[i] == OFF)
|
|
|
{
|
|
{
|
|
|
- flashdb_value.worked_day++;
|
|
|
|
|
- app_flashdb_save("worked_day", &flashdb_value.worked_day);
|
|
|
|
|
- LOG_I("All collection periods completed. worked_day=%d", flashdb_value.worked_day);
|
|
|
|
|
- last_work_day = today;
|
|
|
|
|
- if(flashdb_value.worked_day==flashdb_value.freq_filter){
|
|
|
|
|
- //清零
|
|
|
|
|
- flashdb_value.worked_day = 0;
|
|
|
|
|
- app_flashdb_save("worked_day", &flashdb_value.worked_day);
|
|
|
|
|
- //执行更换
|
|
|
|
|
- Replace_Filter();
|
|
|
|
|
- //上报预警消息
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ device_status.work_done = 1;
|
|
|
|
|
+ LOG_I("alarm%d 采集段结束, 触发转带+对焦", i+1);
|
|
|
}
|
|
}
|
|
|
|
|
+ last_seg_on[i] = seg_on[i];
|
|
|
}
|
|
}
|
|
|
- if(device_status.autotakepic==2){
|
|
|
|
|
- takephoto_cnt++;
|
|
|
|
|
- }else{
|
|
|
|
|
- takephoto_cnt=0;
|
|
|
|
|
- }
|
|
|
|
|
- if(takephoto_cnt==3600){
|
|
|
|
|
- device_status.autotakepic = 0;
|
|
|
|
|
- takephoto_cnt = 0;
|
|
|
|
|
- }
|
|
|
|
|
- //如果当前时间大于
|
|
|
|
|
- if(device_status.work_done!=0)
|
|
|
|
|
- {
|
|
|
|
|
- rt_thread_delay(1000*30);
|
|
|
|
|
- device_status.work_done = 0;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /* 每天23点检查设定的采集时间段是否有效,且总采集时长超过1小时,满足条件则递增 worked_day */
|
|
|
|
|
+ time_t now;
|
|
|
|
|
+ time(&now);
|
|
|
|
|
+ struct tm now_tm = *localtime(&now);
|
|
|
|
|
+ if (now_tm.tm_hour == 23)
|
|
|
|
|
+ {
|
|
|
|
|
+ /* 整个23点整点区间只执行一次,避免每秒循环重复判断 */
|
|
|
|
|
+ if (!work_day_checked)
|
|
|
|
|
+ {
|
|
|
|
|
+ work_day_checked = 1;
|
|
|
|
|
+ /* 计算3段采集时段的累计有效时长(秒)。
|
|
|
|
|
+ * 有效性口径与 alarmCheck 保持一致:开始小时==结束小时视为无效时段 */
|
|
|
|
|
+ uint32_t total_sec = 0;
|
|
|
|
|
+ u_int8_t seg;
|
|
|
|
|
+ for (seg = 0; seg < 3; seg++)
|
|
|
|
|
+ {
|
|
|
|
|
+ u_int8_t sh, eh, sm, em;
|
|
|
|
|
+ if (seg == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ sh = device_status.collecting_sh1; eh = device_status.collecting_eh1;
|
|
|
|
|
+ sm = device_status.collt_min_sh1; em = device_status.collt_min_eh1;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (seg == 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ sh = device_status.collecting_sh2; eh = device_status.collecting_eh2;
|
|
|
|
|
+ sm = device_status.collt_min_sh2; em = device_status.collt_min_eh2;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ sh = device_status.collecting_sh3; eh = device_status.collecting_eh3;
|
|
|
|
|
+ sm = device_status.collt_min_sh3; em = device_status.collt_min_eh3;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (sh != eh) /* 无效时段(开始结束小时相同)不参与累计 */
|
|
|
|
|
+ {
|
|
|
|
|
+ uint32_t start_sec = sh * 3600 + sm * 60;
|
|
|
|
|
+ uint32_t end_sec = eh * 3600 + em * 60;
|
|
|
|
|
+ if (start_sec < end_sec)
|
|
|
|
|
+ total_sec += end_sec - start_sec; /* 当天时段 */
|
|
|
|
|
+ else
|
|
|
|
|
+ total_sec += 24 * 3600 - start_sec + end_sec; /* 跨天时段 */
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* 总采集时长超过1小时则递增 worked_day */
|
|
|
|
|
+ if (total_sec > 3600)
|
|
|
|
|
+ {
|
|
|
|
|
+ flashdb_value.worked_day++;
|
|
|
|
|
+ app_flashdb_save("worked_day", &flashdb_value.worked_day);
|
|
|
|
|
+ LOG_I("采集时段有效且总时长>1h, worked_day=%d", flashdb_value.worked_day);
|
|
|
|
|
+ if(flashdb_value.worked_day==flashdb_value.freq_filter){
|
|
|
|
|
+ //清零
|
|
|
|
|
+ flashdb_value.worked_day = 0;
|
|
|
|
|
+ app_flashdb_save("worked_day", &flashdb_value.worked_day);
|
|
|
|
|
+ //执行更换
|
|
|
|
|
+ Replace_Filter();
|
|
|
|
|
+ //上报预警消息
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ work_day_checked = 0; /* 离开23点后复位,第二天可再次检查 */
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
rt_thread_delay(1000);
|
|
rt_thread_delay(1000);
|
|
|
}
|
|
}
|
|
@@ -1126,12 +1171,36 @@ void slide_thread_entry(void *parameter)
|
|
|
rt_kprintf("The slide's y movement was done ok\n");
|
|
rt_kprintf("The slide's y movement was done ok\n");
|
|
|
rt_thread_delay(1000);
|
|
rt_thread_delay(1000);
|
|
|
if(1){
|
|
if(1){
|
|
|
- char utos[5];
|
|
|
|
|
- rt_sprintf(utos,"%d",slide_para.ystep);
|
|
|
|
|
- char *photo = makeJson_Warn("movy",utos);
|
|
|
|
|
- LOG_I("%s",photo);
|
|
|
|
|
- DTU_Write("%s",photo);
|
|
|
|
|
- rt_free(photo);
|
|
|
|
|
|
|
+ /* 发送movy后等待相机回传focus, 5S超时未收到则重发, 最多重传3次, 避免对焦卡死 */
|
|
|
|
|
+ int focus_ok = 0;
|
|
|
|
|
+ int retry = 0;
|
|
|
|
|
+ do {
|
|
|
|
|
+ char utos[5];
|
|
|
|
|
+ rt_sprintf(utos,"%d",slide_para.ystep);
|
|
|
|
|
+ char *photo = makeJson_Warn("movy",utos);
|
|
|
|
|
+ LOG_I("%s",photo);
|
|
|
|
|
+ focus_valid_flag = 0; /* 清零后再发送, 避免误用上次残留的focus */
|
|
|
|
|
+ DTU_Write("%s",photo);
|
|
|
|
|
+ rt_free(photo);
|
|
|
|
|
+ /* 等待相机回传有效focus, 超时5S */
|
|
|
|
|
+ rt_uint32_t deadline = rt_tick_get() + 5 * RT_TICK_PER_SECOND;
|
|
|
|
|
+ while ((rt_int32_t)(rt_tick_get() - deadline) < 0) {
|
|
|
|
|
+ if (focus_valid_flag) {
|
|
|
|
|
+ focus_valid_flag = 0;
|
|
|
|
|
+ focus_ok = 1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ rt_thread_delay(RT_TICK_PER_SECOND / 10); /* 100ms轮询一次 */
|
|
|
|
|
+ }
|
|
|
|
|
+ if (focus_ok) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ retry++;
|
|
|
|
|
+ LOG_W("movy 未收到focus回传, 重传第%d次", retry);
|
|
|
|
|
+ } while (retry < 3);
|
|
|
|
|
+ if (!focus_ok) {
|
|
|
|
|
+ LOG_W("movy 连续4次未收到focus回传, 放弃重传");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
slide_para.ydis = 0;
|
|
slide_para.ydis = 0;
|
|
|
slide_para.stop_flag = 0;
|
|
slide_para.stop_flag = 0;
|