Skip to content

Commit

Permalink
Rework AT commands
Browse files Browse the repository at this point in the history
  • Loading branch information
beegee-tokyo committed Dec 24, 2023
1 parent 9c503bf commit 9427ead
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Arduino library for RAKWireless WisBlock Core modules that takes all the LoRaWAN

# Release Notes

## 2.0.17 Rework AT commands
- Make AT+PBW and AT+P2P compatible with WisToolBox

## 2.0.16 Add Arduino-Pico support
- Support RAK11300 with Arduino-Pico BSP

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,8 @@ AT Command functions: Taylor Lee ([email protected])
# Changelog
[Code releases](CHANGELOG.md)

- 2023-12-24 Rework AT commands
- Make AT+PBW and AT+P2P compatible with WisToolBox
- 2023-12-19 Add Arduino-Pico support
- Support RAK11300 with Arduino-Pico BSP
- 2023-12-07 Fix ESP32
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "WisBlock-API-V2",
"version": "2.0.16",
"version": "2.0.17",
"keywords": [
"lora",
"Semtech",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=WisBlock-API-V2
version=2.0.16
version=2.0.17
author=Bernd Giesecke <[email protected]>
maintainer=Bernd Giesecke <[email protected]>
sentence=API for WisBlock Core module
Expand Down
85 changes: 73 additions & 12 deletions src/at_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void set_new_config(void)
g_lorawan_settings.p2p_cr, 0, g_lorawan_settings.p2p_preamble_len,
g_lorawan_settings.p2p_symbol_timeout, false,
0, true, 0, 0, false, g_rx_continuous);

// Radio.Rx(0);
}

Expand Down Expand Up @@ -335,7 +335,7 @@ static int at_exec_p2p_sf(char *str)
*/
static int at_query_p2p_bw(void)
{
snprintf(g_at_query_buf, ATQUERY_SIZE, "%s", bandwidths[g_lorawan_settings.p2p_bandwidth]);
snprintf(g_at_query_buf, ATQUERY_SIZE, "%d", g_lorawan_settings.p2p_bandwidth); //%s", bandwidths[g_lorawan_settings.p2p_bandwidth]);
return AT_SUCCESS;
}

Expand All @@ -351,11 +351,29 @@ static int at_exec_p2p_bw(char *str)
{
return AT_ERRNO_NOALLOW;
}
for (int idx = 0; idx < 10; idx++)

/// \todo backward compatible to old BW AT command
long req_bw = strtol(str, NULL, 0);

if (req_bw > 10)
{
for (int idx = 0; idx < 10; idx++)
{
if (strcmp(str, bandwidths[idx]) == 0)
{
g_lorawan_settings.p2p_bandwidth = idx;
save_settings();

set_new_config();
return AT_SUCCESS;
}
}
}
else
{
if (strcmp(str, bandwidths[idx]) == 0)
if ((req_bw >= 0) && (req_bw <= 9))
{
g_lorawan_settings.p2p_bandwidth = idx;
g_lorawan_settings.p2p_bandwidth = req_bw;
save_settings();

set_new_config();
Expand Down Expand Up @@ -483,10 +501,17 @@ static int at_exec_p2p_txp(char *str)
*/
static int at_query_p2p_config(void)
{
snprintf(g_at_query_buf, ATQUERY_SIZE, "%ld:%d:%s:%d:%d:%d",
// snprintf(g_at_query_buf, ATQUERY_SIZE, "%ld:%d:%s:%d:%d:%d",
// g_lorawan_settings.p2p_frequency,
// g_lorawan_settings.p2p_sf,
// bandwidths[g_lorawan_settings.p2p_bandwidth],
// g_lorawan_settings.p2p_cr - 1,
// g_lorawan_settings.p2p_preamble_len,
// g_lorawan_settings.p2p_tx_power);
snprintf(g_at_query_buf, ATQUERY_SIZE, "%ld:%d:%d:%d:%d:%d",
g_lorawan_settings.p2p_frequency,
g_lorawan_settings.p2p_sf,
bandwidths[g_lorawan_settings.p2p_bandwidth],
g_lorawan_settings.p2p_bandwidth,
g_lorawan_settings.p2p_cr - 1,
g_lorawan_settings.p2p_preamble_len,
g_lorawan_settings.p2p_tx_power);
Expand Down Expand Up @@ -540,14 +565,36 @@ static int at_exec_p2p_config(char *str)
if (param != NULL)
{
bool found_bw = false;
for (int idx = 0; idx < 10; idx++)
/// \todo backward compatible to old BW AT command
long req_bw = strtol(param, NULL, 0);
if (req_bw > 10)
{
if (strcmp(param, bandwidths[idx]) == 0)
for (int idx = 0; idx < 10; idx++)
{
g_lorawan_settings.p2p_bandwidth = idx;
if (strcmp(str, bandwidths[idx]) == 0)
{
g_lorawan_settings.p2p_bandwidth = idx;
found_bw = true;
}
}
}
else
{
if ((req_bw >= 0) && (req_bw <= 9))
{
g_lorawan_settings.p2p_bandwidth = req_bw;
found_bw = true;
}
}
// bool found_bw = false;
// for (int idx = 0; idx < 10; idx++)
// {
// if (strcmp(param, bandwidths[idx]) == 0)
// {
// g_lorawan_settings.p2p_bandwidth = idx;
// found_bw = true;
// }
// }
if (!found_bw)
{
return AT_ERRNO_PARA_VAL;
Expand Down Expand Up @@ -1796,10 +1843,24 @@ static int at_query_status(void)
AT_PRINTF("ATC+STATUS=?");
at_settings();
snprintf(g_at_query_buf, ATQUERY_SIZE, " ");
AT_PRINTF("OK");

return AT_CB_PRINT;
}

static int at_exec_status(void)
{
// at_query_status();
at_settings();
return AT_SUCCESS;

// AT_PRINTF("ATC+STATUS=?");
// at_settings();
// snprintf(g_at_query_buf, ATQUERY_SIZE, " ");

// return AT_CB_PRINT;
}

/**
* @brief ATR Restore flash defaults
*
Expand Down Expand Up @@ -1858,7 +1919,7 @@ static int at_exec_dfu(void)
#ifdef ARDUINO_ARCH_RP2040
// No support for OTA DFU
#endif
return AT_SUCCESS;
return AT_SUCCESS;
}

/** Application build time */
Expand Down Expand Up @@ -2352,7 +2413,7 @@ static atcmd_t g_at_cmd_list[] = {
{"+LSTMULC", "Get multicast status", at_query_lstmulc, NULL, NULL, "R"},
// Custom AT commands
{"+DFU", "Force OTA DFU mode", NULL, NULL, at_exec_dfu, "R"},
{"+STATUS", "Status, Show LoRaWAN status", at_query_status, NULL, NULL, "R"},
{"+STATUS", "Status, Show LoRaWAN status", at_query_status, NULL, at_exec_status, "R"},
{"+SENDINT", "Send interval, Get or Set the automatic send interval", at_query_sendint, at_exec_sendint, NULL, "RW"},
{"+PORT", "Get or Set the Port=[1..223]", at_query_port, at_exec_port, NULL, "RW"},
{"+PRD_INFO", "Get product info", at_query_info, NULL, NULL, "R"},
Expand Down

0 comments on commit 9427ead

Please sign in to comment.