upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
rn2903.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2017 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 "rn2903.h"
30 
31 namespace upm {
67  class RN2903 {
68  public:
69 
77  RN2903(unsigned int uart,
78  unsigned int baudrate=RN2903_DEFAULT_BAUDRATE);
79 
88  RN2903(std::string uart_path,
89  unsigned int baudrate=RN2903_DEFAULT_BAUDRATE);
90 
94  virtual ~RN2903();
95 
105  void setResponseWaitTime(
106  unsigned int wait_ms=RN2903_DEFAULT_RESP_DELAY);
107 
118  unsigned int wait_ms=RN2903_DEFAULT_RESP2_DELAY);
119 
129  bool dataAvailable(unsigned int millis);
130 
137  void drain();
138 
152  RN2903_RESPONSE_T command(const std::string cmd);
153 
164  RN2903_RESPONSE_T commandWithArg(const std::string cmd,
165  const std::string arg);
166 
188  RN2903_RESPONSE_T waitForResponse(int wait_ms);
189 
196  std::string getResponse();
197 
204  int getResponseLen();
205 
215  void setDeviceEUI(const std::string str);
216 
224  void getDeviceEUI();
225 
239  void setDeviceAddr(std::string str);
240 
248  void getDeviceAddr();
249 
264  void setNetworkSessionKey(std::string str);
265 
280  void setApplicationSessionKey(std::string str);
281 
291  void setApplicationEUI(const std::string str);
292 
300  void getApplicationEUI();
301 
311  void setApplicationKey(const std::string str);
312 
320  void getApplicationKey();
321 
331  std::string toHex(const std::string src);
332 
341  std::string fromHex(const std::string src);
342 
361  RN2903_JOIN_STATUS_T join(RN2903_JOIN_TYPE_T type);
362 
384  RN2903_MAC_TX_STATUS_T macTx(RN2903_MAC_MSG_TYPE_T type,
385  int port, std::string payload);
386 
399  RN2903_RESPONSE_T radioTx(const std::string payload);
400 
419  RN2903_RESPONSE_T radioRx(int window_size);
420 
430  std::string getHardwareEUI();
431 
439  void updateMacStatus();
440 
448  int getMacStatusWord();
449 
459  RN2903_MAC_STATUS_T getMacStatus();
460 
474  void macSave();
475 
504  void macPause();
505 
515  void macResume();
516 
528  void reset();
529 
545  void macSetBattery(int level);
546 
555  void setDebug(bool enable);
556 
568  void setBaudrate(unsigned int baudrate);
569 
582  void setFlowControl(RN2903_FLOW_CONTROL_T fc);
583 
593  bool find(const std::string str);
594 
602  std::string getRadioRxPayload();
603 
612  bool autobaud(int retries);
613 
614 
615  protected:
616  // rn2903 device context
617  rn2903_context m_rn2903;
618 
625  std::string read(int size);
626 
633  int write(std::string buffer);
634 
635  private:
636  /* Disable implicit copy and assignment operators */
637  RN2903(const RN2903&) = delete;
638  RN2903 &operator=(const RN2903&) = delete;
639  };
640 }
RN2903_RESPONSE_T command(const std::string cmd)
Definition: rn2903.cxx:101
Generic API for the Microchip RN2903 LoRa Radio.
virtual ~RN2903()
Definition: rn2903.cxx:50
void macSave()
Definition: rn2903.cxx:262
void setApplicationEUI(const std::string str)
Definition: rn2903.cxx:157
RN2903_JOIN_STATUS_T join(RN2903_JOIN_TYPE_T type)
Definition: rn2903.cxx:219
int write(std::string buffer)
Definition: rn2903.cxx:68
void setDeviceAddr(std::string str)
Definition: rn2903.cxx:185
int getMacStatusWord()
Definition: rn2903.cxx:252
void reset()
Definition: rn2903.cxx:283
void setApplicationSessionKey(std::string str)
Definition: rn2903.cxx:150
void setBaudrate(unsigned int baudrate)
Definition: rn2903.cxx:302
std::string getResponse()
Definition: rn2903.cxx:118
void getApplicationEUI()
Definition: rn2903.cxx:164
API for the Microchip RN2903 LoRa radio.
Definition: rn2903.hpp:67
int getResponseLen()
Definition: rn2903.cxx:124
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
RN2903_RESPONSE_T radioRx(int window_size)
Definition: rn2903.cxx:235
void setFlowControl(RN2903_FLOW_CONTROL_T fc)
Definition: rn2903.cxx:309
void macSetBattery(int level)
Definition: rn2903.cxx:290
Definition: rn2903.h:50
void setApplicationKey(const std::string str)
Definition: rn2903.cxx:171
std::string getRadioRxPayload()
Definition: rn2903.cxx:321
bool dataAvailable(unsigned int millis)
Definition: rn2903.cxx:90
RN2903_RESPONSE_T waitForResponse(int wait_ms)
Definition: rn2903.cxx:113
void setNetworkSessionKey(std::string str)
Definition: rn2903.cxx:143
std::string read(int size)
Definition: rn2903.cxx:55
void setDeviceEUI(const std::string str)
Definition: rn2903.cxx:129
std::string getHardwareEUI()
Definition: rn2903.cxx:240
void setResponseWaitTime(unsigned int wait_ms=RN2903_DEFAULT_RESP_DELAY)
Definition: rn2903.cxx:80
void updateMacStatus()
Definition: rn2903.cxx:245
void drain()
Definition: rn2903.cxx:95
RN2903_RESPONSE_T radioTx(const std::string payload)
Definition: rn2903.cxx:230
void getDeviceEUI()
Definition: rn2903.cxx:136
void macResume()
Definition: rn2903.cxx:276
void setDebug(bool enable)
Definition: rn2903.cxx:297
bool autobaud(int retries)
Definition: rn2903.cxx:331
void setResponse2WaitTime(unsigned int wait_ms=RN2903_DEFAULT_RESP2_DELAY)
Definition: rn2903.cxx:85
RN2903_RESPONSE_T commandWithArg(const std::string cmd, const std::string arg)
Definition: rn2903.cxx:106
void getDeviceAddr()
Definition: rn2903.cxx:192
void macPause()
Definition: rn2903.cxx:269
void getApplicationKey()
Definition: rn2903.cxx:178
RN2903_MAC_TX_STATUS_T macTx(RN2903_MAC_MSG_TYPE_T type, int port, std::string payload)
Definition: rn2903.cxx:224
std::string fromHex(const std::string src)
Definition: rn2903.cxx:209
std::string toHex(const std::string src)
Definition: rn2903.cxx:199
RN2903_MAC_STATUS_T getMacStatus()
Definition: rn2903.cxx:257
bool find(const std::string str)
Definition: rn2903.cxx:316
RN2903(unsigned int uart, unsigned int baudrate=RN2903_DEFAULT_BAUDRATE)
Definition: rn2903.cxx:34