Programm for decoding radio-signals sent by a ETH-Window-Shutter-Contact, received with a RFM12B-module

Dependencies:   TextLCD mbed

Committer:
charly
Date:
Thu Apr 07 19:54:09 2011 +0000
Revision:
1:fc72e0bdb693
Parent:
0:96794c9fc5a3
Reorganized and created classes for RFM12B and ETH-Comfort

Who changed what in which revision?

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