Richard Nash / xpl

Dependents:   XPL-App4_cleanup XPL-App5

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers xPL.h Source File

xPL.h

00001 /*
00002  * xPL.Arduino v0.1, xPL Implementation for Arduino
00003  *
00004  * This code is parsing a xPL message stored in 'received' buffer
00005  * - isolate and store in 'line' buffer each part of the message -> detection of EOL character (DEC 10)
00006  * - analyse 'line', function of its number and store information in xpl_header memory
00007  * - check for each step if the message respect xPL protocol
00008  * - parse each command line
00009  *
00010  * Copyright (C) 2012 johan@pirlouit.ch, olivier.lebrun@gmail.com
00011  * Original version by Gromain59@gmail.com
00012  *
00013  * This program is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU General Public License
00015  * as published by the Free Software Foundation; either version 2
00016  * of the License, or (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00026 */
00027 
00028 #ifndef xPL_h
00029 #define xPL_h
00030  
00031 #define ENABLE_PARSING 1
00032 
00033 //#include "Arduino.h"
00034 #include "mbed.h"
00035 
00036 #include "xPL_utils.h"
00037 #include "xPL_Message.h"
00038 
00039 #define XPL_CMND 1
00040 #define XPL_STAT 2
00041 #define XPL_TRIG 3
00042 
00043 #define XPL_DEFAULT_HEARTBEAT_INTERVAL   300
00044 
00045 #define XPL_UDP_PORT 3865
00046 
00047 #define XPL_PORT_L  0x19
00048 #define XPL_PORT_H  0xF
00049 
00050 typedef enum {XPL_ACCEPT_ALL, XPL_ACCEPT_SELF, XPL_ACCEPT_SELF_ANY} xpl_accepted_type;
00051 // XPL_ACCEPT_ALL = all xpl messages
00052 // XPL_ACCEPT_SELF = only for me
00053 // XPL_ACCEPT_SELF_ANY = only for me and any (*)
00054 
00055 typedef void (*xPLSendExternal)(char*);
00056 typedef void (*xPLAfterParseAction)(xPL_Message * message);
00057 
00058 class xPL
00059 {
00060   public:
00061     xPL();
00062     ~xPL();
00063 
00064     struct_id source;  // my source
00065     unsigned short udp_port;    // default 3865
00066 
00067     xPLSendExternal SendExternal;
00068 
00069     void SendMessage(char *);
00070     void SendMessage(xPL_Message *, bool = true);
00071 
00072     void SetSource(const char *,const char *,const char *);  // define my source
00073 
00074 #ifdef ENABLE_PARSING
00075     xPLAfterParseAction AfterParseAction;
00076 
00077 
00078     //byte hbeat_interval;  // default 5
00079     short hbeat_interval;  // default 5
00080     xpl_accepted_type xpl_accepted;
00081 
00082 
00083     void Process();
00084     void ParseInputMessage(char *buffer);
00085 
00086     bool TargetIsMe(xPL_Message * message);
00087 
00088     void SendHBeat();
00089 
00090   private:
00091     //void ClearData();
00092     unsigned long last_heartbeat;
00093 //    void SendHBeat();
00094     bool CheckHBeatRequest(xPL_Message * message);
00095 
00096     void Parse(xPL_Message *, char *);
00097     //byte AnalyseHeaderLine(xPL_Message *, char *, byte );
00098     //byte AnalyseCommandLine(xPL_Message *, char *, byte, byte );
00099     short AnalyseHeaderLine(xPL_Message *, char *, short );
00100     short AnalyseCommandLine(xPL_Message *, char *, short, short );
00101 #endif
00102 };
00103 
00104 #endif