upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
hmtrp.h
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 {
81  class HMTRP {
82  public:
83 
84  // HMTRP opcodes
85  typedef enum { RESET = 0xf0,
86  GET_CONFIG = 0xe1,
87  SET_FREQUENCY = 0xd2,
88  SET_RF_DATARATE = 0xc3, // 1200-115200 (baud)
89  SET_RX_BW = 0xb4, // 30-620 (Khz)
90  SET_FREQ_MODULATION = 0xa5, // 10-160 (KHz)
91  SET_TX_POWER = 0x96, // 0-7
92  SET_UART_SPEED = 0x1e, // recommended not to change
93  GET_RF_SIGNAL_STR = 0xa7,
94  GET_MOD_SIGNAL_STR = 0x78
95  } HMTRP_OPCODE_T;
96 
102  HMTRP(int uart=HMTRP_DEFAULT_UART);
103 
107  ~HMTRP();
108 
115  bool dataAvailable(unsigned int millis=0);
116 
126  int readData(char *buffer, size_t len, int millis=-1);
127 
135  int writeData(char *buffer, size_t len);
136 
144  bool setupTty(speed_t baud=B9600);
145 
151  bool checkOK();
152 
158  bool reset();
159 
171  bool getConfig(uint32_t *freq, uint32_t *dataRate, uint16_t *rxBandwidth,
172  uint8_t *modulation, uint8_t *txPower, uint32_t *uartBaud);
173 
181  bool setFrequency(uint32_t freq);
182 
190  bool setRFDataRate(uint32_t rate);
191 
198  bool setRXBandwidth(uint16_t rxBand);
199 
206  bool setFrequencyModulation(uint8_t modulation);
207 
216  bool setTransmitPower(uint8_t power);
217 
227  bool setUARTSpeed(uint32_t speed);
228 
235  bool getRFSignalStrength(uint8_t *strength);
236 
243  bool getModSignalStrength(uint8_t *strength);
244 
245 
246  private:
247  mraa_uart_context m_uart;
248  int m_ttyFd;
249  };
250 }
251 
252 
bool setRFDataRate(uint32_t rate)
Definition: hmtrp.cxx:282
bool setTransmitPower(uint8_t power)
Definition: hmtrp.cxx:355
Definition: a110x.h:29
bool setFrequencyModulation(uint8_t modulation)
Definition: hmtrp.cxx:332
bool setUARTSpeed(uint32_t speed)
Definition: hmtrp.cxx:378
bool getModSignalStrength(uint8_t *strength)
Definition: hmtrp.cxx:435
HMTRP(int uart=HMTRP_DEFAULT_UART)
Definition: hmtrp.cxx:38
bool checkOK()
Definition: hmtrp.cxx:163
bool setupTty(speed_t baud=B9600)
Definition: hmtrp.cxx:135
bool setRXBandwidth(uint16_t rxBand)
Definition: hmtrp.cxx:308
~HMTRP()
Definition: hmtrp.cxx:66
bool setFrequency(uint32_t freq)
Definition: hmtrp.cxx:264
bool reset()
Definition: hmtrp.cxx:184
C++ API for the HMTRP Serial RF Pro.
Definition: hmtrp.h:81
int readData(char *buffer, size_t len, int millis=-1)
Definition: hmtrp.cxx:97
bool getRFSignalStrength(uint8_t *strength)
Definition: hmtrp.cxx:405
int writeData(char *buffer, size_t len)
Definition: hmtrp.cxx:117
bool dataAvailable(unsigned int millis=0)
Definition: hmtrp.cxx:74
bool getConfig(uint32_t *freq, uint32_t *dataRate, uint16_t *rxBandwidth, uint8_t *modulation, uint8_t *txPower, uint32_t *uartBaud)
Definition: hmtrp.cxx:197