From 2fa92d1a4e448b723453862a9c92c48d2a018fc3 Mon Sep 17 00:00:00 2001 From: qiyongzhong0 <917768104@qq.com> Date: Thu, 28 Apr 2022 09:18:57 +0800 Subject: [PATCH 1/2] fix ec200, add power control and rssi reads. --- class/ec200x/at_device_ec200x.c | 67 +++++++++++++++++++++++++++++++-- class/ec200x/at_device_ec200x.h | 2 + samples/at_sample_ec200x.c | 7 ++++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/class/ec200x/at_device_ec200x.c b/class/ec200x/at_device_ec200x.c index 9906770f..5bc7f610 100644 --- a/class/ec200x/at_device_ec200x.c +++ b/class/ec200x/at_device_ec200x.c @@ -28,8 +28,15 @@ static int ec200x_power_on(struct at_device *device) ec200x = (struct at_device_ec200x *)device->user_data; + if (ec200x->power_ctrl) + { + (ec200x->power_ctrl)(1); + rt_thread_mdelay(2000); + } + if (ec200x->power_pin == -1)//no power on pin { + ec200x->power_status = RT_TRUE; return(RT_EOK); } if (ec200x->power_status_pin != -1)//use power status pin @@ -66,6 +73,14 @@ static int ec200x_power_off(struct at_device *device) ec200x = (struct at_device_ec200x *)device->user_data; + if (ec200x->power_ctrl) + { + ec200x->power_status = RT_FALSE; + (ec200x->power_ctrl)(0); + rt_thread_mdelay(2*1000); + return(RT_EOK); + } + if (ec200x->power_pin == -1)//no power on pin { return(RT_EOK); @@ -103,7 +118,7 @@ static int ec200x_power_off(struct at_device *device) static int ec200x_sleep(struct at_device *device) { - at_response_t resp = RT_NULL; + //at_response_t resp = RT_NULL; struct at_device_ec200x *ec200x = RT_NULL; ec200x = (struct at_device_ec200x *)device->user_data; @@ -148,7 +163,7 @@ static int ec200x_sleep(struct at_device *device) static int ec200x_wakeup(struct at_device *device) { - at_response_t resp = RT_NULL; + //at_response_t resp = RT_NULL; struct at_device_ec200x *ec200x = RT_NULL; ec200x = (struct at_device_ec200x *)device->user_data; @@ -234,6 +249,38 @@ static int ec200x_check_link_status(struct at_device *device) return(result); } +static int ec200x_read_rssi(struct at_device *device) +{ + int result = -RT_ERROR; + at_response_t resp = at_create_resp(64, 0, rt_tick_from_millisecond(300)); + if (resp == RT_NULL) + { + LOG_D("no memory for resp create."); + return(result); + } + + if (at_obj_exec_cmd(device->client, resp, "AT+CSQ") == RT_EOK) + { + int rssi = 0; + if (at_resp_parse_line_args_by_kw(resp, "+CSQ:", "+CSQ: %d", &rssi) > 0) + { + struct at_device_ec200x *ec200x = (struct at_device_ec200x *)device->user_data; + if (rssi < 99) + { + ec200x->rssi = rssi * 2 - 113; + } + else if(rssi >= 100 && rssi < 199) + { + ec200x->rssi = rssi - 216; + } + result = RT_EOK; + } + } + + at_delete_resp(resp); + + return(result); +} /* ============================= ec200x network interface operations ============================= */ /* set ec200x network interface device status and address information */ @@ -307,6 +354,18 @@ static int ec200x_netdev_set_info(struct netdev *netdev) } } } + + /* read number of SIM card */ + { + if (at_obj_exec_cmd(device->client, resp, "AT+QCCID") == RT_EOK) + { + char str[32]; + if (at_resp_parse_line_args_by_kw(resp, "+QCCID:", "+QCCID:%s\r", str) > 0) + { + LOG_D("QCCID of SIM card : %s", str); + } + } + } /* set network interface device IP address */ { @@ -392,6 +451,8 @@ static void ec200x_check_link_status_entry(void *parameter) while (1) { + ec200x_read_rssi(device); + rt_thread_delay(EC200X_LINK_DELAY_TIME); is_link_up = (ec200x_check_link_status(device) == RT_EOK); @@ -732,7 +793,7 @@ static void ec200x_init_thread_entry(void *parameter) result = -RT_ERROR; goto __exit; } - + /* check signal strength */ for (i = 0; i < CSQ_RETRY; i++) { diff --git a/class/ec200x/at_device_ec200x.h b/class/ec200x/at_device_ec200x.h index 53216d7b..b613e6e8 100644 --- a/class/ec200x/at_device_ec200x.h +++ b/class/ec200x/at_device_ec200x.h @@ -31,6 +31,7 @@ struct at_device_ec200x int power_status_pin; int wakeup_pin; size_t recv_line_num; + void (*power_ctrl)(int is_on); struct at_device device; void *socket_data; @@ -38,6 +39,7 @@ struct at_device_ec200x rt_bool_t power_status; rt_bool_t sleep_status; + int rssi; }; #ifdef AT_USING_SOCKET diff --git a/samples/at_sample_ec200x.c b/samples/at_sample_ec200x.c index 2d9f1ce8..8356c2a3 100644 --- a/samples/at_sample_ec200x.c +++ b/samples/at_sample_ec200x.c @@ -24,6 +24,7 @@ static struct at_device_ec200x _dev = EC200X_SAMPLE_STATUS_PIN, EC200X_SAMPLE_WAKEUP_PIN, EC200X_SAMPLE_RECV_BUFF_LEN, + RT_NULL }; static int ec200x_device_register(void) @@ -38,3 +39,9 @@ static int ec200x_device_register(void) } INIT_APP_EXPORT(ec200x_device_register); +int ec200x_get_rssi(void) +{ + struct at_device_ec200x *ec200x = &_dev; + return(ec200x->rssi); +} + From 3bf925d838d79fdd23fc9f4e50be00a4998c38e6 Mon Sep 17 00:00:00 2001 From: qyz <917768104@qq.com> Date: Tue, 25 Jun 2024 11:14:20 +0800 Subject: [PATCH 2/2] fix bug and adapt ec800x --- class/ec200x/at_device_ec200x.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/class/ec200x/at_device_ec200x.c b/class/ec200x/at_device_ec200x.c index e969d1e9..edd08b67 100644 --- a/class/ec200x/at_device_ec200x.c +++ b/class/ec200x/at_device_ec200x.c @@ -259,11 +259,7 @@ static int ec200x_read_rssi(struct at_device *device) LOG_D("no memory for resp create."); return(result); } -<<<<<<< HEAD - -======= ->>>>>>> 46e820e47fb62e91410050ec39793f9662366e11 if (at_obj_exec_cmd(device->client, resp, "AT+CSQ") == RT_EOK) { int rssi = 0; @@ -281,11 +277,7 @@ static int ec200x_read_rssi(struct at_device *device) result = RT_EOK; } } -<<<<<<< HEAD - -======= ->>>>>>> 46e820e47fb62e91410050ec39793f9662366e11 at_delete_resp(resp); return(result); @@ -295,7 +287,7 @@ static int ec200x_read_rssi(struct at_device *device) /* set ec200x network interface device status and address information */ static int ec200x_netdev_set_info(struct netdev *netdev) { -#define EC200X_INFO_RESP_SIZE 128 +#define EC200X_INFO_RESP_SIZE 256 #define EC200X_INFO_RESP_TIMO rt_tick_from_millisecond(1000) int result = RT_EOK; @@ -330,7 +322,7 @@ static int ec200x_netdev_set_info(struct netdev *netdev) #define EC200X_NETDEV_HWADDR_LEN 8 #define EC200X_IMEI_LEN 15 - char imei[EC200X_IMEI_LEN] = {0}; + char imei[32] = {0}; int i = 0, j = 0; /* send "AT+GSN" commond to get device IMEI */ @@ -363,18 +355,6 @@ static int ec200x_netdev_set_info(struct netdev *netdev) } } } - - /* read number of SIM card */ - { - if (at_obj_exec_cmd(device->client, resp, "AT+QCCID") == RT_EOK) - { - char str[32]; - if (at_resp_parse_line_args_by_kw(resp, "+QCCID:", "+QCCID:%s\r", str) > 0) - { - LOG_D("QCCID of SIM card : %s", str); - } - } - } /* read number of SIM card */ { @@ -390,7 +370,7 @@ static int ec200x_netdev_set_info(struct netdev *netdev) /* set network interface device IP address */ { - #define IP_ADDR_SIZE_MAX 16 + #define IP_ADDR_SIZE_MAX 128 char ipaddr[IP_ADDR_SIZE_MAX] = {0}; /* send "AT+CGPADDR=1" commond to get IP address */ @@ -473,11 +453,7 @@ static void ec200x_check_link_status_entry(void *parameter) while (1) { ec200x_read_rssi(device); -<<<<<<< HEAD - -======= ->>>>>>> 46e820e47fb62e91410050ec39793f9662366e11 rt_thread_delay(EC200X_LINK_DELAY_TIME); is_link_up = (ec200x_check_link_status(device) == RT_EOK); @@ -905,7 +881,7 @@ static void ec200x_init_thread_entry(void *parameter) result = -RT_ERROR; goto __exit; } - + /* check signal strength */ for (i = 0; i < CSQ_RETRY; i++) {