|
AWS IoT Firmware
Firmware code for AWS IoT Devices
|
Files | |
| file | aws_iot_fmt.hpp |
| used for storing aws iot communication format | |
| file | event_handler_util.cpp |
| folder carrying utils functions that are helpful either to the master handler or to the child handler | |
| file | event_handler_util.hpp |
| header file for event handler utils | |
| file | master_handler.cpp |
| Source files for master handler class. | |
| file | master_handler.hpp |
| header file for master handler class | |
| file | mqtt.hpp |
| header file for mqtt functionalities | |
| file | parent_handler.cpp |
| contain the source files for the ParentHandler class | |
| file | parent_handler.hpp |
| contain class declaration for the ParentHandler class | |
Classes | |
| struct | ErrDescript |
| used for storing the error code and its corresponding error message More... | |
| struct | frozen |
| struct | fstate |
| struct | scan_array_info |
| struct | json_scanf_info |
| struct | json_setf_data |
| struct | prettify_data |
| struct | next_data |
| struct | json_token |
| struct | json_out |
| class | ParentHandler |
| the parent handler class that is the blueprint for other child handlers to implement, it also defines a couple functions that child handler can use More... | |
Macros | |
| #define | PAYLOAD_BEGIN "{payload:" |
| #define | PAYLOAD_END "}" |
| #define | PWR_CTRL_FMT "{%Q: %Q, %Q: %Q, %Q: %Q}" |
| power controller devices reply format | |
| #define | PWR_CTRL_TOTAL_ARG 6 |
| power controller total arguments | |
| #define | SPKR_CTRL_FMT "{%Q: %Q, %Q: %Q, %Q: %d}, {%Q: %Q, %Q: %Q, %Q: %B}" |
| #define | SPKR_CTRL_TOTAL_ARG 12 |
| #define | SPKR_ADJUST_VOL_PAYLOAD_FMT PAYLOAD_BEGIN "{volume:%d, volumeDefault:%B}" PAYLOAD_END |
| #define | SPKR_ADJUST_VOL_PAYLOAD_TOTAL_ARG 2 |
| #define | SPKR_SET_MUTE_PAYLOAD_FMT PAYLOAD_BEGIN "{mute:%B}" PAYLOAD_END |
| #define | SPKR_SET_MUTE_PAYLOAD_TOTAL_ARG 1 |
| #define | SPKR_SET_VOL_PAYLOAD_FMT PAYLOAD_BEGIN "{volume:%d}" PAYLOAD_END |
| #define | SPKR_SET_VOL_PAYLOAD_TOTAL_ARG 1 |
| #define | TEMP_SENSOR_FMT "{%Q: %Q, %Q: %Q, %Q: {%Q: %.1f, %Q: %Q}}" |
| temperature controller devices reply format | |
| #define | TEMP_SENSOR_TOTAL_ARG 9 |
| temperature sensor reply total arguments | |
| #define | MAX_COMMAND_LEN 30 |
| maximum length in characters of command name sent by the server | |
| #define | MAX_NAMESPACE_LEN 30 |
| maximum length in characters of the namespace name sent by the server | |
| #define | HANDLER_TRY_FUNC(funcToExecute) |
| helper function used to create error message and exit upon errors More... | |
| #define | MAX_PAYLOAD_SIZE 150 |
| Maximum characters that the payload received by the mqtt will have. | |
| #define | MAX_RESPONSE_LEN 1500 |
| Maximum length in character of the response. | |
| #define | SUB_QOS 1 |
| #define | PUB_QOS 1 |
| #define | _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005+ */ |
| #define | WEAK |
| #define | __STDC_FORMAT_MACROS |
| #define | INT64_FMT PRId64 |
| #define | UINT64_FMT PRIu64 |
| #define | va_copy(x, y) x = y |
| #define | JSON_MAX_PATH_LEN 256 |
| #define | SET_STATE(fr, ptr, str, len) |
| #define | CALL_BACK(fr, tok, value, len) |
| #define | EXPECT(cond, err_code) |
| #define | TRY(expr) |
| #define | END_OF_STRING (-1) |
| #define | JSON_INVALID_TOKEN { 0, 0, JSON_TYPE_INVALID } |
| #define | JSON_STRING_INVALID -1 |
| #define | JSON_STRING_INCOMPLETE -2 |
| #define | JSON_OUT_BUF(buf, len) |
| #define | JSON_OUT_FILE(fp) |
| #define | TEMP_BUF_LEN 700 |
| length in characters of the temporary buffer used for holding a temp json string before it can be copied to the string returned to the master handler | |
Typedefs | |
| typedef void(* | json_walk_callback_t) (void *callback_data, const char *name, size_t name_len, const char *path, const struct json_token *token) |
| typedef int(* | json_printf_callback_t) (struct json_out *, va_list *ap) |
| typedef void(* | json_scanner_t) (const char *str, int len, void *user_data) |
Enumerations | |
| enum | HandlerError { HANDLER_NO_ERR = 0, MQTT_ERR_UNKNOWN_COMMAND, MQTT_ERR_GPIO, JSON_NOT_ENOUGH_ARG, MQTT_CONFIG_NOT_SET, JSON_UNKNOWN_NAMESPACE, JSON_VPRINTF_ERROR, JSON_VSCANF_ERROR, HANDLER_NULL } |
| enum defining errors that the system(including master handler and other child handler) may have | |
| enum | json_token_type { JSON_TYPE_INVALID = 0, JSON_TYPE_STRING, JSON_TYPE_NUMBER, JSON_TYPE_TRUE, JSON_TYPE_FALSE, JSON_TYPE_NULL, JSON_TYPE_OBJECT_START, JSON_TYPE_OBJECT_END, JSON_TYPE_ARRAY_START, JSON_TYPE_ARRAY_END, JSON_TYPES_CNT } |
Functions | |
| HandlerError | create_error_message (const HandlerError error, struct mg_str *payload, char *errorMessage) |
| create error message based on the error code given and stores it in the given buffer More... | |
| HandlerError | write_pin (const uint8_t pinNum, const uint8_t pinState) |
| used for writing to a digital pin given its pin number and state More... | |
| HandlerError | read_pin (const uint8_t pinNum, uint8_t *pinState) |
| used to reat the status of a digital pin More... | |
| HandlerError | getCommandInfo (struct mg_str *message, char *commandName, char *nameSpace) |
| get command name as well as command namespace of messages sent from aws lambda More... | |
| HandlerError | getAwsPayload (const struct mg_str *message, const char *awsPayloadFormat, const uint8_t &totalArg,...) |
| Get the Aws Payload json key. More... | |
| HandlerError | printStateReportOpen (char *jsonOut) |
| print the beginning of an aws smarthome state report More... | |
| HandlerError | printStateReportDelimiter (char *jsonOut) |
| print the delimiter between endpoints reports in aws iot state report More... | |
| HandlerError | printStateReportEnd (char *jsonOut) |
| print the ending part of an aws iot state report More... | |
| enum mgos_app_init_result | mgos_app_init (void) |
| the starting point of the program register the master handler as well as any interrupts define by the user More... | |
| void | handleAllReq (struct mg_connection *mgCon, int eventType, void *rawMessage, void *user_data) |
| The entry point of all events, when an mcu receives an event, whether it's a request from aws or just a confirmation from the mqtt server, it is triaged here. More... | |
| void | handleAwsRequest (struct mg_connection *mgCon, struct mg_str *payload, char *jsonBuf, ParentHandler *_handlerList[]) |
| function used for finding the appropriate handler and hands the request to them or create error message to report to the server More... | |
| void | handlePolling (struct mg_connection *mgCon, ParentHandler *handlerList[], char *jsonBuf) |
| dummy empty function since bed room light controller has no polling need More... | |
| void | sub (struct mg_connection *mgConnection, const char *fmt,...) |
| function used for subscribing to mqtt channels, has variable arguments support More... | |
| void | pub (struct mg_connection *mgConnection, const char *pubTopic, const char *fmt,...) |
| used for publishing to a specific channel of the mqtt server More... | |
| int | json_escape (struct json_out *out, const char *p, size_t len) WEAK |
| int | json_printer_buf (struct json_out *out, const char *buf, size_t len) WEAK |
| int | json_printer_file (struct json_out *out, const char *buf, size_t len) WEAK |
| int | json_vprintf (struct json_out *out, const char *fmt, va_list xap) WEAK |
| int | json_printf (struct json_out *out, const char *fmt,...) WEAK |
| int | json_printf_array (struct json_out *out, va_list *ap) WEAK |
| int | json_walk (const char *json_string, int json_string_length, json_walk_callback_t callback, void *callback_data) WEAK |
| int | json_scanf_array_elem (const char *s, int len, const char *path, int idx, struct json_token *token) WEAK |
| int | json_unescape (const char *src, int slen, char *dst, int dlen) WEAK |
| int | json_vscanf (const char *s, int len, const char *fmt, va_list ap) WEAK |
| int | json_scanf (const char *str, int len, const char *fmt,...) WEAK |
| int | json_vfprintf (const char *file_name, const char *fmt, va_list ap) WEAK |
| int | json_fprintf (const char *file_name, const char *fmt,...) WEAK |
| char * | json_fread (const char *path) WEAK |
| int | json_vsetf (const char *s, int len, struct json_out *out, const char *json_path, const char *json_fmt, va_list ap) WEAK |
| int | json_setf (const char *s, int len, struct json_out *out, const char *json_path, const char *json_fmt,...) WEAK |
| int | json_prettify (const char *s, int len, struct json_out *out) WEAK |
| int | json_prettify_file (const char *file_name) WEAK |
| void * | json_next_key (const char *s, int len, void *handle, const char *path, struct json_token *key, struct json_token *val) WEAK |
| void * | json_next_elem (const char *s, int len, void *handle, const char *path, int *idx, struct json_token *val) WEAK |
| char * | json_vasprintf (const char *fmt, va_list ap) WEAK |
| char * | json_asprintf (const char *fmt,...) WEAK |
| HandlerError | ParentHandler::createReport (char *report, const char *fmt, uint8_t totalArg,...) |
| used for generating a json report string based on the format given, usually child handler uses this to prepare replies to the aws lambda server More... | |
| bool | ParentHandler::canHandleRequest (char *requestNameSpace) |
| used to check if a handler object can handle a request with a specific namespace More... | |
| char * | ParentHandler::getNameSpace (void) |
| return the command namespace that the handler support More... | |
| #define CALL_BACK | ( | fr, | |
| tok, | |||
| value, | |||
| len | |||
| ) |
| #define EXPECT | ( | cond, | |
| err_code | |||
| ) |
| #define HANDLER_TRY_FUNC | ( | funcToExecute | ) |
helper function used to create error message and exit upon errors
| #define JSON_OUT_BUF | ( | buf, | |
| len | |||
| ) |
| #define JSON_OUT_FILE | ( | fp | ) |
| #define SET_STATE | ( | fr, | |
| ptr, | |||
| str, | |||
| len | |||
| ) |
| #define TRY | ( | expr | ) |
| bool ParentHandler::canHandleRequest | ( | char * | requestNameSpace | ) |
used to check if a handler object can handle a request with a specific namespace
| requestNameSpace | the namespace extracted from the message |
compare the namespace given with the namespace that the object says it supports and return result
| HandlerError create_error_message | ( | const HandlerError | error, |
| struct mg_str * | payload, | ||
| char * | errorMessage | ||
| ) |
create error message based on the error code given and stores it in the given buffer
| error | error code of the problems |
| payload | the payload of the message received by the mcu |
| errorMessage | the buffer to store the error message |
The function stores a list of struct that stores the error code and their corresponding error message, the function searches through the struct to find the correct message
| HandlerError ParentHandler::createReport | ( | char * | report, |
| const char * | fmt, | ||
| uint8_t | totalArg, | ||
| ... | |||
| ) |
used for generating a json report string based on the format given, usually child handler uses this to prepare replies to the aws lambda server
| report | the string to write the report to |
| fmt | format of the report, can be found in aws_iot_fmt.hpp |
| totalArg | total arguments to be printed for the report string |
| ... |
| HandlerError getAwsPayload | ( | const struct mg_str * | message, |
| const char * | awsPayloadFormat, | ||
| const uint8_t & | totalArg, | ||
| ... | |||
| ) |
Get the Aws Payload json key.
| message | messsage received by mongoose OS from mqtt server |
| awsPayloadFormat | the payload format of the specific aws device type such as speaker, power controller, etc |
| totalArg | how many arg to parse in the payload format |
| HandlerError getCommandInfo | ( | struct mg_str * | message, |
| char * | commandName, | ||
| char * | nameSpace | ||
| ) |
get command name as well as command namespace of messages sent from aws lambda
| message | message received by the mcu through mqtt |
| commandName | name of the command like "TurnOff" |
| nameSpace | namespace of the command like "Alexa.PowerController" |
| char * ParentHandler::getNameSpace | ( | void | ) |
return the command namespace that the handler support
| void handleAllReq | ( | struct mg_connection * | mgCon, |
| int | eventType, | ||
| void * | rawMessage, | ||
| void * | user_data | ||
| ) |
The entry point of all events, when an mcu receives an event, whether it's a request from aws or just a confirmation from the mqtt server, it is triaged here.
| mgCon | struct representing connection to server |
| eventType | type of event that is being processed |
| rawMessage | the raw message given to the handler |
| user_data | user data, this is rarely used and is here to only fulill the prototype request for a handler |
| void handleAwsRequest | ( | struct mg_connection * | mgCon, |
| struct mg_str * | payload, | ||
| char * | jsonBuf, | ||
| ParentHandler * | _handlerList[] | ||
| ) |
function used for finding the appropriate handler and hands the request to them or create error message to report to the server
| mgCon | struct representing connection to server |
| payload | payload of message given to the function by the handleAllReq function |
| jsonBuf | buffer to store repy to the aws lambda |
| void handlePolling | ( | struct mg_connection * | mgCon, |
| ParentHandler * | handlerList[], | ||
| char * | jsonBuf | ||
| ) |
dummy empty function since bed room light controller has no polling need
| mgCon | mongoose network connection |
| handlerList | list of pointer to handler object |
| jsonBuf | json buffer for writing data |
dummy empty function since bed room light controller has no polling need
| mgCon | mongoose network connection |
| handlerList | list of pointer to handler object |
| jsonBuf | json buffer for writing data |
dummy empty function since bed room light controller has no polling need
| mgCon | object representing connection to the internet |
| _handlerList | the list of handler that user defined |
| jsonBuf | if you write something to this buffer, it will be published to the mqtt server of the device |
| enum mgos_app_init_result mgos_app_init | ( | void | ) |
the starting point of the program register the master handler as well as any interrupts define by the user
| HandlerError printStateReportDelimiter | ( | char * | jsonOut | ) |
print the delimiter between endpoints reports in aws iot state report
| jsonOut | buffer to store the json report |
| HandlerError printStateReportEnd | ( | char * | jsonOut | ) |
print the ending part of an aws iot state report
| jsonOut | buffer to store the json report |
| HandlerError printStateReportOpen | ( | char * | jsonOut | ) |
print the beginning of an aws smarthome state report
| jsonOut | the buffer to store the report |
| void pub | ( | struct mg_connection * | mgConnection, |
| const char * | pubTopic, | ||
| const char * | fmt, | ||
| ... | |||
| ) |
used for publishing to a specific channel of the mqtt server
| mgConnection | struct represents connection to server |
| pubTopic | topic to publish to |
| fmt | format of the message to be published |
| ... | variable arguments for the format specified |
| HandlerError read_pin | ( | const uint8_t | pinNum, |
| uint8_t * | pinState | ||
| ) |
used to reat the status of a digital pin
| pinNum | pin number to read |
| pinState | pointer to write the result of the read to |
| void sub | ( | struct mg_connection * | mgConnection, |
| const char * | fmt, | ||
| ... | |||
| ) |
function used for subscribing to mqtt channels, has variable arguments support
| mgConnection | struct represents connection to server |
| fmt | format of the string to be sent to server for subscribing |
| ... | variable arguments for the format specified |
| HandlerError write_pin | ( | const uint8_t | pinNum, |
| const uint8_t | pinState | ||
| ) |
used for writing to a digital pin given its pin number and state
| pinNum | pin to write |
| pinState | state of the pin, 0 for off, 1 for on |
1.8.11