Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
fix: implemented gps search without lte connection
Browse files Browse the repository at this point in the history
  • Loading branch information
simensrostad committed Aug 23, 2019
1 parent a815b7f commit 4371d40
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
4 changes: 2 additions & 2 deletions applications/cat_tracker/src/gps_controller/gps_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
39 changes: 34 additions & 5 deletions applications/cat_tracker/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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";
Expand All @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
16 changes: 16 additions & 0 deletions drivers/lte_link_control/lte_lc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions include/lte_lc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4371d40

Please sign in to comment.