Program for decoding radio-signals sent by a ETH-Window-Shutter-Contact, received with a RFM12B-module. The messages are sent to KNX via a freebus rs-interface. Details see http://mbed.org/users/charly/notebook/connecting-a-radio-window-shutter-contact-to-knx/

Dependencies:   TextLCD mbed ConfigFile

Committer:
charly
Date:
Wed Apr 27 19:02:00 2011 +0000
Revision:
0:b79cb3278583

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charly 0:b79cb3278583 1 #ifndef ETH_COMFORT_H
charly 0:b79cb3278583 2 #define ETH_COMFORT_H
charly 0:b79cb3278583 3
charly 0:b79cb3278583 4 /*!
charly 0:b79cb3278583 5 * \file eth_comfort.h
charly 0:b79cb3278583 6 * \brief Read the messages from the ETH-Radio-Shutter
charly 0:b79cb3278583 7 * \author Karl Zweimüller
charly 0:b79cb3278583 8 */
charly 0:b79cb3278583 9
charly 0:b79cb3278583 10
charly 0:b79cb3278583 11 #include "mbed.h"
charly 0:b79cb3278583 12
charly 0:b79cb3278583 13 #include "rfm12b.h"
charly 0:b79cb3278583 14
charly 0:b79cb3278583 15 // a message from the eth-Device
charly 0:b79cb3278583 16 struct eth_message {
charly 0:b79cb3278583 17 uint8_t cnt; //message-counter
charly 0:b79cb3278583 18 uint8_t len; //message-length
charly 0:b79cb3278583 19 uint32_t adr; // unique address of device
charly 0:b79cb3278583 20 uint8_t cmd; // the command
charly 0:b79cb3278583 21 uint8_t data; // optional data
charly 0:b79cb3278583 22 uint8_t xdata; // optional extra data
charly 0:b79cb3278583 23 uint16_t crc; // crc fro the message
charly 0:b79cb3278583 24 };
charly 0:b79cb3278583 25
charly 0:b79cb3278583 26 /**
charly 0:b79cb3278583 27 * Class for the ETH-Window shutter by ELV(R)
charly 0:b79cb3278583 28 * Uses the rfm12B to receive the signals sent by the radio-shutter
charly 0:b79cb3278583 29 *
charly 0:b79cb3278583 30 */
charly 0:b79cb3278583 31 class eth_comfort {
charly 0:b79cb3278583 32
charly 0:b79cb3278583 33 public:
charly 0:b79cb3278583 34
charly 0:b79cb3278583 35 /**
charly 0:b79cb3278583 36 * Constructor.
charly 0:b79cb3278583 37 *
charly 0:b79cb3278583 38 * @param mosi SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p5 or p11
charly 0:b79cb3278583 39 * @param miso SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p6 or p12
charly 0:b79cb3278583 40 * @param sclk SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p7 or p13
charly 0:b79cb3278583 41 * @param nsel Chip-Select. A Digial Output of mbed
charly 0:b79cb3278583 42 * @param rxdata Data-Pin for received data. A DigitalIn of mbed
charly 0:b79cb3278583 43 * @param rxled LED1 - LED4 for showing received bytes
charly 0:b79cb3278583 44 */
charly 0:b79cb3278583 45 eth_comfort(PinName mosi, PinName miso, PinName sclk, PinName nsel, PinName rxdata, PinName rxled);
charly 0:b79cb3278583 46
charly 0:b79cb3278583 47
charly 0:b79cb3278583 48 // initialize eth_comfort-receiver
charly 0:b79cb3278583 49 void init();
charly 0:b79cb3278583 50
charly 0:b79cb3278583 51 // is a new message readable - non blocking
charly 0:b79cb3278583 52 bool readable();
charly 0:b79cb3278583 53
charly 0:b79cb3278583 54 // read a eth-messsage - non blocking, shows the old message if no new is available
charly 0:b79cb3278583 55 eth_message getMessage();
charly 0:b79cb3278583 56
charly 0:b79cb3278583 57
charly 0:b79cb3278583 58
charly 0:b79cb3278583 59 private:
charly 0:b79cb3278583 60
charly 0:b79cb3278583 61 // Interrupt Routine
charly 0:b79cb3278583 62 void ISR();
charly 0:b79cb3278583 63
charly 0:b79cb3278583 64 // the last received message
charly 0:b79cb3278583 65 eth_message last_message;
charly 0:b79cb3278583 66
charly 0:b79cb3278583 67 // new meeesage
charly 0:b79cb3278583 68 eth_message new_message;
charly 0:b79cb3278583 69
charly 0:b79cb3278583 70 // is a new message in the buffer?
charly 0:b79cb3278583 71 bool message_received;
charly 0:b79cb3278583 72
charly 0:b79cb3278583 73 // calcualte the crc for eth
charly 0:b79cb3278583 74 uint16_t calcCRC16r( uint16_t c,uint16_t crc, uint16_t mask);
charly 0:b79cb3278583 75
charly 0:b79cb3278583 76 volatile uint8_t bit_cnt;
charly 0:b79cb3278583 77 volatile uint16_t buffer_cnt;
charly 0:b79cb3278583 78
charly 0:b79cb3278583 79 volatile uint8_t rbyte;
charly 0:b79cb3278583 80
charly 0:b79cb3278583 81 volatile uint8_t buf[1024];
charly 0:b79cb3278583 82 volatile uint8_t pack_ok,startbit;
charly 0:b79cb3278583 83 volatile uint8_t decode,bcnt,lastbit;
charly 0:b79cb3278583 84 volatile uint8_t state;
charly 0:b79cb3278583 85 volatile uint16_t b;
charly 0:b79cb3278583 86 volatile uint8_t blocklength;
charly 0:b79cb3278583 87 int i,j,k;
charly 0:b79cb3278583 88 bool crc_ok;
charly 0:b79cb3278583 89 uint16_t crc, swapped;
charly 0:b79cb3278583 90
charly 0:b79cb3278583 91 rfm12b *rfm12b_spi;
charly 0:b79cb3278583 92
charly 0:b79cb3278583 93 DigitalOut *rxLED;
charly 0:b79cb3278583 94
charly 0:b79cb3278583 95 };
charly 0:b79cb3278583 96
charly 0:b79cb3278583 97 #endif
charly 0:b79cb3278583 98