add /dev/jdq ctrl
authorkyz <kyz@kyz-vbox.myguest.virtualbox.org>
Mon, 26 May 2025 07:09:48 +0000 (15:09 +0800)
committerkyz <kyz@kyz-vbox.myguest.virtualbox.org>
Mon, 26 May 2025 07:09:48 +0000 (15:09 +0800)
app/src/am_main.c
app/src/iot_report.c

index 025b6a49d0b0256f2278b1859fd9afa402b423fd..5418a38499b5585c7610f5ba26e35dc05ef62667 100644 (file)
@@ -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 );
     }
 }
 
index 2a194bd848c82ceb27b94fec95daaaf1a06a1afd..a3f25d6ef3e6f930f8ef04904b9e7239e87fbfe2 100644 (file)
@@ -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" );
         }
     }