diff --git a/src/energenie/Registry.py b/src/energenie/Registry.py index eba308b..f2316b0 100644 --- a/src/energenie/Registry.py +++ b/src/energenie/Registry.py @@ -18,7 +18,7 @@ return result -def updateDirectory(message): +def update(message): """Update the local directory with information about this device""" now = time.time() header = message["header"] diff --git a/src/energenie/drv/hrfm69.c b/src/energenie/drv/hrfm69.c index 99cb2af..cb15335 100644 --- a/src/energenie/drv/hrfm69.c +++ b/src/energenie/drv/hrfm69.c @@ -73,6 +73,7 @@ uint8_t data; spi_select(); + spi_byte(HRF_ADDR_FIFO); /* prime the fifo burst reader */ /* Read the first byte, and then decide how many remaining bytes to receive */ data = spi_byte(HRF_ADDR_FIFO); @@ -82,6 +83,9 @@ if (data > buflen) { spi_deselect(); + TRACE_OUTS("buffer too small for payload len="); + TRACE_OUTN(data); + TRACE_NL(); return HRF_RESULT_ERR_BUFFER_TOO_SMALL; } @@ -112,6 +116,7 @@ uint8_t data; spi_select(); + spi_byte(HRF_ADDR_FIFO); /* prime the fifo burst reader */ while (buflen != 0) { diff --git a/src/energenie/drv/radio.c b/src/energenie/drv/radio.c index 5f57aca..81a408f 100644 --- a/src/energenie/drv/radio.c +++ b/src/energenie/drv/radio.c @@ -134,11 +134,11 @@ {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) + {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)) @@ -494,15 +494,18 @@ RADIO_RESULT radio_get_payload_cbp(uint8_t* buf, uint8_t buflen) { - if (buflen > MAX_FIFO_BUFFER) - { /* At the moment, the receiver cannot reliably cope with payloads > 1 FIFO buffer. - * It *might* be able to in the future. - */ - return RADIO_RESULT_ERR_LONG_PAYLOAD; - } + ////if (buflen > MAX_FIFO_BUFFER) + ////{ /* At the moment, the receiver cannot reliably cope with payloads > 1 FIFO buffer. + //// * It *might* be able to in the future. + //// */ + //// return RADIO_RESULT_ERR_LONG_PAYLOAD; + ////} HRF_RESULT r = HRF_readfifo_burst_cbp(buf, buflen); if (r != HRF_RESULT_OK) { + TRACE_OUTS("radio_get_payload_cbp failed, error="); + TRACE_OUTN(r); + TRACE_NL(); return RADIO_RESULT_ERR_READ_FAILED; } return RADIO_RESULT_OK; diff --git a/src/energenie/drv/radio_rpi.so b/src/energenie/drv/radio_rpi.so index e7b100f..b18de90 100755 --- a/src/energenie/drv/radio_rpi.so +++ b/src/energenie/drv/radio_rpi.so Binary files differ diff --git a/src/energenie/radio2.py b/src/energenie/radio2.py index b96099d..f5f0249 100644 --- a/src/energenie/radio2.py +++ b/src/energenie/radio2.py @@ -15,8 +15,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 @@ -48,6 +48,17 @@ #TODO RADIO_RESULT_XX +def trace(msg): + print(str(msg)) + + +def tohex(l): + line = "" + for item in l: + line += hex(item) + " " + return line + + def unimplemented(m): print("warning: method is not implemented:%s" % m) return m @@ -160,7 +171,6 @@ time.sleep(outer_delay) -@untested def receiver(fsk=None, ook=None): """Change into receiver mode""" #extern void radio_receiver(RADIO_MODULATION mod); @@ -174,7 +184,6 @@ radio_receiver_fn(m) -@untested def is_receive_waiting(): """Check to see if a payload is waiting in the receive buffer""" #extern RADIO_RESULT radio_is_receive_waiting(void); @@ -184,7 +193,6 @@ return (res != 0) -@untested def receive(size=None): """Receive a single payload""" @@ -194,12 +202,12 @@ return receive_len(size) -@untested def receive_cbp(): """Receive a count byte preceded payload""" + ##trace("receive_cbp") - bufsize = MAX_RX_SIZE - + ##bufsize = MAX_RX_SIZE + bufsize = 255 # testing Buffer = ctypes.c_ubyte * bufsize rxbuf = Buffer() buflen = ctypes.c_ubyte(bufsize) @@ -208,7 +216,7 @@ result = radio_get_payload_cbp_fn(rxbuf, buflen) if result != 0: # RADIO_RESULT_OK - raise RuntimeError("Receive failed, error code %s" % hex(result)) + raise RuntimeError("Receive failed, radio.c error code %s" % hex(result)) size = 1+rxbuf[0] # The count byte in the payload @@ -217,6 +225,7 @@ for i in range(size): rxlist.append(rxbuf[i]) + ##trace("receive_cbp returhs %s" % tohex(rxlist)) return rxlist # Python len(rxlist) tells us how many bytes including length byte if present @@ -291,7 +300,7 @@ print(str(msg)) -@deprecated +@disabled def spi_reset(): spi_trace("reset") @@ -310,13 +319,14 @@ gpio_setout_fn(led_green) gpio_low_fn(led_green) -@deprecated + +@disabled def spi_init_defaults(): spi_trace("calling init_defaults") spi_init_defaults_fn() -@deprecated +@disabled def spi_init(): spi_trace("calling init") #TODO build a config structure @@ -324,7 +334,7 @@ #spi_init_fn() -@deprecated +@disabled def spi_start_transaction(): """Start a transmit or receive, perhaps multiple bursts""" # turn the GREEN LED on @@ -332,7 +342,7 @@ gpio_high_fn(led_green) -@deprecated +@disabled def spi_end_transaction(): """End a transmit or receive, perhaps multiple listens""" # turn the GREEN LED off @@ -340,19 +350,19 @@ gpio_low_fn(led_green) -@deprecated +@disabled def spi_select(): spi_trace("calling select") spi_select_fn() -@deprecated +@disabled def spi_deselect(): spi_trace("calling deselect") spi_deselect_fn() -@deprecated +@disabled def spi_byte(tx): txbyte = ctypes.c_ubyte(tx) #spi_trace("calling byte") @@ -360,7 +370,7 @@ return rxbyte -@deprecated +@disabled def spi_frame(txlist): spi_trace("calling frame ") framelen = len(txlist) @@ -376,7 +386,7 @@ return rxlist -@deprecated +@disabled def spi_finished(): spi_trace("calling finished") spi_finished_fn() diff --git a/src/switch.py b/src/switch.py index 062f245..ab816b7 100644 --- a/src/switch.py +++ b/src/switch.py @@ -35,7 +35,7 @@ """Listen to sensor messages and add them to the Registry""" # See if there is a payload, and if there is, process it - if radio.isReceiveWaiting(): + if radio.is_receive_waiting(): ##trace("receiving payload") payload = radio.receive() try: @@ -87,7 +87,7 @@ for i in range(4): radio.transmit(p) - ##radio.receiver() + radio.receiver() ##print("receive") switch_state = (switch_state+1) % 2 # toggle @@ -104,17 +104,17 @@ header_mfrid = Devices.MFRID, header_productid = Devices.PRODUCTID_MIHO005, # adaptor plus header_sensorid = SENSOR_ID) - Registry.updateDirectory(device_header) + Registry.update(device_header) sendSwitchTimer = Timer(TX_RATE, 1) # every n seconds offset by initial 1 switch_state = 0 # OFF - ##radio.receiver() - radio.transmitter() + radio.receiver() + ##radio.transmitter() try: while True: - ##switch_sniff_loop() + switch_sniff_loop() switch_toggle_loop() finally: