Programm for decoding radio-signals sent by a ETH-Window-Shutter-Contact, received with a RFM12B-module
Diff: eth_comfort.h
- Revision:
- 1:fc72e0bdb693
- Parent:
- 0:96794c9fc5a3
--- a/eth_comfort.h Wed Mar 02 20:46:57 2011 +0000
+++ b/eth_comfort.h Thu Apr 07 19:54:09 2011 +0000
@@ -1,45 +1,98 @@
#ifndef ETH_COMFORT_H
#define ETH_COMFORT_H
+/*!
+ * \file eth_comfort.h
+ * \brief Read the messages from the ETH-Radio-Shutter
+ * \author Karl Zweimüller
+ */
+
+
#include "mbed.h"
+#include "rfm12b.h"
+
+// a message from the eth-Device
+struct eth_message {
+ uint8_t cnt; //message-counter
+ uint8_t len; //message-length
+ uint32_t adr; // unique address of device
+ uint8_t cmd; // the command
+ uint8_t data; // optional data
+ uint8_t xdata; // optional extra data
+ uint16_t crc; // crc fro the message
+};
+
+/**
+ * Class for the ETH-Window shutter by ELV(R)
+ * Uses the rfm12B to receive the signals sent by the radio-shutter
+ *
+ */
+class eth_comfort {
+
+public:
+
+ /**
+ * Constructor.
+ *
+ * @param mosi SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p5 or p11
+ * @param miso SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p6 or p12
+ * @param sclk SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p7 or p13
+ * @param nsel Chip-Select. A Digial Output of mbed
+ * @param rxdata Data-Pin for received data. A DigitalIn of mbed
+ * @param rxled LED1 - LED4 for showing received bytes
+ */
+ eth_comfort(PinName mosi, PinName miso, PinName sclk, PinName nsel, PinName rxdata, PinName rxled);
+
+
+// initialize eth_comfort-receiver
+ void init();
+
+// is a new message readable - non blocking
+ bool readable();
+
+// read a eth-messsage - non blocking, shows the old message if no new is available
+ eth_message getMessage();
-extern volatile uint8_t transmit,start,phase,bit_cnt,data;
-extern volatile uint16_t buffer_cnt;
-
-
-extern volatile unsigned char old ;
+private:
-extern volatile uint8_t rbyte;
-
-extern volatile uint8_t buf[1024];
-extern volatile uint8_t pack_ok,startbit;
-extern volatile uint8_t decode,bcnt,lastbit;
-extern volatile uint8_t state;
+// Interrupt Routine
+ void ISR();
-struct eth_message{
- uint8_t cnt;
- uint8_t len;
- uint32_t adr;
- uint8_t cmd;
- uint8_t data;
- uint8_t xdata;
- uint16_t crc;
-};
+// the last received message
+ eth_message last_message;
-// led3 shows received bits
-extern DigitalOut led3;
+// new meeesage
+ eth_message new_message;
+
+// is a new message in the buffer?
+ bool message_received;
// calcualte the crc for eth
-uint16_t calcCRC16r( uint16_t c,uint16_t crc, uint16_t mask);
+ uint16_t calcCRC16r( uint16_t c,uint16_t crc, uint16_t mask);
+
+ volatile uint8_t bit_cnt;
+ volatile uint16_t buffer_cnt;
+
+ volatile uint8_t rbyte;
-// initialize eth_comfort-receiver
-void eth_init();
+ volatile uint8_t buf[1024];
+ volatile uint8_t pack_ok,startbit;
+ volatile uint8_t decode,bcnt,lastbit;
+ volatile uint8_t state;
+ volatile uint16_t b;
+ volatile uint8_t blocklength;
+ int i,j,k;
+ bool crc_ok;
+ uint16_t crc, swapped;
-// interupt-routine for received data
-void ISR();
+ rfm12b *rfm12b_spi;
+
+ DigitalOut *rxLED;
+
+};
#endif