upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions
HMTRP Class Reference

API for the HM-TRP Serial RF Pro transceiver. More...

Detailed Description

UPM support for the HM-TRP Serial RF Pro transceiver. This was tested specifically with the Grove Serial RF Pro transceiver. In theory, this class should work with the following devices:

HM-TRP-433: 414000000-454000000Hz HM-TRP-470: 450000000-490000000Hz HM-TRP-868: 849000000-889000000Hz HM-TRP-915: 895000000-935000000Hz

The only difference is the transmit and receive frequencies supported.

By default, the device simply sends and receives any data presented on its UART interface. It can be put into a configuration mode by grounding the CONFIG pin on the transceiver.

hmtrp.jpg
// Instantiate a HMTRP radio device on uart 0
upm::HMTRP* radio = new upm::HMTRP(0);
// make sure port is initialized properly. 9600 baud is the default.
if (!radio->setupTty(B9600))
{
cerr << "Failed to setup tty port parameters" << endl;
return 1;
}
printUsage();
// By default, this radio simply transmits data sent via writeData()
// and reads any available data via readData().
// It can be placed into a configuration mode by grounding the
// CONFIG pin on the module. When this is done, the various
// configuration query and config methods can be used. In this
// example, by default, we just read any data available fom the
// device, and periodically transmit "Hello World".
// If any argument was specified on the command line, do a simple
// configuration query and output the results. The radio must be in
// CONFIG mode for this to work.
if (argc > 1)
{
// config mode
uint32_t freq;
uint32_t dataRate;
uint16_t rxBandwidth;
uint8_t modulation;
uint8_t txPower;
uint32_t uartBaud;
if (radio->getConfig(&freq, &dataRate, &rxBandwidth, &modulation,
&txPower, &uartBaud))
{
cout << "Radio configuration:" << endl;
cout << "freq: " << freq << " dataRate: " << dataRate
<< " rxBandwidth: " << rxBandwidth << "Khz" << endl;
cout << "modulation: " << int(modulation) << "Khz txPower: "
<< int(txPower) << " uartBaud: " << uartBaud << endl;
}
else
{
cerr << "getConfig() failed. Make sure the radio is in "
<< "CONFIG mode." << endl;
}
}
else
{
// normal read/write mode
char radioBuffer[bufferLength];
int counter = 0;
cout << "Running in normal read/write mode." << endl;
while (shouldRun)
{
// we don't want the read to block in this example, so always
// check to see if data is available first.
if (radio->dataAvailable())
{
memset(radioBuffer, 0, bufferLength);
int rv = radio->readData(radioBuffer, bufferLength - 1);
if (rv > 0)
cout << "Received: " << radioBuffer << endl;
if (rv < 0) // some sort of read error occured
{
cerr << "Port read error." << endl;
break;
}
continue;
}
usleep(100000); // 100ms
counter++;
// every second, transmit "Hello World"
if (counter > 10)
{
static const char *hello = "Hello World!";
cout << "Transmitting hello world..." << endl;
radio->writeData((char *)hello, strlen(hello) + 1);
counter = 0;
}
}
}

Public Types

enum  HMTRP_OPCODE_T {
  RESET = 0xf0, GET_CONFIG = 0xe1, SET_FREQUENCY = 0xd2, SET_RF_DATARATE = 0xc3,
  SET_RX_BW = 0xb4, SET_FREQ_MODULATION = 0xa5, SET_TX_POWER = 0x96, SET_UART_SPEED = 0x1e,
  GET_RF_SIGNAL_STR = 0xa7, GET_MOD_SIGNAL_STR = 0x78
}
 

Public Member Functions

 HMTRP (int uart=HMTRP_DEFAULT_UART)
 
 ~HMTRP ()
 
bool dataAvailable (unsigned int millis=0)
 
int readData (char *buffer, int len, int millis=-1)
 
int writeData (char *buffer, int len)
 
bool setupTty (speed_t baud=B9600)
 
bool checkOK ()
 
bool reset ()
 
bool getConfig (uint32_t *freq, uint32_t *dataRate, uint16_t *rxBandwidth, uint8_t *modulation, uint8_t *txPower, uint32_t *uartBaud)
 
bool setFrequency (uint32_t freq)
 
bool setRFDataRate (uint32_t rate)
 
bool setRXBandwidth (uint16_t rxBand)
 
bool setFrequencyModulation (uint8_t modulation)
 
bool setTransmitPower (uint8_t power)
 
bool setUARTSpeed (uint32_t speed)
 
bool getRFSignalStrength (uint8_t *strength)
 
uint8_t getRFSignalStrength ()
 
bool getModSignalStrength (uint8_t *strength)
 
uint8_t getModSignalStrength ()
 

Constructor & Destructor Documentation

HMTRP ( int  uart = HMTRP_DEFAULT_UART)

HMTRP Serial RF Pro transceiver constructor

Parameters
uartDefault UART to use (0 or 1)
~HMTRP ( )

HMTRP destructor

Member Function Documentation

bool dataAvailable ( unsigned int  millis = 0)

Checks to see if there is data available for reading

Parameters
millisNumber of milliseconds to wait; 0 means no waiting (default).
Returns
True if there is data available for reading
int readData ( char *  buffer,
int  len,
int  millis = -1 
)

Reads any available data in a user-supplied buffer

Parameters
bufferBuffer to hold the data read
lenLength of the buffer
millisMaximum time in milliseconds to wait for input. -1 means waiting forever (default).
Returns
Number of bytes read; 0 if timed out and millis is >= 0
int writeData ( char *  buffer,
int  len 
)

Writes the data in the buffer to the device

Parameters
bufferBuffer to hold the data read
lenLength of the buffer
Returns
Number of bytes written
bool setupTty ( speed_t  baud = B9600)

Sets up proper tty I/O modes and the baud rate. The default baud rate is 9,600 (B9600).

Parameters
baudDesired baud rate.
Returns
True if successful
bool checkOK ( )

Looks for and verifies an OK response. This looks like "OK\r\n"

Returns
True if OK received
bool reset ( )

Resets the device to default parameters, except for the UART baud rate

Returns
True if successful
bool getConfig ( uint32_t *  freq,
uint32_t *  dataRate,
uint16_t *  rxBandwidth,
uint8_t *  modulation,
uint8_t *  txPower,
uint32_t *  uartBaud 
)

Queries the radio to determine its configuration

Parameters
freqOperating frequency
dataRateTX/RX bit rate
rxBandwidthReceiving bandwidth in Khz
modulationModulation frequency in Khz
txPowerTransmission power (1-7)
uartBaudUART baud rate
Returns
True if successful
bool setFrequency ( uint32_t  freq)

Sets the frequency. Note: this is limited depending on which HM-TRP device you are using. Consult the datasheet.

Parameters
freqOperating frequency
Returns
True if successful
bool setRFDataRate ( uint32_t  rate)

Sets the RF data transmission rate. Valid values are between 1,200 and 115,200.

Parameters
rateRadio transmission rate in baud (1,200-115,200)
Returns
True if successful
bool setRXBandwidth ( uint16_t  rxBand)

Sets the RX bandwidth. Valid values are between 30 and 620 (in Khz)

Parameters
rxBandRX bandwidth in Khz (30-620)
Returns
True if successful
bool setFrequencyModulation ( uint8_t  modulation)

Sets the frequency modulation. Valid values are between 10 and 160 (in Khz)

Parameters
modulationFrequency modulation to use, in Khz (10-160)
Returns
True if successful
bool setTransmitPower ( uint8_t  power)

Sets the transmit power level. Valid values are between 0 and 7, 7 being the maximum power.

Parameters
powerPower level to use during transmission. Valid values are between 0 and 7.
Returns
True if successful
bool setUARTSpeed ( uint32_t  speed)

Sets the configured baud rate of the UART. It is strongly recommended you do not change this, or you may lose the ability to communicate with the transceiver. Valid values are 1,200-115,200.

Parameters
speedDesired baud rate to configure the device to use Valid values are between 1,200 and 115,200.
Returns
True if successful
bool getRFSignalStrength ( uint8_t *  strength)

Gets the RF signal strength

Parameters
strengthReturned strength
Returns
True if successful
uint8_t getRFSignalStrength ( )

Gets the RF signal strength

Returns
Signal strength
Exceptions
std::runtime_errorif reading from the sensor failed
bool getModSignalStrength ( uint8_t *  strength)

Gets the modulation signal strength.

Parameters
strengthReturned strength
Returns
True if successful
uint8_t getModSignalStrength ( )

Gets the modulation signal strength.

Returns
Signal strength
Exceptions
std::runtime_errorif reading from the sensor failed

The documentation for this class was generated from the following files: