From e2bdaebb86429fd64e5952ec5699a2cf0a21fe1a Mon Sep 17 00:00:00 2001 From: kyz Date: Mon, 26 May 2025 15:09:48 +0800 Subject: [PATCH] add /dev/jdq ctrl --- app/src/am_main.c | 17 +++++++++++++++++ app/src/iot_report.c | 11 ++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/am_main.c b/app/src/am_main.c index 025b6a4..5418a38 100644 --- a/app/src/am_main.c +++ b/app/src/am_main.c @@ -102,11 +102,28 @@ int32_t alarm_stop( am_dev_t *dev ) void device_power_ctrl( int dev, int on ) { + int cmd[2]; + //TODO ctrl hw gpio if( dev==0 ){ //jbq + cmd[0] = 4; }else if( dev==1 ){ //jbkzq + cmd[0] = 5; + }else{ + return ; + } + cmd[1] = on?1:0; + + + int fd = open( "/dev/jdq", O_WRONLY ); + if( fd >= 0 ){ + printf( "write /dev/jdq ....\n" ); + write( fd, cmd, sizeof(cmd) ); + close(fd); + }else{ + AM_LOGE( "device pwer ctl(%d,%d): open /dev/jdq fail!", dev, on ); } } diff --git a/app/src/iot_report.c b/app/src/iot_report.c index 2a194bd..a3f25d6 100644 --- a/app/src/iot_report.c +++ b/app/src/iot_report.c @@ -607,7 +607,7 @@ char* handle_iot_rx_data( char * data, int sz ) if( item_ccode && item_devices && item_time && item_type && item_devices_device && cJSON_IsString(item_devices_device ) - && item_devices tagcode && cJSON_IsString(item_devices_tagcode ) + && item_devices_tagcode && cJSON_IsString(item_devices_tagcode ) && strcmp( item_type->valuestring, "write")== 0){ if( strcmp(item_devices_device->valuestring, "gddykz" )==0 ){ //power ctrl @@ -667,6 +667,15 @@ char* handle_iot_rx_data( char * data, int sz ) }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" ); + if( strcmp(item_devices_value->valuestring,"0" )==0 ){ + AM_LOGI( "remote Unlocked!" ); + dev_unlocked(); + + }else if( strcmp(item_devices_value->valuestring,"1" )==0 ){ + AM_LOGI( "remote Locked!" ); + dev_locked(2); + + } resp = wrap_ctrl_resp_json( item_ccode->valuestring, item_devices_device->valuestring, "true", item_devices_tagcode->valuestring, item_devices_value->valuestring, NULL, "write" ); } } -- 2.34.1