altos: Create macros to convert from/to radio RSSI representation
authorKeith Packard <keithp@keithp.com>
Wed, 11 Jul 2012 20:50:56 +0000 (13:50 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 11 Jul 2012 20:50:56 +0000 (13:50 -0700)
AO_RSSI_FROM_RADIO and AO_RADIO_FROM_RSSI.

Removes a bunch of open-coded versions of the same function.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao.h
src/core/ao_monitor.c
src/drivers/ao_cc1120.c
src/product/ao_terraui.c

index 06daf48f98aa4af597bfe0a7344c6c665f7cdaf8..eb2d47cf063d68e62cc41bdbce3af40c1b095d00 100644 (file)
@@ -487,6 +487,12 @@ struct ao_telemetry_tiny_recv {
        uint8_t                         status;
 };
 
+/* Unfortunately, we've exposed the CC1111 rssi units as the 'usual' method
+ * for reporting RSSI. So, now we use these values everywhere
+ */
+#define AO_RSSI_FROM_RADIO(radio)      ((int16_t) ((int8_t) (radio) >> 1) - 74)
+#define AO_RADIO_FROM_RSSI(rssi)       (((int8_t) (rssi) + 74) << 1)
+
 /*
  * ao_radio_recv tacks on rssi and status bytes
  */
index 51d614254ab5e19db14a0cd6c89fb7ae887f30de..d492e32a8424d312d104ba24772c1d1baeaff8aa 100644 (file)
@@ -141,8 +141,7 @@ ao_monitor_put(void)
                case AO_MONITORING_ORIG:
                        state = recv_orig.telemetry_orig.flight_state;
 
-                       /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
-                       rssi = (int16_t) (recv_orig.rssi >> 1) - 74;
+                       rssi = (int16_t) AO_RSSI_FROM_RADIO(recv_orig.rssi);
                        ao_xmemcpy(callsign, recv_orig.telemetry_orig.callsign, AO_MAX_CALLSIGN);
                        if (state > ao_flight_invalid)
                                state = ao_flight_invalid;
@@ -240,7 +239,7 @@ ao_monitor_put(void)
                        putchar ('\n');
 #if HAS_RSSI
                        if (recv_raw.packet[ao_monitoring + 1] & PKT_APPEND_STATUS_1_CRC_OK) {
-                               rssi = ((int16_t) recv_raw.packet[ao_monitoring] >> 1) - 74;
+                               rssi = AO_RSSI_FROM_RADIO(recv_raw.packet[ao_monitoring]);
                                ao_rssi_set(rssi);
                        }
 #endif
index a36d922c15ac27bca4d28e75418e39665d2771d0..569df3b7c80ad92416130ac6391dda1130f42f18 100644 (file)
@@ -729,7 +729,7 @@ ao_radio_recv(__xdata void *d, uint8_t size)
 
        /* Convert from 'real' rssi to cc1111-style values */
 
-       rssi = (((int8_t) ao_radio_reg_read(CC1120_RSSI1)) + 74) * 2;
+       rssi = AO_RADIO_FROM_RSSI(ao_radio_reg_read(CC1120_RSSI1));
 
        ao_radio_put();
 
@@ -998,7 +998,7 @@ ao_radio_test_recv()
                        printf ("CRC OK");
                else
                        printf ("CRC BAD");
-               printf (" RSSI %d", (int16_t) ((int8_t) bytes[32] >> 1) - 74);
+               printf (" RSSI %d", AO_RSSI_FROM_RADIO(bytes[32]));
                for (b = 0; b < 32; b++)
                        printf (" %02x", bytes[b]);
                printf ("\n");
index 963c7be41182d938479ec6c07a4b13878816c692..1866eb0c1183af7ac4bff51387eaca4c2ec6c31a 100644 (file)
@@ -594,7 +594,7 @@ ao_terramonitor(void)
                        continue;
                if (!(ao_monitor_ring[monitor].all.status & PKT_APPEND_STATUS_1_CRC_OK))
                        continue;
-               ao_tel_rssi = (ao_monitor_ring[monitor].all.rssi >> 1) - 74;
+               ao_tel_rssi = AO_RSSI_FROM_RADIO(ao_monitor_ring[monitor].all.rssi);
                switch (ao_monitor_ring[monitor].all.telemetry.generic.type) {
                case AO_TELEMETRY_SENSOR_TELEMETRUM:
                case AO_TELEMETRY_SENSOR_TELEMINI: