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@2:73b87761ce69, 2014-04-16 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Wed Apr 16 08:03:48 2014 +0000
- Revision:
- 2:73b87761ce69
- Parent:
- 1:8f3ec117823d
- Child:
- 3:08f5e8989688
Added more comments
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 | 0:c1b97c30cbc5 | 40 | char cMessage[13]; // Raw receive buffer |
SomeRandomBloke | 0:c1b97c30cbc5 | 41 | char* inPtr; |
SomeRandomBloke | 2:73b87761ce69 | 42 | bool checkDevID = false; |
SomeRandomBloke | 0:c1b97c30cbc5 | 43 | void processMessage(); |
SomeRandomBloke | 0:c1b97c30cbc5 | 44 | void SerialEvent(); |
SomeRandomBloke | 0:c1b97c30cbc5 | 45 | Serial srf; |
SomeRandomBloke | 0:c1b97c30cbc5 | 46 | |
SomeRandomBloke | 0:c1b97c30cbc5 | 47 | public: |
SomeRandomBloke | 2:73b87761ce69 | 48 | /** Default Constructor |
SomeRandomBloke | 2:73b87761ce69 | 49 | * @param txPin Pin name for UART TX |
SomeRandomBloke | 2:73b87761ce69 | 50 | * @param rxPin Pin name for UART RX |
SomeRandomBloke | 2:73b87761ce69 | 51 | * @param checkNodeID Check the incoming Device ID and ignore if it doesnt match |
SomeRandomBloke | 2:73b87761ce69 | 52 | * @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 | 53 | */ |
SomeRandomBloke | 2:73b87761ce69 | 54 | LLAPSerial(PinName txPin, PinName rxPin, bool checkDevID = false, char *dID = "--" ); |
SomeRandomBloke | 0:c1b97c30cbc5 | 55 | |
SomeRandomBloke | 2:73b87761ce69 | 56 | /** Send a message |
SomeRandomBloke | 2:73b87761ce69 | 57 | * @param sToSend Character pointer to message to send, will be padded with - to full length or truncated if too long |
SomeRandomBloke | 2:73b87761ce69 | 58 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 59 | void sendMessage(char* sToSend); |
SomeRandomBloke | 2:73b87761ce69 | 60 | |
SomeRandomBloke | 2:73b87761ce69 | 61 | /** Send a message with a value. Both are concatenated in the message with padding - if needed |
SomeRandomBloke | 2:73b87761ce69 | 62 | * @param sToSend Character pointer to message to send |
SomeRandomBloke | 2:73b87761ce69 | 63 | * @param valueToSend The value to send as a series of characters |
SomeRandomBloke | 2:73b87761ce69 | 64 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 65 | void sendMessage(char* sToSend, char* valueToSend); |
SomeRandomBloke | 2:73b87761ce69 | 66 | |
SomeRandomBloke | 2:73b87761ce69 | 67 | /** Send an integer |
SomeRandomBloke | 2:73b87761ce69 | 68 | * @param sToSend Character pointer to message to send |
SomeRandomBloke | 2:73b87761ce69 | 69 | * @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 | 70 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 71 | void sendInt(char *sToSend, int value); |
SomeRandomBloke | 2:73b87761ce69 | 72 | |
SomeRandomBloke | 2:73b87761ce69 | 73 | /** Send integer message to specified decimal places |
SomeRandomBloke | 2:73b87761ce69 | 74 | * @param sToSend Character pointer to message to send |
SomeRandomBloke | 2:73b87761ce69 | 75 | * @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 | 76 | * @param decimalPlaces The number of decimal places to use. |
SomeRandomBloke | 2:73b87761ce69 | 77 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 78 | void sendIntWithDP(char *sToSend, int value, int decimalPlaces); |
SomeRandomBloke | 2:73b87761ce69 | 79 | |
SomeRandomBloke | 2:73b87761ce69 | 80 | /** Set device ID |
SomeRandomBloke | 2:73b87761ce69 | 81 | * @param cId New device ID to set |
SomeRandomBloke | 2:73b87761ce69 | 82 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 83 | void setDeviceId(char* cId); |
SomeRandomBloke | 2:73b87761ce69 | 84 | |
SomeRandomBloke | 2:73b87761ce69 | 85 | // Public variables for message processing by main application (ideally should be getter functions) |
SomeRandomBloke | 2:73b87761ce69 | 86 | |
SomeRandomBloke | 2:73b87761ce69 | 87 | /** ID of this device |
SomeRandomBloke | 2:73b87761ce69 | 88 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 89 | char deviceId[2]; |
SomeRandomBloke | 2:73b87761ce69 | 90 | |
SomeRandomBloke | 2:73b87761ce69 | 91 | /** Received message buffer |
SomeRandomBloke | 2:73b87761ce69 | 92 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 93 | char sMessage[15]; // Received message buffer |
SomeRandomBloke | 2:73b87761ce69 | 94 | |
SomeRandomBloke | 2:73b87761ce69 | 95 | /** Flag to indicate a new message has been received, must be cleared after message processed |
SomeRandomBloke | 2:73b87761ce69 | 96 | */ |
SomeRandomBloke | 0:c1b97c30cbc5 | 97 | bool bMsgReceived; |
SomeRandomBloke | 0:c1b97c30cbc5 | 98 | }; |
SomeRandomBloke | 0:c1b97c30cbc5 | 99 | |
SomeRandomBloke | 0:c1b97c30cbc5 | 100 | #endif |
SomeRandomBloke | 0:c1b97c30cbc5 | 101 |