From 4371d404480258cc3331b7bcccdf09d732241929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20S=2E=20R=C3=B8stad?= Date: Fri, 23 Aug 2019 10:33:31 +0200 Subject: [PATCH] fix: implemented gps search without lte connection --- .../src/gps_controller/gps_controller.c | 4 +- applications/cat_tracker/src/main.c | 39 ++++++++++++++++--- drivers/lte_link_control/lte_lc.c | 16 ++++++++ include/lte_lc.h | 6 +++ 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/applications/cat_tracker/src/gps_controller/gps_controller.c b/applications/cat_tracker/src/gps_controller/gps_controller.c index d8c6d6d5d09..83b2d21941b 100644 --- a/applications/cat_tracker/src/gps_controller/gps_controller.c +++ b/applications/cat_tracker/src/gps_controller/gps_controller.c @@ -56,7 +56,7 @@ static void gps_work_handler(struct k_work *work) void gps_control_stop(void) { - lte_lc_psm_req(false); + // lte_lc_psm_req(false); gps_work.type = GPS_WORK_STOP; k_work_submit(&gps_work.work); @@ -74,7 +74,7 @@ void gps_control_stop(void) void gps_control_start(void) { - lte_lc_psm_req(true); + // lte_lc_psm_req(true); gps_work.type = GPS_WORK_START; k_work_submit(&gps_work.work); diff --git a/applications/cat_tracker/src/main.c b/applications/cat_tracker/src/main.c index 95f485ece46..a2e6fe38fea 100644 --- a/applications/cat_tracker/src/main.c +++ b/applications/cat_tracker/src/main.c @@ -21,9 +21,13 @@ #define AT_CMD_SIZE(x) (sizeof(x) - 1) +#define LTE_CONN_TIMEOUT 1 + static bool active; static bool lte_connected = false; +static struct k_sem connect_sem; + K_SEM_DEFINE(gps_timeout_sem, 0, 1); K_SEM_DEFINE(accel_trig_sem, 0, 1); @@ -111,6 +115,7 @@ static void work_init(void) k_work_init(&cloud_get_work, cloud_get_work_fn); } +/*Fix*/ static const char status1[] = "+CEREG: 1"; static const char status2[] = "+CEREG:1"; static const char status3[] = "+CEREG: 5"; @@ -136,9 +141,8 @@ void connection_handler(char *response) printk("Error fetching modem time\n"); } - k_work_submit(&cloud_get_work); - lte_connected = true; + k_sem_give(&connect_sem); } } else { @@ -243,13 +247,34 @@ static void start_restart_mov_timer(void) K_SECONDS(check_mov_timeout())); } +static void lte_connect() +{ + int err; + + k_sem_init(&connect_sem, 0, 1); + err = lte_lc_init_connect_manager(connection_handler); + if (err != 0) { + printk("Error setting lte_connect manager: %d\n", err); + } + + if (k_sem_take(&connect_sem, K_MINUTES(LTE_CONN_TIMEOUT)) == 0) { + lte_lc_psm_req(true); + cloud_publish(NO_GPS_FIX, SYNCRONIZATION, INCLUDE_MOD_D); + } else { + lte_lc_offline(); + lte_lc_gps_mode(); + lte_lc_normal(); + } +} + void main(void) { - work_init(); printk("The cat tracker has started\n"); - cloud_configuration_init(); - lte_lc_init_connect_manager(connection_handler); + work_init(); adxl362_init(); + // led_init(); led thread should be fixed to use thread start + cloud_configuration_init(); + lte_connect(); gps_control_init(gps_control_handler); check_mode: @@ -289,5 +314,9 @@ void main(void) events[0].state = K_POLL_STATE_NOT_READY; k_sleep(K_SECONDS(check_active_wait(active))); + if (!lte_connected) { + lte_connect(); + } + goto check_mode; } diff --git a/drivers/lte_link_control/lte_lc.c b/drivers/lte_link_control/lte_lc.c index 9decb487b3a..b53936d9bc9 100644 --- a/drivers/lte_link_control/lte_lc.c +++ b/drivers/lte_link_control/lte_lc.c @@ -52,6 +52,9 @@ static const char network_mode[] = "AT%XSYSTEMMODE=0,1,1,0"; /* Set network mode to LTE-M */ static const char network_mode[] = "AT%XSYSTEMMODE=1,0,1,0"; #endif +/*Set netowrk mode to GPS */ +static const char gps_mode[] = "AT%XSYSTEMMODE=0,0,1,0"; + /* Accepted network statuses read from modem */ static const char status1[] = "+CEREG: 1"; static const char status2[] = "+CEREG:1"; @@ -144,6 +147,10 @@ int lte_lc_init_connect_manager(at_cmd_handler_t connection_handler) return ret; } + if (at_cmd_write(offline, NULL, 0, NULL) != 0) { + return -EIO; + } + if (at_cmd_write(network_mode, NULL, 0, NULL) != 0) { return -EIO; } @@ -191,6 +198,15 @@ int lte_lc_init_and_connect(void) return err; } +int lte_lc_gps_mode(void) +{ + if (at_cmd_write(gps_mode, NULL, 0, NULL) != 0) { + return -EIO; + } + + return 0; +} + int lte_lc_offline(void) { if (at_cmd_write(offline, NULL, 0, NULL) != 0) { diff --git a/include/lte_lc.h b/include/lte_lc.h index c96cb4cf7e4..ebbfe1769e2 100644 --- a/include/lte_lc.h +++ b/include/lte_lc.h @@ -57,6 +57,12 @@ int lte_lc_power_off(void); */ int lte_lc_normal(void); +/** @brief Function for requesting gps mode + * + * @return Zero on success or (negative) error code otherwise. + */ +int lte_lc_gps_mode(void); + /** @brief Function for requesting modem to go to or disable * power saving mode (PSM) with default settings defined in kconfig. * For reference see 3GPP 27.007 Ch. 7.38.