add alarmmonitor daemon
authorkyz <kyz@kyz-vbox.myguest.virtualbox.org>
Wed, 14 May 2025 09:59:33 +0000 (17:59 +0800)
committerkyz <kyz@kyz-vbox.myguest.virtualbox.org>
Wed, 14 May 2025 09:59:33 +0000 (17:59 +0800)
20 files changed:
CMakeLists.txt
app/CMakeLists.txt
app/S99_alarmmonitor [new file with mode: 0755]
app/alarmmonitor_d [new file with mode: 0755]
app/log4crc [new file with mode: 0644]
app/src/am_main.c
app/src/led.c
app/src/log.c
app/ui/ascii_14b.zi [deleted file]
app/ui/bd_icon_400x400.png [deleted file]
app/ui/bd_icon_400x400.xcf [deleted file]
app/ui/defencealarm.HMI [deleted file]
app/ui/ir.jpg [deleted file]
app/ui/ir_icon_400x400.png [deleted file]
app/ui/ir_icon_400x400.xcf [deleted file]
app/ui/lora_icon_400x400.png [deleted file]
app/ui/lora_icon_400x400.xcf [deleted file]
app/ui/page_main.png [deleted file]
app/ui/utf8_alarm_32.zi [deleted file]
app/ui/utf8_onoff_16.zi [deleted file]

index 54e074cf9bfca1d3f8326c25edbda5b1cb333c1b..ca7c9414b3a73e6f429f464612ee7ed524123467 100644 (file)
@@ -1,8 +1,8 @@
 cmake_minimum_required(VERSION 3.8)
 
-project(defencealarm)
+project(alarmmonitor)
 
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE -g2 -O2")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE -g2 -O0")
 
 # Add the posix targets
 add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/app )
index c4d48591010d6d6e9571435378ddbd9414b581f8..80e218b608a6b66ec7796cfe7c4bbb226cf64fd9 100644 (file)
@@ -1,6 +1,6 @@
 cmake_minimum_required(VERSION 3.8)
 
-project(alarmMonitor)
+project(alarmmonitor)
 
 add_definitions(-DRKAIQ)
 aux_source_directory(common COMMON_SRCS)
@@ -9,8 +9,6 @@ include_directories(
        ${PROJECT_SOURCE_DIR}/./
        ${PROJECT_SOURCE_DIR}/src/
        ${PROJECT_SOURCE_DIR}/inc/
-       #{PROJECT_SOURCE_DIR}/../button/inc/
-       #${PROJECT_SOURCE_DIR}/../led/inc/
        ${PROJECT_SOURCE_DIR}/../log/inc/
        ${CMAKE_SYSROOT}/usr/include/
        )
@@ -48,4 +46,5 @@ target_link_libraries(
  )
 
 install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION /app)
-#install(FILES ${PROJECT_SOURCE_DIR}/libsteria/libstasteria.so DESTINATION /usr/lib)
+install(FILES ${PROJECT_SOURCE_DIR}/alarmmonitor_d DESTINATION /app)
+install(FILES ${PROJECT_SOURCE_DIR}/log4crc DESTINATION /app)
diff --git a/app/S99_alarmmonitor b/app/S99_alarmmonitor
new file mode 100755 (executable)
index 0000000..79ccb67
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+#
+# Start init
+#
+
+start() {
+    /bin/sh /app/alarmMonitor_d start &
+}
+
+case "$1" in
+  start)
+       start
+       ;;
+  stop)
+       ;;
+  restart|reload)
+       ;;
+  *)
+       echo "Usage: $0 {start|stop|restart}"
+       exit 1
+esac
+
+exit $?
diff --git a/app/alarmmonitor_d b/app/alarmmonitor_d
new file mode 100755 (executable)
index 0000000..a1a1528
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+mkdir -p /var/run/alarmmonitor
+
+# 定义守护进程的名称和运行路径
+DAEMON_NAME="alarmmonitor"
+#DAEMON_PATH="/app/"
+DAEMON_PATH="/tmp/" ##debug path
+
+
+# 检查守护进程是否已经在运行
+is_running() {
+    ps -ef | grep "./$DAEMON_NAME" | grep -v grep > /dev/null
+}
+
+
+# 启动守护进程
+start() {
+    if is_running; then
+        echo "守护进程 $DAEMON_NAME 已经在运行。"
+    fi
+
+    echo "启动守护进程 $DAEMON_NAME ..."
+    cd "$DAEMON_PATH"
+    ./"$DAEMON_NAME" &
+    echo "守护进程 $DAEMON_NAME 启动成功。"
+}
+
+# 监测守护进程并重新启动
+monitor() {
+    while true; do
+        if ! is_running; then
+            echo "守护进程 $DAEMON_NAME 未在运行,重新启动..."
+            start
+        fi
+
+        ###TODO: add ota check
+
+        sleep 10
+    done
+}
+
+# 检查命令行参数
+case "$1" in 
+    start)
+    start
+       monitor
+        ;;
+    *)
+        echo "error"
+        exit 1
+        ;;
+esac
diff --git a/app/log4crc b/app/log4crc
new file mode 100644 (file)
index 0000000..8f4b2eb
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE log4c SYSTEM "">
+
+<log4c>
+
+    <config>
+        <bufsize>0</bufsize>
+        <debug level="0"/>
+        <nocleanup>0</nocleanup>
+    </config>
+
+    <!-- root category ========================================= -->
+    <category name="root" priority="notice"/>
+
+    <!-- 输出到文件mylogfilename.x ========================================= -->
+    <category name="rfjb_app" priority="debug" appender = "myrollingappender"/>
+    <appender name="myrollingappender" type="rollingfile" logdir="./" prefix="rfjb_app-log" layout="dated" rollingpolicy="myrollingpolicy" />
+    <rollingpolicy name="myrollingpolicy" type="sizewin" maxsize="102400" maxnum="3" />
+
+    <!-- default appenders ===================================== -->
+    <appender name="stdout" type="stream" layout="basic"/>
+    <appender name="stderr" type="stream" layout="dated"/>
+    <appender name="syslog" type="syslog" layout="basic"/>
+
+    <!-- default layouts ======================================= -->
+    <layout name="basic" type="basic"/>
+    <layout name="dated" type="dated"/>
+</log4c>
+
index 30653316c6cd7983174e7bdb687b59c453febeb3..c3032aeb00780bf38f76d0ea1cf0086847031364 100644 (file)
@@ -72,7 +72,11 @@ int32_t alarm_start( am_dev_t *dev, uint32_t alarm )
         dev->alarm.time_ms = 0;
         dev->alarm.start = 0;
         dev->state = 0;
-event_recorder_dispall();
+
+        event_recorder_dispall();
+
+        led_off( LED_KEY_ALARM_1|LED_KEY_ALARM_2|LED_KEY_ALARM_3|LED_KEY_ALARM_4|LED_KEY_ALARM_5 );
+
     }else{
         printf( "\n\n\n---------- alarm start %d -> %d   -----------------\n\n\n", dev->alarm.type, alarm );
         //alarm start
@@ -81,6 +85,13 @@ event_recorder_dispall();
         dev->alarm.start = 1;
         dev->state = 1;
         iot_rpt_alarm_event();
+
+        if( alarm == 1 ) led_on( LED_KEY_ALARM_1 );
+        else if( alarm == 2 ) led_on( LED_KEY_ALARM_2 );
+        else if( alarm == 3 ) led_on( LED_KEY_ALARM_3 );
+        else if( alarm == 4 ) led_on( LED_KEY_ALARM_4 );
+        else if( alarm == 5 ) led_on( LED_KEY_ALARM_5 );
+
     }
     return 0;
 }
@@ -213,15 +224,9 @@ printf( "=========     btn_cb : code:%d, ev:%d\n", btn_code, btn_event );
     if( g_dev.state== 1 && alarm==0  ){
         //报警状态,键盘未锁定,长按停止键,停止警报输出
         alarm_stop( &g_dev );
-        led_off( LED_KEY_ALARM_1|LED_KEY_ALARM_2|LED_KEY_ALARM_3|LED_KEY_ALARM_4|LED_KEY_ALARM_5 );
     }else if( g_dev.state ==0 && alarm>0 ){
         //待机状态,键盘未锁定,长按报警键,启动警报输出
         alarm_start( &g_dev, alarm );
-        if( alarm == 1 ) led_on( LED_KEY_ALARM_1 );
-        else if( alarm == 2 ) led_on( LED_KEY_ALARM_2 );
-        else if( alarm == 3 ) led_on( LED_KEY_ALARM_3 );
-        else if( alarm == 4 ) led_on( LED_KEY_ALARM_4 );
-        else if( alarm == 5 ) led_on( LED_KEY_ALARM_5 );
     }else{
 
     }
@@ -297,10 +302,11 @@ int main( int argc, char ** argv )
                exit( -1 );
        }
 
-    printf( "Alarm Monitor start ...\n" );
 
     am_log_init();
 
+    AM_LOGI( "Alarm Monitor start ...\n" );
+
     memset( dev, 0, sizeof( am_dev_t ) );
     dev->loop = uv_default_loop();
 
@@ -319,7 +325,7 @@ int main( int argc, char ** argv )
     ///device_sensor_init( dev );
     ///sensor_board_init( dev );
 
-    iot_init( dev );
+    //iot_init( dev );
 
     event_recorder_init(); //init sqlite
 
index 0015e9a7adb54bcf94965876a5fc6fe926214b71..6d42c6727e187497522c481c4b85343644629485 100644 (file)
@@ -1,20 +1,21 @@
 #include "alarm_monitor.h"
 
 static const char * led_dev_name[LED_NRS] = {
-    "k1",
-    "k2",
-    "k3",
-    "k4",
-    "k5",
-    "k6",
-    "k7",
-    "k8",
-    "4g",
-    "sys",
-    "lora",
-    "laki",
-    "bd",
-    "eth",
+    "early_led ",    // 预警
+    "disaster_led",  // 灾警
+    "airstrike_led", // 空袭
+    "jiejing_led",   // 解警
+    "relief_led",    // 解灾
+    "unlock_led",    // 解锁
+    "stop_led",      // 停止
+    "power_led",     // Power
+
+    "net_led",       // 网络
+    "lora_led",      // Lora
+    "laki_led",      // 千米
+    "beidou_led",    // 北斗
+    "work",          // sys
+    "modem_led",     // 4g
 };
 
 static led_ctrl_t *s_led;
index 078b45daf258ca502611fbdd8e40939968947e17..5241773d33b691a85bd6d1fe55490ca857c75d4a 100644 (file)
@@ -24,7 +24,7 @@ void am_log_init( void )
 
     /* 获取已配置的category */
     am_log_category = log4c_category_get( LOG_CATEGORY );
-    printf("am_log_init:  log4c_category_get ret:%p\n", am_log_category );
+    //printf("am_log_init:  log4c_category_get ret:%p\n", am_log_category );
 
 err:
     return;
diff --git a/app/ui/ascii_14b.zi b/app/ui/ascii_14b.zi
deleted file mode 100644 (file)
index 89ad9fb..0000000
Binary files a/app/ui/ascii_14b.zi and /dev/null differ
diff --git a/app/ui/bd_icon_400x400.png b/app/ui/bd_icon_400x400.png
deleted file mode 100644 (file)
index ada663c..0000000
Binary files a/app/ui/bd_icon_400x400.png and /dev/null differ
diff --git a/app/ui/bd_icon_400x400.xcf b/app/ui/bd_icon_400x400.xcf
deleted file mode 100644 (file)
index aadb9d1..0000000
Binary files a/app/ui/bd_icon_400x400.xcf and /dev/null differ
diff --git a/app/ui/defencealarm.HMI b/app/ui/defencealarm.HMI
deleted file mode 100644 (file)
index c0ec930..0000000
Binary files a/app/ui/defencealarm.HMI and /dev/null differ
diff --git a/app/ui/ir.jpg b/app/ui/ir.jpg
deleted file mode 100644 (file)
index ecb6fc3..0000000
Binary files a/app/ui/ir.jpg and /dev/null differ
diff --git a/app/ui/ir_icon_400x400.png b/app/ui/ir_icon_400x400.png
deleted file mode 100644 (file)
index 4111987..0000000
Binary files a/app/ui/ir_icon_400x400.png and /dev/null differ
diff --git a/app/ui/ir_icon_400x400.xcf b/app/ui/ir_icon_400x400.xcf
deleted file mode 100644 (file)
index 15ab824..0000000
Binary files a/app/ui/ir_icon_400x400.xcf and /dev/null differ
diff --git a/app/ui/lora_icon_400x400.png b/app/ui/lora_icon_400x400.png
deleted file mode 100644 (file)
index bc72559..0000000
Binary files a/app/ui/lora_icon_400x400.png and /dev/null differ
diff --git a/app/ui/lora_icon_400x400.xcf b/app/ui/lora_icon_400x400.xcf
deleted file mode 100644 (file)
index add4fc1..0000000
Binary files a/app/ui/lora_icon_400x400.xcf and /dev/null differ
diff --git a/app/ui/page_main.png b/app/ui/page_main.png
deleted file mode 100644 (file)
index 37d1df5..0000000
Binary files a/app/ui/page_main.png and /dev/null differ
diff --git a/app/ui/utf8_alarm_32.zi b/app/ui/utf8_alarm_32.zi
deleted file mode 100644 (file)
index 0a9441b..0000000
Binary files a/app/ui/utf8_alarm_32.zi and /dev/null differ
diff --git a/app/ui/utf8_onoff_16.zi b/app/ui/utf8_onoff_16.zi
deleted file mode 100644 (file)
index f67a94e..0000000
Binary files a/app/ui/utf8_onoff_16.zi and /dev/null differ