AKM Development Platform. This is the D7.014 version.

Dependencies:   AK09970 AK099XX AK7401 AK7451 AK8963X AK9750 AK9752 AkmSensor BLE_API I2CNano MCP342x SerialNano SpiNano TCA9554A mbed nRF51822

Fork of AKDP by Masahiko Fukasawa

Committer:
masahikofukasawa
Date:
Wed May 03 18:31:33 2017 +0000
Branch:
multi_sensor_test
Revision:
40:24065d634473
Parent:
39:8222b59a822e
re-publish for Rev D7.014.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
masahikofukasawa 0:c240899240e7 1 #ifndef __MESSAGE_H__
masahikofukasawa 0:c240899240e7 2 #define __MESSAGE_H__
masahikofukasawa 0:c240899240e7 3
masahikofukasawa 0:c240899240e7 4 /**
masahikofukasawa 0:c240899240e7 5 * Message is sent from the host. A message consists of a command and arguments.
masahikofukasawa 0:c240899240e7 6 */
masahikofukasawa 0:c240899240e7 7 class Message {
masahikofukasawa 0:c240899240e7 8 public:
masahikofukasawa 0:c240899240e7 9 typedef enum {
masahikofukasawa 0:c240899240e7 10 CMD_GET_FW_VERSION = 0x01, /**< Gets FW version. */
masahikofukasawa 0:c240899240e7 11 CMD_GET_MAG_PART = 0x02, /**< Gets magnetic sensor ID */
masahikofukasawa 18:d75838bceaaf 12 CMD_BOOT_STATUS = 0x0F, /**< Boot status. */
masahikofukasawa 38:f6fef368e695 13 CMD_GET_SENSOR_INDEX = 0x06, /**< . */
masahikofukasawa 38:f6fef368e695 14 CMD_SET_SENSOR_INDEX = 0x07, /**< . */
masahikofukasawa 38:f6fef368e695 15 CMD_GET_TOTAL_SENSOR_NUM = 0x08, /**< . */
masahikofukasawa 11:53e52f5f1051 16 // CMD_GET_THRESHOLD = 0x80, /**< Gets threshold of AK0997x */
masahikofukasawa 11:53e52f5f1051 17 // CMD_SET_THRESHOLD_FROM_HOST = 0x81, /**< Sets threshold of AK0997x from host. */
masahikofukasawa 11:53e52f5f1051 18 // CMD_SET_MEASUREMENT_FREQUENCY = 0x82, /**< Sets measurement frequency. */
masahikofukasawa 11:53e52f5f1051 19 // CMD_SEND_SWITCH_MODE_MEASUREMENT_DATA = 0x83, /**< Sends measurement data on/off */
masahikofukasawa 11:53e52f5f1051 20 // CMD_SWITCH_MODE_MEASUREMENT_DATA = 0x84, /**< Measurement data in switch mode */
masahikofukasawa 11:53e52f5f1051 21 // CMD_GET_POLARITY = 0x85, /**< Gets polarity of AK0997x */
masahikofukasawa 11:53e52f5f1051 22 // CMD_SET_POLARITY = 0x86, /**< Sets polarity of AK0997x */
masahikofukasawa 11:53e52f5f1051 23 CMD_PROGSW_GET_THRESHOLD = 0x80, /**< Gets threshold of AK09970. */
masahikofukasawa 11:53e52f5f1051 24 CMD_PROGSW_SET_THRESHOLD = 0x81, /**< Sets threshold of AK09970. */
masahikofukasawa 11:53e52f5f1051 25 // CMD_PROGSW_GET_READ_ADDRESS = 0x82, /**< Gets read address of AK09970. */
masahikofukasawa 11:53e52f5f1051 26 // CMD_PROGSW_SET_READ_ADDRESS = 0x83, /**< Sets read address of AK09970. */
masahikofukasawa 11:53e52f5f1051 27 // CMD_PROGSW_GET_SWITCH_MODE = 0x84, /**< Gets interrupt mode of AK09970. */
masahikofukasawa 11:53e52f5f1051 28 // CMD_PROGSW_SET_SWITCH_MODE = 0x85, /**< Sets interrupt mode of AK09970. */
masahikofukasawa 11:53e52f5f1051 29 CMD_PROGSW_GET_READ_COFIGURATION = 0x82, /**< Gets read configuration of AK09970. */
masahikofukasawa 11:53e52f5f1051 30 CMD_PROGSW_SET_READ_COFIGURATION = 0x83, /**< Sets read configuration of AK09970. */
masahikofukasawa 11:53e52f5f1051 31 CMD_PROGSW_GET_SWITCH_COFIGURATION = 0x84, /**< Gets switch configuration of AK09970. */
masahikofukasawa 11:53e52f5f1051 32 CMD_PROGSW_SET_SWITCH_COFIGURATION = 0x85, /**< Sets switch configuration of AK09970. */
masahikofukasawa 11:53e52f5f1051 33 CMD_PROGSW_GET_OPERATION_MODE = 0x86, /**< Gets operation mode of AK09970. */
masahikofukasawa 11:53e52f5f1051 34 CMD_PROGSW_SET_OPERATION_MODE = 0x87, /**< Sets operation mode of AK09970. */
masahikofukasawa 0:c240899240e7 35
masahikofukasawa 0:c240899240e7 36 CMD_IR_GET_THRESHOLD = 0x90, /**< Gets threshold of AK9750. */
masahikofukasawa 0:c240899240e7 37 CMD_IR_SET_THRESHOLD = 0x91, /**< Sets threshold of AK9750. */
masahikofukasawa 0:c240899240e7 38 CMD_IR_GET_HYSTERESIS = 0x92, /**< Gets hysteresis setting of AK9750 */
masahikofukasawa 0:c240899240e7 39 CMD_IR_SET_HYSTERESIS = 0x93, /**< Sets hysteresis to AK9750 */
masahikofukasawa 1:0914af311974 40 CMD_IR_GET_INTERRUPT = 0x94, /**< Gets interrupt mode of AK9750 */
masahikofukasawa 1:0914af311974 41 CMD_IR_SET_INTERRUPT = 0x95, /**< Sets interrupt mode of AK9750 */
masahikofukasawa 1:0914af311974 42 CMD_IR_GET_OPERATION_MODE = 0x96, /**< Gets operation mode of AK9750 */
masahikofukasawa 1:0914af311974 43 CMD_IR_SET_OPERATION_MODE = 0x97, /**< Sets operation mode of AK9750 */
masahikofukasawa 1:0914af311974 44 CMD_IR_GET_THRESHOLD_EEPROM = 0x98, /**< Gets EEPROM threshold of AK9750. */
masahikofukasawa 1:0914af311974 45 CMD_IR_SET_THRESHOLD_EEPROM = 0x99, /**< Sets EEPROM threshold of AK9750. */
masahikofukasawa 1:0914af311974 46 CMD_IR_GET_HYSTERESIS_EEPROM = 0x9A, /**< Gets EEPROM hysteresis setting of AK9750 */
masahikofukasawa 1:0914af311974 47 CMD_IR_SET_HYSTERESIS_EEPROM = 0x9B, /**< Sets EEPROM hysteresis to AK9750 */
masahikofukasawa 1:0914af311974 48 CMD_IR_GET_INTERRUPT_EEPROM = 0x9C, /**< Gets EEPROM interrupt mode of AK9750 */
masahikofukasawa 1:0914af311974 49 CMD_IR_SET_INTERRUPT_EEPROM = 0x9D, /**< Sets EEPROM interrupt mode of AK9750 */
masahikofukasawa 1:0914af311974 50 CMD_IR_GET_OPERATION_MODE_EEPROM = 0x9E, /**< Gets EEPROM operation mode of AK9750 */
masahikofukasawa 1:0914af311974 51 CMD_IR_SET_OPERATION_MODE_EEPROM = 0x9F, /**< Sets EEPROM operation mode of AK9750 */
masahikofukasawa 0:c240899240e7 52
masahikofukasawa 0:c240899240e7 53 CMD_DOOR_STATE_CHANGED = 0xA0, /**< Door state changed. */
masahikofukasawa 0:c240899240e7 54 CMD_UPDATE_MAG_VECTOR = 0xA1, /**< Update magnetic vector state. */
masahikofukasawa 0:c240899240e7 55 CMD_THRESHOLD_UPDATED = 0xA2, /**< Threshold updated. */
masahikofukasawa 0:c240899240e7 56 CMD_GET_CURRENT_DOOR_STATE = 0xA3, /**< Gets the current door state. */
masahikofukasawa 0:c240899240e7 57 CMD_IR_STATE_CHANGED = 0xA5, /**< IR state changed. */
masahikofukasawa 0:c240899240e7 58 CMD_UPDATE_IR_STATE = 0xA6, /**< Update IR state 1 or 2 */
masahikofukasawa 0:c240899240e7 59 CMD_GET_CURRENT_HUMAN_PRESENCE_STATE = 0xA7, /**< Gets the current human presence state. */
masahikofukasawa 0:c240899240e7 60 CMD_IR_THRESHOLD_UPDATED = 0xA8, /**< IR threshold updated. */
masahikofukasawa 0:c240899240e7 61
masahikofukasawa 0:c240899240e7 62 // CMD_MOTION_DETECTED = 0xB1, /**< Motion detected. */
masahikofukasawa 0:c240899240e7 63 // CMD_GET_MOTION_THRESHOLD = 0xB2, /**< Get motion threshold */
masahikofukasawa 0:c240899240e7 64 // CMD_SET_MOTION_THRESHOLD = 0xB3, /**< Set motion threshold */
masahikofukasawa 0:c240899240e7 65 CMD_UNKNOWN = 0x00, /**< Unknown command. */
masahikofukasawa 0:c240899240e7 66 CMD_SET_SERIAL_TARGET = 0x0A, /**< Set serial output target */
masahikofukasawa 0:c240899240e7 67 CMD_REG_WRITE = 0x11, /**< Register write 1 byte */
masahikofukasawa 0:c240899240e7 68 CMD_REG_WRITEN = 0x12, /**< Register write N bytes */
masahikofukasawa 0:c240899240e7 69 CMD_REG_READ = 0x13, /**< Register read 1 byte */
masahikofukasawa 0:c240899240e7 70 CMD_REG_READN = 0x14, /**< Register read N bytes */
masahikofukasawa 11:53e52f5f1051 71 CMD_COMPASS_GET_OPERATION_MODE = 0x16, /**< Gets operation mode of e-compass*/
masahikofukasawa 11:53e52f5f1051 72 CMD_COMPASS_SET_OPERATION_MODE = 0x17, /**< Sets operation mode of e-compass*/
masahikofukasawa 0:c240899240e7 73 CMD_GET_ID = 0xB0, /**< Get connected sensor ID */
masahikofukasawa 0:c240899240e7 74 CMD_STOP_MEASUREMENT = 0xBA, /**< Stop Measurement */
masahikofukasawa 0:c240899240e7 75 CMD_START_MEASUREMENT = 0xBB, /**< Start Measurement */
masahikofukasawa 0:c240899240e7 76 CMD_ANGLE_ZERO_RESET = 0xBC, /**< Angle sensor zero reset */
masahikofukasawa 39:8222b59a822e 77 CMD_ANGLE_READ = 0xBD, /**< Angle sensor read angle */
masahikofukasawa 0:c240899240e7 78 } Command;
masahikofukasawa 11:53e52f5f1051 79
masahikofukasawa 11:53e52f5f1051 80 typedef enum{
masahikofukasawa 11:53e52f5f1051 81 SW_OFF = 0x00,
masahikofukasawa 11:53e52f5f1051 82 SW_ON = 0x01,
masahikofukasawa 11:53e52f5f1051 83 } SwitchState;
masahikofukasawa 11:53e52f5f1051 84
masahikofukasawa 0:c240899240e7 85 typedef enum {
masahikofukasawa 0:c240899240e7 86 SUCCESS = 0,
masahikofukasawa 0:c240899240e7 87 END_OF_STR,
masahikofukasawa 0:c240899240e7 88 ERROR_ILLEGAL_CHAR,
masahikofukasawa 0:c240899240e7 89 ERROR_INDEX_OUT_OF_BOUNDS,
masahikofukasawa 0:c240899240e7 90 } Status;
masahikofukasawa 0:c240899240e7 91
masahikofukasawa 0:c240899240e7 92 /**
masahikofukasawa 0:c240899240e7 93 * Constructor.
masahikofukasawa 0:c240899240e7 94 */
masahikofukasawa 0:c240899240e7 95 Message() : cmd(CMD_UNKNOWN), num_arg(0){
masahikofukasawa 0:c240899240e7 96 };
masahikofukasawa 0:c240899240e7 97
masahikofukasawa 0:c240899240e7 98 /**
masahikofukasawa 0:c240899240e7 99 * Convert an ascii into one byte value.
masahikofukasawa 0:c240899240e7 100 * @param out Pointer to the buffer stores result value
masahikofukasawa 0:c240899240e7 101 * @param in Pointer to a hex format ascii value. The value must be expressed by two-byte ascii chars. For example, the value 5 must be expressed as "05", not "5".
masahikofukasawa 0:c240899240e7 102 */
masahikofukasawa 0:c240899240e7 103 static Status asciiToChar(char *out, const char *in);
masahikofukasawa 0:c240899240e7 104
masahikofukasawa 0:c240899240e7 105 /**
masahikofukasawa 0:c240899240e7 106 * Convert a byte value into a hex format ascii value. The result value have two-byte length. If the input value is 5, the result string is "05", not "5".
masahikofukasawa 0:c240899240e7 107 * @param out Pointer to the buffer stores result ascii. The buffer must have two byte length.
masahikofukasawa 0:c240899240e7 108 * @param in Pointer to a byte value to be converted.
masahikofukasawa 0:c240899240e7 109 */
masahikofukasawa 0:c240899240e7 110 static void charToAscii(char *out, const char *in);
masahikofukasawa 0:c240899240e7 111
masahikofukasawa 0:c240899240e7 112 /**
masahikofukasawa 0:c240899240e7 113 * Parses given string and construct a message object.
masahikofukasawa 0:c240899240e7 114 * @param msg Pointer to an message object.
masahikofukasawa 0:c240899240e7 115 * @param str Pointer to an string to be parsed.
masahikofukasawa 0:c240899240e7 116 * @return Returns SUCCESS if parsed successfully, otherwise returns other code.
masahikofukasawa 0:c240899240e7 117 */
masahikofukasawa 0:c240899240e7 118 static Status parse(Message *msg, const char *str);
masahikofukasawa 0:c240899240e7 119
masahikofukasawa 0:c240899240e7 120 /**
masahikofukasawa 0:c240899240e7 121 * Sets command of this message.
masahikofukasawa 0:c240899240e7 122 * @param cmd Command to be set.
masahikofukasawa 0:c240899240e7 123 */
masahikofukasawa 0:c240899240e7 124 void setCommand(Command cmd);
masahikofukasawa 0:c240899240e7 125
masahikofukasawa 0:c240899240e7 126 /**
masahikofukasawa 0:c240899240e7 127 * Sets argument(s) to this message.
masahikofukasawa 0:c240899240e7 128 * @param arg pointer to the argument(s) to be stored.
masahikofukasawa 0:c240899240e7 129 * @param len length of the argument in bytes
masahikofukasawa 0:c240899240e7 130 */
masahikofukasawa 0:c240899240e7 131 void setArguments(const char *arg, int len);
masahikofukasawa 0:c240899240e7 132
masahikofukasawa 0:c240899240e7 133 /**
masahikofukasawa 0:c240899240e7 134 * Sets argument at the specified index.
masahikofukasawa 0:c240899240e7 135 * @param arg value of the argument
masahikofukasawa 0:c240899240e7 136 */
masahikofukasawa 0:c240899240e7 137 void setArgument(int index, char arg);
masahikofukasawa 0:c240899240e7 138
masahikofukasawa 0:c240899240e7 139 /**
masahikofukasawa 0:c240899240e7 140 * Gets the command contained in this message.
masahikofukasawa 0:c240899240e7 141 * @return The command contained in this message.
masahikofukasawa 0:c240899240e7 142 */
masahikofukasawa 0:c240899240e7 143 Command getCommand() const;
masahikofukasawa 0:c240899240e7 144
masahikofukasawa 0:c240899240e7 145 /**
masahikofukasawa 0:c240899240e7 146 * Gets n th argument of the message.
masahikofukasawa 0:c240899240e7 147 * @param index argument to be gotten. Index must be less than the number obtained from getArgNum().
masahikofukasawa 0:c240899240e7 148 * @return Returns value of the argument specified by index. If the value larger than argsize is specified, returns 0.
masahikofukasawa 0:c240899240e7 149 */
masahikofukasawa 0:c240899240e7 150 char getArgument(int index) const;
masahikofukasawa 0:c240899240e7 151
masahikofukasawa 0:c240899240e7 152 /**
masahikofukasawa 0:c240899240e7 153 * Gets number of arguments.
masahikofukasawa 0:c240899240e7 154 * @return Returns number of arguments included in this message.
masahikofukasawa 0:c240899240e7 155 */
masahikofukasawa 0:c240899240e7 156 int getArgNum() const;
masahikofukasawa 0:c240899240e7 157
masahikofukasawa 0:c240899240e7 158 /**
masahikofukasawa 0:c240899240e7 159 * Gets maximum message length in byte unit.
masahikofukasawa 0:c240899240e7 160 * @return maximum length of message in byte.
masahikofukasawa 0:c240899240e7 161 */
masahikofukasawa 0:c240899240e7 162 static int getMaxMessageLength();
masahikofukasawa 0:c240899240e7 163
masahikofukasawa 0:c240899240e7 164 /**
masahikofukasawa 0:c240899240e7 165 * Gets arguments.
masahikofukasawa 0:c240899240e7 166 * @param buf
masahikofukasawa 0:c240899240e7 167 * @param maxNum maximum number of arguments to be get
masahikofukasawa 0:c240899240e7 168 */
masahikofukasawa 0:c240899240e7 169 void getArguments(char *buf, int maxNum) const;
masahikofukasawa 0:c240899240e7 170
masahikofukasawa 0:c240899240e7 171
masahikofukasawa 0:c240899240e7 172 private:
masahikofukasawa 12:522a22a23f8a 173 const static int NUM_MAX_ARG = 32; /**< Maximum number of arguments in message. */
masahikofukasawa 0:c240899240e7 174 const static int MAX_LEN = 1 + 2 + 2*NUM_MAX_ARG + 1 + 1; /**< Maximum length of message in byte unit. $ + command(2bytes) + data + \r + \n */
masahikofukasawa 0:c240899240e7 175
masahikofukasawa 0:c240899240e7 176 Command cmd; /**< Holds command. */
masahikofukasawa 0:c240899240e7 177 char arg[NUM_MAX_ARG]; /**< Holds arguments. */
masahikofukasawa 0:c240899240e7 178 int num_arg; /**< Holds number of arguments. */
masahikofukasawa 0:c240899240e7 179 };
masahikofukasawa 0:c240899240e7 180
masahikofukasawa 0:c240899240e7 181 #endif // __MESSAGE_H__