demo project

Dependencies:   AX-12A Dynamixel mbed iothub_client EthernetInterface NTPClient ConfigFile SDFileSystem iothub_amqp_transport mbed-rtos proton-c-mbed wolfSSL

Committer:
henryrawas
Date:
Thu Feb 04 20:10:33 2016 +0000
Revision:
33:8b9dcbf6d8ec
Parent:
20:891b5270845a
update libs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
henryrawas 19:2f0ec9ac1238 1 // Copyright (c) Microsoft. All rights reserved.
henryrawas 19:2f0ec9ac1238 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
henryrawas 19:2f0ec9ac1238 3
henryrawas 7:6723f6887d00 4 #include "mbed.h"
henryrawas 7:6723f6887d00 5 #include "crt_abstractions.h"
henryrawas 7:6723f6887d00 6
henryrawas 7:6723f6887d00 7 #include "Alert.h"
henryrawas 7:6723f6887d00 8
henryrawas 7:6723f6887d00 9
henryrawas 7:6723f6887d00 10
henryrawas 7:6723f6887d00 11 SafeCircBuf<Alert, AlertBufSize, uint32_t> AlertBuf;
henryrawas 7:6723f6887d00 12
henryrawas 20:891b5270845a 13 void Alert::SetAlert(time_t created, int createdMs, char* msg, char* atype)
henryrawas 7:6723f6887d00 14 {
henryrawas 7:6723f6887d00 15 Created = created;
henryrawas 20:891b5270845a 16 CreatedMs = createdMs;
henryrawas 7:6723f6887d00 17
henryrawas 7:6723f6887d00 18 if (strlen(atype) >= AlertTypeMaxLen)
henryrawas 7:6723f6887d00 19 {
henryrawas 7:6723f6887d00 20 strncpy(AlertType, atype, AlertTypeMaxLen);
henryrawas 7:6723f6887d00 21 AlertType[AlertTypeMaxLen - 1] = 0;
henryrawas 7:6723f6887d00 22 }
henryrawas 7:6723f6887d00 23 else
henryrawas 7:6723f6887d00 24 {
henryrawas 7:6723f6887d00 25 strcpy(AlertType, atype);
henryrawas 7:6723f6887d00 26 }
henryrawas 7:6723f6887d00 27 if (strlen(msg) >= AlertMsgMaxLen)
henryrawas 7:6723f6887d00 28 {
henryrawas 7:6723f6887d00 29 strncpy(Msg, msg, AlertMsgMaxLen);
henryrawas 7:6723f6887d00 30 Msg[AlertMsgMaxLen - 1] = 0;
henryrawas 7:6723f6887d00 31 }
henryrawas 7:6723f6887d00 32 else
henryrawas 7:6723f6887d00 33 {
henryrawas 7:6723f6887d00 34 strcpy(Msg, msg);
henryrawas 7:6723f6887d00 35 }
henryrawas 7:6723f6887d00 36 }
henryrawas 7:6723f6887d00 37
henryrawas 7:6723f6887d00 38
henryrawas 20:891b5270845a 39 void Alert::SetPositionAlert(time_t created, int createdMs, int partIx, float diff)
henryrawas 7:6723f6887d00 40 {
henryrawas 13:ffeff9b5e513 41 char* msg = "Arm joint failed to move to desired position. Joint %d is off by %f";
henryrawas 7:6723f6887d00 42 int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, diff);
henryrawas 13:ffeff9b5e513 43
henryrawas 7:6723f6887d00 44 Created = created;
henryrawas 20:891b5270845a 45 CreatedMs = createdMs;
henryrawas 13:ffeff9b5e513 46 strcpy(MeasureName, "rot");
henryrawas 13:ffeff9b5e513 47 Index = partIx;
henryrawas 13:ffeff9b5e513 48 Value = diff;
henryrawas 7:6723f6887d00 49
henryrawas 7:6723f6887d00 50 strcpy(AlertType, "Position");
henryrawas 8:d98e2dec0f40 51 }
henryrawas 8:d98e2dec0f40 52
henryrawas 20:891b5270845a 53 void Alert::SetLoadAlert(time_t created, int createdMs, int partIx, float val)
henryrawas 8:d98e2dec0f40 54 {
henryrawas 13:ffeff9b5e513 55 char* msg = "Arm joint reported a high load. Joint %d, load %f";
henryrawas 13:ffeff9b5e513 56 int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, val);
henryrawas 13:ffeff9b5e513 57
henryrawas 13:ffeff9b5e513 58 Created = created;
henryrawas 20:891b5270845a 59 CreatedMs = createdMs;
henryrawas 13:ffeff9b5e513 60 strcpy(MeasureName, "load");
henryrawas 13:ffeff9b5e513 61 Index = partIx;
henryrawas 13:ffeff9b5e513 62 Value = val;
henryrawas 13:ffeff9b5e513 63
henryrawas 13:ffeff9b5e513 64 strcpy(AlertType, "Load");
henryrawas 13:ffeff9b5e513 65 }
henryrawas 13:ffeff9b5e513 66
henryrawas 20:891b5270845a 67 void Alert::SetHardwareAlert(time_t created, int createdMs, int partIx, int code)
henryrawas 13:ffeff9b5e513 68 {
henryrawas 13:ffeff9b5e513 69 char* msg = "Arm joint reported an error. Joint %d error code %d";
henryrawas 8:d98e2dec0f40 70 int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, code);
henryrawas 13:ffeff9b5e513 71
henryrawas 8:d98e2dec0f40 72 Created = created;
henryrawas 20:891b5270845a 73 CreatedMs = createdMs;
henryrawas 13:ffeff9b5e513 74 strcpy(MeasureName, "error");
henryrawas 13:ffeff9b5e513 75 Index = partIx;
henryrawas 13:ffeff9b5e513 76 Value = (float)code;
henryrawas 8:d98e2dec0f40 77
henryrawas 8:d98e2dec0f40 78 strcpy(AlertType, "Hardware");
henryrawas 7:6723f6887d00 79 }
henryrawas 8:d98e2dec0f40 80
henryrawas 20:891b5270845a 81 void Alert::SetTemperatureAlert(time_t created, int createdMs, int partIx, float temp)
henryrawas 8:d98e2dec0f40 82 {
henryrawas 13:ffeff9b5e513 83 char* msg = "Arm joint reported a high temperature. Joint %d temperature %f";
henryrawas 8:d98e2dec0f40 84 int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, temp);
henryrawas 13:ffeff9b5e513 85
henryrawas 8:d98e2dec0f40 86 Created = created;
henryrawas 20:891b5270845a 87 CreatedMs = createdMs;
henryrawas 13:ffeff9b5e513 88 strcpy(MeasureName, "temp");
henryrawas 13:ffeff9b5e513 89 Index = partIx;
henryrawas 13:ffeff9b5e513 90 Value = temp;
henryrawas 8:d98e2dec0f40 91
henryrawas 8:d98e2dec0f40 92 strcpy(AlertType, "Temperature");
henryrawas 8:d98e2dec0f40 93 }
henryrawas 13:ffeff9b5e513 94
henryrawas 20:891b5270845a 95 void Alert::SetVoltageAlert(time_t created, int createdMs, int partIx, float val)
henryrawas 13:ffeff9b5e513 96 {
henryrawas 13:ffeff9b5e513 97 char* msg = "Arm joint reported an unexpected voltge. Joint %d volt %f";
henryrawas 13:ffeff9b5e513 98 int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, val);
henryrawas 13:ffeff9b5e513 99
henryrawas 13:ffeff9b5e513 100 Created = created;
henryrawas 20:891b5270845a 101 CreatedMs = createdMs;
henryrawas 13:ffeff9b5e513 102 strcpy(MeasureName, "volt");
henryrawas 13:ffeff9b5e513 103 Index = partIx;
henryrawas 13:ffeff9b5e513 104 Value = val;
henryrawas 13:ffeff9b5e513 105
henryrawas 13:ffeff9b5e513 106 strcpy(AlertType, "Voltage");
henryrawas 13:ffeff9b5e513 107 }