1 | /*
|
---|
2 | ****************************************************************************
|
---|
3 | * Copyright (c) 2015 Arduino srl. All right reserved.
|
---|
4 | *
|
---|
5 | * File : Ciao.h
|
---|
6 | * Date : 2016/02/16
|
---|
7 | * Revision : 0.0.2 $
|
---|
8 | * Author: andrea[at]arduino[dot]org
|
---|
9 | * Author: adriano[at]arduino[dot]org
|
---|
10 | *
|
---|
11 | ****************************************************************************
|
---|
12 |
|
---|
13 | This library is free software; you can redistribute it and/or
|
---|
14 | modify it under the terms of the GNU Lesser General Public
|
---|
15 | License as published by the Free Software Foundation; either
|
---|
16 | version 2.1 of the License, or (at your option) any later version.
|
---|
17 |
|
---|
18 | This library is distributed in the hope that it will be useful,
|
---|
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | Lesser General Public License for more details.
|
---|
22 |
|
---|
23 | You should have received a copy of the GNU Lesser General Public
|
---|
24 | License along with this library; if not, write to the Free Software
|
---|
25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef CIAO_H_
|
---|
29 | #define CIAO_H_
|
---|
30 |
|
---|
31 | #include <Arduino.h>
|
---|
32 | #include "lib/CiaoData.h"
|
---|
33 | #if defined(__AVR_ATmega328P__)
|
---|
34 | #include "lib/rest.h"
|
---|
35 | #include "lib/SC16IS750.h"
|
---|
36 | #include "lib/espduino.h"
|
---|
37 | #else
|
---|
38 | #include <Stream.h>
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #if defined(__AVR_ATmega32U4__) || defined(ARDUINO_ARCH_SAMD)
|
---|
42 |
|
---|
43 | #if defined(__AVR_ATmega32U4__)
|
---|
44 | #define BAUDRATE 250000
|
---|
45 | #elif defined(ARDUINO_ARCH_SAMD)
|
---|
46 | #define BAUDRATE 115200
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | class CiaoClass {
|
---|
50 | public:
|
---|
51 | void begin();
|
---|
52 | CiaoData read( String protocol, String param1 = "", String param2 = "", String param3 = "");
|
---|
53 | CiaoData write( String protocol, String param1, String param2 = "", String param3 = "");
|
---|
54 | CiaoData writeResponse( String protocol, String id, String param1="", String param2 = "", String param3 = "");
|
---|
55 | CiaoData parse( String, String);
|
---|
56 | void println(String log){};
|
---|
57 | #if defined(__AVR_ATmega32U4__)
|
---|
58 | CiaoClass(Stream &_stream);
|
---|
59 | #elif defined(ARDUINO_ARCH_SAMD)
|
---|
60 | CiaoClass(Serial_ stream);
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | private:
|
---|
64 | void dropAll();
|
---|
65 | bool started;
|
---|
66 | #if defined(__AVR_ATmega32U4__)
|
---|
67 | Stream &stream;
|
---|
68 | #elif defined(ARDUINO_ARCH_SAMD)
|
---|
69 | Serial_ stream;
|
---|
70 | #endif
|
---|
71 | };
|
---|
72 |
|
---|
73 | // This subclass uses a serial port Stream
|
---|
74 | class SerialCiaoClass : public CiaoClass {
|
---|
75 | public:
|
---|
76 | #if defined(__AVR_ATmega32U4__)
|
---|
77 | SerialCiaoClass(HardwareSerial &_serial)
|
---|
78 | : CiaoClass(_serial), serial(_serial) {
|
---|
79 | // Empty
|
---|
80 | }
|
---|
81 | #elif defined(ARDUINO_ARCH_SAMD)
|
---|
82 | SerialCiaoClass(Serial_ serial)
|
---|
83 | : CiaoClass(serial){
|
---|
84 | // Empty
|
---|
85 | }
|
---|
86 | #endif
|
---|
87 | void begin( unsigned long baudrate = BAUDRATE) {
|
---|
88 | serial.begin(baudrate);
|
---|
89 | CiaoClass::begin();
|
---|
90 | }
|
---|
91 | private:
|
---|
92 | #if defined(__AVR_ATmega32U4__)
|
---|
93 | HardwareSerial &serial;
|
---|
94 | #elif defined(ARDUINO_ARCH_SAMD)
|
---|
95 | Serial_ serial;
|
---|
96 | #endif
|
---|
97 | };
|
---|
98 |
|
---|
99 | void splitString(String, String, String[], int size);
|
---|
100 |
|
---|
101 | extern SerialCiaoClass Ciao;
|
---|
102 |
|
---|
103 | #else
|
---|
104 |
|
---|
105 | // class CiaoData {
|
---|
106 | // public:
|
---|
107 |
|
---|
108 | // char* get(int index){
|
---|
109 | // return msg_split[index];
|
---|
110 | // }
|
---|
111 |
|
---|
112 | // public:
|
---|
113 | // char* msg_split[3];
|
---|
114 |
|
---|
115 | // };
|
---|
116 |
|
---|
117 | class CiaoClass {
|
---|
118 | public:
|
---|
119 | void begin();
|
---|
120 |
|
---|
121 | CiaoData read( char*, char*, String ); // ârestâ, âhostnameâ, âStringoneâ,
|
---|
122 | CiaoData read( char*, char*, String, char*); // ârestâ, âhostnameâ, âStringoneâ, âmethodâ
|
---|
123 |
|
---|
124 | CiaoData write( char*, char*, String ); // ârestâ, âhostnameâ, âStringoneâ,
|
---|
125 | CiaoData write( char*, char*, String, char*); // ârestâ, âhostnameâ, âStringoneâ, âmethodâ
|
---|
126 |
|
---|
127 | void print(String str);
|
---|
128 | void println(String str);
|
---|
129 |
|
---|
130 | };
|
---|
131 | extern CiaoClass Ciao;
|
---|
132 |
|
---|
133 | #endif
|
---|
134 |
|
---|
135 |
|
---|
136 | #endif /* CIAO_H_ */
|
---|