LLAP Library for Ciseco wireless products.
Dependents: Ciseco_LLAP_Test Ciseco_SRF_Shield
Library for Ciseco wireless modules http://shop.ciseco.co.uk/rf-module-range/
Tested with Nucleo F401RE and http://shop.ciseco.co.uk/srf-shield-wireless-transciever-for-all-arduino-type-boards/
LLAPSerial.h@4:34499a4a4ec7, 2014-04-16 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Wed Apr 16 10:55:24 2014 +0000
- Revision:
- 4:34499a4a4ec7
- Parent:
- 3:08f5e8989688
- Child:
- 5:ec6fbf70d110
more comment updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SomeRandomBloke | 1:8f3ec117823d | 1 | /** LLAPSerial.h |
SomeRandomBloke | 2:73b87761ce69 | 2 | * @author Andrew Lindsay |
SomeRandomBloke | 1:8f3ec117823d | 3 | * |
SomeRandomBloke | 2:73b87761ce69 | 4 | * @section LICENSE |
SomeRandomBloke | 2:73b87761ce69 | 5 | * |
SomeRandomBloke | 1:8f3ec117823d | 6 | * The MIT License (MIT) |
SomeRandomBloke | 1:8f3ec117823d | 7 | * |
SomeRandomBloke | 1:8f3ec117823d | 8 | * Copyright (c) 2014 Andrew Lindsay |
SomeRandomBloke | 1:8f3ec117823d | 9 | * |
SomeRandomBloke | 1:8f3ec117823d | 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
SomeRandomBloke | 1:8f3ec117823d | 11 | * of this software and associated documentation files (the "Software"), to deal |
SomeRandomBloke | 1:8f3ec117823d | 12 | * in the Software without restriction, including without limitation the rights |
SomeRandomBloke | 1:8f3ec117823d | 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
SomeRandomBloke | 1:8f3ec117823d | 14 | * copies of the Software, and to permit persons to whom the Software is |
SomeRandomBloke | 1:8f3ec117823d | 15 | * furnished to do so, subject to the following conditions: |
SomeRandomBloke | 1:8f3ec117823d | 16 | * |
SomeRandomBloke | 1:8f3ec117823d | 17 | * The above copyright notice and this permission notice shall be included in |
SomeRandomBloke | 1:8f3ec117823d | 18 | * all copies or substantial portions of the Software. |
SomeRandomBloke | 1:8f3ec117823d | 19 | * |
SomeRandomBloke | 1:8f3ec117823d | 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
SomeRandomBloke | 1:8f3ec117823d | 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
SomeRandomBloke | 1:8f3ec117823d | 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
SomeRandomBloke | 1:8f3ec117823d | 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
SomeRandomBloke | 1:8f3ec117823d | 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
SomeRandomBloke | 1:8f3ec117823d | 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
SomeRandomBloke | 1:8f3ec117823d | 26 | * THE SOFTWARE. |
SomeRandomBloke | 1:8f3ec117823d | 27 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 28 | |
SomeRandomBloke | 0:c1b97c30cbc5 | 29 | #ifndef _LLAPSERIAL_h |
SomeRandomBloke | 0:c1b97c30cbc5 | 30 | #define _LLAPSERIAL_h |
SomeRandomBloke | 0:c1b97c30cbc5 | 31 | |
SomeRandomBloke | 0:c1b97c30cbc5 | 32 | #include "mbed.h" |
SomeRandomBloke | 0:c1b97c30cbc5 | 33 | |
SomeRandomBloke | 2:73b87761ce69 | 34 | /** LLAP Serial class for communicating with Ciseco wireless devices |
SomeRandomBloke | 2:73b87761ce69 | 35 | * |
SomeRandomBloke | 2:73b87761ce69 | 36 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 37 | class LLAPSerial |
SomeRandomBloke | 0:c1b97c30cbc5 | 38 | { |
SomeRandomBloke | 0:c1b97c30cbc5 | 39 | private: |
SomeRandomBloke | 4:34499a4a4ec7 | 40 | /** Private internal received message buffer used when receivign characters |
SomeRandomBloke | 4:34499a4a4ec7 | 41 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 42 | char cMessage[13]; // Raw receive buffer |
SomeRandomBloke | 4:34499a4a4ec7 | 43 | |
SomeRandomBloke | 4:34499a4a4ec7 | 44 | /** Internal pointer to next character to write in buffer |
SomeRandomBloke | 4:34499a4a4ec7 | 45 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 46 | char* inPtr; |
SomeRandomBloke | 4:34499a4a4ec7 | 47 | |
SomeRandomBloke | 4:34499a4a4ec7 | 48 | /** Boolean flag to determine if code needs to check the incoming ID and match to device ID, if true and no match, |
SomeRandomBloke | 4:34499a4a4ec7 | 49 | message is ignored |
SomeRandomBloke | 4:34499a4a4ec7 | 50 | */ |
SomeRandomBloke | 2:73b87761ce69 | 51 | bool checkDevID = false; |
SomeRandomBloke | 4:34499a4a4ec7 | 52 | |
SomeRandomBloke | 4:34499a4a4ec7 | 53 | /** Process a received message, determine if its for us, starts with 'a' and optionally matches device ID. |
SomeRandomBloke | 4:34499a4a4ec7 | 54 | Automatically responds to HELLO and CHDEVID requests (TODO - Add more auto responses) |
SomeRandomBloke | 4:34499a4a4ec7 | 55 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 56 | void processMessage(); |
SomeRandomBloke | 4:34499a4a4ec7 | 57 | |
SomeRandomBloke | 4:34499a4a4ec7 | 58 | /** Serial interrupt handler, deals with a single character, builds up internal receive message buffer and calls processmessage when |
SomeRandomBloke | 4:34499a4a4ec7 | 59 | enough characters have been received. |
SomeRandomBloke | 4:34499a4a4ec7 | 60 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 61 | void SerialEvent(); |
SomeRandomBloke | 4:34499a4a4ec7 | 62 | |
SomeRandomBloke | 4:34499a4a4ec7 | 63 | /** Serial object to communicate with the SRF/XRF |
SomeRandomBloke | 4:34499a4a4ec7 | 64 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 65 | Serial srf; |
SomeRandomBloke | 0:c1b97c30cbc5 | 66 | |
SomeRandomBloke | 0:c1b97c30cbc5 | 67 | public: |
SomeRandomBloke | 2:73b87761ce69 | 68 | /** Default Constructor |
SomeRandomBloke | 2:73b87761ce69 | 69 | * @param txPin Pin name for UART TX |
SomeRandomBloke | 2:73b87761ce69 | 70 | * @param rxPin Pin name for UART RX |
SomeRandomBloke | 2:73b87761ce69 | 71 | * @param checkNodeID Check the incoming Device ID and ignore if it doesnt match |
SomeRandomBloke | 2:73b87761ce69 | 72 | * @param dID ID for device, used in sending messages and if checkNodeID is true then only messages for this ID are accepted |
SomeRandomBloke | 2:73b87761ce69 | 73 | */ |
SomeRandomBloke | 3:08f5e8989688 | 74 | LLAPSerial(PinName txPin, PinName rxPin, bool checkDevIDin = false, char *dID = "--" ); |
SomeRandomBloke | 0:c1b97c30cbc5 | 75 | |
SomeRandomBloke | 2:73b87761ce69 | 76 | /** Send a message |
SomeRandomBloke | 2:73b87761ce69 | 77 | * @param sToSend Character pointer to message to send, will be padded with - to full length or truncated if too long |
SomeRandomBloke | 2:73b87761ce69 | 78 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 79 | void sendMessage(char* sToSend); |
SomeRandomBloke | 2:73b87761ce69 | 80 | |
SomeRandomBloke | 2:73b87761ce69 | 81 | /** Send a message with a value. Both are concatenated in the message with padding - if needed |
SomeRandomBloke | 2:73b87761ce69 | 82 | * @param sToSend Character pointer to message to send |
SomeRandomBloke | 2:73b87761ce69 | 83 | * @param valueToSend The value to send as a series of characters |
SomeRandomBloke | 2:73b87761ce69 | 84 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 85 | void sendMessage(char* sToSend, char* valueToSend); |
SomeRandomBloke | 2:73b87761ce69 | 86 | |
SomeRandomBloke | 2:73b87761ce69 | 87 | /** Send an integer |
SomeRandomBloke | 2:73b87761ce69 | 88 | * @param sToSend Character pointer to message to send |
SomeRandomBloke | 2:73b87761ce69 | 89 | * @param value The value to send as a series of characters, will be padded with - to full length or truncated if too long |
SomeRandomBloke | 2:73b87761ce69 | 90 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 91 | void sendInt(char *sToSend, int value); |
SomeRandomBloke | 2:73b87761ce69 | 92 | |
SomeRandomBloke | 2:73b87761ce69 | 93 | /** Send integer message to specified decimal places |
SomeRandomBloke | 2:73b87761ce69 | 94 | * @param sToSend Character pointer to message to send |
SomeRandomBloke | 2:73b87761ce69 | 95 | * @param value The value to send as a series of characters, will be padded with - to full length or truncated if too long |
SomeRandomBloke | 2:73b87761ce69 | 96 | * @param decimalPlaces The number of decimal places to use. |
SomeRandomBloke | 2:73b87761ce69 | 97 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 98 | void sendIntWithDP(char *sToSend, int value, int decimalPlaces); |
SomeRandomBloke | 2:73b87761ce69 | 99 | |
SomeRandomBloke | 2:73b87761ce69 | 100 | /** Set device ID |
SomeRandomBloke | 2:73b87761ce69 | 101 | * @param cId New device ID to set |
SomeRandomBloke | 2:73b87761ce69 | 102 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 103 | void setDeviceId(char* cId); |
SomeRandomBloke | 2:73b87761ce69 | 104 | |
SomeRandomBloke | 2:73b87761ce69 | 105 | // Public variables for message processing by main application (ideally should be getter functions) |
SomeRandomBloke | 2:73b87761ce69 | 106 | |
SomeRandomBloke | 2:73b87761ce69 | 107 | /** ID of this device |
SomeRandomBloke | 2:73b87761ce69 | 108 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 109 | char deviceId[2]; |
SomeRandomBloke | 2:73b87761ce69 | 110 | |
SomeRandomBloke | 4:34499a4a4ec7 | 111 | /** Public Received message buffer |
SomeRandomBloke | 2:73b87761ce69 | 112 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 113 | char sMessage[15]; // Received message buffer |
SomeRandomBloke | 2:73b87761ce69 | 114 | |
SomeRandomBloke | 2:73b87761ce69 | 115 | /** Flag to indicate a new message has been received, must be cleared after message processed |
SomeRandomBloke | 2:73b87761ce69 | 116 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 117 | bool bMsgReceived; |
SomeRandomBloke | 0:c1b97c30cbc5 | 118 | }; |
SomeRandomBloke | 0:c1b97c30cbc5 | 119 | |
SomeRandomBloke | 0:c1b97c30cbc5 | 120 | #endif |
SomeRandomBloke | 0:c1b97c30cbc5 | 121 |