From: kyz Date: Thu, 15 May 2025 12:43:31 +0000 (+0800) Subject: add device maintain info X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=7d88b44ded1a607c9af173797b437108e4f36543;p=yn%2Falarmmonitor.git add device maintain info --- diff --git a/UI/alarmmonitor.HMI b/UI/alarmmonitor.HMI new file mode 100755 index 0000000..f3e593d Binary files /dev/null and b/UI/alarmmonitor.HMI differ diff --git a/UI/ascii_14b.zi b/UI/ascii_14b.zi old mode 100644 new mode 100755 diff --git a/UI/bd_icon_400x400.png b/UI/bd_icon_400x400.png old mode 100644 new mode 100755 diff --git a/UI/bd_icon_400x400.xcf b/UI/bd_icon_400x400.xcf old mode 100644 new mode 100755 diff --git a/UI/bg/p_main_01.png b/UI/bg/p_main_01.png new file mode 100755 index 0000000..a08ca75 Binary files /dev/null and b/UI/bg/p_main_01.png differ diff --git a/UI/bg/p_main_02.png b/UI/bg/p_main_02.png new file mode 100755 index 0000000..518ff0e Binary files /dev/null and b/UI/bg/p_main_02.png differ diff --git a/UI/bg/p_main_03.png b/UI/bg/p_main_03.png new file mode 100755 index 0000000..7aea62f Binary files /dev/null and b/UI/bg/p_main_03.png differ diff --git a/UI/bg/p_unlock.png b/UI/bg/p_unlock.png new file mode 100755 index 0000000..f0fa90b Binary files /dev/null and b/UI/bg/p_unlock.png differ diff --git a/UI/bg/p_xj_01.png b/UI/bg/p_xj_01.png new file mode 100755 index 0000000..e6bce7c Binary files /dev/null and b/UI/bg/p_xj_01.png differ diff --git a/UI/bg/p_xj_02.png b/UI/bg/p_xj_02.png new file mode 100755 index 0000000..45fe2aa Binary files /dev/null and b/UI/bg/p_xj_02.png differ diff --git a/UI/bg/p_xj_03.png b/UI/bg/p_xj_03.png new file mode 100755 index 0000000..310483d Binary files /dev/null and b/UI/bg/p_xj_03.png differ diff --git a/UI/bg/page_main_1.png b/UI/bg/page_main_1.png deleted file mode 100644 index 467c5fb..0000000 Binary files a/UI/bg/page_main_1.png and /dev/null differ diff --git a/UI/bg/page_main_2.png b/UI/bg/page_main_2.png deleted file mode 100644 index 49c0f93..0000000 Binary files a/UI/bg/page_main_2.png and /dev/null differ diff --git a/UI/bg/page_main_3.png b/UI/bg/page_main_3.png deleted file mode 100644 index 840f77b..0000000 Binary files a/UI/bg/page_main_3.png and /dev/null differ diff --git a/UI/bg/page_unlock.png b/UI/bg/page_unlock.png deleted file mode 100644 index 6efe239..0000000 Binary files a/UI/bg/page_unlock.png and /dev/null differ diff --git a/UI/defencealarm.HMI b/UI/defencealarm.HMI deleted file mode 100644 index dc2dbb2..0000000 Binary files a/UI/defencealarm.HMI and /dev/null differ diff --git a/UI/icon/Locked-b.png b/UI/icon/Locked-b.png old mode 100644 new mode 100755 diff --git a/UI/icon/Locked-g.png b/UI/icon/Locked-g.png old mode 100644 new mode 100755 diff --git a/UI/icon/Locked-g.xcf b/UI/icon/Locked-g.xcf old mode 100644 new mode 100755 diff --git a/UI/ir.jpg b/UI/ir.jpg old mode 100644 new mode 100755 diff --git a/UI/ir_icon_400x400.png b/UI/ir_icon_400x400.png old mode 100644 new mode 100755 diff --git a/UI/ir_icon_400x400.xcf b/UI/ir_icon_400x400.xcf old mode 100644 new mode 100755 diff --git a/UI/locked_B_50x40.png b/UI/locked_B_50x40.png old mode 100644 new mode 100755 diff --git a/UI/locked_G_50x40.png b/UI/locked_G_50x40.png old mode 100644 new mode 100755 diff --git a/UI/lora_icon_400x400.png b/UI/lora_icon_400x400.png old mode 100644 new mode 100755 diff --git a/UI/lora_icon_400x400.xcf b/UI/lora_icon_400x400.xcf old mode 100644 new mode 100755 diff --git a/UI/utf8_alarm_32.zi b/UI/utf8_alarm_32.zi old mode 100644 new mode 100755 diff --git a/UI/utf8_onoff_16.zi b/UI/utf8_onoff_16.zi old mode 100644 new mode 100755 diff --git a/app/inc/alarm_monitor.h b/app/inc/alarm_monitor.h index 3826414..def319c 100644 --- a/app/inc/alarm_monitor.h +++ b/app/inc/alarm_monitor.h @@ -28,11 +28,20 @@ //#warning "PC Version Debug" #endif +#define WH_INFO_PATH "./wh_info" #define IOT_CFG_PATH "./iot.cfg" #define DEV_CFG_PATH "./dev.cfg" #define FACTORY_CFG_PATH "./factory.cfg" #define READ_UUID_CMD "cat /proc/cpuinfo | grep Serial" +typedef struct{ + char whid[80]; //wh id + time_t create_time; + time_t start_time; + time_t end_time; + int status; //whbz 0: None, 1:start, 2:stop +} wh_info_t; + typedef struct{ char serial[32]; @@ -157,6 +166,8 @@ typedef struct{ btn_ctrl_t btn; led_ctrl_t led_ctrl; + wh_info_t wh_info; + int32_t keypad_unlocked; //0:IDLE, 1:ALARM, 2:SETTING, 3:UNLOCKING int32_t keypad_unlocked_time; // int32_t state; //0:IDLE, 1:ALARM, 2:SETTING, 3:UNLOCKING diff --git a/app/src/am_main.c b/app/src/am_main.c index c3032ae..93ce648 100644 --- a/app/src/am_main.c +++ b/app/src/am_main.c @@ -9,7 +9,7 @@ #include "alarm_monitor.h" #include "led.h" -#define PID_FILE "/var/run/am_app/am_app.pid" +#define PID_FILE "/var/run/alarmmonitor/alarmmonitor.pid" #define SW_VERSION "v1.0" am_dev_t g_dev; @@ -128,6 +128,7 @@ int32_t lcd_write_alarm( int alarm, int alarm_time ); int32_t lcd_write_date_time( void ); int32_t lcd_write_sensor_info( int sensor, float data ); int32_t lcd_write_sound_type( int sound ); +int32_t lcd_write_wh_info( wh_info_t *info ); int32_t device_lcd_refresh( am_dev_t *dev ) { @@ -144,8 +145,10 @@ int32_t device_lcd_refresh( am_dev_t *dev ) lcd_write_sensor_info( 9, dev->disp.sensor[9] ); lcd_write_sound_type( dev->disp.sound_type ); + return 0; } + void keypad_lock_timer_cb( uv_timer_t *handle ) { g_dev.keypad_unlocked = 0; @@ -240,6 +243,9 @@ int32_t device_lcd_init( am_dev_t *dev ) handle=lcd_open(); if( handle ){ dev->disp.lcd = handle; + + lcd_write_page( 0 ); + lcd_write_wh_info(&g_dev.wh_info); return 0; } return -1; @@ -317,15 +323,17 @@ int main( int argc, char ** argv ) load_device_cfg( &dev->cfg ); load_iot_cfg( &dev->iot); + load_wh_info( &dev->wh_info); + read_device_uuid( dev ); device_button_init( dev ); device_led_init( dev ); - ///device_lcd_init( dev ); + device_lcd_init( dev ); ///device_sensor_init( dev ); ///sensor_board_init( dev ); - //iot_init( dev ); + iot_init( dev ); event_recorder_init(); //init sqlite diff --git a/app/src/config.c b/app/src/config.c index 846ae41..fcba028 100644 --- a/app/src/config.c +++ b/app/src/config.c @@ -203,7 +203,7 @@ cJSON * load_json_data_from_file( char *path ) json_data[ file_size ] = 0; root = cJSON_Parse((const char *)json_data); if( !root ){ - printf( "parser json data fail!\r\n" ); + printf( "parser[%s] json data fail!\r\n", path ); } }else{ AM_LOGE( "read file[%s] fail!\n", path ); @@ -438,6 +438,102 @@ int32_t store_device_cfg( dev_cfg_t *cfg ) return ret; } +//maintain +/* /app/whinfo + { + "whid":"123456", + "create":0 + "start":0 + "end":"0 + "status":1 + } +*/ +int32_t load_wh_info( wh_info_t *out) +{ + FILE *fd; + size_t n; + cJSON *root; + cJSON *id; + cJSON *status; + cJSON *ts_start; + cJSON *ts_end; + cJSON *ts_create; + + cJSON *item; + int32_t ret = 0; + + wh_info_t info; + + memset( &info, 0, sizeof(info)); + + if((root =load_json_data_from_file( WH_INFO_PATH )) ){ + id = cJSON_GetObjectItem(root, "whid"); + ts_create = cJSON_GetObjectItem(root, "create"); + ts_start = cJSON_GetObjectItem(root, "start"); + ts_end = cJSON_GetObjectItem(root, "end"); + status = cJSON_GetObjectItem(root, "status"); + if( ts_create && cJSON_IsNumber( ts_create ) && id && cJSON_IsString( id )){ + + strcpy( info.whid, id->valuestring ); + info.create_time = ts_create->valueint; + if( status && cJSON_IsNumber( status )){ + info.status = status->valueint; + if( info.status > 0 && ts_start && cJSON_IsNumber( ts_start )){ + info.start_time = ts_start->valueint; + if( info.status == 2 && ts_end && cJSON_IsNumber( ts_end )){ + info.end_time = ts_end->valueint; + } + } + + } + + } + + cJSON_Delete( root ); + } + + if( out ) + memcpy( out, &info, sizeof(*out) ); + + printf( "\n\n" ); + printf( "-----------------------------------------------\n" ); + printf( "load maintain info:\n"); + printf( "whid:%s\n", info.whid ); + printf( "Create:%s\n", ctime( &info.create_time) ); + printf( "Start:%s\n", ctime( &info.start_time) ); + printf( "End:%s\n", ctime( &info.end_time) ); + printf( "whbz:%d\n", info.status ); + printf( "-----------------------------------------------\n" ); + printf( "\n\n" ); + + return ret; +} + +int32_t store_wh_info( wh_info_t *wh ) +{ + int ret = 0; + FILE *fd; + size_t n; + cJSON *root; + cJSON *item; + + root = cJSON_CreateObject(); + if( root ){ + + cJSON_AddStringToObject( root, "whid", wh->whid ); + cJSON_AddNumberToObject( root, "create", wh->create_time); + cJSON_AddNumberToObject( root, "start", wh->start_time); + cJSON_AddNumberToObject( root, "end", wh->end_time); + cJSON_AddNumberToObject( root, "status", wh->status); + write_json_data_to_file( root, WH_INFO_PATH); + cJSON_Delete( root ); + ret = 0; + }else{ + ret = -1; + printf( "store device cfg fail!\n" ); + } + return ret; +} //iot cfg /* /app/iot.cfg { diff --git a/app/src/iot_report.c b/app/src/iot_report.c index 62872b4..cf2e1bd 100644 --- a/app/src/iot_report.c +++ b/app/src/iot_report.c @@ -462,6 +462,8 @@ uint8_t * iot_wrap_button_event_pkt( int button ) return pkt_data; } +extern void dev_wh_create( char * whid ); +extern void dev_wh_delete( char * whid ); char* handle_iot_rx_data( char * data, int sz ) { cJSON *root; @@ -575,6 +577,13 @@ char* handle_iot_rx_data( char * data, int sz ) }else if( strcmp(item_devices_device->valuestring, "xj" )==0 ){ //xj printf( "\n\n---------XJ, ID:%s, start:%s\n", item_devices_tagcode->valuestring, item_devices_value->valuestring ); + + if( strcmp( item_devices_value->valuestring, "1") == 0 ){ + dev_wh_create( item_devices_tagcode->valuestring ); + }else if( strcmp( item_devices_value->valuestring, "0") == 0 ){ + dev_wh_delete( item_devices_tagcode->valuestring ); + } + }else if( strcmp(item_devices_device->valuestring, "lock" )==0 ){ // remote lock/unlock printf( "remote %s !\n", strcmp(item_devices_value->valuestring,"1" )==0?"Lock":"Unlock" ); diff --git a/app/src/lcd.c b/app/src/lcd.c index 5ffc4be..9fbc5d7 100644 --- a/app/src/lcd.c +++ b/app/src/lcd.c @@ -91,7 +91,7 @@ error: return -1; } -static char lcd_recv_data[512]; +static uint8_t lcd_recv_data[512]; static int lcd_recv_cnt; static clock_t lcd_recv_time; @@ -123,10 +123,122 @@ void dev_locked( uint8_t lock ) } +int lcd_write_str( lcd_ctrl_t *p_lcd, char *str ) +{ + return lcd_write( p_lcd, str, strlen(str) ); +} + +extern char * time_str( char * str, time_t ts ); + +int32_t lcd_write_wh_info( wh_info_t *info ) +{ + char cmd[100]; + char buf[50]; + + printf( "\n\n\n----lcd_write_wh_info--------- whid:%s, create_time:%s, status:%d\n", info->whid, ctime(&info->create_time), info->status ); + if( info->create_time==0 ){ + lcd_write_str( &s_lcd, "main.b1.picc=0\xFF\xFF\xFF" ); + lcd_write_str( &s_lcd, "wh.b0.picc=4\xFF\xFF\xFF" ); +printf( ">>>>>> wh b0 picc -> 4\n" ); + lcd_write_str( &s_lcd, "wh.t0.txt=\"\"\xFF\xFF\xFF" ); + lcd_write_str( &s_lcd, "wh.t1.txt=\"\"\xFF\xFF\xFF" ); + lcd_write_str( &s_lcd, "wh.t2.txt=\"\"\xFF\xFF\xFF" ); + lcd_write_str( &s_lcd, "wh.t3.txt=\"\"\xFF\xFF\xFF" ); + }else{ + if( info->status == 0 ){ + lcd_write_str( &s_lcd, "main.b1.picc=1\xFF\xFF\xFF" ); + lcd_write_str( &s_lcd, "wh.b0.picc=5\xFF\xFF\xFF" ); +printf( ">>>>>> wh b0 picc -> 5\n" ); + + sprintf( cmd, "wh.t0.txt=\"%s\"\xFF\xFF\xFF", info->whid ); + lcd_write_str( &s_lcd, cmd ); + sprintf( cmd, "wh.t1.txt=\"%s\"\xFF\xFF\xFF", time_str( buf, info->create_time) ); + lcd_write_str( &s_lcd, cmd ); + sprintf( cmd, "wh.t2.txt=\"%s\"\xFF\xFF\xFF", "" ); + lcd_write_str( &s_lcd, cmd ); + sprintf( cmd, "wh.t3.txt=\"%s\"\xFF\xFF\xFF", "" ); + lcd_write_str( &s_lcd, cmd ); + }else if( info->status == 1 ){ + lcd_write_str( &s_lcd, "main.b1.picc=2\xFF\xFF\xFF" ); + lcd_write_str( &s_lcd, "wh.b0.picc=6\xFF\xFF\xFF" ); +printf( ">>>>>> wh b0 picc -> 6\n" ); + sprintf( cmd, "wh.t0.txt=\"%s\"\xFF\xFF\xFF", info->whid ); + lcd_write_str( &s_lcd, cmd ); + sprintf( cmd, "wh.t1.txt=\"%s\"\xFF\xFF\xFF", time_str(buf, info->create_time) ); + lcd_write_str( &s_lcd, cmd ); + sprintf( cmd, "wh.t2.txt=\"%s\"\xFF\xFF\xFF", time_str(buf, info->start_time) ); + lcd_write_str( &s_lcd, cmd ); + sprintf( cmd, "wh.t3.txt=\"%s\"\xFF\xFF\xFF", "" ); + lcd_write_str( &s_lcd, cmd ); + }else if( info->status == 2 ){ + lcd_write_str( &s_lcd, "main.b1.picc=0\xFF\xFF\xFF" ); + lcd_write_str( &s_lcd, "wh.b0.picc=4\xFF\xFF\xFF" ); +printf( ">>>>>> wh b0 picc -> 4\n" ); + + sprintf( cmd, "wh.t0.txt=\"%s\"\xFF\xFF\xFF", info->whid ); + lcd_write_str( &s_lcd, cmd ); + sprintf( cmd, "wh.t1.txt=\"%s\"\xFF\xFF\xFF", time_str( buf, info->create_time) ); + lcd_write_str( &s_lcd, cmd ); + sprintf( cmd, "wh.t2.txt=\"%s\"\xFF\xFF\xFF", time_str(buf, info->start_time) ); + lcd_write_str( &s_lcd, cmd ); + sprintf( cmd, "wh.t3.txt=\"%s\"\xFF\xFF\xFF", time_str(buf, info->end_time) ); + lcd_write_str( &s_lcd, cmd ); + } + } + + return 0; +} + +extern char * time_str( char * str, time_t ts ); +void dev_wh_stop( void ); +void dev_wh_start( void ); +void dev_wh_create( char * whid ); +void dev_wh_delete( char * whid ); + +void dev_wh_delete( char * whid ) +{ + memset( &g_dev.wh_info, 0, sizeof( g_dev.wh_info) ); + store_wh_info( &g_dev.wh_info ); + lcd_write_wh_info( &g_dev.wh_info ); +} + +void dev_wh_create( char * whid ) +{ + strcpy( g_dev.wh_info.whid, whid ); + g_dev.wh_info.status=0; + g_dev.wh_info.create_time = time(NULL); + g_dev.wh_info.start_time = 0; + g_dev.wh_info.end_time = 0; + store_wh_info( &g_dev.wh_info ); + lcd_write_wh_info( &g_dev.wh_info ); +} +void dev_wh_stop( void ) +{ + g_dev.wh_info.status=2; + g_dev.wh_info.end_time = time(NULL); + store_wh_info( &g_dev.wh_info ); + lcd_write_wh_info( &g_dev.wh_info ); +} + +void dev_wh_start( void ) +{ + g_dev.wh_info.status=1; + g_dev.wh_info.start_time = time(NULL); + g_dev.wh_info.end_time = 0; + store_wh_info( &g_dev.wh_info ); + lcd_write_wh_info( &g_dev.wh_info ); +} + void lcd_resp_handle( uint8_t *lcd_recv_data, uint16_t lcd_recv_cnt ) { uint8_t *p = lcd_recv_data; uint16_t n = lcd_recv_cnt; + + char *cmd_xj_start ="xj.b0.picc=6\xFF\xFF\xFF"; + char *cmd_xj_stop ="xj.b0.picc=5\xFF\xFF\xFF"; + char cmd[100]; + char time_buf[100]; + char passwd[16]; if( n >= 4 && p[n-3] == 0xFF && p[n-2] == 0xFF && p[n-1] == 0xFF ){ if( p[0] == 0xF0 && p[1] == 0x01 ){ @@ -134,6 +246,12 @@ void lcd_resp_handle( uint8_t *lcd_recv_data, uint16_t lcd_recv_cnt ) if( memcmp( "666666", p+2, 6 )==0 ){ dev_unlocked(); } + }else if( p[0] == 0xF0 && p[1] == 0x02 && p[2] == 0xA0 ){ + //wh stop + dev_wh_stop(); + }else if( p[0] == 0xF0 && p[1] == 0x02 && p[2] == 0xA1 ){ + //wh start + dev_wh_start(); } } } @@ -154,7 +272,7 @@ void lcd_data_ready_cb( uv_poll_t *handle, int status, int events ) printf( "lcd uart read data %d Bytes\n", nbytes ); printf( "\n[" ); - for( int i=0; i