1 | /*
|
---|
2 | ****************************************************************************
|
---|
3 | * Copyright (c) 2015 Arduino srl. All right reserved.
|
---|
4 | *
|
---|
5 | * File : CiaoData.h
|
---|
6 | * Date : 2015/09/17
|
---|
7 | * Revision : 0.0.1 $
|
---|
8 | * Author: andrea[at]arduino[dot]org
|
---|
9 | *
|
---|
10 | ****************************************************************************
|
---|
11 |
|
---|
12 | This library is free software; you can redistribute it and/or
|
---|
13 | modify it under the terms of the GNU Lesser General Public
|
---|
14 | License as published by the Free Software Foundation; either
|
---|
15 | version 2.1 of the License, or (at your option) any later version.
|
---|
16 |
|
---|
17 | This library is distributed in the hope that it will be useful,
|
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | Lesser General Public License for more details.
|
---|
21 |
|
---|
22 | You should have received a copy of the GNU Lesser General Public
|
---|
23 | License along with this library; if not, write to the Free Software
|
---|
24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include <Arduino.h>
|
---|
28 |
|
---|
29 | #define ID_ERROR String(-1)
|
---|
30 | #define ID_EMPTY String(0)
|
---|
31 | #define ID_READY String(1)
|
---|
32 | #define END_TX_CHAR (char)4
|
---|
33 | #define DATA_SPLIT_CHAR (char)30
|
---|
34 | #define ID_SIZE_TX 25
|
---|
35 |
|
---|
36 | class CiaoData {
|
---|
37 | public:
|
---|
38 |
|
---|
39 | String get(int index){
|
---|
40 | return msg_split[index];
|
---|
41 | }
|
---|
42 |
|
---|
43 | void parseMessage(String command){
|
---|
44 | int statusIndex = command.indexOf(DATA_SPLIT_CHAR);
|
---|
45 | msg_split[1] = command.substring(0, statusIndex);
|
---|
46 | msg_split[2] = command.substring(statusIndex+1);
|
---|
47 | }
|
---|
48 |
|
---|
49 | bool isError(){ //check for an error in data received
|
---|
50 | if(get(0) == ID_ERROR)
|
---|
51 | return true;
|
---|
52 | else
|
---|
53 | return false;
|
---|
54 | }
|
---|
55 |
|
---|
56 | bool isEmpty(){ //check if data received is empty
|
---|
57 | if(get(0) == ID_EMPTY)
|
---|
58 | return true;
|
---|
59 | else
|
---|
60 | return false;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public:
|
---|
64 | String msg_split[3];
|
---|
65 |
|
---|
66 | };
|
---|
67 |
|
---|
68 |
|
---|