Skip to content

Commit

Permalink
unwired-modules: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
olegart committed Nov 6, 2017
1 parent c313906 commit f8dee1b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 22 deletions.
32 changes: 18 additions & 14 deletions examples/loralan/main-node.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ void joined_timeout_cb(void)

if ((current_join_retries >= unwds_get_node_settings().max_retr) && (unwds_get_node_settings().nodeclass == LS_ED_CLASS_A)) {
/* class A node: go to sleep */
puts("ls-ed: maximum join retries exceeded, stopping");
puts("[LoRa] maximum join retries exceeded, stopping");
} else {
puts("ls: join request timed out, resending");

/* Pseudorandom delay for collision avoidance */
unsigned int delay = random_uint32_range(5 + current_join_retries*30, 30 + current_join_retries*30);
printf("ls-ed: random delay %d s\n", (unsigned int) (delay));
printf("[LoRa] random delay %d s\n", (unsigned int) (delay));

rtctimers_sleep(delay);

Expand All @@ -110,9 +110,9 @@ void joined_timeout_cb(void)
}

if (unwds_get_node_settings().nodeclass == LS_ED_CLASS_A) {
printf("ls-ed: rejoining, attempt %d / %d\n", current_join_retries, unwds_get_node_settings().max_retr);
printf("[LoRa] rejoining, attempt %d / %d\n", current_join_retries, unwds_get_node_settings().max_retr);
} else {
puts("ls-ed: rejoining");
puts("[LoRa] rejoining");
}

ls_ed_join(&ls);
Expand All @@ -123,18 +123,18 @@ void joined_cb(void)
{
current_join_retries = 0;

puts("ls-ed: successfully joined to the network");
puts("[LoRa] successfully joined to the network");
blink_led();
}

void appdata_send_failed_cb(void)
{
if (!unwds_get_node_settings().no_join) {
puts("ls-ed: application data confirmation timeout. Rejoining...");
puts("[LoRa] rejoining");
// joined_timeout_cb();
ls_ed_join(&ls);
} else
puts("ls-ed: failed to send confirmed application data");
puts("[LoRa] failed to send confirmed application data");
}

static bool appdata_received_cb(uint8_t *buf, size_t buflen)
Expand All @@ -143,7 +143,7 @@ static bool appdata_received_cb(uint8_t *buf, size_t buflen)

bytes_to_hex(buf, buflen, hex, false);

printf("ls-ed: received data: \"%s\"\n", hex);
printf("[LoRa] received data: \"%s\"\n", hex);
blink_led();

if (buflen < 2) {
Expand All @@ -164,17 +164,21 @@ static bool appdata_received_cb(uint8_t *buf, size_t buflen)
module_data_t reply = {};

/* Send app. data */
if (!unwds_send_to_module(modid, &cmd, &reply)) {
int result = unwds_send_to_module(modid, &cmd, &reply);

if (result == UNWDS_MODULE_NOT_FOUND) {
/* No module with specified ID present */
reply.as_ack = true;
reply.length = 2;
reply.data[0] = UNWDS_MODULE_NOT_FOUND;
reply.data[1] = modid;
}

int res = ls_ed_send_app_data(&ls, reply.data, reply.length, true, true);
if (res < 0) {
printf("send: error #%d\n", res);
if (result != UNWDS_MODULE_NO_DATA) {
int res = ls_ed_send_app_data(&ls, reply.data, reply.length, true, true, false);
if (res < 0) {
printf("send: error #%d\n", res);
}
}

/* Don't allow to send app. data ACK by the network.
Expand All @@ -188,7 +192,7 @@ static bool broadcast_appdata_received_cb(uint8_t *buf, size_t buflen) {

bytes_to_hex(buf, buflen, hex, false);

printf("ls-ed: received broadcast data: \"%s\"\n", hex);
printf("[LoRa] received broadcast data: \"%s\"\n", hex);
blink_led();

if (buflen < 2) {
Expand Down Expand Up @@ -617,7 +621,7 @@ shell_command_t shell_commands[UNWDS_SHELL_COMMANDS_MAX] = {

static void unwds_callback(module_data_t *buf)
{
int res = ls_ed_send_app_data(&ls, buf->data, buf->length, true, buf->as_ack);
int res = ls_ed_send_app_data(&ls, buf->data, buf->length, true, buf->as_ack, false);

if (res < 0) {
if (res == -LS_SEND_E_FQ_OVERFLOW) {
Expand Down
1 change: 0 additions & 1 deletion unwired-modules/umdk-adc/umdk-adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ int umdk_adc_shell_cmd(int argc, char **argv) {
}

if (strcmp(cmd, "send") == 0) {
is_polled = true;
/* Send signal to publisher thread */
msg_send(&timer_msg, timer_pid);
}
Expand Down
1 change: 0 additions & 1 deletion unwired-modules/umdk-bme280/umdk-bme280.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ int umdk_bme280_shell_cmd(int argc, char **argv) {
}

if (strcmp(cmd, "send") == 0) {
is_polled = true;
/* Send signal to publisher thread */
msg_send(&timer_msg, timer_pid);
}
Expand Down
1 change: 0 additions & 1 deletion unwired-modules/umdk-lmt01/umdk-lmt01.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ int umdk_lmt01_shell_cmd(int argc, char **argv) {
}

if (strcmp(cmd, "send") == 0) {
is_polled = true;
/* Send signal to publisher thread */
msg_send(&timer_msg, timer_pid);
}
Expand Down
1 change: 0 additions & 1 deletion unwired-modules/umdk-lps331/umdk-lps331.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ int umdk_lps331_shell_cmd(int argc, char **argv) {
}

if (strcmp(cmd, "send") == 0) {
is_polled = true;
/* Send signal to publisher thread */
msg_send(&timer_msg, timer_pid);
}
Expand Down
1 change: 0 additions & 1 deletion unwired-modules/umdk-mhz19/umdk-mhz19.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ int umdk_mhz19_shell_cmd(int argc, char **argv) {
char *cmd = argv[1];

if (strcmp(cmd, "send") == 0) {
is_polled = true;
mhz19_get(&mhz19);
}

Expand Down
1 change: 0 additions & 1 deletion unwired-modules/umdk-opt3001/umdk-opt3001.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ int umdk_opt3001_shell_cmd(int argc, char **argv) {
}

if (strcmp(cmd, "send") == 0) {
is_polled = true;
/* Send signal to publisher thread */
msg_send(&timer_msg, timer_pid);
}
Expand Down
1 change: 0 additions & 1 deletion unwired-modules/umdk-range/umdk-range.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ int umdk_range_shell_cmd(int argc, char **argv) {
}

if (strcmp(cmd, "send") == 0) {
is_polled = true;
/* Send signal to publisher thread */
msg_send(&timer_msg, timer_pid);
}
Expand Down
1 change: 0 additions & 1 deletion unwired-modules/umdk-sht21/umdk-sht21.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ int umdk_sht21_shell_cmd(int argc, char **argv) {
}

if (strcmp(cmd, "send") == 0) {
is_polled = true;
/* Send signal to publisher thread */
msg_send(&timer_msg, timer_pid);
}
Expand Down

0 comments on commit f8dee1b

Please sign in to comment.