upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.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 {
66  class RN2903 {
67  public:
68 
76  RN2903(unsigned int uart,
77  unsigned int baudrate=RN2903_DEFAULT_BAUDRATE);
78 
87  RN2903(std::string uart_path,
88  unsigned int baudrate=RN2903_DEFAULT_BAUDRATE);
89 
93  virtual ~RN2903();
94 
104  void setResponseWaitTime(
105  unsigned int wait_ms=RN2903_DEFAULT_RESP_DELAY);
106 
117  unsigned int wait_ms=RN2903_DEFAULT_RESP2_DELAY);
118 
128  bool dataAvailable(unsigned int millis);
129 
136  void drain();
137 
151  RN2903_RESPONSE_T command(const std::string cmd);
152 
163  RN2903_RESPONSE_T commandWithArg(const std::string cmd,
164  const std::string arg);
165 
187  RN2903_RESPONSE_T waitForResponse(int wait_ms);
188 
195  std::string getResponse();
196 
203  int getResponseLen();
204 
214  void setDeviceEUI(const std::string str);
215 
223  void getDeviceEUI();
224 
238  void setDeviceAddr(std::string str);
239 
247  void getDeviceAddr();
248 
263  void setNetworkSessionKey(std::string str);
264 
279  void setApplicationSessionKey(std::string str);
280 
290  void setApplicationEUI(const std::string str);
291 
299  void getApplicationEUI();
300 
310  void setApplicationKey(const std::string str);
311 
319  void getApplicationKey();
320 
330  std::string toHex(const std::string src);
331 
340  std::string fromHex(const std::string src);
341 
360  RN2903_JOIN_STATUS_T join(RN2903_JOIN_TYPE_T type);
361 
383  RN2903_MAC_TX_STATUS_T macTx(RN2903_MAC_MSG_TYPE_T type,
384  int port, std::string payload);
385 
398  RN2903_RESPONSE_T radioTx(const std::string payload);
399 
418  RN2903_RESPONSE_T radioRx(int window_size);
419 
429  std::string getHardwareEUI();
430 
438  void updateMacStatus();
439 
447  int getMacStatusWord();
448 
458  RN2903_MAC_STATUS_T getMacStatus();
459 
473  void macSave();
474 
503  void macPause();
504 
514  void macResume();
515 
527  void reset();
528 
544  void macSetBattery(int level);
545 
554  void setDebug(bool enable);
555 
567  void setBaudrate(unsigned int baudrate);
568 
581  void setFlowControl(RN2903_FLOW_CONTROL_T fc);
582 
592  bool find(const std::string str);
593 
601  std::string getRadioRxPayload();
602 
611  bool autobaud(int retries);
612 
613 
614  protected:
615  // rn2903 device context
616  rn2903_context m_rn2903;
617 
624  std::string read(int size);
625 
632  int write(std::string buffer);
633 
634  private:
635  /* Disable implicit copy and assignment operators */
636  RN2903(const RN2903&) = delete;
637  RN2903 &operator=(const RN2903&) = delete;
638  };
639 }
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:66
int getResponseLen()
Definition: rn2903.cxx:124
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