robot arm demo team / Mbed 2 deprecated RobotArmDemo Featured

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Alert.cpp Source File

Alert.cpp

00001 // Copyright (c) Microsoft. All rights reserved.
00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
00003 
00004 #include "mbed.h"
00005 #include "crt_abstractions.h"
00006 
00007 #include "Alert.h"
00008 
00009 
00010 
00011 SafeCircBuf<Alert, AlertBufSize, uint32_t> AlertBuf;
00012 
00013 void Alert::SetAlert(time_t created, int createdMs, char* msg, char* atype)
00014 {
00015     Created = created;
00016     CreatedMs = createdMs;
00017     
00018     if (strlen(atype) >= AlertTypeMaxLen)
00019     {
00020         strncpy(AlertType, atype, AlertTypeMaxLen);
00021         AlertType[AlertTypeMaxLen - 1] = 0;
00022     }
00023     else
00024     {
00025         strcpy(AlertType, atype);
00026     }
00027     if (strlen(msg) >= AlertMsgMaxLen)
00028     {
00029         strncpy(Msg, msg, AlertMsgMaxLen);
00030         Msg[AlertMsgMaxLen - 1] = 0;
00031     }
00032     else
00033     {
00034         strcpy(Msg, msg);
00035     }
00036 }
00037 
00038 
00039 void Alert::SetPositionAlert(time_t created, int createdMs, int partIx, float diff)
00040 {
00041     char* msg = "Arm joint failed to move to desired position. Joint %d is off by %f";
00042     int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, diff);
00043 
00044     Created = created;
00045     CreatedMs = createdMs;
00046     strcpy(MeasureName, "rot");
00047     Index = partIx;
00048     Value = diff;
00049     
00050     strcpy(AlertType, "Position");
00051 }
00052 
00053 void Alert::SetLoadAlert(time_t created, int createdMs, int partIx, float val)
00054 {
00055     char* msg = "Arm joint reported a high load. Joint %d, load %f";
00056     int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, val);
00057 
00058     Created = created;
00059     CreatedMs = createdMs;
00060     strcpy(MeasureName, "load");
00061     Index = partIx;
00062     Value = val;
00063     
00064     strcpy(AlertType, "Load");
00065 }
00066 
00067 void Alert::SetHardwareAlert(time_t created, int createdMs, int partIx, int code)
00068 {
00069     char* msg = "Arm joint reported an error. Joint %d error code %d";
00070     int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, code);
00071 
00072     Created = created;
00073     CreatedMs = createdMs;
00074     strcpy(MeasureName, "error");
00075     Index = partIx;
00076     Value = (float)code;
00077     
00078     strcpy(AlertType, "Hardware");
00079 }
00080 
00081 void Alert::SetTemperatureAlert(time_t created, int createdMs, int partIx, float temp)
00082 {
00083     char* msg = "Arm joint reported a high temperature. Joint %d temperature %f";
00084     int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, temp);
00085 
00086     Created = created;
00087     CreatedMs = createdMs;
00088     strcpy(MeasureName, "temp");
00089     Index = partIx;
00090     Value = temp;
00091     
00092     strcpy(AlertType, "Temperature");
00093 }
00094 
00095 void Alert::SetVoltageAlert(time_t created, int createdMs, int partIx, float val)
00096 {
00097     char* msg = "Arm joint reported an unexpected voltge. Joint %d volt %f";
00098     int slen = sprintf_s(Msg, AlertMsgMaxLen, msg, partIx, val);
00099 
00100     Created = created;
00101     CreatedMs = createdMs;
00102     strcpy(MeasureName, "volt");
00103     Index = partIx;
00104     Value = val;
00105     
00106     strcpy(AlertType, "Voltage");
00107 }