wayne roberts / Mbed OS utility_sx12xx

Files at this revision

API Documentation at this revision

Comitter:
dudmuck
Date:
Mon Aug 05 20:07:16 2024 +0000
Parent:
14:14b9e1c08bfc
Commit message:
add reading of RSSI

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
radio.h Show annotated file Show diff for this revision Revisions of this file
radio_lr1110.cpp Show annotated file Show diff for this revision Revisions of this file
radio_sx126x.cpp Show annotated file Show diff for this revision Revisions of this file
radio_sx127x.cpp Show annotated file Show diff for this revision Revisions of this file
radio_sx128x.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/main.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -3,6 +3,13 @@
 
 //#define MENU_DEBUG
 
+#ifdef TARGET_NUCLEO_L073RZ
+BufferedSerial logpc(PC_10, PC_11, 115200);
+#else
+    //#error log_uart_for_target
+#endif
+void logpc_printf(const char* format, ...);
+
 static BufferedSerial pc(USBTX, USBRX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
 namespace mbed {
 	FileHandle *mbed_override_console(int fd) {
@@ -284,6 +291,12 @@
 }
 const button_item_t tx_preamble_item = { _ITEM_BUTTON, "TX_PREAMBLE", tx_preamble_push };
 
+void get_rssi_push()
+{
+    Radio::get_rssi();
+}
+const button_item_t get_rssi_item = { _ITEM_BUTTON, "GET_RSSI", get_rssi_push };
+
 const value_item_t sweep_start_item = { _ITEM_VALUE, 5, sweep_start_print, sweep_start_write};
 const value_item_t sweep_step_item = { _ITEM_VALUE, 5, sweep_step_print, sweep_step_write};
 const value_item_t sweep_stop_item = { _ITEM_VALUE, 5, sweep_stop_print, sweep_stop_write};
@@ -299,6 +312,7 @@
     { {LAST_CHIP_MENU_ROW+3, 10},                 NULL,            &rx_pkt_item, FLAG_MSGTYPE_PKT },
     { {LAST_CHIP_MENU_ROW+3, 20},                 NULL,        &tx_carrier_item, FLAG_MSGTYPE_PKT, &opmode_item },
     { {LAST_CHIP_MENU_ROW+3, 45},                 NULL,       &tx_preamble_item, FLAG_MSGTYPE_PKT, &opmode_item },
+    { {LAST_CHIP_MENU_ROW+3, 58},                 NULL,          &get_rssi_item, FLAG_MSGTYPE_PKT, &opmode_item },
     { {LAST_CHIP_MENU_ROW+4,  1},    "cf sweep start:",       &sweep_start_item, FLAG_MSGTYPE_PKT },
     { {LAST_CHIP_MENU_ROW+4, 28},              "step:",        &sweep_step_item, FLAG_MSGTYPE_PKT },
     { {LAST_CHIP_MENU_ROW+4, 45},              "stop:",        &sweep_stop_item, FLAG_MSGTYPE_PKT },
@@ -803,6 +817,7 @@
 
 void navigate_menu(uint8_t ch)
 {
+    //logpc_printf("navigate_menu %c\r\n", ch);
     read_menu_item(menu_table[curpos.row][curpos.tableCol], false);
 
     switch (ch) {
@@ -1415,6 +1430,8 @@
     curpos.tableCol = 0;
 
     tx_ipd_ms = 100;
+
+    logpc_printf("\r\nRESET\r\n");
     
     for (;;) {
         if (pc.readable()) {
@@ -1490,3 +1507,17 @@
     pc.sync();
 }
 
+void logpc_printf(const char* format, ...)  /* printing on 2nd uart */
+{
+    int len;
+    va_list arglist;
+
+    va_start(arglist, format);
+    len = vsprintf(strbuf, format, arglist);
+    va_end(arglist);
+
+    //logpc.write(strbuf, len);
+    
+    fflush(stdout);
+    pc.sync();
+}
--- a/radio.h	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio.h	Mon Aug 05 20:07:16 2024 +0000
@@ -139,6 +139,7 @@
         static void readChip(void);
         static void tx_carrier(void);
         static void tx_preamble(void);
+        static void get_rssi(void);
         static void txPkt(void);
         static void Rx(void);
         static void setFS(void);
--- a/radio_lr1110.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio_lr1110.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -488,6 +488,15 @@
     print_stat(stat);
 }
 
+void Radio::get_rssi()
+{
+    stat_t stat;
+    uint8_t buf;
+    stat.word = radio.xfer(OPCODE_GET_RSSI_INST, 0, 0, NULL);
+    stat.word = radio.xfer(0x0000, 0, 1, &buf); 
+    log_printf("-%0.1f dBm\r\n", buf/2.0);   
+}
+
 void Radio::print_stat(stat_t stat)
 {
     char out[96];
--- a/radio_sx126x.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio_sx126x.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -328,6 +328,13 @@
     radio.xfer(OPCODE_SET_TX_PREAMBLE, 0, 0, NULL);
 }
 
+void Radio::get_rssi()
+{
+    uint8_t buf[3];
+    radio.xfer(OPCODE_GET_RSSIINST, 0, 3, buf);
+    log_printf("-%0.1f dBm\r\n", buf[1]/2.0);
+}
+
 void Radio::txPkt()
 {
     uint8_t txlen = get_payload_length();
--- a/radio_sx127x.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio_sx127x.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -181,6 +181,20 @@
     }
 }
 
+void Radio::get_rssi()
+{
+    //uint8_t buf[3];
+    //radio.xfer(OPCODE_GET_RSSIINST, 0, 3, buf);
+    //log_printf("-%0.1f dBm\r\n", buf[1]/2.0);
+    if (radio.RegOpMode.bits.LongRangeMode) {
+        log_printf("lora rssi %d dBm", lora.get_current_rssi());
+        //REG_LR_RSSIVALUE
+    } else {
+        uint8_t v = radio.read_reg(REG_FSK_RSSIVALUE);
+        log_printf("-%0.1f dBm\r\n", v/2.0);
+    }
+}
+
 bool Radio::service(int8_t statusRow)
 {
     bool ret = false;
@@ -697,7 +711,7 @@
 
 void Radio::fsk_ook_bps_print(void)
 {
-    printf("%lu", fsk.get_bitrate());
+    printf("%u", fsk.get_bitrate());
 }
 
 bool Radio::fsk_ook_bps_write(const char* txt)
@@ -714,7 +728,7 @@
 
 void Radio::gfsk_fdev_print(void)
 {
-    printf("%lu", fsk.get_tx_fdev_hz());
+    printf("%u", fsk.get_tx_fdev_hz());
 
 }
 
--- a/radio_sx128x.cpp	Thu Sep 16 21:57:23 2021 +0000
+++ b/radio_sx128x.cpp	Mon Aug 05 20:07:16 2024 +0000
@@ -561,6 +561,14 @@
     chipModeChange();
 }
 
+void Radio::get_rssi()
+{
+    uint8_t buf[3];
+    radio.xfer(OPCODE_GET_RSSIINST, 0, 3, buf);
+    log_printf("-%0.1f dBm\r\n", buf[1]/2.0);
+}
+
+
 void Radio::rngTx()
 {
     IrqFlags_t irqEnable;