upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
hmtrp.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <iostream>
28 
29 #include <stdint.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <fcntl.h>
34 #include <errno.h>
35 #include <termios.h>
36 #include <sys/time.h>
37 #include <sys/select.h>
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 
41 #include <mraa/uart.h>
42 
43 #define HMTRP_DEFAULT_UART 0
44 
45 namespace upm {
83  class HMTRP {
84  public:
85 
86  // HMTRP opcodes
87  typedef enum { RESET = 0xf0,
88  GET_CONFIG = 0xe1,
89  SET_FREQUENCY = 0xd2,
90  SET_RF_DATARATE = 0xc3, // 1200-115200 (baud)
91  SET_RX_BW = 0xb4, // 30-620 (Khz)
92  SET_FREQ_MODULATION = 0xa5, // 10-160 (KHz)
93  SET_TX_POWER = 0x96, // 0-7
94  SET_UART_SPEED = 0x1e, // recommended not to change
95  GET_RF_SIGNAL_STR = 0xa7,
96  GET_MOD_SIGNAL_STR = 0x78
97  } HMTRP_OPCODE_T;
98 
104  HMTRP(int uart=HMTRP_DEFAULT_UART);
105 
109  ~HMTRP();
110 
117  bool dataAvailable(unsigned int millis=0);
118 
128  int readData(char *buffer, int len, int millis=-1);
129 
137  int writeData(char *buffer, int len);
138 
146  bool setupTty(speed_t baud=B9600);
147 
153  bool checkOK();
154 
160  bool reset();
161 
173  bool getConfig(uint32_t *freq, uint32_t *dataRate, uint16_t *rxBandwidth,
174  uint8_t *modulation, uint8_t *txPower, uint32_t *uartBaud);
175 
183  bool setFrequency(uint32_t freq);
184 
192  bool setRFDataRate(uint32_t rate);
193 
200  bool setRXBandwidth(uint16_t rxBand);
201 
208  bool setFrequencyModulation(uint8_t modulation);
209 
218  bool setTransmitPower(uint8_t power);
219 
229  bool setUARTSpeed(uint32_t speed);
230 
237  bool getRFSignalStrength(uint8_t *strength);
238 
245  uint8_t getRFSignalStrength();
246 
253  bool getModSignalStrength(uint8_t *strength);
254 
261  uint8_t getModSignalStrength();
262 
263 
264  private:
265  mraa_uart_context m_uart;
266  int m_ttyFd;
267  };
268 }
269 
270 
uint8_t getModSignalStrength()
Definition: hmtrp.cxx:495
bool setRFDataRate(uint32_t rate)
Definition: hmtrp.cxx:294
bool setTransmitPower(uint8_t power)
Definition: hmtrp.cxx:370
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
bool setFrequencyModulation(uint8_t modulation)
Definition: hmtrp.cxx:346
bool setUARTSpeed(uint32_t speed)
Definition: hmtrp.cxx:394
HMTRP(int uart=HMTRP_DEFAULT_UART)
Definition: hmtrp.cxx:40
bool checkOK()
Definition: hmtrp.cxx:175
bool setupTty(speed_t baud=B9600)
Definition: hmtrp.cxx:145
bool setRXBandwidth(uint16_t rxBand)
Definition: hmtrp.cxx:321
~HMTRP()
Definition: hmtrp.cxx:72
bool setFrequency(uint32_t freq)
Definition: hmtrp.cxx:276
bool reset()
Definition: hmtrp.cxx:196
API for the HM-TRP Serial RF Pro transceiver.
Definition: hmtrp.hpp:83
int writeData(char *buffer, int len)
Definition: hmtrp.cxx:125
uint8_t getRFSignalStrength()
Definition: hmtrp.cxx:454
bool dataAvailable(unsigned int millis=0)
Definition: hmtrp.cxx:78
int readData(char *buffer, int len, int millis=-1)
Definition: hmtrp.cxx:100
bool getConfig(uint32_t *freq, uint32_t *dataRate, uint16_t *rxBandwidth, uint8_t *modulation, uint8_t *txPower, uint32_t *uartBaud)
Definition: hmtrp.cxx:209