فهرست منبع

新增函数compareWithUpdateTime
用于更新时间和拉合闸的时间点比较,判断是否在2min以内

cuci 1 سال پیش
والد
کامیت
961f3c73c8
3فایلهای تغییر یافته به همراه110 افزوده شده و 3 حذف شده
  1. 106 2
      core/core.c
  2. 3 0
      core/core.h
  3. 1 1
      lib/decode.c

+ 106 - 2
core/core.c

@@ -311,8 +311,12 @@ int CoreAlarmGateway()
         }
      }
 
-     if(!row[8] && !row[9]) continue;
      strftime(timeString, sizeof(timeString), "%H:%M", &tm_time);
+
+     //判断是否在时间段点的2min以内
+     if(compareWithUpdateTime(timeString,switch_time1,switch_time2,switch_time3,switch_time4)) continue;
+
+     if(!row[8] && !row[9]) continue;
      debug("timeString:%s \n",timeString);
      //判断自动模式
      if(control_mode==0)
@@ -537,8 +541,12 @@ int CoreAlarmNode()
         }
      }
 
+    strftime(timeString, sizeof(timeString), "%H:%M", &tm_time);
+
+     //判断是否在时间段点的2min以内
+     if(compareWithUpdateTime(timeString,switch_time1,switch_time2,switch_time3,switch_time4)) continue;
+
      if(!row[9] || !row[10] || !row[11] || !row[12]) continue;
-     strftime(timeString, sizeof(timeString), "%H:%M", &tm_time);
      debug("timeString:%s \n",timeString);
      //判断自动模式
      if(control_mode==0)
@@ -1495,6 +1503,102 @@ int compareWithCurrentTime(struct tm t1)
     }
 }
 
+//更新时间和拉合闸的时间点比较
+int compareWithUpdateTime(const char *timeString,const char *time1,const char *time2,const char *time3,const char *time4)
+{
+  struct tm tm_base, tm_timeString, tm_time1, tm_time2,tm_time3, tm_time4;
+
+  // 设置基准日期为当前日期
+  time_t current_time = time(NULL);
+  localtime_r(&current_time, &tm_base);
+
+  // 解析timeString
+  if (strptime(timeString, "%H:%M", &tm_timeString) == NULL) 
+  {
+    fprintf(stderr, "Failed to parse tm_timeString\n");
+    return 0; // or handle the error in an appropriate way
+    
+  }
+
+  // 设置日期部分为基准日期的日期部分
+  tm_timeString.tm_year = tm_base.tm_year;
+  tm_timeString.tm_mon = tm_base.tm_mon;
+  tm_timeString.tm_mday = tm_base.tm_mday;
+
+  // 将 struct tm 结构转换为 time_t 类型
+  time_t t0 = mktime(&tm_timeString);//重新计算时间
+
+  // 解析时间字符串1
+  if (strlen(time1)==5 && strptime(time1, "%H:%M", &tm_time1)) 
+  {
+    tm_time1.tm_year = tm_base.tm_year;
+    tm_time1.tm_mon = tm_base.tm_mon;
+    tm_time1.tm_mday = tm_base.tm_mday;
+    time_t t1 = mktime(&tm_time1);
+    // 计算两个时间的差值
+    double timeDifference = difftime(t0,t1);
+    debug("time1:%s和更新时间:%s,差值为%.2f\n",time1,timeString,timeDifference);
+    if(fabs(timeDifference)<120.0)//更新时间在2分钟内
+    {
+      debug("time1更新时间在2分钟内\n");
+      return 1;
+    }
+  }
+
+  // 解析时间字符串2
+  if (strlen(time2)==5 && strptime(time2, "%H:%M", &tm_time2)) 
+  {
+    tm_time2.tm_year = tm_base.tm_year;
+    tm_time2.tm_mon = tm_base.tm_mon;
+    tm_time2.tm_mday = tm_base.tm_mday;
+    time_t t2 = mktime(&tm_time2);
+    // 计算两个时间的差值
+    double timeDifference = difftime(t0,t2);
+    debug("time2:%s和更新时间:%s,差值为%.2f\n",time2,timeString,timeDifference);
+    if(fabs(timeDifference)<120.0)//更新时间在2分钟内
+    {
+      debug("time2更新时间在2分钟内\n");
+      return 1;
+    }
+  }
+
+  // 解析时间字符串3
+  if (strlen(time3)==5 && strptime(time3, "%H:%M", &tm_time3)) 
+  {
+    tm_time3.tm_year = tm_base.tm_year;
+    tm_time3.tm_mon = tm_base.tm_mon;
+    tm_time3.tm_mday = tm_base.tm_mday;
+    time_t t3 = mktime(&tm_time3);
+    // 计算两个时间的差值
+    double timeDifference = difftime(t0,t3);
+    debug("time3:%s和更新时间:%s,差值为%.2f\n",time3,timeString,timeDifference);
+    if(fabs(timeDifference)<120.0)//更新时间在2分钟内
+    {
+      debug("time3更新时间在2分钟内\n");
+      return 1;
+    }
+  }
+
+  // 解析时间字符串4
+  if (strlen(time4)==5 && strptime(time4, "%H:%M", &tm_time4)) 
+  {
+    tm_time4.tm_year = tm_base.tm_year;
+    tm_time4.tm_mon = tm_base.tm_mon;
+    tm_time4.tm_mday = tm_base.tm_mday;
+    time_t t4 = mktime(&tm_time4);
+    // 计算两个时间的差值
+    double timeDifference = difftime(t0,t4);
+    debug("time4:%s和更新时间:%s,差值为%.2f\n",time4,timeString,timeDifference);
+    if(fabs(timeDifference)<120.0)//更新时间在2分钟内
+    {
+      debug("time4更新时间在2分钟内\n");
+      return 1;
+    }
+  }
+  
+  return 0;
+}
+
 
 //将需要处理sql放入队列
 void* sendtoqueue(ArrQueue *pQueue,char* stringSql)

+ 3 - 0
core/core.h

@@ -426,6 +426,9 @@ int compareModifiedTimes(struct tm t1, struct tm t2);
  */
 int compareWithCurrentTime(struct tm t1);
 
+//更新时间和拉合闸的时间点比较
+int compareWithUpdateTime(const char *timeString,const char *time1,const char *time2,const char *time3,const char *time4);
+
 #ifdef UPGRADE_BY_FILE
 /******************************************************************
 *	Function Name:	calc_file_crc32

+ 1 - 1
lib/decode.c

@@ -93,7 +93,7 @@ void AlarmNode(void)
 		{
 			CoreAlarmNode();
 			lastHeartTime = nowTime;
-			log("AlarmNode used:%ds=(%d-%d)\n", timeGloble_g - nowTime, timeGloble_g, nowTime);
+			log("AlarmNode used:%ds=(%d-%d)----------------------------------------------------------------------------\n", timeGloble_g - nowTime, timeGloble_g, nowTime);
 			fflush(stdout);
 		}
 	}