lora sensnode

Dependencies:   libmDot mbed-rtos mbed

Fork of mDot_LoRa_Sensornode by Adrian Mitevski

Committer:
socie123
Date:
Wed Aug 10 12:54:10 2016 +0000
Revision:
1:e67174cc4953
Parent:
0:f2815503561f
lora sensnode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mitea1 0:f2815503561f 1 /**
mitea1 0:f2815503561f 2 * @file Decoder.h
mitea1 0:f2815503561f 3 *
mitea1 0:f2815503561f 4 * @author Adrian
mitea1 0:f2815503561f 5 * @date 16.05.2016
mitea1 0:f2815503561f 6 */
mitea1 0:f2815503561f 7
mitea1 0:f2815503561f 8 #ifndef APP_DECODER_H_
mitea1 0:f2815503561f 9 #define APP_DECODER_H_
mitea1 0:f2815503561f 10
mitea1 0:f2815503561f 11 #include <RawSerial.h>
mitea1 0:f2815503561f 12
mitea1 0:f2815503561f 13 #define HEADER_LENGHT 2
mitea1 0:f2815503561f 14 #define ID_LENGHT 2
mitea1 0:f2815503561f 15 #define LENGHT_LENGHT 2
mitea1 0:f2815503561f 16 #define PAYLOAD_LENGHT 28
mitea1 0:f2815503561f 17 #define CRC_LENGHT 2
mitea1 0:f2815503561f 18 #define MESSAGE_LENGHT (HEADER_LENGHT+ID_LENGHT+LENGHT_LENGHT+PAYLOAD_LENGHT+CRC_LENGHT)
mitea1 0:f2815503561f 19
mitea1 0:f2815503561f 20 /**
mitea1 0:f2815503561f 21 * States in which the Decoder can be
mitea1 0:f2815503561f 22 */
mitea1 0:f2815503561f 23 enum DecoderState{
mitea1 0:f2815503561f 24 INIT = 0,//!< INIT
mitea1 0:f2815503561f 25 RECEIVE, //!< RECEIVE
mitea1 0:f2815503561f 26 DECODE, //!< DECODE
mitea1 0:f2815503561f 27 };
mitea1 0:f2815503561f 28
mitea1 0:f2815503561f 29 /**
mitea1 0:f2815503561f 30 * Container that can hold GPS Information
mitea1 0:f2815503561f 31 */
mitea1 0:f2815503561f 32 typedef struct POSLHH{
mitea1 0:f2815503561f 33 unsigned long iTOW;
mitea1 0:f2815503561f 34 long lon;
mitea1 0:f2815503561f 35 long lat;
mitea1 0:f2815503561f 36 long height;
mitea1 0:f2815503561f 37 long hMSL;
mitea1 0:f2815503561f 38 unsigned long hAcc;
mitea1 0:f2815503561f 39 unsigned long vAcc;
mitea1 0:f2815503561f 40 };
mitea1 0:f2815503561f 41
mitea1 0:f2815503561f 42 /**
mitea1 0:f2815503561f 43 * @class Decoder
mitea1 0:f2815503561f 44 * @brief This Class is used to decode the byte stream thats sent from the uBlox. At the moment
mitea1 0:f2815503561f 45 * it only decodes the NAV-POLLSH byte stream. For correct usage all other messages of the uBlox
mitea1 0:f2815503561f 46 * needs to be deactivated or at least the NAV-POLLSH needs to be activated
mitea1 0:f2815503561f 47 */
mitea1 0:f2815503561f 48 class Decoder {
mitea1 0:f2815503561f 49 public:
mitea1 0:f2815503561f 50 Decoder(mbed::RawSerial*);
mitea1 0:f2815503561f 51 virtual ~Decoder();
mitea1 0:f2815503561f 52
mitea1 0:f2815503561f 53 /**
mitea1 0:f2815503561f 54 * @brief Gets the actual State in which the decoder is
mitea1 0:f2815503561f 55 * @return
mitea1 0:f2815503561f 56 */
mitea1 0:f2815503561f 57 DecoderState getActualState();
mitea1 0:f2815503561f 58
mitea1 0:f2815503561f 59 /**
mitea1 0:f2815503561f 60 * @brief Gets the receive Buffer in which all received Bytes from the NAV-POLLSH are
mitea1 0:f2815503561f 61 * stored
mitea1 0:f2815503561f 62 * @return
mitea1 0:f2815503561f 63 */
mitea1 0:f2815503561f 64 char* getReceiveBuffer();
mitea1 0:f2815503561f 65
mitea1 0:f2815503561f 66 /**
mitea1 0:f2815503561f 67 * @brief Gets the last successfully decoded NAV-POLLSH Bytestream
mitea1 0:f2815503561f 68 * @return
mitea1 0:f2815503561f 69 */
mitea1 0:f2815503561f 70 POSLHH getLastPoslhh();
mitea1 0:f2815503561f 71
mitea1 0:f2815503561f 72 private:
mitea1 0:f2815503561f 73 DecoderState actualState;
mitea1 0:f2815503561f 74 mbed::RawSerial* serial;
mitea1 0:f2815503561f 75 char lastReceivedChar;
mitea1 0:f2815503561f 76 POSLHH lastPoslhh;
mitea1 0:f2815503561f 77 char receiveBuffer[MESSAGE_LENGHT];
mitea1 0:f2815503561f 78 int bufferPosition;
mitea1 0:f2815503561f 79
mitea1 0:f2815503561f 80 /**
mitea1 0:f2815503561f 81 * @brief Sets the actual State of the Decoder
mitea1 0:f2815503561f 82 * @param actualState
mitea1 0:f2815503561f 83 */
mitea1 0:f2815503561f 84 void setActualState(DecoderState actualState);
mitea1 0:f2815503561f 85
mitea1 0:f2815503561f 86 /**
mitea1 0:f2815503561f 87 * @brief Gets the latest character from the serial internal buffer
mitea1 0:f2815503561f 88 */
mitea1 0:f2815503561f 89 void getCharacterFromSerial();
mitea1 0:f2815503561f 90
mitea1 0:f2815503561f 91 /**
mitea1 0:f2815503561f 92 * @brief Checks if the specific Char was the last received Char
mitea1 0:f2815503561f 93 * @param specificChar
mitea1 0:f2815503561f 94 * @return
mitea1 0:f2815503561f 95 */
mitea1 0:f2815503561f 96 bool hasReceived(char specificChar);
mitea1 0:f2815503561f 97
mitea1 0:f2815503561f 98 /**
mitea1 0:f2815503561f 99 * @brief Buffers the last received Char at the beginning of the buffer
mitea1 0:f2815503561f 100 */
mitea1 0:f2815503561f 101 void bufferReceivedCharacterAtBegin();
mitea1 0:f2815503561f 102
mitea1 0:f2815503561f 103 /**
mitea1 0:f2815503561f 104 * @brief Buffers the last received char at the actual position of the buffer
mitea1 0:f2815503561f 105 */
mitea1 0:f2815503561f 106 void bufferReceivedCharacter();
mitea1 0:f2815503561f 107
mitea1 0:f2815503561f 108 /**
mitea1 0:f2815503561f 109 * @brief Checks if the whole buffer is filled up
mitea1 0:f2815503561f 110 * @return
mitea1 0:f2815503561f 111 */
mitea1 0:f2815503561f 112 bool isBufferFilled();
mitea1 0:f2815503561f 113
mitea1 0:f2815503561f 114 /**
mitea1 0:f2815503561f 115 * @brief The Decoding routing thats called when some Data is recieved via the serial
mitea1 0:f2815503561f 116 */
mitea1 0:f2815503561f 117 void rxInterrupt();
mitea1 0:f2815503561f 118
mitea1 0:f2815503561f 119 /**
mitea1 0:f2815503561f 120 * @brief Sets the position where the next Byte should be stored inside the buffer
mitea1 0:f2815503561f 121 * @param desiredPosition
mitea1 0:f2815503561f 122 */
mitea1 0:f2815503561f 123 void setBufferPosition(uint8_t desiredPosition);
mitea1 0:f2815503561f 124
mitea1 0:f2815503561f 125 /**
mitea1 0:f2815503561f 126 * @brief Increments the position where the next Byte should be stored by 1
mitea1 0:f2815503561f 127 */
mitea1 0:f2815503561f 128 void incrementBufferPosition();
mitea1 0:f2815503561f 129
mitea1 0:f2815503561f 130 /**
mitea1 0:f2815503561f 131 * @brief Clears the whole buffer
mitea1 0:f2815503561f 132 */
mitea1 0:f2815503561f 133 void clearReceiveBuffer();
mitea1 0:f2815503561f 134
mitea1 0:f2815503561f 135 /**
mitea1 0:f2815503561f 136 * @brief Decodes the whole buffer
mitea1 0:f2815503561f 137 */
mitea1 0:f2815503561f 138 void decodeReceiveBuffer();
mitea1 0:f2815503561f 139 };
mitea1 0:f2815503561f 140
mitea1 0:f2815503561f 141 #endif /* APP_DECODER_H_ */