Richard Nash
/
XPL-App1_working-clean
mbed xpl base example
xPL_Message.h@0:0fc77069cf70, 2018-07-30 (annotated)
- Committer:
- richnash
- Date:
- Mon Jul 30 14:10:27 2018 +0000
- Revision:
- 0:0fc77069cf70
base xpl listener sender
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
richnash | 0:0fc77069cf70 | 1 | /* |
richnash | 0:0fc77069cf70 | 2 | * xPL.Arduino v0.1, xPL Implementation for Arduino |
richnash | 0:0fc77069cf70 | 3 | * |
richnash | 0:0fc77069cf70 | 4 | * This code is parsing a xPL message stored in 'received' buffer |
richnash | 0:0fc77069cf70 | 5 | * - isolate and store in 'line' buffer each part of the message -> detection of EOL character (DEC 10) |
richnash | 0:0fc77069cf70 | 6 | * - analyse 'line', function of its number and store information in xpl_header memory |
richnash | 0:0fc77069cf70 | 7 | * - check for each step if the message respect xPL protocol |
richnash | 0:0fc77069cf70 | 8 | * - parse each command line |
richnash | 0:0fc77069cf70 | 9 | * |
richnash | 0:0fc77069cf70 | 10 | * Copyright (C) 2012 johan@pirlouit.ch, olivier.lebrun@gmail.com |
richnash | 0:0fc77069cf70 | 11 | * Original version by Gromain59@gmail.com |
richnash | 0:0fc77069cf70 | 12 | * |
richnash | 0:0fc77069cf70 | 13 | * This program is free software; you can redistribute it and/or |
richnash | 0:0fc77069cf70 | 14 | * modify it under the terms of the GNU General Public License |
richnash | 0:0fc77069cf70 | 15 | * as published by the Free Software Foundation; either version 2 |
richnash | 0:0fc77069cf70 | 16 | * of the License, or (at your option) any later version. |
richnash | 0:0fc77069cf70 | 17 | * |
richnash | 0:0fc77069cf70 | 18 | * This program is distributed in the hope that it will be useful, |
richnash | 0:0fc77069cf70 | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
richnash | 0:0fc77069cf70 | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
richnash | 0:0fc77069cf70 | 21 | * GNU General Public License for more details. |
richnash | 0:0fc77069cf70 | 22 | * |
richnash | 0:0fc77069cf70 | 23 | * You should have received a copy of the GNU General Public License |
richnash | 0:0fc77069cf70 | 24 | * along with this program; if not, write to the Free Software |
richnash | 0:0fc77069cf70 | 25 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
richnash | 0:0fc77069cf70 | 26 | */ |
richnash | 0:0fc77069cf70 | 27 | |
richnash | 0:0fc77069cf70 | 28 | #ifndef xPLMessage_h |
richnash | 0:0fc77069cf70 | 29 | #define xPLMessage_h |
richnash | 0:0fc77069cf70 | 30 | |
richnash | 0:0fc77069cf70 | 31 | //#include "Arduino.h" |
richnash | 0:0fc77069cf70 | 32 | #include "mbed.h" |
richnash | 0:0fc77069cf70 | 33 | #include "xPL_utils.h" |
richnash | 0:0fc77069cf70 | 34 | |
richnash | 0:0fc77069cf70 | 35 | #define XPL_CMND 1 |
richnash | 0:0fc77069cf70 | 36 | #define XPL_STAT 2 |
richnash | 0:0fc77069cf70 | 37 | #define XPL_TRIG 3 |
richnash | 0:0fc77069cf70 | 38 | |
richnash | 0:0fc77069cf70 | 39 | #define XPL_MESSAGE_BUFFER_MAX 256 // going over 256 would mean changing index from byte to int |
richnash | 0:0fc77069cf70 | 40 | #define XPL_MESSAGE_COMMAND_MAX 10 |
richnash | 0:0fc77069cf70 | 41 | |
richnash | 0:0fc77069cf70 | 42 | class xPL_Message |
richnash | 0:0fc77069cf70 | 43 | { |
richnash | 0:0fc77069cf70 | 44 | public: |
richnash | 0:0fc77069cf70 | 45 | short type; // 1=cmnd, 2=stat, 3=trig |
richnash | 0:0fc77069cf70 | 46 | short hop; // Hop count |
richnash | 0:0fc77069cf70 | 47 | |
richnash | 0:0fc77069cf70 | 48 | struct_id source; // source identification |
richnash | 0:0fc77069cf70 | 49 | struct_id target; // target identification |
richnash | 0:0fc77069cf70 | 50 | |
richnash | 0:0fc77069cf70 | 51 | struct_xpl_schema schema; |
richnash | 0:0fc77069cf70 | 52 | struct_command *command; |
richnash | 0:0fc77069cf70 | 53 | //byte command_count; |
richnash | 0:0fc77069cf70 | 54 | short command_count; |
richnash | 0:0fc77069cf70 | 55 | |
richnash | 0:0fc77069cf70 | 56 | bool AddCommand(const char *,const char *); |
richnash | 0:0fc77069cf70 | 57 | bool AddCommand(char*, char*); |
richnash | 0:0fc77069cf70 | 58 | |
richnash | 0:0fc77069cf70 | 59 | xPL_Message(); |
richnash | 0:0fc77069cf70 | 60 | ~xPL_Message(); |
richnash | 0:0fc77069cf70 | 61 | |
richnash | 0:0fc77069cf70 | 62 | char *toString(); |
richnash | 0:0fc77069cf70 | 63 | |
richnash | 0:0fc77069cf70 | 64 | bool IsSchema(char*, char*); |
richnash | 0:0fc77069cf70 | 65 | bool IsSchema(const char*, const char*); |
richnash | 0:0fc77069cf70 | 66 | |
richnash | 0:0fc77069cf70 | 67 | void SetSource(char *, char *, char *); // define my source |
richnash | 0:0fc77069cf70 | 68 | void SetTarget(const char *, const char * = NULL, const char * = NULL); |
richnash | 0:0fc77069cf70 | 69 | void SetSchema(const char *, const char *); |
richnash | 0:0fc77069cf70 | 70 | |
richnash | 0:0fc77069cf70 | 71 | |
richnash | 0:0fc77069cf70 | 72 | private: |
richnash | 0:0fc77069cf70 | 73 | bool CreateCommand(); |
richnash | 0:0fc77069cf70 | 74 | }; |
richnash | 0:0fc77069cf70 | 75 | |
richnash | 0:0fc77069cf70 | 76 | #endif |