source: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/CiaoData.h@ 175

Last change on this file since 175 was 175, checked in by ertl-honda, 8 years ago

ライブラリを Arduino IDE 1.7.9 にupdate

File size: 2.1 KB
Line 
1/*
2****************************************************************************
3* Copyright (c) 2015 Arduino srl. All right reserved.
4*
5* File : CiaoData.h
6* Date : 2016/02/16
7* Revision : 0.0.2 $
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#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_ARCH_SAMD)
37class CiaoData {
38 public:
39
40 String get(int index){
41 return msg_split[index];
42 }
43
44 void parseMessage(String command){
45 int statusIndex = command.indexOf(DATA_SPLIT_CHAR);
46 msg_split[1] = command.substring(0, statusIndex);
47 msg_split[2] = command.substring(statusIndex+1);
48 }
49
50 bool isError(){ //check for an error in data received
51 if(get(0) == ID_ERROR)
52 return true;
53 else
54 return false;
55 }
56
57 bool isEmpty(){ //check if data received is empty
58 if(get(0) == ID_EMPTY)
59 return true;
60 else
61 return false;
62 }
63
64 public:
65 String msg_split[3];
66};
67
68#elif defined(__AVR_ATmega328P__)
69
70class CiaoData {
71 public:
72
73 char* get(int index){
74 return msg_split[index];
75 }
76
77 bool isEmpty(){
78 if (atoi( get(1) ) > 0)
79 return false;
80 else
81 return true;
82 }
83
84 public:
85 char* msg_split[3];
86};
87
88#endif
89
Note: See TracBrowser for help on using the repository browser.