rpt ir event
authorkyz <kyz@kyz-vbox.myguest.virtualbox.org>
Fri, 30 May 2025 08:49:17 +0000 (16:49 +0800)
committerkyz <kyz@kyz-vbox.myguest.virtualbox.org>
Fri, 30 May 2025 08:56:10 +0000 (16:56 +0800)
CMakeLists.txt
app/src/am_main.c
app/src/iot.c
app/src/iot_report.c
app/src/sensor.c
app/src/tcp.c

index ca7c9414b3a73e6f429f464612ee7ed524123467..a07c2dbaa10cbd869b3fd99c48d19605dfe400e8 100644 (file)
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.8)
 
 project(alarmmonitor)
 
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE -g2 -O0")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE -g2 -O2")
 
 # Add the posix targets
 add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/app )
index 1349078e17d6323484a11ae9403b79041482c98c..793efc1c68b387ae262a974bfa46d40ca78f2cda 100644 (file)
@@ -119,7 +119,8 @@ void device_power_ctrl( int dev, int on )
 
     int fd = open( "/dev/jdq", O_WRONLY );
     if( fd >= 0 ){
-        write( fd, cmd, sizeof(cmd) );
+        if( write( fd, cmd, sizeof(cmd) ) != sizeof(cmd) ){
+        }
         close(fd);
     }else{
         AM_LOGE( "device pwer ctl(%d,%d) open /dev/jdq fail!", dev, on );
@@ -375,7 +376,6 @@ int main( int argc, char ** argv )
     device_sensor_init( dev );
     sensor_board_init( dev );
 
-    spk_init( dev );
 
     //ec200 ACM
     ec200_acm_start();
index 1c7f58a24cb2776e43286b41fa2d55064a73e06a..33e4904819ae2ed50d421229920a21d34a27f512 100644 (file)
@@ -38,6 +38,7 @@ static uint16_t pkt_sn = 0;
 extern char * handle_iot_rx_data( char * data, int sz );
 extern uint8_t * iot_wrap_button_event_pkt( int button  );
 extern uint8_t * iot_wrap_heartbeat_pkt( void );
+extern uint8_t * iot_wrap_ir_event_pkt( void );
 
 extern char* wrap_status_pkt( char *task_id );
 extern char* wrap_connect_pkt( void );
@@ -49,6 +50,25 @@ void heartbeat_timer_cb( uv_timer_t * handle );
 
 void iot_tx_data( uint8_t *data, uint32_t sz );
 
+void iot_rpt_ir_event( void )
+{
+    iot_t *p_iot;
+    char * pkt_str;
+    p_iot = &s_iot;
+
+    if( p_iot->connected == 2  ){
+
+        pkt_str = iot_wrap_ir_event_pkt();
+        if( pkt_str ){
+            iot_tx_data( pkt_str, strlen( pkt_str ) );
+            free( pkt_str );
+
+            uv_timer_stop( &s_iot.heartbeat_timer);
+            uv_timer_start( &s_iot.heartbeat_timer, heartbeat_timer_cb, 30*1000, 30*1000 );
+        }
+    }
+}
+
 void iot_rpt_alarm_event( void )
 {
     iot_t *p_iot;
@@ -240,14 +260,14 @@ void iot_rx_cb( uv_stream_t *client, uint8_t * rx_data, uint16_t rx_sz )
 void iot_tcp_conn_cb( tcp_cli_t *client, int connected )
 {
     if( connected ){
-        printf( "------------------IOT TCP CONNECTED\n" );
+        AM_LOGI( "------------------IOT TCP CONNECTED" );
         s_iot.connected = 0;
         uv_timer_stop( &s_iot.iot_timer );
         uv_timer_stop( &s_iot.heartbeat_timer);
         uv_timer_start( &s_iot.iot_timer, connect_timer_cb, 100, 0 );
 
     }else{
-        printf( "------------------IOT TCP DISCONNECT\n" );
+        AM_LOGI( "------------------IOT TCP DISCONNECT" );
         s_iot.connected = 0;
         uv_timer_stop( &s_iot.iot_timer );
     }
index 8953062d10e46e264e47f9649f29b7fe1ef61905..348ef1ae6bf664639d6f1f2e922e9f42707edb6c 100644 (file)
@@ -449,6 +449,29 @@ uint8_t * iot_wrap_alarm_event_pkt( void  )
     return pkt_data;
 }
 
+/*-------------------------------------------------------------------------------------------
+//ir event pkt
+//-------------------------------------------------------------------------------------------*/
+uint8_t * iot_wrap_ir_event_pkt( void  )
+{
+    char starttime[32];
+    char *pkt_data = NULL;
+    time_t ts;
+    cJSON *payload;
+    cJSON *root;
+
+    ts = time( NULL );
+    time_str( starttime, ts );
+
+    payload = wrap_ir_event_json( g_dev.sensor_data.ir?1:0, starttime );
+    if( payload ){
+        root = rpt_pkt_encrypted( 1, payload );
+        pkt_data = cJSON_Print( root );
+        cJSON_Delete( root );
+    }
+    return pkt_data;
+}
+
 /*-------------------------------------------------------------------------------------------
 //button event pkt
 //-------------------------------------------------------------------------------------------*/
@@ -519,6 +542,8 @@ extern void dev_wh_delete( char * whid );
 extern void remote_jbkzq_power( int on );
 extern void remote_jbkzq_power( int on );
 extern void remote_alarm( int alarm );
+extern void dev_unlocked( void );
+extern void dev_locked( uint8_t lock );
 
 char* handle_iot_rx_data( char * data, int sz )
 {
index 0922e74588ba601aa0dc713e02e4971949735826..531abb88ce0a90b8a39f605b255c40adb54fbb73 100644 (file)
@@ -135,7 +135,7 @@ int read_temperature( float *temperature, float*humidity )
 
         if( temperature ) *temperature = t;
         if( humidity ) *humidity = h;
-        AM_LOGD( "TEM:%.2f, %.2f", t, h );
+        //AM_LOGD( "TEM:%.2f, %.2f", t, h );
         ret = 0;
     }else{
         AM_LOGD( "TEM read fail!" );
@@ -145,6 +145,7 @@ int read_temperature( float *temperature, float*humidity )
     return ret;
 }
 
+void iot_rpt_ir_event( void );
 void sensor_read_cb( uv_work_t *req, int status )
 {
     if( s_sensor.data_ready ){
@@ -160,6 +161,8 @@ void sensor_read_cb( uv_work_t *req, int status )
         if( g_dev.sensor_data.ir != s_sensor.ir){
             AM_LOGI( "IR -> %d", s_sensor.ir);
             g_dev.sensor_data.ir = s_sensor.ir;
+
+            iot_rpt_ir_event();
         }
     }
 }
index 14d7ee84797a2282ca50df3560d24b93a7ba2daf..74c067d8478b58225af626467fa22c33e1bcf663 100644 (file)
@@ -63,11 +63,11 @@ void on_tcp_write(uv_write_t* req, int status)
 void on_connect(uv_connect_t* req, int status)
 {
     tcp_cli_t *p_cli = (tcp_cli_t*)req->data;
-    printf( "---------------------tcp test on_connect st:%d-------------------------------------\n", status );
+    printf( "-------tcp test on_connect st:%d-------\n", status );
        if (status < 0)
        {
                fprintf(stderr, "Connection error %s\n", uv_strerror(status));
-        uv_close( &p_cli->sock, NULL );
+        uv_close( (uv_handle_t*)&p_cli->sock, NULL );
         tcp_cli_start( p_cli, 10*1000 );
                return;
        }
@@ -101,13 +101,12 @@ void on_resolved(uv_getaddrinfo_t *resolver, int status, struct addrinfo *res)
         return;
     }
 
-    //p_cli->state = 1;
-
     uv_ip4_name((struct sockaddr_in*) res->ai_addr, addr, 16);
     fprintf(stderr, "on_resolved: [struct addrinfo *res:%p], - str %s\n", res, addr);
 
     uv_tcp_init( p_cli->loop, &p_cli->sock);
     p_cli->conn_req.data = p_cli;
+
     uv_tcp_connect(&p_cli->conn_req, &p_cli->sock, (const struct sockaddr *) res->ai_addr, on_connect);
 
     uv_freeaddrinfo(res);