diff --git a/src/energenie/Devices.py b/src/energenie/Devices.py index dcd0b13..981acf9 100644 --- a/src/energenie/Devices.py +++ b/src/energenie/Devices.py @@ -84,8 +84,8 @@ def hasSwitch(mfrid, productid): - if mfrid != MFRID: return False - if productid == PRODUCTID_R1_MONITOR_AND_CONTROL: return True + if mfrid != MFRID: return False + if productid == PRODUCTID_MIHO005: return True return False diff --git a/src/energenie/Messages.py b/src/energenie/Messages.py index 397c3ba..b2863f1 100644 --- a/src/energenie/Messages.py +++ b/src/energenie/Messages.py @@ -8,7 +8,7 @@ SWITCH = { "header": { "mfrid": Devices.MFRID, - "productid": Devices.PRODUCTID_R1_MONITOR_AND_CONTROL, + "productid": Devices.PRODUCTID_MIHO005, "encryptPIP": Devices.CRYPT_PIP, "sensorid": 0 # FILL IN }, diff --git a/src/energenie/drv/radio.c b/src/energenie/drv/radio.c index 495a556..07095d4 100644 --- a/src/energenie/drv/radio.c +++ b/src/energenie/drv/radio.c @@ -6,19 +6,16 @@ */ /* TODO +DONE: push the FSK configuration into radio.c +DONE: remove radio.py (the old version of the radio interface) +DONE: contrive a switch.py that only transmits +DONE: hard code device address into the dictionary +DONE: disable the call to the receive check +DONE: radio_modulation fix for FSK +DONE: implement FSK transmit in radio.c (it's just transmit()) +DONE: move radio.py modulation switcher to radio2.py modulation (as it is written better?) -push the FSK configuration into radio.c -remove radio.py (the old version of the radio interface) -implement FSK transmit in radio.c and test with switch.py and hard coded ID number -radio_modulation fix for FSK -move radio.py modulation to radio2.py modulation as it is better? - -contrive a switch.py that only transmits -hard code device address into the dictionary -disable the call to the receive check -run the code, it should turn the switch on and off repeatedly. - - +TODO: run the code, it should turn the switch on and off repeatedly. */ @@ -39,13 +36,11 @@ // Energenie specific radio config values -//#define RADIO_VAL_SYNCVALUE1FSK 0x2D // 1st byte of Sync word -//#define RADIO_VAL_SYNCVALUE2FSK 0xD4 // 2nd byte of Sync word -//#define RADIO_VAL_SYNCVALUE1OOK 0x80 // 1nd byte of Sync word +#define RADIO_VAL_SYNCVALUE1FSK 0x2D // 1st byte of Sync word +#define RADIO_VAL_SYNCVALUE2FSK 0xD4 // 2nd byte of Sync word +#define RADIO_VAL_SYNCVALUE1OOK 0x80 // 1nd byte of Sync word //#define RADIO_VAL_PACKETCONFIG1FSK 0xA2 // Variable length, Manchester coding, Addr must match NodeAddress -//#define RADIO_VAL_PACKETCONFIG1FSKNO 0xA0 // Variable length, Manchester coding -//#define RADIO_VAL_PACKETCONFIG1OOK 0 // Fixed length, no Manchester coding -//#define RADIO_VAL_PAYLOADLEN_OOK (13 + 8 * 17) // Payload Length (WRONG!) +#define RADIO_VAL_PACKETCONFIG1FSKNO 0xA0 // Variable length, Manchester coding //TODO: Not sure, might pass this in? What about on Arduino? //What about if we have multiple chip selects on same SPI? @@ -76,28 +71,27 @@ //----- ENERGENIE SPECIFIC CONFIGURATIONS -------------------------------------- -// config_FSK = [ -// [ADDR_REGDATAMODUL, VAL_REGDATAMODUL_FSK], # modulation scheme FSK -// [ADDR_FDEVMSB, VAL_FDEVMSB30], # frequency deviation 5kHz 0x0052 -> 30kHz 0x01EC -// [ADDR_FDEVLSB, VAL_FDEVLSB30], # frequency deviation 5kHz 0x0052 -> 30kHz 0x01EC -// [ADDR_FRMSB, VAL_FRMSB434], # carrier freq -> 434.3MHz 0x6C9333 -// [ADDR_FRMID, VAL_FRMID434], # carrier freq -> 434.3MHz 0x6C9333 -// [ADDR_FRLSB, VAL_FRLSB434], # carrier freq -> 434.3MHz 0x6C9333 -// [ADDR_AFCCTRL, VAL_AFCCTRLS], # standard AFC routine -// [ADDR_LNA, VAL_LNA50], # 200ohms, gain by AGC loop -> 50ohms -// [ADDR_RXBW, VAL_RXBW60], # channel filter bandwidth 10kHz -> 60kHz page:26 -// [ADDR_BITRATEMSB, 0x1A], # 4800b/s -// [ADDR_BITRATELSB, 0x0B], # 4800b/s -// [ADDR_SYNCCONFIG, VAL_SYNCCONFIG2], # Size of the Synch word = 2 (SyncSize + 1) -// [ADDR_SYNCVALUE1, VAL_SYNCVALUE1FSK], # 1st byte of Sync word -// [ADDR_SYNCVALUE2, VAL_SYNCVALUE2FSK], # 2nd byte of Sync word -// [ADDR_PACKETCONFIG1, VAL_PACKETCONFIG1FSKNO], # Variable length, Manchester coding -// [ADDR_PAYLOADLEN, VAL_PAYLOADLEN66], # max Length in RX, not used in Tx -// [ADDR_NODEADDRESS, 0x06], # Node address used in address filtering TODO??? -// [ADDR_FIFOTHRESH, VAL_FIFOTHRESH1], # Condition to start packet transmission: at least one byte in FIFO -// [ADDR_OPMODE, MODE_RECEIVER] # Operating mode to Receiver -// ] -//#define CONFIG_FSK_COUNT (sizeof(config_FSK)/sizeof(HRF_CONFIG_REC)) + +static HRF_CONFIG_REC config_FSK[] = { + {HRF_ADDR_REGDATAMODUL, HRF_VAL_REGDATAMODUL_FSK}, // modulation scheme FSK + {HRF_ADDR_FDEVMSB, HRF_VAL_FDEVMSB30}, // frequency deviation 5kHz 0x0052 -> 30kHz 0x01EC + {HRF_ADDR_FDEVLSB, HRF_VAL_FDEVLSB30}, // frequency deviation 5kHz 0x0052 -> 30kHz 0x01EC + {HRF_ADDR_FRMSB, HRF_VAL_FRMSB434}, // carrier freq -> 434.3MHz 0x6C9333 + {HRF_ADDR_FRMID, HRF_VAL_FRMID434}, // carrier freq -> 434.3MHz 0x6C9333 + {HRF_ADDR_FRLSB, HRF_VAL_FRLSB434}, // carrier freq -> 434.3MHz 0x6C9333 + {HRF_ADDR_AFCCTRL, HRF_VAL_AFCCTRLS}, // standard AFC routine + {HRF_ADDR_LNA, HRF_VAL_LNA50}, // 200ohms, gain by AGC loop -> 50ohms + {HRF_ADDR_RXBW, HRF_VAL_RXBW60}, // channel filter bandwidth 10kHz -> 60kHz page:26 + {HRF_ADDR_BITRATEMSB, 0x1A}, // 4800b/s + {HRF_ADDR_BITRATELSB, 0x0B}, // 4800b/s + {HRF_ADDR_SYNCCONFIG, HRF_VAL_SYNCCONFIG2}, // Size of the Synch word = 2 (SyncSize + 1) + {HRF_ADDR_SYNCVALUE1, RADIO_VAL_SYNCVALUE1FSK}, // 1st byte of Sync word + {HRF_ADDR_SYNCVALUE2, RADIO_VAL_SYNCVALUE2FSK}, // 2nd byte of Sync word + {HRF_ADDR_PACKETCONFIG1, RADIO_VAL_PACKETCONFIG1FSKNO}, // Variable length, Manchester coding + //{HRF_ADDR_PAYLOADLEN, HRF_VAL_PAYLOADLEN66}, // max Length in RX, not used in Tx + //{HRF_ADDR_NODEADDRESS, 0x06}, // Node address used in address filtering (not used) +}; +#define CONFIG_FSK_COUNT (sizeof(config_FSK)/sizeof(HRF_CONFIG_REC)) static HRF_CONFIG_REC config_OOK[] = { @@ -272,11 +266,11 @@ _config(config_OOK, CONFIG_OOK_COUNT); radio_data.modu = mod; } - //else if (mod == RADIO_MODULATION_FSK) - //{ - // _config(config_FSK, CONFIG_FSK_COUNT); - // radio_data.modu = mod; - //} + else if (mod == RADIO_MODULATION_FSK) + { + _config(config_FSK, CONFIG_FSK_COUNT); + radio_data.modu = mod; + } else //TODO: make this ASSERT() { TRACE_FAIL("Unknown modulation\n"); diff --git a/src/energenie/radio.py b/src/energenie/radio.py index 6932d24..25288b7 100644 --- a/src/energenie/radio.py +++ b/src/energenie/radio.py @@ -14,6 +14,9 @@ # Eventually a lot of this will be pushed into a separate module, # and then pushed back into C once it is proved working. +raise RuntimeError("DEPRECATED, do not use this module any more") + + import radio2 as r # A temporary adaptor layer to gain access to SPI directly def warning(msg): diff --git a/src/energenie/radio2.py b/src/energenie/radio2.py index b6e9716..da3c2dc 100644 --- a/src/energenie/radio2.py +++ b/src/energenie/radio2.py @@ -16,8 +16,8 @@ #TODO: Should really add parameter validation here, so that C code doesn't have to. #although it will be faster in C (C could be made optional, like an assert?) -LIBNAME = "drv/radio_rpi.so" -#LIBNAME = "drv/radio_mac.so" # testing +##LIBNAME = "drv/radio_rpi.so" +LIBNAME = "drv/radio_mac.so" # testing import time import ctypes @@ -67,6 +67,8 @@ m = ctypes.c_int(RADIO_MODULATION_OOK) elif fsk: m = ctypes.c_int(RADIO_MODULATION_FSK) + else: + raise RuntimeError("Must choose fsk or ook mode") radio_modulation_fn(m) @@ -77,6 +79,8 @@ m = ctypes.c_int(RADIO_MODULATION_OOK) elif fsk: m = ctypes.c_int(RADIO_MODULATION_FSK) + else: # defaults to FSK + m = ctypes.c_int(RADIO_MODULATION_FSK) radio_transmitter_fn(m) diff --git a/src/monitor.py b/src/monitor.py index 8d8d92b..bf92d4c 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -10,7 +10,7 @@ # to a CSV log file, so could be the basis for a non-controlling energy logging app. from energenie import Registry, Devices, Messages, OpenThings -from energenie import radio +from energenie import radio2 as radio import Logger diff --git a/src/switch.py b/src/switch.py index 78e5962..f425138 100644 --- a/src/switch.py +++ b/src/switch.py @@ -11,7 +11,7 @@ # Consider waiting for me to finish developing the device object interface first. from energenie import Devices, Messages, Registry, OpenThings -from energenie import radio +from energenie import radio2 as radio from Timer import Timer @@ -67,7 +67,7 @@ global switch_state - if len(Registry.size()) > 0 and sendSwitchTimer.check(): + if Registry.size() > 0 and sendSwitchTimer.check(): print("transmit") radio.transmitter() @@ -87,8 +87,8 @@ for i in range(4): radio.transmit(p) - radio.receiver() - print("receive") + ##radio.receiver() + ##print("receive") switch_state = (switch_state+1) % 2 # toggle