Simple sample that demonstrates reading the FXOS8700CQ accelerometer, convert the data to JSON and send to an Azure IoT Hub.
Dependencies: azure_umqtt_c iothub_mqtt_transport mbed-rtos mbed wolfSSL Socket lwip-eth lwip-sys lwip
azure_c_shared_utility/uniqueid_stub.c@3:c0556ff7b8e3, 2016-12-08 (annotated)
- Committer:
- markrad
- Date:
- Thu Dec 08 00:11:40 2016 +0000
- Revision:
- 3:c0556ff7b8e3
Hack the code to get restart working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markrad | 3:c0556ff7b8e3 | 1 | // Copyright (c) Microsoft. All rights reserved. |
markrad | 3:c0556ff7b8e3 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
markrad | 3:c0556ff7b8e3 | 3 | |
markrad | 3:c0556ff7b8e3 | 4 | #include <stdlib.h> |
markrad | 3:c0556ff7b8e3 | 5 | #include <stdint.h> |
markrad | 3:c0556ff7b8e3 | 6 | #include "azure_c_shared_utility/uniqueid.h" |
markrad | 3:c0556ff7b8e3 | 7 | #include "azure_c_shared_utility/xlogging.h" |
markrad | 3:c0556ff7b8e3 | 8 | #include <time.h> |
markrad | 3:c0556ff7b8e3 | 9 | |
markrad | 3:c0556ff7b8e3 | 10 | DEFINE_ENUM_STRINGS(UNIQUEID_RESULT, UNIQUEID_RESULT_VALUES); |
markrad | 3:c0556ff7b8e3 | 11 | |
markrad | 3:c0556ff7b8e3 | 12 | static const char tochar[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; |
markrad | 3:c0556ff7b8e3 | 13 | static void generate128BitUUID(unsigned char* arrayOfByte) |
markrad | 3:c0556ff7b8e3 | 14 | { |
markrad | 3:c0556ff7b8e3 | 15 | size_t arrayIndex; |
markrad | 3:c0556ff7b8e3 | 16 | |
markrad | 3:c0556ff7b8e3 | 17 | for (arrayIndex = 0; arrayIndex < 16; arrayIndex++) |
markrad | 3:c0556ff7b8e3 | 18 | { |
markrad | 3:c0556ff7b8e3 | 19 | arrayOfByte[arrayIndex] = (unsigned char)rand(); |
markrad | 3:c0556ff7b8e3 | 20 | } |
markrad | 3:c0556ff7b8e3 | 21 | |
markrad | 3:c0556ff7b8e3 | 22 | // |
markrad | 3:c0556ff7b8e3 | 23 | // Stick in the version field for random uuid. |
markrad | 3:c0556ff7b8e3 | 24 | // |
markrad | 3:c0556ff7b8e3 | 25 | arrayOfByte[7] &= 0x0f; //clear the bit field |
markrad | 3:c0556ff7b8e3 | 26 | arrayOfByte[7] |= 0x40; //set the ones we care about |
markrad | 3:c0556ff7b8e3 | 27 | |
markrad | 3:c0556ff7b8e3 | 28 | // |
markrad | 3:c0556ff7b8e3 | 29 | // Stick in the variant field for the random uuid. |
markrad | 3:c0556ff7b8e3 | 30 | // |
markrad | 3:c0556ff7b8e3 | 31 | arrayOfByte[8] &= 0xf3; // Clear |
markrad | 3:c0556ff7b8e3 | 32 | arrayOfByte[8] |= 0x08; // Set |
markrad | 3:c0556ff7b8e3 | 33 | |
markrad | 3:c0556ff7b8e3 | 34 | } |
markrad | 3:c0556ff7b8e3 | 35 | |
markrad | 3:c0556ff7b8e3 | 36 | // TODO: The User will need to call srand before calling this function |
markrad | 3:c0556ff7b8e3 | 37 | UNIQUEID_RESULT UniqueId_Generate(char* uid, size_t len) |
markrad | 3:c0556ff7b8e3 | 38 | { |
markrad | 3:c0556ff7b8e3 | 39 | UNIQUEID_RESULT result; |
markrad | 3:c0556ff7b8e3 | 40 | unsigned char arrayOfChar[16]; |
markrad | 3:c0556ff7b8e3 | 41 | |
markrad | 3:c0556ff7b8e3 | 42 | /* Codes_SRS_UNIQUEID_07_002: [If uid is NULL then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */ |
markrad | 3:c0556ff7b8e3 | 43 | /* Codes_SRS_UNIQUEID_07_003: [If len is less then 37 then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */ |
markrad | 3:c0556ff7b8e3 | 44 | if (uid == NULL || len < 37) |
markrad | 3:c0556ff7b8e3 | 45 | { |
markrad | 3:c0556ff7b8e3 | 46 | result = UNIQUEID_INVALID_ARG; |
markrad | 3:c0556ff7b8e3 | 47 | LogError("Buffer Size is Null or length is less then 37 bytes"); |
markrad | 3:c0556ff7b8e3 | 48 | } |
markrad | 3:c0556ff7b8e3 | 49 | else |
markrad | 3:c0556ff7b8e3 | 50 | { |
markrad | 3:c0556ff7b8e3 | 51 | size_t arrayIndex; |
markrad | 3:c0556ff7b8e3 | 52 | size_t shiftCount; |
markrad | 3:c0556ff7b8e3 | 53 | size_t characterPosition = 0; |
markrad | 3:c0556ff7b8e3 | 54 | |
markrad | 3:c0556ff7b8e3 | 55 | /* Codes_SRS_UNIQUEID_07_001: [UniqueId_Generate shall create a unique Id 36 character long string.] */ |
markrad | 3:c0556ff7b8e3 | 56 | generate128BitUUID(arrayOfChar); |
markrad | 3:c0556ff7b8e3 | 57 | for (arrayIndex = 0; arrayIndex < 16; arrayIndex++) |
markrad | 3:c0556ff7b8e3 | 58 | { |
markrad | 3:c0556ff7b8e3 | 59 | for (shiftCount = 0; shiftCount <= 1; shiftCount++) |
markrad | 3:c0556ff7b8e3 | 60 | { |
markrad | 3:c0556ff7b8e3 | 61 | char hexChar = tochar[arrayOfChar[arrayIndex] & 0xf]; |
markrad | 3:c0556ff7b8e3 | 62 | if ((characterPosition == 8) || (characterPosition == 13) || (characterPosition == 18) || (characterPosition == 23)) |
markrad | 3:c0556ff7b8e3 | 63 | { |
markrad | 3:c0556ff7b8e3 | 64 | uid[characterPosition] = '-'; |
markrad | 3:c0556ff7b8e3 | 65 | characterPosition++; |
markrad | 3:c0556ff7b8e3 | 66 | } |
markrad | 3:c0556ff7b8e3 | 67 | uid[characterPosition] = hexChar; |
markrad | 3:c0556ff7b8e3 | 68 | characterPosition++; |
markrad | 3:c0556ff7b8e3 | 69 | arrayOfChar[arrayIndex] = arrayOfChar[arrayIndex] >> 4; |
markrad | 3:c0556ff7b8e3 | 70 | } |
markrad | 3:c0556ff7b8e3 | 71 | } |
markrad | 3:c0556ff7b8e3 | 72 | uid[characterPosition] = 0; |
markrad | 3:c0556ff7b8e3 | 73 | result = UNIQUEID_OK; |
markrad | 3:c0556ff7b8e3 | 74 | } |
markrad | 3:c0556ff7b8e3 | 75 | return result; |
markrad | 3:c0556ff7b8e3 | 76 | } |