For robots and stuff
Radio/Radio.h@1:05a48c038381, 2014-12-28 (annotated)
- Committer:
- jjones646
- Date:
- Sun Dec 28 06:28:42 2014 +0000
- Revision:
- 1:05a48c038381
- Parent:
- Wireless/Radio/Radio.h@0:c5afea7b9057
- Child:
- 2:c42a035d71ed
updating;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jjones646 | 0:c5afea7b9057 | 1 | #ifndef RADIO_H |
jjones646 | 0:c5afea7b9057 | 2 | #define RADIO_H |
jjones646 | 0:c5afea7b9057 | 3 | |
jjones646 | 0:c5afea7b9057 | 4 | #if 0 |
jjones646 | 0:c5afea7b9057 | 5 | |
jjones646 | 0:c5afea7b9057 | 6 | #include "mbed.h" |
jjones646 | 0:c5afea7b9057 | 7 | #include "rtos.h" |
jjones646 | 0:c5afea7b9057 | 8 | |
jjones646 | 0:c5afea7b9057 | 9 | // THREAD SUPPORT SIGNALS |
jjones646 | 0:c5afea7b9057 | 10 | #define START_THREAD 0x01 |
jjones646 | 0:c5afea7b9057 | 11 | #define NEW_DATA 0x02 |
jjones646 | 0:c5afea7b9057 | 12 | #define SET_LED_TICK 0x04 |
jjones646 | 0:c5afea7b9057 | 13 | |
jjones646 | 0:c5afea7b9057 | 14 | typedef struct RTP_t { |
jjones646 | 0:c5afea7b9057 | 15 | uint8_t *payload; |
jjones646 | 0:c5afea7b9057 | 16 | uint8_t port; |
jjones646 | 0:c5afea7b9057 | 17 | bool ack; |
jjones646 | 0:c5afea7b9057 | 18 | uint8_t destination; |
jjones646 | 0:c5afea7b9057 | 19 | uint8_t source; |
jjones646 | 0:c5afea7b9057 | 20 | uint8_t size; |
jjones646 | 0:c5afea7b9057 | 21 | } RTP_t; |
jjones646 | 0:c5afea7b9057 | 22 | |
jjones646 | 0:c5afea7b9057 | 23 | |
jjones646 | 0:c5afea7b9057 | 24 | class Radio |
jjones646 | 0:c5afea7b9057 | 25 | { |
jjones646 | 0:c5afea7b9057 | 26 | public: |
jjones646 | 0:c5afea7b9057 | 27 | Radio(); |
jjones646 | 0:c5afea7b9057 | 28 | Radio(PinName, PinName); |
jjones646 | 0:c5afea7b9057 | 29 | virtual ~Radio() {}; |
jjones646 | 0:c5afea7b9057 | 30 | |
jjones646 | 0:c5afea7b9057 | 31 | bool send(const RTP_t&); |
jjones646 | 0:c5afea7b9057 | 32 | |
jjones646 | 0:c5afea7b9057 | 33 | virtual void address(uint8_t address) {}; |
jjones646 | 0:c5afea7b9057 | 34 | uint8_t address(void) const { |
jjones646 | 0:c5afea7b9057 | 35 | return _addr; |
jjones646 | 0:c5afea7b9057 | 36 | } |
jjones646 | 0:c5afea7b9057 | 37 | |
jjones646 | 0:c5afea7b9057 | 38 | virtual void freq(uint32_t) {}; |
jjones646 | 0:c5afea7b9057 | 39 | uint32_t freq(void) const { |
jjones646 | 0:c5afea7b9057 | 40 | return _freq; |
jjones646 | 0:c5afea7b9057 | 41 | } |
jjones646 | 0:c5afea7b9057 | 42 | |
jjones646 | 0:c5afea7b9057 | 43 | virtual void channel(uint8_t) {}; |
jjones646 | 0:c5afea7b9057 | 44 | uint8_t channel(void) const { |
jjones646 | 0:c5afea7b9057 | 45 | return _channel; |
jjones646 | 0:c5afea7b9057 | 46 | } |
jjones646 | 0:c5afea7b9057 | 47 | |
jjones646 | 0:c5afea7b9057 | 48 | virtual void powerUp(void) = 0; |
jjones646 | 0:c5afea7b9057 | 49 | |
jjones646 | 0:c5afea7b9057 | 50 | void mailbox(const Mail<RTP_t, 6>*); |
jjones646 | 0:c5afea7b9057 | 51 | |
jjones646 | 0:c5afea7b9057 | 52 | protected: |
jjones646 | 0:c5afea7b9057 | 53 | virtual void put_pck(uint8_t*, uint8_t) = 0; |
jjones646 | 0:c5afea7b9057 | 54 | virtual bool get_pck(uint8_t*, uint8_t*) = 0; |
jjones646 | 0:c5afea7b9057 | 55 | |
jjones646 | 0:c5afea7b9057 | 56 | static const int BUFFER_SIZE = 70; |
jjones646 | 0:c5afea7b9057 | 57 | uint8_t buffer[BUFFER_SIZE]; |
jjones646 | 0:c5afea7b9057 | 58 | |
jjones646 | 0:c5afea7b9057 | 59 | Mail<RTP_t, 6> _rx_data; |
jjones646 | 0:c5afea7b9057 | 60 | Mail<RTP_t, 5> _tx_data; |
jjones646 | 0:c5afea7b9057 | 61 | |
jjones646 | 0:c5afea7b9057 | 62 | bool _need_ack; |
jjones646 | 0:c5afea7b9057 | 63 | uint8_t _channel; |
jjones646 | 0:c5afea7b9057 | 64 | uint32_t _freq; |
jjones646 | 0:c5afea7b9057 | 65 | uint8_t _addr; |
jjones646 | 0:c5afea7b9057 | 66 | int8_t _rssi; |
jjones646 | 0:c5afea7b9057 | 67 | |
jjones646 | 0:c5afea7b9057 | 68 | static void transmit_thread(void const*); |
jjones646 | 0:c5afea7b9057 | 69 | static void receive_thread(void const*); |
jjones646 | 0:c5afea7b9057 | 70 | SPI *_spi; |
jjones646 | 0:c5afea7b9057 | 71 | |
jjones646 | 0:c5afea7b9057 | 72 | private: |
jjones646 | 0:c5afea7b9057 | 73 | void isr_receive(void); |
jjones646 | 0:c5afea7b9057 | 74 | InterruptIn *_rx_int; |
jjones646 | 0:c5afea7b9057 | 75 | DigitalOut _tx_led; |
jjones646 | 0:c5afea7b9057 | 76 | DigitalOut _rx_led; |
jjones646 | 0:c5afea7b9057 | 77 | static void led_tick(void const*); |
jjones646 | 0:c5afea7b9057 | 78 | |
jjones646 | 0:c5afea7b9057 | 79 | Thread _receive_thread; |
jjones646 | 0:c5afea7b9057 | 80 | Thread _transmit_thread; |
jjones646 | 0:c5afea7b9057 | 81 | Thread _tx_led_thread; |
jjones646 | 0:c5afea7b9057 | 82 | Thread _rx_led_thread; |
jjones646 | 0:c5afea7b9057 | 83 | }; |
jjones646 | 0:c5afea7b9057 | 84 | |
jjones646 | 0:c5afea7b9057 | 85 | #endif // RADIO_H |
jjones646 | 0:c5afea7b9057 | 86 | #endif |