xpl lib

Dependents:   XPL-App4_cleanup XPL-App5

Committer:
richnash
Date:
Tue Oct 09 17:37:05 2018 +0000
Revision:
0:23c0d0e1c31d
ready to move to cli to explore D11 pin fix

Who changed what in which revision?

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