소스 검색

1, 优化修改脚本, 相机拍照超时由60秒扩大到300秒 2, 底层c信号量等待不再依赖系统时间

niujiuru 4 주 전
부모
커밋
e4f1f6b6a1
10개의 변경된 파일51개의 추가작업 그리고 26개의 파일을 삭제
  1. 1 1
      Makefile
  2. 2 2
      config.ini
  3. 1 1
      package/armv7hf.sh
  4. 1 1
      reporter/takephoto.go
  5. 5 3
      scripts/serverdaemon
  6. 0 8
      scripts/set_env
  7. 8 0
      scripts/start
  8. 6 1
      scripts/stop
  9. 26 8
      swapi/swsignal.c
  10. 1 1
      tests/mvs_takephoto/main.go

+ 1 - 1
Makefile

@@ -7,7 +7,7 @@ DEFINS = -D_GNU_SOURCE
 
 GO := go
 GO_BUILD := $(GO) build
-GO_FLAGS := -ldflags "-s -w -X hnyfkj.com.cn/rtu/bxs-sy/baseapp.Version=1.0.0.4 -X hnyfkj.com.cn/rtu/bxs-sy/baseapp.BuildTime=$(shell date +%Y-%m-%dT%H:%M:%S)"
+GO_FLAGS := -ldflags "-s -w -X hnyfkj.com.cn/rtu/bxs-sy/baseapp.Version=1.0.0.5 -X hnyfkj.com.cn/rtu/bxs-sy/baseapp.BuildTime=$(shell date +%Y-%m-%dT%H:%M:%S)"
 
 target ?= x86_64
 ifeq ($(target),armv7hf)

+ 2 - 2
config.ini

@@ -10,7 +10,7 @@ MaxBackupFileCnts = 5
 
 [MQTTSrv]
 ; 地址端口
-BrokerAddress = tcp://mqtt.hnyfwlw.com:61883
+BrokerAddress = tcp://www.hnyfwlw.com:61883
 ; 用户名称
 Username = user
 ; 接入密码
@@ -18,7 +18,7 @@ Password = f335bf402c655ee5fd2b5300905124e
 
 [Img2Ftp]
 ; 地址端口
-ServerAddress = ftp.hnyfwlw.com:21
+ServerAddress = 8.136.98.49:21
 ; 用户名称
 Username = bxsban
 ; 接入密码

+ 1 - 1
package/armv7hf.sh

@@ -4,7 +4,7 @@
 set -e
 set -o pipefail
 
-ver_num="1.0.0.4"
+ver_num="1.0.0.5"
 cur_dir="$(pwd)"
 pre_dir="$(dirname "$cur_dir")"
 pkg_dir="${cur_dir}/rtu_bxs_seyou"

+ 1 - 1
reporter/takephoto.go

@@ -31,7 +31,7 @@ func TakePhotoAndUpToFtp(ctx context.Context) (string, error) {
 	baseapp.Logger.Infof("[%s] 拍照中, 稍后...", MODULE_NAME)
 	now := time.Now()
 	imgFile := filepath.Join(baseapp.IMG_DIR, fmt.Sprintf("%s.jpg", now.Format("2006-01-02_15-04-05.000")))
-	_, err := takephoto.TakePhoto(takephoto.IMG_TYPE_JPG, imgFile, 60 /*秒*/)
+	_, err := takephoto.TakePhoto(takephoto.IMG_TYPE_JPG, imgFile, 300 /*秒*/)
 	if err != nil {
 		baseapp.Logger.Errorf("[%s] 拍照失败: %v!!", MODULE_NAME, err)
 		return "", err

+ 5 - 3
scripts/serverdaemon

@@ -2,18 +2,20 @@
 # a daemon, start and monitor servers
 # 2013-09-27 09:28 created by niujiuru
 
+. $(dirname $0)/set_env
 . $(dirname $0)/modules/funcs/functions.sh
 export_env
 
 INTERVAL=60
+APP_NAME="rtu_bxs_seyou.out"
 
 while true
 do
-  if ! is_running "rtu_bxs_seyou.out"
+  if ! is_running "$APP_NAME"
   then
-    echo "starting rtu_bxs_seyou.out: ${APPBINS_PATH}/rtu_bxs_seyou.out &"
+    echo "starting $APP_NAME: ${APPBINS_PATH}/$APP_NAME &"
     rm -rf ${APPRUNS_PATH}/*.lock
-    ${APPBINS_PATH}/rtu_bxs_seyou.out &
+    ${APPBINS_PATH}/$APP_NAME &
   fi
   sleep $INTERVAL
 done

+ 0 - 8
scripts/set_env

@@ -13,11 +13,3 @@ echo 528000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
 # 设置一秒落盘
 echo 100 > /proc/sys/vm/dirty_writeback_centisecs
 echo 100 > /proc/sys/vm/dirty_expire_centisecs
-
-# 重置海康相机
-HKCAM_RESET="${APPBINS_PATH}/hkcam_reset.out"
-if [ -e "$HKCAM_RESET" ]; then
-  chmod a+x "$HKCAM_RESET"
-  "$HKCAM_RESET"
-  sleep 5
-fi

+ 8 - 0
scripts/start

@@ -6,6 +6,14 @@
 . $(dirname $0)/modules/funcs/functions.sh
 export_env
 
+# 重置海康相机(1200W海康U口相机在RTU板子上冷启动时, 需要先重置相机, 才能正常工作)
+HKCAM_RESET="${APPBINS_PATH}/hkcam_reset.out"
+if [ -e "$HKCAM_RESET" ]; then
+  chmod a+x "$HKCAM_RESET"
+  "$HKCAM_RESET"
+  sleep 5
+fi
+
 ORDER="
 rtu_bxs_seyou
 daemon

+ 6 - 1
scripts/stop

@@ -2,6 +2,7 @@
 # script that runs on system stop
 # 2013-09-26 09:50 created by niujiuru
 
+. $(dirname $0)/set_env
 . $(dirname $0)/modules/funcs/functions.sh
 export_env
 
@@ -14,5 +15,9 @@ for m in ${ORDER}
 do
   echo ":: stopping $m"
   call_module "$m" stop
-  rm -rf ${APPRUNS_PATH}/*.lock
 done
+
+if [ -d "${APPRUNS_PATH}" ]; then
+  echo ":: removing all files from ${APPRUNS_PATH}"
+  rm -f ${APPRUNS_PATH}/* 2>/dev/null
+fi

+ 26 - 8
swapi/swsignal.c

@@ -5,6 +5,8 @@
  * NOTE: 主要用于状态通知
  * HISTORY:
  * 1, [2010-12-17] created by NiuJiuRu
+ * 2, [2025-11-24] 优化修改"sw_signal_wait()"函数, 避免依赖系统时间, 导致的
+ *                 超时误差或跳变问题
  ***********************************************************************/
 #include "swapi.h"
 #include "swmem.h"
@@ -37,8 +39,6 @@ void sw_signal_destroy(void *hSignal)
 int sw_signal_wait(void *hSignal, int timeout)
 {
 	sem_t *sem = (sem_t *)hSignal;
-	struct timeval tv = { 0 };
-	struct timespec ts = { 0 };
 	int ret;
 	
 	if(timeout < 0)
@@ -50,15 +50,33 @@ wait_p1:
 	}
 	else
 	{
-		gettimeofday(&tv, NULL);
-		ts.tv_sec = tv.tv_sec + timeout/1000;
-		ts.tv_nsec = tv.tv_usec*1000 + (timeout%1000)*1000*1000;
-		ts.tv_sec += ts.tv_nsec/(1000*1000*1000);
-		ts.tv_nsec %= (1000*1000*1000);
+#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30)
+		struct timespec ts, now;
+		clock_gettime(CLOCK_MONOTONIC/*单调时钟, 不受系统时间影响*/, &now);
+		ts.tv_sec = now.tv_sec + timeout/1000;
+		ts.tv_nsec = now.tv_nsec + (timeout%1000)*1000*1000;
+		if(ts.tv_nsec >= (1000*1000*1000))
+		{
+		  ts.tv_sec += ts.tv_nsec/(1000*1000*1000);
+		  ts.tv_nsec %= (1000*1000*1000);
+		}
 wait_p2:
-		ret = sem_timedwait(sem, &ts);
+		ret = sem_clockwait(sem, CLOCK_MONOTONIC, &ts); // 非POSIX标准, GNU扩展, 需定义:"_GNU_SOURCE"支持
+		                                                // , 同时glic库版本需大于等于2.30
 		if(ret < 0 && errno == EINTR) goto wait_p2;
 		else return ret;
+#else
+		struct timespec start, now; struct timespec ts = { 0, 1000*1000 };
+		clock_gettime(CLOCK_MONOTONIC, &start);
+		while((ret = sem_trywait(sem)) < 0 && errno == EAGAIN)
+		{
+		  clock_gettime(CLOCK_MONOTONIC, &now);
+		  long elapsed = (now.tv_sec - start.tv_sec)*1000 + (now.tv_nsec-start.tv_nsec)/(1000*1000);
+		  if(elapsed >= timeout) { errno = ETIMEDOUT; return -1; }
+			nanosleep(&ts, NULL);
+		}
+		return ret;
+#endif
 	}
 }
 

+ 1 - 1
tests/mvs_takephoto/main.go

@@ -31,7 +31,7 @@ func main() {
 		var err error
 
 		start := time.Now()
-		imgMark, err = takephoto.TakePhoto(imgType, imgFile, 60)
+		imgMark, err = takephoto.TakePhoto(imgType, imgFile, 300)
 		elapsed := time.Since(start).Milliseconds()
 
 		if err == nil {