forked from packetmax/QNI-Chariot-EP-Lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChariotEPLib.h
127 lines (103 loc) · 3.19 KB
/
ChariotEPLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* ChariotLib.h - Library for interfacing to Chariot IoT Shield
*
* Created by George Wayne for Qualia Networks, Inc., 2016.
* BSD license, all text above must be included in any redistribution.
*/
#ifndef CHARIOT_EP_LIBINCLUDED
#define CHARIOT_EP_LIBINCLUDED
#include <Arduino.h>
#include <Wire.h> // the Arduino I2C library
#include <SoftwareSerial.h>
#define EP_DEBUG 0
#define UNO 1
#define LEONARDO 2
#define MEGA_DUE 3
/*
* Determine Chariot-Arduino channel and event resource setup
*/
#if !defined(HAVE_HWSERIAL0) && defined(HAVE_HWSERIAL1)
// LEONARDO Host
#define LEONARDO_HOST 1
#define UNO_HOST 0
#define MEGA_DUE_HOST 0
#define RX_PIN 11
#define TX_PIN 4
#define MAX_RESOURCES 6
#elif defined(HAVE_HWSERIAL0) && !defined(HAVE_HWSERIAL1)
//# UNO Host
#define LEONARDO_HOST 0
#define UNO_HOST 1
#define MEGA_DUE_HOST 0
#define RX_PIN 11
#define TX_PIN 12
#define MAX_RESOURCES 4
#elif defined(HAVE_HWSERIAL3)
// MEGA Host
#define LEONARDO_HOST 0
#define UNO_HOST 0
#define MEGA_DUE_HOST 1
#define MAX_RESOURCES 8 // the limit of Chariot
#define ChariotClient Serial3
#else
#error Board type not supported by Chariot at this time--contact Qualia Networks Tech Support.
#endif
/*
* Chariot HW parameters
* --events, serial, CoAP resource
*/
#define RSRC_EVENT_INT_PIN 9 // initiate external event interrupt
#define CHARIOT_STATE_PIN 8 // driven HIGH when Chariot is online
#define MAX_BUFLEN 64
#define TMP275_ADDRESS 0x48
#define FAHRENHEIT 1
#define CELSIUS 2
#define KELVIN 3
#define JSON 50 // per CoAP RFC
#define LT 1
#define GT 2
#define EQ 3
#define ON true
#define OFF false
#define LF 10
#define CR 13
#define MINUTES 1
#define SECONDS 2
class ChariotEPClass
{
public:
ChariotEPClass();
~ChariotEPClass();
boolean begin();
int available();
void process();
int createResource(String& uri, uint8_t maxBufLen, String& attrib);
int createResource(const __FlashStringHelper* uri, uint8_t maxBufLen, const __FlashStringHelper* attrib);
bool triggerResourceEvent(int handle, String& event, bool signalChariot);
bool triggerResourceEvent(int handle, const __FlashStringHelper* event, bool signalChariot);
void serialChariotCmd();
int getIdFromURI(String& uri);
int setPutHandler(int handle, void (*putCallback)(String& putCmd));
float readTMP275(uint8_t units);
inline uint8_t getArduinoModel();
private:
uint8_t arduinoType;
bool chariotAvailable;
uint8_t maxBufLen;
// Event resources--these are stored in Chariot
int nextRsrcId;
String rsrcURIs[MAX_RESOURCES];
String rsrcATTRs[MAX_RESOURCES];
void (*putCallbacks[MAX_RESOURCES])(String& putCmd);
uint8_t rsrcChariotBufSizes[MAX_RESOURCES];
void digitalCommand();
void analogCommand();
void modeCommand();
void chariotSignal(int pin);
void coapResponse();
};
extern ChariotEPClass ChariotEP; // the EndPoint object for Chariot
#if defined(LEONARDO_HOST) || defined(UNO_HOST)
extern SoftwareSerial ChariotClient;
#endif
#endif