rrrrr
Fork of Communication_Robot by
Utilities.h@4:7ebd932a9bef, 2015-12-08 (annotated)
- Committer:
- Tiz
- Date:
- Tue Dec 08 21:04:18 2015 +0000
- Revision:
- 4:7ebd932a9bef
- Parent:
- 0:0c88691e3904
dee
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
soulx | 0:0c88691e3904 | 1 | /* Copyright (c) 2012 Georgios Petrou, MIT License |
soulx | 0:0c88691e3904 | 2 | * |
soulx | 0:0c88691e3904 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
soulx | 0:0c88691e3904 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
soulx | 0:0c88691e3904 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
soulx | 0:0c88691e3904 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
soulx | 0:0c88691e3904 | 7 | * furnished to do so, subject to the following conditions: |
soulx | 0:0c88691e3904 | 8 | * |
soulx | 0:0c88691e3904 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
soulx | 0:0c88691e3904 | 10 | * substantial portions of the Software. |
soulx | 0:0c88691e3904 | 11 | * |
soulx | 0:0c88691e3904 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
soulx | 0:0c88691e3904 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
soulx | 0:0c88691e3904 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
soulx | 0:0c88691e3904 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
soulx | 0:0c88691e3904 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
soulx | 0:0c88691e3904 | 17 | */ |
soulx | 0:0c88691e3904 | 18 | |
soulx | 0:0c88691e3904 | 19 | #ifndef MX28_UTILITIES_H |
soulx | 0:0c88691e3904 | 20 | #define MX28_UTILITIES_H |
soulx | 0:0c88691e3904 | 21 | |
soulx | 0:0c88691e3904 | 22 | #include "mbed.h" |
soulx | 0:0c88691e3904 | 23 | |
soulx | 0:0c88691e3904 | 24 | /** MX28 utility functions class |
soulx | 0:0c88691e3904 | 25 | */ |
soulx | 0:0c88691e3904 | 26 | class Utilities |
soulx | 0:0c88691e3904 | 27 | { |
soulx | 0:0c88691e3904 | 28 | public: |
soulx | 0:0c88691e3904 | 29 | /** Get the checksum for a packet. |
soulx | 0:0c88691e3904 | 30 | * |
soulx | 0:0c88691e3904 | 31 | * @param data The array of bytes. |
soulx | 0:0c88691e3904 | 32 | * @param length The size of the array. |
soulx | 0:0c88691e3904 | 33 | * @return checksum |
soulx | 0:0c88691e3904 | 34 | */ |
soulx | 0:0c88691e3904 | 35 | static uint8_t GetCheckSum(const uint8_t *data, uint8_t length); |
soulx | 0:0c88691e3904 | 36 | |
soulx | 0:0c88691e3904 | 37 | /** Convert a UInt16 number to array of chars. |
soulx | 0:0c88691e3904 | 38 | * |
soulx | 0:0c88691e3904 | 39 | * @param value The number value. |
soulx | 0:0c88691e3904 | 40 | * @param data The array to store the conversion. |
soulx | 0:0c88691e3904 | 41 | */ |
soulx | 0:0c88691e3904 | 42 | static void ConvertUInt16ToUInt8Array(uint16_t value, uint8_t* data); |
soulx | 0:0c88691e3904 | 43 | |
soulx | 0:0c88691e3904 | 44 | /** Convert an Int16 number to array of chars. |
soulx | 0:0c88691e3904 | 45 | * |
soulx | 0:0c88691e3904 | 46 | * @param value The number value. |
soulx | 0:0c88691e3904 | 47 | * @param data The array to store the conversion. |
soulx | 0:0c88691e3904 | 48 | */ |
soulx | 0:0c88691e3904 | 49 | static void ConvertInt16ToUInt8Array(int16_t value, uint8_t* data); |
soulx | 0:0c88691e3904 | 50 | |
soulx | 0:0c88691e3904 | 51 | /** Convert a UInt32 number to array of chars. |
soulx | 0:0c88691e3904 | 52 | * |
soulx | 0:0c88691e3904 | 53 | * @param value The number value. |
soulx | 0:0c88691e3904 | 54 | * @param data The array to store the conversion. |
soulx | 0:0c88691e3904 | 55 | */ |
soulx | 0:0c88691e3904 | 56 | static void ConvertUInt32ToUInt8Array(uint32_t value, uint8_t* data); |
soulx | 0:0c88691e3904 | 57 | |
soulx | 0:0c88691e3904 | 58 | /** Convert an Int32 number to array of chars. |
soulx | 0:0c88691e3904 | 59 | * |
soulx | 0:0c88691e3904 | 60 | * @param value The number value. |
soulx | 0:0c88691e3904 | 61 | * @param data The array to store the conversion. |
soulx | 0:0c88691e3904 | 62 | */ |
soulx | 0:0c88691e3904 | 63 | static void ConvertInt32ToUInt8Array(int32_t value, uint8_t* data); |
soulx | 0:0c88691e3904 | 64 | |
soulx | 0:0c88691e3904 | 65 | /** Convert an array of char to UInt16. |
soulx | 0:0c88691e3904 | 66 | * |
soulx | 0:0c88691e3904 | 67 | * @param data The array containing the chars. |
soulx | 0:0c88691e3904 | 68 | * @return UInt16 converted number. |
soulx | 0:0c88691e3904 | 69 | */ |
soulx | 0:0c88691e3904 | 70 | static uint16_t ConvertUInt8ArrayToUInt16(uint8_t* data); |
soulx | 0:0c88691e3904 | 71 | |
soulx | 0:0c88691e3904 | 72 | /** Convert an array of char to Int16. |
soulx | 0:0c88691e3904 | 73 | * |
soulx | 0:0c88691e3904 | 74 | * @param data The array containing the chars. |
soulx | 0:0c88691e3904 | 75 | * @return Int16 converted number. |
soulx | 0:0c88691e3904 | 76 | */ |
soulx | 0:0c88691e3904 | 77 | static int16_t ConvertUInt8ArrayToInt16(uint8_t* data); |
soulx | 0:0c88691e3904 | 78 | |
soulx | 0:0c88691e3904 | 79 | /** Convert an array of char to Int32. |
soulx | 0:0c88691e3904 | 80 | * |
soulx | 0:0c88691e3904 | 81 | * @param data The array containing the chars. |
soulx | 0:0c88691e3904 | 82 | * @return Int32 number. |
soulx | 0:0c88691e3904 | 83 | */ |
soulx | 0:0c88691e3904 | 84 | static int32_t ConvertUInt8ArrayToInt32(uint8_t* data); |
soulx | 0:0c88691e3904 | 85 | }; |
soulx | 0:0c88691e3904 | 86 | |
soulx | 0:0c88691e3904 | 87 | #endif // MX28_UTILITIES_H |
soulx | 0:0c88691e3904 | 88 |