Alarm generator, transmitter side

Dependencies:   sx12xx_hal

radio chip selection

Radio chip driver is not included, allowing choice of radio device.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.

This is transmitter project; Receiver side is Alarm Slave project.
This project generates alarm (transmits) from grounding certain pins.
To find the actual pins used, refer to the code where pin[A-D] is declared as DigitalIn.

Alarm message is sent N times with future timestamp indicating when alarm is to occur. This accommodates dropped packets, resulting in alarm occurring when as few as 1 packet is received.

Revision:
2:0b7620bda2c9
Parent:
1:3199506bc2e5
Child:
3:d8b57eca8c45
--- a/main.cpp	Thu Aug 31 23:15:04 2017 +0000
+++ b/main.cpp	Fri Sep 01 23:03:35 2017 +0000
@@ -106,7 +106,47 @@
             ;
     }
 }
- 
+
+void cmd_op(int dbm)
+{
+    int i = dbm;
+    RegPdsTrim1_t pds_trim;
+    uint8_t adr;
+    if (radio.type == SX1276)
+        adr = REG_PDSTRIM1_SX1276;
+    else
+        adr = REG_PDSTRIM1_SX1272;
+       
+    pds_trim.octet = radio.read_reg(adr);   
+
+    if (radio.RegPaConfig.bits.PaSelect) {
+        /* PABOOST used: +2dbm to +17, or +20 */
+        if (i == 20) {
+            printf("+20dBm PADAC bias\r\n");
+            i -= 3;
+            pds_trim.bits.prog_txdac = 7;
+            radio.write_reg(adr, pds_trim.octet);
+        }
+        if (i > 1)
+                radio.RegPaConfig.bits.OutputPower = i - 2;
+    } else {
+        /* RFO used: -1 to +14dbm */
+        if (i < 15)
+            radio.RegPaConfig.bits.OutputPower = i + 1;
+    }
+    radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
+
+    radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
+    if (radio.RegPaConfig.bits.PaSelect) {
+        printf("PA_BOOST ");
+        dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
+    } else {
+        printf("RFO ");
+        dbm = radio.RegPaConfig.bits.OutputPower - 1;
+    }
+    printf("OutputPower:%ddBm\r\n", dbm);
+}
+
 int main()
 {
     printf("\r\nreset-tx\r\n");
@@ -135,10 +175,12 @@
             radio.RegPaConfig.bits.PaSelect = 1;
         else
             radio.RegPaConfig.bits.PaSelect = 0;
+        cmd_op(20);
     } else {
         /* MAS shield board, only RFO TX */
         radio.RegPaConfig.bits.PaSelect = 0;
         printf("MAS\r\n");
+        cmd_op(14);
     }
     rfsw.output();
     radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);