xpl lib
Dependents: XPL-App4_cleanup XPL-App5
xPL_utils.h@0:23c0d0e1c31d, 2018-10-09 (annotated)
- 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?
User | Revision | Line number | New 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 xPLutil_h |
richnash | 0:23c0d0e1c31d | 29 | #define xPLutil_h |
richnash | 0:23c0d0e1c31d | 30 | |
richnash | 0:23c0d0e1c31d | 31 | //#include "Arduino.h" |
richnash | 0:23c0d0e1c31d | 32 | #include "mbed.h" |
richnash | 0:23c0d0e1c31d | 33 | #include <string.h> |
richnash | 0:23c0d0e1c31d | 34 | |
richnash | 0:23c0d0e1c31d | 35 | #define XPL_VENDOR_ID_MAX 8 |
richnash | 0:23c0d0e1c31d | 36 | #define XPL_DEVICE_ID_MAX 20 |
richnash | 0:23c0d0e1c31d | 37 | #define XPL_INSTANCE_ID_MAX 16 |
richnash | 0:23c0d0e1c31d | 38 | #define XPL_CLASS_ID_MAX 8 |
richnash | 0:23c0d0e1c31d | 39 | #define XPL_TYPE_ID_MAX 8 |
richnash | 0:23c0d0e1c31d | 40 | #define XPL_NAME_LENGTH_MAX 20 |
richnash | 0:23c0d0e1c31d | 41 | #define XPL_VALUE_LENGTH_MAX 128 // should be 128 but need to spare RAM |
richnash | 0:23c0d0e1c31d | 42 | |
richnash | 0:23c0d0e1c31d | 43 | #define XPL_HOP_COUNT_PARSER "hop=%d" |
richnash | 0:23c0d0e1c31d | 44 | #define XPL_SOURCE_PARSER "source=%20[^-]-%20[^'.'].%16s" |
richnash | 0:23c0d0e1c31d | 45 | #define XPL_TARGET_PARSER "target=%20[^-]-%20[^'.'].%16s" |
richnash | 0:23c0d0e1c31d | 46 | #define XPL_SCHEMA_PARSER "%8[^'.'].%8s" |
richnash | 0:23c0d0e1c31d | 47 | // 32 shall match XPL_VALUE_LENGTH_MAX |
richnash | 0:23c0d0e1c31d | 48 | #define XPL_COMMAND_PARSER "%20[^'=']=%32s" |
richnash | 0:23c0d0e1c31d | 49 | |
richnash | 0:23c0d0e1c31d | 50 | typedef struct struct_id struct_id; |
richnash | 0:23c0d0e1c31d | 51 | struct struct_id // source or target |
richnash | 0:23c0d0e1c31d | 52 | { |
richnash | 0:23c0d0e1c31d | 53 | char vendor_id[XPL_VENDOR_ID_MAX+1]; // vendor id |
richnash | 0:23c0d0e1c31d | 54 | char device_id[XPL_DEVICE_ID_MAX+1]; // device id |
richnash | 0:23c0d0e1c31d | 55 | char instance_id[XPL_INSTANCE_ID_MAX+1]; // instance id |
richnash | 0:23c0d0e1c31d | 56 | }; |
richnash | 0:23c0d0e1c31d | 57 | |
richnash | 0:23c0d0e1c31d | 58 | typedef struct struct_xpl_schema struct_xpl_schema; |
richnash | 0:23c0d0e1c31d | 59 | struct struct_xpl_schema |
richnash | 0:23c0d0e1c31d | 60 | { |
richnash | 0:23c0d0e1c31d | 61 | char class_id[XPL_CLASS_ID_MAX+1]; // class of schema (x10, alarm...) |
richnash | 0:23c0d0e1c31d | 62 | char type_id[XPL_TYPE_ID_MAX+1]; // type of schema (basic...) |
richnash | 0:23c0d0e1c31d | 63 | }; |
richnash | 0:23c0d0e1c31d | 64 | |
richnash | 0:23c0d0e1c31d | 65 | typedef struct struct_command struct_command; |
richnash | 0:23c0d0e1c31d | 66 | struct struct_command // source or target |
richnash | 0:23c0d0e1c31d | 67 | { |
richnash | 0:23c0d0e1c31d | 68 | char name[XPL_NAME_LENGTH_MAX+1]; // vendor id |
richnash | 0:23c0d0e1c31d | 69 | char value[XPL_VALUE_LENGTH_MAX+1]; // device id |
richnash | 0:23c0d0e1c31d | 70 | }; |
richnash | 0:23c0d0e1c31d | 71 | |
richnash | 0:23c0d0e1c31d | 72 | void clearStr (char* str); |
richnash | 0:23c0d0e1c31d | 73 | |
richnash | 0:23c0d0e1c31d | 74 | #endif |