sqefqsdf
Dependencies: C12832 EthernetInterface LM75B mbed-rtos mbed
Fork of app-board-LM75B by
Packet.h@7:0618a1e407d0, 2017-05-09 (annotated)
- Committer:
- gimohd
- Date:
- Tue May 09 12:26:57 2017 +0000
- Revision:
- 7:0618a1e407d0
- Parent:
- 6:77a4c45f6416
dfdsqf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gimohd | 6:77a4c45f6416 | 1 | #ifndef Packet_H |
gimohd | 6:77a4c45f6416 | 2 | #define Packet_H |
gimohd | 6:77a4c45f6416 | 3 | |
gimohd | 6:77a4c45f6416 | 4 | #include "mbed.h" |
gimohd | 6:77a4c45f6416 | 5 | #include <vector> |
gimohd | 6:77a4c45f6416 | 6 | #include <string> |
gimohd | 6:77a4c45f6416 | 7 | |
gimohd | 6:77a4c45f6416 | 8 | #define FRAME_BYTE_1 0xAA |
gimohd | 6:77a4c45f6416 | 9 | #define FRAME_BYTE_2 0x55 |
gimohd | 6:77a4c45f6416 | 10 | #define SERVER_PORT 4000 |
gimohd | 6:77a4c45f6416 | 11 | |
gimohd | 6:77a4c45f6416 | 12 | class Packet |
gimohd | 6:77a4c45f6416 | 13 | { |
gimohd | 6:77a4c45f6416 | 14 | public: |
gimohd | 6:77a4c45f6416 | 15 | |
gimohd | 6:77a4c45f6416 | 16 | /** |
gimohd | 6:77a4c45f6416 | 17 | * Makes an object of Packet with initial values 0 |
gimohd | 6:77a4c45f6416 | 18 | */ |
gimohd | 6:77a4c45f6416 | 19 | Packet(); |
gimohd | 6:77a4c45f6416 | 20 | |
gimohd | 6:77a4c45f6416 | 21 | /** |
gimohd | 6:77a4c45f6416 | 22 | * Converts the data from the packet to a data string used to send to an other MBED |
gimohd | 6:77a4c45f6416 | 23 | * |
gimohd | 6:77a4c45f6416 | 24 | * @return the data string with the packet data included |
gimohd | 6:77a4c45f6416 | 25 | * @ref Communication |
gimohd | 6:77a4c45f6416 | 26 | */ |
gimohd | 6:77a4c45f6416 | 27 | std::string toDataString(); |
gimohd | 6:77a4c45f6416 | 28 | |
gimohd | 6:77a4c45f6416 | 29 | /** |
gimohd | 6:77a4c45f6416 | 30 | * Inputs the data string received by the Communication class, takes the data |
gimohd | 6:77a4c45f6416 | 31 | * out of this string to input this in the packet |
gimohd | 6:77a4c45f6416 | 32 | * |
gimohd | 6:77a4c45f6416 | 33 | * @param str the received data from the Communication class |
gimohd | 6:77a4c45f6416 | 34 | * @ref Communication |
gimohd | 6:77a4c45f6416 | 35 | */ |
gimohd | 6:77a4c45f6416 | 36 | void dataInput(std::string str); |
gimohd | 6:77a4c45f6416 | 37 | |
gimohd | 6:77a4c45f6416 | 38 | /** |
gimohd | 6:77a4c45f6416 | 39 | * Adds and modifies the inserted data to the packet |
gimohd | 6:77a4c45f6416 | 40 | * |
gimohd | 6:77a4c45f6416 | 41 | * @param num the number of ids that has been visited (will be added +1 in the function) |
gimohd | 6:77a4c45f6416 | 42 | * @param destID the destination id that has to be changed |
gimohd | 6:77a4c45f6416 | 43 | * @param pwm the pwm that has to be changed |
gimohd | 6:77a4c45f6416 | 44 | * @param ownID the id that has to be added to the list |
gimohd | 6:77a4c45f6416 | 45 | * @param temp the temperature that has to be added to the list |
gimohd | 6:77a4c45f6416 | 46 | */ |
gimohd | 6:77a4c45f6416 | 47 | void addValues(uint8_t num, uint8_t destID,uint8_t pwm,uint8_t ownID,int16_t temp); |
gimohd | 6:77a4c45f6416 | 48 | |
gimohd | 6:77a4c45f6416 | 49 | /** |
gimohd | 6:77a4c45f6416 | 50 | * Calculates the crc checksum of a given string, ending with a trailing character |
gimohd | 6:77a4c45f6416 | 51 | * chk. |
gimohd | 6:77a4c45f6416 | 52 | * - If this check byte is zero it will calculate the crc checksum itself |
gimohd | 6:77a4c45f6416 | 53 | * - If the check byte has a value, the returned char will be 0 if chk is |
gimohd | 6:77a4c45f6416 | 54 | * the correct checksum value. |
gimohd | 6:77a4c45f6416 | 55 | * |
gimohd | 6:77a4c45f6416 | 56 | * @param str the string where the checksum has to be calculated from |
gimohd | 6:77a4c45f6416 | 57 | * @param chk the checksum value that has to be checked (will be 0 if the crc checksum has to be calculated) |
gimohd | 6:77a4c45f6416 | 58 | * |
gimohd | 6:77a4c45f6416 | 59 | * @return the calculated checksum char |
gimohd | 6:77a4c45f6416 | 60 | */ |
gimohd | 6:77a4c45f6416 | 61 | unsigned char crc(std::string str, char chk); |
gimohd | 6:77a4c45f6416 | 62 | |
gimohd | 6:77a4c45f6416 | 63 | /** |
gimohd | 6:77a4c45f6416 | 64 | * Checks if the CRC is the correct value in the packet |
gimohd | 6:77a4c45f6416 | 65 | * |
gimohd | 6:77a4c45f6416 | 66 | * @return true if the crc is correct, else false |
gimohd | 6:77a4c45f6416 | 67 | */ |
gimohd | 6:77a4c45f6416 | 68 | bool crcCheck(); |
gimohd | 6:77a4c45f6416 | 69 | |
gimohd | 6:77a4c45f6416 | 70 | /** |
gimohd | 6:77a4c45f6416 | 71 | * Checks if the IDN vector contains an ID |
gimohd | 6:77a4c45f6416 | 72 | * |
gimohd | 6:77a4c45f6416 | 73 | * @param ID the ID that has to be checked |
gimohd | 6:77a4c45f6416 | 74 | * @return true if IDN vector contains the ID, else false |
gimohd | 6:77a4c45f6416 | 75 | */ |
gimohd | 6:77a4c45f6416 | 76 | bool idCheck(int ID); |
gimohd | 6:77a4c45f6416 | 77 | |
gimohd | 6:77a4c45f6416 | 78 | /** Sets the number of MBEDs visited |
gimohd | 6:77a4c45f6416 | 79 | * |
gimohd | 6:77a4c45f6416 | 80 | * @param NUM the number of MBEDs visited |
gimohd | 6:77a4c45f6416 | 81 | */ |
gimohd | 6:77a4c45f6416 | 82 | void setNUM(uint8_t NUM); |
gimohd | 6:77a4c45f6416 | 83 | |
gimohd | 6:77a4c45f6416 | 84 | /** Returns the amount of mbeds visited |
gimohd | 6:77a4c45f6416 | 85 | * |
gimohd | 6:77a4c45f6416 | 86 | * @return number of MBEDs visited |
gimohd | 6:77a4c45f6416 | 87 | */ |
gimohd | 6:77a4c45f6416 | 88 | uint8_t getNUM(); |
gimohd | 6:77a4c45f6416 | 89 | |
gimohd | 6:77a4c45f6416 | 90 | /** Sets the destination ID |
gimohd | 6:77a4c45f6416 | 91 | * |
gimohd | 6:77a4c45f6416 | 92 | * @param IDD the destination ID |
gimohd | 6:77a4c45f6416 | 93 | */ |
gimohd | 6:77a4c45f6416 | 94 | void setIDD(uint8_t IDD); |
gimohd | 6:77a4c45f6416 | 95 | |
gimohd | 6:77a4c45f6416 | 96 | /** Returns the destination ID |
gimohd | 6:77a4c45f6416 | 97 | * |
gimohd | 6:77a4c45f6416 | 98 | * @return the destination ID |
gimohd | 6:77a4c45f6416 | 99 | */ |
gimohd | 6:77a4c45f6416 | 100 | uint8_t getIDD(); |
gimohd | 6:77a4c45f6416 | 101 | |
gimohd | 6:77a4c45f6416 | 102 | /** Sets the CRC byte |
gimohd | 6:77a4c45f6416 | 103 | * |
gimohd | 6:77a4c45f6416 | 104 | * @param CRC the CRC byte |
gimohd | 6:77a4c45f6416 | 105 | */ |
gimohd | 6:77a4c45f6416 | 106 | void setCRC(uint8_t CRC); |
gimohd | 6:77a4c45f6416 | 107 | |
gimohd | 6:77a4c45f6416 | 108 | /** Returns the CRC byte |
gimohd | 6:77a4c45f6416 | 109 | * |
gimohd | 6:77a4c45f6416 | 110 | * @return the CRC byte |
gimohd | 6:77a4c45f6416 | 111 | */ |
gimohd | 6:77a4c45f6416 | 112 | uint8_t getCRC(); |
gimohd | 6:77a4c45f6416 | 113 | |
gimohd | 6:77a4c45f6416 | 114 | /** Sets the pulse width modulation value |
gimohd | 6:77a4c45f6416 | 115 | * |
gimohd | 6:77a4c45f6416 | 116 | * @param PWM the pulse width modulation value |
gimohd | 6:77a4c45f6416 | 117 | */ |
gimohd | 6:77a4c45f6416 | 118 | void setPWM(uint8_t PWM); |
gimohd | 6:77a4c45f6416 | 119 | |
gimohd | 6:77a4c45f6416 | 120 | /** Returns the pulse width modulation value |
gimohd | 6:77a4c45f6416 | 121 | * |
gimohd | 6:77a4c45f6416 | 122 | * @return the pulse width modulation value |
gimohd | 6:77a4c45f6416 | 123 | */ |
gimohd | 6:77a4c45f6416 | 124 | uint8_t getPWM(); |
gimohd | 6:77a4c45f6416 | 125 | |
gimohd | 6:77a4c45f6416 | 126 | /** Sets vector IDN to an other vector |
gimohd | 6:77a4c45f6416 | 127 | * |
gimohd | 6:77a4c45f6416 | 128 | * @param IDN a vector with the visited IDS |
gimohd | 6:77a4c45f6416 | 129 | */ |
gimohd | 6:77a4c45f6416 | 130 | void setIDN(vector<uint8_t> IDN); |
gimohd | 6:77a4c45f6416 | 131 | |
gimohd | 6:77a4c45f6416 | 132 | /** Returns the vector with all visited IDs |
gimohd | 6:77a4c45f6416 | 133 | * |
gimohd | 6:77a4c45f6416 | 134 | * @return the vector with all visited IDs |
gimohd | 6:77a4c45f6416 | 135 | */ |
gimohd | 6:77a4c45f6416 | 136 | vector<uint8_t> getIDN(); |
gimohd | 6:77a4c45f6416 | 137 | |
gimohd | 6:77a4c45f6416 | 138 | /** Sets the vector TMP to an other vector |
gimohd | 6:77a4c45f6416 | 139 | * |
gimohd | 6:77a4c45f6416 | 140 | * @param TMP a vector with all visted MBED's temperatures |
gimohd | 6:77a4c45f6416 | 141 | */ |
gimohd | 6:77a4c45f6416 | 142 | void setTMP(vector<int16_t> TMP); |
gimohd | 6:77a4c45f6416 | 143 | |
gimohd | 6:77a4c45f6416 | 144 | /** Returns the vector of Temperatures |
gimohd | 6:77a4c45f6416 | 145 | * |
gimohd | 6:77a4c45f6416 | 146 | * @return the vector of Temperatures |
gimohd | 6:77a4c45f6416 | 147 | */ |
gimohd | 6:77a4c45f6416 | 148 | vector<int16_t> getTMP(); |
gimohd | 6:77a4c45f6416 | 149 | |
gimohd | 6:77a4c45f6416 | 150 | |
gimohd | 6:77a4c45f6416 | 151 | private: |
gimohd | 6:77a4c45f6416 | 152 | std::string crcString(); |
gimohd | 6:77a4c45f6416 | 153 | uint8_t NUM; |
gimohd | 6:77a4c45f6416 | 154 | uint8_t IDD; |
gimohd | 6:77a4c45f6416 | 155 | uint8_t PWM; |
gimohd | 6:77a4c45f6416 | 156 | uint8_t CRC; |
gimohd | 6:77a4c45f6416 | 157 | vector<uint8_t> IDN; |
gimohd | 6:77a4c45f6416 | 158 | vector<int16_t> TMP; |
gimohd | 6:77a4c45f6416 | 159 | |
gimohd | 6:77a4c45f6416 | 160 | |
gimohd | 6:77a4c45f6416 | 161 | }; |
gimohd | 6:77a4c45f6416 | 162 | |
gimohd | 6:77a4c45f6416 | 163 | #endif |