SCPI interface to SX1272 and SX1276

Dependencies:   SX127x lib_gps lib_mma8451q lib_mpl3115a2 lib_sx9500 libscpi mbed

Description

This program implements a SCPI command parser. When connected via the debug virtual comm port, you can command the radio and peripherals to perform specific tasks or to set specific parameters. The serial port defaults to 9600bps N-8-1.

Example

The following exampling causes the NA Mote to transmit a continuous LoRa signal.

Example SCPI Commands

*IDN?
RA:MOD LORA
RA:FREQ 903
RA:PAS PA_BOOST
RA:OCP 170
RA:BGR 7
RA:POW 15
RA:LORA:TXContinuous ON
RA:FI "test"

Commands

SCPI is case-insensitive. Commands can be entered lower case.

  • RAdio
    • :FIfo "text" write to fifo, and transmit packet
    • :FIfo? read from fifo (last received packet)
    • :REGister { address }, {value} write radio register (SCPI takes #H for hex prefix)
    • :REGister? { address } read radio register (SCPI takes #H for hex prefix)
    • :MODulation { FSK | OOK | LORa } set modem type
    • :MODulation? get modem type
    • :OPmode { SLE | STB | FST | TX | FSR | RXC | RXS | CAD } set mode
    • :OPmode? get mode
    • :DIOMap { 0 - 5 }, { 0 - 3 } set DIO pin function {pin number}, {map value}
    • :DIOMap? { 0 - 5 } get DIO pin function {pin number}
    • :DIO? { 0 - 5 } read DIO pin level
    • :RSSI? read received signal strength (if in RXC mode)
    • :PASelect { RFO | PA_BOOST } set RF output pin
    • :PASelect? get RF output pin selected
    • :OCP {mA} set over current protection
    • :OCP? read current limit
    • :POWer {0 to 15} set OutputPower
    • :POWer? get OutputPower
    • :BGR { 0 - 7 } set PA ref current
    • :BGR? get PA ref current
    • :FREQuency {MHz} set FRF
    • :FREQuency? get FRF
    • :LNABoost { OFF | ON } set LNA boost
    • :LNABoost? get LNA boost
    • :LORa
      • :BW {KHz} set lora bandwidth
      • :BW? get lora bandwidth (in KHz)
      • :SF {7 to 12} set spreading factor
      • :SF? get spreading factor
      • :TXContinuous { OFF | ON } set continuous TX (end transmit by turning off)
      • :TXContinuous? get continuous TX
      • :PRELen {n-symbols} set preamble length
      • :PRELen? get preamble length
      • :CR {0-4} set coding rate
      • :CR? get coding rate
      • :LDRO { OFF | ON } set LowDataRateOptimize bit
      • :LDRO? get LowDataRateOptimize bit
      • :CRC { OFF | ON} enable CRC in transmitted packet
      • :CRC? read CRC enabled state
      • :INVRx { OFF | ON } enable receiver spectral invert
      • :INVRx? get receiver inversion state
      • :INVTx { OFF | ON } enable transmitter spectral invert
      • :INVTx? get transmitter inversion state
      • :FEI? get frequency error of last received packet
      • :PKTSnr? get S/N (dB) of last received packet
    • :FSK
      • :DATAMode { CONT | PKT } select continuous/packet mode
      • :DATAMode? get packet mode / continuous
      • :FDev {Hz} set TX frequency deviation
      • :FDev? get TX frequency deviation
      • :BITRate {bps} set bit rate
      • :BITRate? get bit rate
      • :BT { 1.0 | 0.5 | 0.3 | 0.0 } set transmit shaping
      • :BT? get transmit shaping
      • :PRELen {n} set preamble size
      • :PRELen? get preamble size
      • :RXBW {Hz} set receive bandwidth
      • :RXBW? set receive bandwidth
      • :AFCBW {Hz} set receive bandwidth (during preamble)
      • :AFCBW? set receive bandwidth (during preamble)
      • :DCFree { OFF | MAN | WHIT } set DC-free encoding
      • :DCFree? get DC-free encoding
      • :RXTrigger { OFF | RSSI | PRE | BOTH } set RX trigger mode
      • :RXTrigger? get RX trigger selection

radio events

Radio events are reported into the Questionable Data Status Event Register, which is summarized in Bit 3 (QSB) of Status Byte Register.

enabling event and reading event

RA:MOD?
"LORa"
RA:OP?
"RXC"
STAT:QUES:ENAB 512
*STB?
8
STAT:QUES:EVEN?
512
RA:FI?
"4747474747474747"
*STB?
0

Bit 9 of QUEStionable event register indicates DIO0 event occurred upon radio packet reception.

NA Mote-72 specific commands

  • PD2 { OFF | ON } set power amplifier voltage state
  • PD2? get power amplifier voltage state
  • VBAT? read battery voltage
  • GPS
    • :EN { OFF | ON } enable GPS
    • :EN? get GPS enabled state
    • :NUMCoords {n} set count of coordinates received (use to clear count)
    • :NUMCoords? get count of coordinates received
    • :LOngitude {n} set longitude
    • :LOngitude? get longitude
    • :LAtitude {n} set latitude
    • :LAtitude? get latitude
  • MMA MMA8451Q
    • :ID? read ID register (WHO_AM_I == 0x1a)
  • MPL MPL3115A2
    • :ID? read ID register (WHO_AM_I == 0xc4)
  • SX9500
    • :RST reset SX9500
    • :REGister {addr}, {value} write SX9500 register
    • :REGister? {addr} read SX9500 register
Revision:
2:547cc73f8887
Parent:
1:33d322ad66b1
Child:
3:ab152c7086b4
diff -r 33d322ad66b1 -r 547cc73f8887 scpi-def.cpp
--- a/scpi-def.cpp	Fri Aug 14 01:43:32 2015 +0000
+++ b/scpi-def.cpp	Tue Aug 18 00:51:59 2015 +0000
@@ -18,7 +18,11 @@
 #define RADIO_SCLK               PB_13 //NorAm_Mote  SPI2 Clk
 #define RADIO_NSS                PB_12 //NorAm_Mote SPI2 Nss
 #define RADIO_DIO_0              PC_6 //NorAm_Mote DIO0 
-#define RADIO_DIO_1              PC_10 //NorAm_Mote DIO1 
+#define RADIO_DIO_1              PC_10 //NorAm_Mote DIO1
+#define RADIO_DIO_2              PC_8 //NorAm_Mote DIO2 
+#define RADIO_DIO_3              PB_4 //NorAm_Mote DIO3 
+#define RADIO_DIO_4              PB_5 //NorAm_Mote DIO4 
+#define RADIO_DIO_5              PB_6 //NorAm_Mote DIO5
 //             mosi,      miso,      sclk,       cs,        rst,        dio0,         dio1
 SX127x radio(RADIO_MOSI, RADIO_MISO, RADIO_SCLK, RADIO_NSS, RADIO_RESET, RADIO_DIO_0, RADIO_DIO_1);
 
@@ -57,6 +61,11 @@
 
 DigitalOut pd2(PD_2);
 
+DigitalIn dio2_pin(RADIO_DIO_2);
+DigitalIn dio3_pin(RADIO_DIO_3);
+DigitalIn dio4_pin(RADIO_DIO_4);
+DigitalIn dio5_pin(RADIO_DIO_5);
+
 #else // sx1276 shield...
 //  pin:       3     8     1      7    10    12     5
 //           mosi, miso, sclk,   cs,  rst,  dio0, dio1
@@ -76,6 +85,11 @@
         rfsw = 0;
 }
 
+DigitalIn dio2_pin(D4);
+DigitalIn dio3_pin(D5);
+DigitalIn dio4_pin(A3);
+DigitalIn dio5_pin(D9);
+
 #endif /* !TARGET_MOTE_L152RC */
 
 SX127x_fsk fsk(radio);
@@ -83,6 +97,12 @@
 
 volatile bool tx_busy = false;
 
+bool is_lora()
+{
+    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
+    return radio.RegOpMode.bits.LongRangeMode;
+}
+
 void
 service_radio()
 {
@@ -194,8 +214,7 @@
 {
     int idx;
     
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode) {
+    if (is_lora()) {
         idx = 2;    // lora
     } else {
         if (radio.RegOpMode.bits.ModulationType)
@@ -215,8 +234,7 @@
     if (!SCPI_ParamInt(context, &i, TRUE))
         return SCPI_RES_ERR;
             
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())
         return SCPI_RES_ERR;
         
     fsk.set_tx_fdev_hz(i);
@@ -225,14 +243,162 @@
 
 scpi_result_t fsk_fdevQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())
         return SCPI_RES_ERR;
         
     SCPI_ResultInt(context, fsk.get_tx_fdev_hz());    
     return SCPI_RES_OK;      
 }
 
+const scpi_choice_def_t rxtrigs[] = {
+    { "OFF", 0 },
+    { "RSSI", 1 },
+    { "PRE", 6 },        
+    { "BOTH", 7 },          
+    SCPI_CHOICE_LIST_END
+};
+
+scpi_result_t fsk_rxtrig(scpi_t* context)
+{
+    int32_t value;
+    
+    if (is_lora())
+        return SCPI_RES_ERR;
+        
+    if (!SCPI_ParamChoice(context, rxtrigs, &value, TRUE))
+        return SCPI_RES_ERR;           
+        
+    fsk.RegRxConfig.octet = radio.read_reg(REG_FSK_RXCONFIG);       
+    fsk.RegRxConfig.bits.RxTrigger = value;
+    radio.write_reg(REG_FSK_RXCONFIG, fsk.RegRxConfig.octet);
+    return SCPI_RES_OK;
+}
+
+scpi_result_t fsk_rxtrigQ(scpi_t* context)
+{
+    int idx;
+    
+    if (is_lora())
+        return SCPI_RES_ERR;    
+        
+    fsk.RegRxConfig.octet = radio.read_reg(REG_FSK_RXCONFIG);
+    idx = fsk.RegRxConfig.bits.RxTrigger;
+    SCPI_ResultText(context, rxtrigs[idx].name);
+    return SCPI_RES_OK;             
+}
+
+scpi_result_t fsk_bt(scpi_t* context)
+{
+    double bt;    
+    
+    if (is_lora())
+        return SCPI_RES_ERR;        
+    
+    if (!SCPI_ParamDouble(context, &bt, TRUE))
+        return SCPI_RES_ERR; 
+                
+    if (bt < 0.2)                
+        radio.RegOpMode.bits.ModulationShaping = 0; // no shaping
+    else if (bt < 0.4)
+        radio.RegOpMode.bits.ModulationShaping = 3; // BT0.3  (most shaping)
+    else if (bt < 0.9)
+        radio.RegOpMode.bits.ModulationShaping = 2; // BT0.5
+    else
+        radio.RegOpMode.bits.ModulationShaping = 1; // BT1.0
+        
+    radio.write_reg(REG_OPMODE, radio.RegOpMode.octet);       
+    return SCPI_RES_OK;    
+}
+
+scpi_result_t fsk_btQ(scpi_t* context)
+{
+    double bt;
+    
+    if (is_lora())
+        return SCPI_RES_ERR;        
+        
+    switch (radio.RegOpMode.bits.ModulationShaping) {
+        case 0: bt = 0.0; break;
+        case 1: bt = 1.0; break;
+        case 2: bt = 0.5; break;
+        case 3: bt = 0.3; break;
+    }
+    
+    SCPI_ResultDouble(context, bt);
+    return SCPI_RES_OK;    
+}
+
+const scpi_choice_def_t datamodes[] = {
+    { "CONT", 0 },
+    { "PKT", 1 },       
+    SCPI_CHOICE_LIST_END
+};
+
+scpi_result_t fsk_datamode(scpi_t* context)
+{
+    int32_t value;
+    
+    if (!SCPI_ParamChoice(context, datamodes, &value, TRUE))
+        return SCPI_RES_ERR;
+            
+    if (is_lora())
+        return SCPI_RES_ERR;  
+             
+    fsk.RegPktConfig2.word = radio.read_u16(REG_FSK_PACKETCONFIG2);
+    fsk.RegPktConfig2.bits.DataModePacket = value;
+    radio.write_reg(REG_FSK_PACKETCONFIG2, fsk.RegPktConfig2.word);
+    return SCPI_RES_OK;
+}
+
+scpi_result_t fsk_datamodeQ(scpi_t* context)
+{
+    int idx;
+    
+    if (is_lora())
+        return SCPI_RES_ERR;       
+    
+    fsk.RegPktConfig2.word = radio.read_u16(REG_FSK_PACKETCONFIG2);
+    idx = fsk.RegPktConfig2.bits.DataModePacket;    
+    SCPI_ResultText(context, datamodes[idx].name);
+    return SCPI_RES_OK;
+}
+  
+const scpi_choice_def_t dcfrees[] = {
+    { "OFF", 0 },
+    { "MAN", 1 },
+    { "WHIT", 2 },        
+    SCPI_CHOICE_LIST_END
+};
+
+scpi_result_t fsk_dcfree(scpi_t* context)
+{
+    int32_t value;
+        
+    if (is_lora())
+        return SCPI_RES_ERR;    
+   
+    if (!SCPI_ParamChoice(context, dcfrees, &value, TRUE))
+        return SCPI_RES_ERR;        
+        
+    fsk.RegPktConfig1.octet = radio.read_reg(REG_FSK_PACKETCONFIG1);        
+    fsk.RegPktConfig1.bits.DcFree = value;
+    radio.write_reg(REG_FSK_PACKETCONFIG1, fsk.RegPktConfig1.octet);
+    return SCPI_RES_OK;    
+}
+
+scpi_result_t fsk_dcfreeQ(scpi_t* context)
+{
+    int idx;
+    
+    if (is_lora())
+        return SCPI_RES_ERR;
+        
+    fsk.RegPktConfig1.octet = radio.read_reg(REG_FSK_PACKETCONFIG1);        
+    idx = fsk.RegPktConfig1.bits.DcFree ;
+    SCPI_ResultText(context, dcfrees[idx].name);
+    return SCPI_RES_OK;
+}
+
 scpi_result_t fsk_rxbw(scpi_t* context)
 {
     int32_t i;
@@ -240,8 +406,7 @@
     if (!SCPI_ParamInt(context, &i, TRUE))
         return SCPI_RES_ERR; 
         
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())
         return SCPI_RES_ERR;
         
     fsk.set_rx_dcc_bw_hz(i, 0);
@@ -250,8 +415,7 @@
 
 scpi_result_t fsk_rxbwQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())
         return SCPI_RES_ERR;    
         
     SCPI_ResultInt(context, fsk.get_rx_bw_hz(REG_FSK_RXBW));    
@@ -265,8 +429,7 @@
     if (!SCPI_ParamInt(context, &i, TRUE))
         return SCPI_RES_ERR; 
         
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())        
         return SCPI_RES_ERR;
         
     fsk.set_rx_dcc_bw_hz(i, 1);
@@ -275,8 +438,7 @@
 
 scpi_result_t fsk_afcbwQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())    
         return SCPI_RES_ERR;    
         
     SCPI_ResultInt(context, fsk.get_rx_bw_hz(REG_FSK_AFCBW));    
@@ -290,8 +452,7 @@
     if (!SCPI_ParamInt(context, &i, TRUE))
         return SCPI_RES_ERR;
             
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())            
         return SCPI_RES_ERR;    
         
     fsk.set_bitrate(i);
@@ -300,8 +461,7 @@
 
 scpi_result_t fsk_bitrateQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())    
         return SCPI_RES_ERR;    
     
     SCPI_ResultInt(context, fsk.get_bitrate());    
@@ -315,8 +475,7 @@
     if (!SCPI_ParamInt(context, &i, TRUE))
         return SCPI_RES_ERR;
         
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())        
         return SCPI_RES_ERR;     
         
     radio.write_u16(REG_FSK_PREAMBLEMSB, i); 
@@ -325,8 +484,7 @@
 
 scpi_result_t fsk_prelenQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())    
         return SCPI_RES_ERR;     
         
     SCPI_ResultInt(context, radio.read_u16(REG_FSK_PREAMBLEMSB) );    
@@ -336,23 +494,22 @@
 scpi_result_t fsk_sync(scpi_t* context)
 {
     char buffer[100];
-    size_t copy_len;
-    int len, i;
+    size_t _copy_len, _len, i;
     uint8_t addr;
     uint8_t sync_size;
         
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())        
         return SCPI_RES_ERR;
         
-    buffer[0] = 0;
-    SCPI_ParamCopyText(context, buffer, 100, &copy_len, false);
+    memset(buffer, 0, sizeof(buffer));    
+    SCPI_ParamCopyText(context, buffer, 100, &_copy_len, false);
+    for (_len = 0; buffer[_len] != 0; _len++)
+        ;  
    
     fsk.RegSyncConfig.octet = radio.read_reg(REG_FSK_SYNCCONFIG);
-    len = strlen(buffer);
     sync_size = 0;
     addr = REG_FSK_SYNCVALUE1;
-    for (i = 0; i < len; i+=2) {
+    for (i = 0; i < _len; i+=2) {
         int o;
         sscanf(buffer+i, "%02x", &o);
         radio.write_reg(addr++, o);
@@ -372,8 +529,7 @@
     char txt[64];
     char *ptr = txt;
     
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode)
+    if (is_lora())    
         return SCPI_RES_ERR;
         
     fsk.RegSyncConfig.octet = radio.read_reg(REG_FSK_SYNCCONFIG);
@@ -395,7 +551,7 @@
     if (radio.RegOpMode.bits.Mode != RF_OPMODE_RECEIVER)
         return SCPI_RES_ERR;
 
-    if (radio.RegOpMode.bits.LongRangeMode) {
+    if (is_lora()) {
         reg_val = radio.read_reg(REG_LR_RSSIVALUE);    // 0x1b: dbm = -125 + regvalue
         SCPI_ResultDouble(context, -125 + reg_val);
     } else {
@@ -415,8 +571,7 @@
      if (!SCPI_ParamArbitraryBlock(context, &buf, &len, TRUE))
         return SCPI_RES_ERR; 
 
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode) {
+    if (is_lora()) {
         lora.RegPayloadLength = len;
         radio.write_reg(REG_LR_PAYLOADLENGTH, lora.RegPayloadLength);
         lora.start_tx(lora.RegPayloadLength);        
@@ -433,9 +588,8 @@
 {
     int len;
     const char* buf = (const char *)radio.rx_buf;
-        
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode) {
+
+    if (is_lora()) {
         len = lora.RegRxNbBytes;  
     } else {
         len = fsk.rx_buf_length;
@@ -454,8 +608,7 @@
     char txt[520];
     char *ptr = txt;
         
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode) {
+    if (is_lora()) {
         for (i = 0; i < lora.RegRxNbBytes; i++) {
             sprintf(ptr, "%02x", radio.rx_buf[i]);
             ptr += 2;
@@ -474,27 +627,27 @@
 scpi_result_t radio_fifo(scpi_t* context)
 {
     char buffer[100];
-    size_t copy_len, i;
+    size_t copy_len, i, len;
     
     if (tx_busy)
         return SCPI_RES_ERR;
                 
-    buffer[0] = 0;
+    memset(buffer, 0, sizeof(buffer));
     SCPI_ParamCopyText(context, buffer, 100, &copy_len, false);
 
-    //printf("TEXT: ***%s***\r\n", buffer);            
-    
-    for (i = 0; i < copy_len; i++)
+    for (len = 0; buffer[len] != 0; len++)
+        ;
+
+    for (i = 0; i < len; i++)
         radio.tx_buf[i] = buffer[i];
     
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (radio.RegOpMode.bits.LongRangeMode) {
-        lora.RegPayloadLength = copy_len;
+    if (is_lora()) {
+        lora.RegPayloadLength = len;
         radio.write_reg(REG_LR_PAYLOADLENGTH, lora.RegPayloadLength);
         lora.start_tx(lora.RegPayloadLength);        
     } else {
         /* fsk todo */
-        fsk.start_tx(copy_len);
+        fsk.start_tx(len);
     }    
     
     tx_busy = true;
@@ -506,8 +659,8 @@
     { "SLE", 0 },
     { "STB", 1 },
     { "FST", 2 },        
-    { "FSR", 3 },
-    { "TX", 4 },
+    { "TX", 3 },
+    { "FSR", 4 },
     { "RXC", 5 },       
     { "RXS", 6 },         
     { "CAD", 7 },         
@@ -723,6 +876,55 @@
     return SCPI_RES_OK;    
 }
 
+scpi_result_t radio_reg(scpi_t* context)
+{
+    int32_t addr, data;
+
+    if (!SCPI_ParamInt(context, &addr, TRUE))
+        return SCPI_RES_ERR;  
+        
+    if (!SCPI_ParamInt(context, &data, TRUE))
+        return SCPI_RES_ERR;  
+
+    radio.write_reg(addr, data);
+        
+    return SCPI_RES_OK;
+}
+
+scpi_result_t radio_regQ(scpi_t* context)
+{
+    int32_t addr;
+    
+    if (!SCPI_ParamInt(context, &addr, TRUE))
+        return SCPI_RES_ERR; 
+     
+    SCPI_ResultIntBase(context, radio.read_reg(addr), 16);
+    return SCPI_RES_OK;     
+}
+
+
+scpi_result_t radio_dioQ(scpi_t* context)
+{
+    int32_t dioN, value = -1;
+    
+    if (!SCPI_ParamInt(context, &dioN, TRUE))
+        return SCPI_RES_ERR;     
+        
+    switch (dioN) {
+        case 0: value = radio.dio0.read(); break;
+        case 1: value = radio.dio1.read(); break;
+        case 2: value = dio2_pin.read(); break;
+        case 3: value = dio3_pin.read(); break;
+        case 4: value = dio4_pin.read(); break;
+        case 5: value = dio5_pin.read(); break;
+        default:      
+            return SCPI_RES_ERR;          
+    } // ..switch (dioN)      
+    
+    SCPI_ResultInt(context, value);
+    return SCPI_RES_OK;    
+}
+
 scpi_result_t radio_freq(scpi_t* context)
 {
     double MHz;
@@ -747,9 +949,8 @@
     
     if (!SCPI_ParamInt(context, &i, TRUE))
         return SCPI_RES_ERR;
-            
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+
+    if (!is_lora())            
         return SCPI_RES_ERR;    
         
     lora.setCodingRate(i);
@@ -758,14 +959,84 @@
 
 scpi_result_t lora_crQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;    
 
      SCPI_ResultInt(context, lora.getCodingRate(false));
      return SCPI_RES_OK;   
 }  
 
+scpi_result_t lora_invrx(scpi_t* context)
+{
+    scpi_bool_t param1;
+    
+    if (!SCPI_ParamBool(context, &param1, TRUE))
+        return SCPI_RES_ERR;
+            
+    if (!is_lora())     
+        return SCPI_RES_ERR;   
+        
+    lora.invert_rx(param1);
+    return SCPI_RES_OK; 
+}
+
+scpi_result_t lora_invrxQ(scpi_t* context)
+{
+    if (!is_lora())     
+        return SCPI_RES_ERR;   
+        
+    lora.RegTest33.octet = radio.read_reg(REG_LR_TEST33);
+    SCPI_ResultBool(context, lora.RegTest33.bits.invert_i_q );
+    return SCPI_RES_OK;                
+}
+
+scpi_result_t lora_invtx(scpi_t* context)
+{
+    scpi_bool_t param1;
+    
+    if (!SCPI_ParamBool(context, &param1, TRUE))
+        return SCPI_RES_ERR;
+            
+    if (!is_lora())     
+        return SCPI_RES_ERR;  
+        
+    lora.invert_tx(param1);
+    return SCPI_RES_OK;           
+}
+
+scpi_result_t lora_invtxQ(scpi_t* context)
+{
+    if (!is_lora())     
+        return SCPI_RES_ERR;  
+        
+    lora.RegTest33.octet = radio.read_reg(REG_LR_TEST33);
+    SCPI_ResultBool(context, !lora.RegTest33.bits.chirp_invert_tx);        
+    return SCPI_RES_OK;    
+}
+
+scpi_result_t lora_crc(scpi_t* context)
+{
+    scpi_bool_t param1;
+    
+    if (!SCPI_ParamBool(context, &param1, TRUE))
+        return SCPI_RES_ERR;
+            
+    if (!is_lora())             
+        return SCPI_RES_ERR;       
+
+    lora.setRxPayloadCrcOn(param1);
+    return SCPI_RES_OK;    
+}
+
+scpi_result_t lora_crcQ(scpi_t* context)
+{
+    if (!is_lora())     
+        return SCPI_RES_ERR;   
+        
+    SCPI_ResultBool(context, lora.getRxPayloadCrcOn());
+    return SCPI_RES_OK;         
+}
+ 
 scpi_result_t lora_ih(scpi_t* context)
 {
     scpi_bool_t param1;
@@ -773,8 +1044,7 @@
     if (!SCPI_ParamBool(context, &param1, TRUE))
         return SCPI_RES_ERR;
             
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())             
         return SCPI_RES_ERR;    
 
     lora.setHeaderMode(param1);   
@@ -783,8 +1053,7 @@
 
 scpi_result_t lora_ihQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;     
         
     SCPI_ResultBool(context, lora.getHeaderMode());
@@ -797,9 +1066,8 @@
     
     if (!SCPI_ParamBool(context, &param1, TRUE))
         return SCPI_RES_ERR;
-            
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+
+    if (!is_lora())             
         return SCPI_RES_ERR; 
         
     if (radio.type == SX1272) {
@@ -820,8 +1088,7 @@
 {
     scpi_bool_t param1;
     
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;   
         
     if (radio.type == SX1272) {
@@ -841,8 +1108,7 @@
 {
     double KHz;
         
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())         
         return SCPI_RES_ERR;
         
     if (!SCPI_ParamDouble(context, &KHz, TRUE))
@@ -857,8 +1123,7 @@
     int bw;
     double khz;
     
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora()) 
         return SCPI_RES_ERR;
         
     bw = lora.getBw();
@@ -892,8 +1157,7 @@
 {
     int32_t i;
         
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())         
         return SCPI_RES_ERR;      
     
     if (!SCPI_ParamInt(context, &i, TRUE))
@@ -905,8 +1169,7 @@
 
 scpi_result_t lora_sfQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;    
         
      SCPI_ResultInt(context, lora.getSf());
@@ -915,8 +1178,7 @@
 
 scpi_result_t lora_feiQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;     
         
     SCPI_ResultInt(context, lora.get_freq_error_Hz());    
@@ -925,8 +1187,7 @@
 
 scpi_result_t lora_pktsnrQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;     
         
     SCPI_ResultDouble(context, lora.RegPktSnrValue / 4.0);
@@ -935,8 +1196,7 @@
 
 scpi_result_t lora_pktrssiQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;
         
     SCPI_ResultDouble(context, lora.get_pkt_rssi());
@@ -948,8 +1208,7 @@
 {
     int32_t i;
         
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())         
         return SCPI_RES_ERR;
     
     if (!SCPI_ParamInt(context, &i, TRUE))
@@ -962,8 +1221,7 @@
 
 scpi_result_t lora_prelenQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;
         
     lora.RegPreamble = radio.read_u16(REG_LR_PREAMBLEMSB);
@@ -975,8 +1233,7 @@
 {
     scpi_bool_t param1;
     
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;         
     
     if (!SCPI_ParamBool(context, &param1, TRUE))
@@ -991,8 +1248,7 @@
 
 scpi_result_t lora_txcQ(scpi_t* context)
 {
-    radio.RegOpMode.octet = radio.read_reg(REG_OPMODE);
-    if (!radio.RegOpMode.bits.LongRangeMode)
+    if (!is_lora())     
         return SCPI_RES_ERR;        
         
     lora.RegModemConfig2.octet = radio.read_reg(REG_LR_MODEMCONFIG2);        
@@ -1089,7 +1345,9 @@
     {.pattern = "RAdio:FREQuency?", .callback = radio_freqQ,},
     {.pattern = "RAdio:DIOMap", .callback = radio_diomap,},
     {.pattern = "RAdio:DIOMap?", .callback = radio_diomapQ,},
-    
+    {.pattern = "RAdio:DIO?", .callback = radio_dioQ,},
+    {.pattern = "RAdio:REGister", .callback = radio_reg,},
+    {.pattern = "RAdio:REGister?", .callback = radio_regQ,},
        
     {.pattern = "RAdio:FSK:SYNC", .callback = fsk_sync,},
     {.pattern = "RAdio:FSK:SYNC?", .callback = fsk_syncQ,}, 
@@ -1102,7 +1360,15 @@
     {.pattern = "RAdio:FSK:RXBW", .callback = fsk_rxbw,},
     {.pattern = "RAdio:FSK:RXBW?", .callback = fsk_rxbwQ,},        
     {.pattern = "RAdio:FSK:AFCBW", .callback = fsk_afcbw,},
-    {.pattern = "RAdio:FSK:AFCBW?", .callback = fsk_afcbwQ,},    
+    {.pattern = "RAdio:FSK:AFCBW?", .callback = fsk_afcbwQ,}, 
+    {.pattern = "RAdio:FSK:DCFree", .callback = fsk_dcfree,},
+    {.pattern = "RAdio:FSK:DCFree?", .callback = fsk_dcfreeQ,},       
+    {.pattern = "RAdio:FSK:RXTrigger", .callback = fsk_rxtrig,},
+    {.pattern = "RAdio:FSK:RXTrigger?", .callback = fsk_rxtrigQ,},     
+    {.pattern = "RAdio:FSK:DATAMode", .callback = fsk_datamode,},
+    {.pattern = "RAdio:FSK:DATAMode?", .callback = fsk_datamodeQ,}, 
+    {.pattern = "RAdio:FSK:BT", .callback = fsk_bt,},
+    {.pattern = "RAdio:FSK:BT?", .callback = fsk_btQ,},     
     
     {.pattern = "RAdio:LORa:BW", .callback = lora_bw,},
     {.pattern = "RAdio:LORa:BW?", .callback = lora_bwQ,},    
@@ -1121,8 +1387,12 @@
     {.pattern = "RAdio:LORa:PKTRssi?", .callback = lora_pktrssiQ,},     
     {.pattern = "RAdio:LORa:Ih", .callback = lora_ih,},
     {.pattern = "RAdio:LORa:Ih?", .callback = lora_ihQ,},        
-        
-    //{.pattern = "SET9", .callback = wbr_set_bit9,},
+    {.pattern = "RAdio:LORa:CRC", .callback = lora_crc,},
+    {.pattern = "RAdio:LORa:CRC?", .callback = lora_crcQ,},  
+    {.pattern = "RAdio:LORa:INVRx", .callback = lora_invrx,},
+    {.pattern = "RAdio:LORa:INVRx?", .callback = lora_invrxQ,},  
+    {.pattern = "RAdio:LORa:INVTx", .callback = lora_invtx,},
+    {.pattern = "RAdio:LORa:INVTx?", .callback = lora_invtxQ,},            
     
 #ifdef TARGET_MOTE_L152RC
     {.pattern = "PD2", .callback = pd2_set,},