upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
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 {
82  class HMTRP {
83  public:
84 
85  // HMTRP opcodes
86  typedef enum { RESET = 0xf0,
87  GET_CONFIG = 0xe1,
88  SET_FREQUENCY = 0xd2,
89  SET_RF_DATARATE = 0xc3, // 1200-115200 (baud)
90  SET_RX_BW = 0xb4, // 30-620 (Khz)
91  SET_FREQ_MODULATION = 0xa5, // 10-160 (KHz)
92  SET_TX_POWER = 0x96, // 0-7
93  SET_UART_SPEED = 0x1e, // recommended not to change
94  GET_RF_SIGNAL_STR = 0xa7,
95  GET_MOD_SIGNAL_STR = 0x78
96  } HMTRP_OPCODE_T;
97 
103  HMTRP(int uart=HMTRP_DEFAULT_UART);
104 
108  ~HMTRP();
109 
116  bool dataAvailable(unsigned int millis=0);
117 
127  int readData(char *buffer, int len, int millis=-1);
128 
136  int writeData(char *buffer, int len);
137 
145  bool setupTty(speed_t baud=B9600);
146 
152  bool checkOK();
153 
159  bool reset();
160 
172  bool getConfig(uint32_t *freq, uint32_t *dataRate, uint16_t *rxBandwidth,
173  uint8_t *modulation, uint8_t *txPower, uint32_t *uartBaud);
174 
182  bool setFrequency(uint32_t freq);
183 
191  bool setRFDataRate(uint32_t rate);
192 
199  bool setRXBandwidth(uint16_t rxBand);
200 
207  bool setFrequencyModulation(uint8_t modulation);
208 
217  bool setTransmitPower(uint8_t power);
218 
228  bool setUARTSpeed(uint32_t speed);
229 
236  bool getRFSignalStrength(uint8_t *strength);
237 
244  uint8_t getRFSignalStrength();
245 
252  bool getModSignalStrength(uint8_t *strength);
253 
260  uint8_t getModSignalStrength();
261 
262 
263  private:
264  mraa_uart_context m_uart;
265  int m_ttyFd;
266  };
267 }
268 
269 
uint8_t getModSignalStrength()
Definition: hmtrp.cxx:496
bool setRFDataRate(uint32_t rate)
Definition: hmtrp.cxx:295
bool setTransmitPower(uint8_t power)
Definition: hmtrp.cxx:371
bool setFrequencyModulation(uint8_t modulation)
Definition: hmtrp.cxx:347
bool setUARTSpeed(uint32_t speed)
Definition: hmtrp.cxx:395
HMTRP(int uart=HMTRP_DEFAULT_UART)
Definition: hmtrp.cxx:40
bool checkOK()
Definition: hmtrp.cxx:176
bool setupTty(speed_t baud=B9600)
Definition: hmtrp.cxx:146
bool setRXBandwidth(uint16_t rxBand)
Definition: hmtrp.cxx:322
~HMTRP()
Definition: hmtrp.cxx:72
bool setFrequency(uint32_t freq)
Definition: hmtrp.cxx:277
bool reset()
Definition: hmtrp.cxx:197
API for the HM-TRP Serial RF Pro transceiver.
Definition: hmtrp.h:82
int writeData(char *buffer, int len)
Definition: hmtrp.cxx:126
uint8_t getRFSignalStrength()
Definition: hmtrp.cxx:455
bool dataAvailable(unsigned int millis=0)
Definition: hmtrp.cxx:78
int readData(char *buffer, int len, int millis=-1)
Definition: hmtrp.cxx:101
bool getConfig(uint32_t *freq, uint32_t *dataRate, uint16_t *rxBandwidth, uint8_t *modulation, uint8_t *txPower, uint32_t *uartBaud)
Definition: hmtrp.cxx:210