System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Committer:
pspatel321
Date:
Wed Feb 11 23:09:57 2015 +0000
Revision:
39:ddf38df9699e
Parent:
38:8efacce315ae
Updated CAN IDs for datalogging.  Changed profile encoding.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pspatel321 38:8efacce315ae 1 #ifndef INMACROS_H
pspatel321 38:8efacce315ae 2 #define INMACROS_H
pspatel321 38:8efacce315ae 3
pspatel321 38:8efacce315ae 4 /*************** Serial String Input ****************/
pspatel321 38:8efacce315ae 5
pspatel321 38:8efacce315ae 6 // Compare string to a word in the serial input, shorthand
pspatel321 38:8efacce315ae 7 #define CMP(w, string) if (!strcasecmp(word[w-1], string))
pspatel321 38:8efacce315ae 8
pspatel321 38:8efacce315ae 9 // Macro linking a serial string to a change function, 2 word command
pspatel321 38:8efacce315ae 10 #define CHANGE_VAR(STR, NAME) \
pspatel321 38:8efacce315ae 11 CMP(1, STR) { \
pspatel321 38:8efacce315ae 12 float f = strtof(word[1], &next); \
pspatel321 38:8efacce315ae 13 if (*next == 0) { \
pspatel321 38:8efacce315ae 14 if (param->change_##NAME(f)) { \
pspatel321 38:8efacce315ae 15 op->profileModded=true; \
pspatel321 38:8efacce315ae 16 parsed=true; \
pspatel321 38:8efacce315ae 17 } \
pspatel321 38:8efacce315ae 18 } \
pspatel321 38:8efacce315ae 19 }
pspatel321 38:8efacce315ae 20
pspatel321 38:8efacce315ae 21 /*************** CAN Message Profile Out ***************/
pspatel321 38:8efacce315ae 22 #include "outMacros.h"
pspatel321 38:8efacce315ae 23
pspatel321 38:8efacce315ae 24 // Send out an item from the profile
pspatel321 38:8efacce315ae 25 #define CAN_PROFILE(DATA, ID) \
pspatel321 38:8efacce315ae 26 SEND_CAN_SINGLE(param->DATA, ID);
pspatel321 38:8efacce315ae 27
pspatel321 38:8efacce315ae 28 // Replies for commands that do not return data
pspatel321 38:8efacce315ae 29 #define CAN_SUCCESS \
pspatel321 38:8efacce315ae 30 msg.data[0]=1; \
pspatel321 38:8efacce315ae 31 SEND_CAN(1, msg.id) \
pspatel321 38:8efacce315ae 32 return 1;
pspatel321 38:8efacce315ae 33
pspatel321 38:8efacce315ae 34 #define CAN_FAIL \
pspatel321 38:8efacce315ae 35 msg.data[0]=0; \
pspatel321 38:8efacce315ae 36 SEND_CAN(1, msg.id) \
pspatel321 38:8efacce315ae 37 return 0;
pspatel321 38:8efacce315ae 38
pspatel321 38:8efacce315ae 39 /*********************** CAN Bus Input ******************************/
pspatel321 38:8efacce315ae 40
pspatel321 38:8efacce315ae 41 template <class Type>
pspatel321 38:8efacce315ae 42 Type CAN_EXTRACT(Type type, CANMessage& msg) {
pspatel321 38:8efacce315ae 43 return *((Type*)((void*)(&msg.data[0])));
pspatel321 38:8efacce315ae 44 }
pspatel321 38:8efacce315ae 45
pspatel321 38:8efacce315ae 46 #define CAN_CHANGE(NAME, ID) \
pspatel321 38:8efacce315ae 47 if (msg.id == ID) { \
pspatel321 38:8efacce315ae 48 if (msg.len == sizeof(param->NAME)) { \
pspatel321 38:8efacce315ae 49 if (param->change_##NAME(CAN_EXTRACT(param->NAME, msg))) { \
pspatel321 38:8efacce315ae 50 op->profileModded=true; \
pspatel321 38:8efacce315ae 51 parsed = true; \
pspatel321 38:8efacce315ae 52 } \
pspatel321 38:8efacce315ae 53 } \
pspatel321 38:8efacce315ae 54 CAN_PROFILE(NAME, ID) \
pspatel321 38:8efacce315ae 55 }
pspatel321 38:8efacce315ae 56
pspatel321 38:8efacce315ae 57
pspatel321 38:8efacce315ae 58 #endif