Host library for controlling a WiConnect enabled Wi-Fi module.
Dependents: wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more
internal/wiconnect/CommandCommon.h@17:7268f365676b, 2014-08-23 (annotated)
- Committer:
- dan_ackme
- Date:
- Sat Aug 23 05:39:17 2014 -0700
- Revision:
- 17:7268f365676b
- Parent:
- 16:7f1d6d359787
- Child:
- 24:e27e23297f02
Fixes and documentation updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dan_ackme | 16:7f1d6d359787 | 1 | /** |
dan_ackme | 16:7f1d6d359787 | 2 | * ACKme WiConnect Host Library is licensed under the BSD licence: |
dan_ackme | 16:7f1d6d359787 | 3 | * |
dan_ackme | 16:7f1d6d359787 | 4 | * Copyright (c)2014 ACKme Networks. |
dan_ackme | 16:7f1d6d359787 | 5 | * All rights reserved. |
dan_ackme | 16:7f1d6d359787 | 6 | * |
dan_ackme | 16:7f1d6d359787 | 7 | * Redistribution and use in source and binary forms, with or without modification, |
dan_ackme | 16:7f1d6d359787 | 8 | * are permitted provided that the following conditions are met: |
dan_ackme | 16:7f1d6d359787 | 9 | * |
dan_ackme | 16:7f1d6d359787 | 10 | * 1. Redistributions of source code must retain the above copyright notice, |
dan_ackme | 16:7f1d6d359787 | 11 | * this list of conditions and the following disclaimer. |
dan_ackme | 16:7f1d6d359787 | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
dan_ackme | 16:7f1d6d359787 | 13 | * this list of conditions and the following disclaimer in the documentation |
dan_ackme | 16:7f1d6d359787 | 14 | * and/or other materials provided with the distribution. |
dan_ackme | 16:7f1d6d359787 | 15 | * 3. The name of the author may not be used to endorse or promote products |
dan_ackme | 16:7f1d6d359787 | 16 | * derived from this software without specific prior written permission. |
dan_ackme | 16:7f1d6d359787 | 17 | * |
dan_ackme | 16:7f1d6d359787 | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED |
dan_ackme | 16:7f1d6d359787 | 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
dan_ackme | 16:7f1d6d359787 | 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
dan_ackme | 16:7f1d6d359787 | 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
dan_ackme | 16:7f1d6d359787 | 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
dan_ackme | 16:7f1d6d359787 | 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
dan_ackme | 16:7f1d6d359787 | 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
dan_ackme | 16:7f1d6d359787 | 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
dan_ackme | 16:7f1d6d359787 | 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
dan_ackme | 16:7f1d6d359787 | 27 | * OF SUCH DAMAGE. |
dan_ackme | 0:ea85c4bb5e1f | 28 | */ |
dan_ackme | 0:ea85c4bb5e1f | 29 | #pragma once |
dan_ackme | 0:ea85c4bb5e1f | 30 | |
dan_ackme | 0:ea85c4bb5e1f | 31 | |
dan_ackme | 0:ea85c4bb5e1f | 32 | #include <stdio.h> |
dan_ackme | 0:ea85c4bb5e1f | 33 | #include <stdarg.h> |
dan_ackme | 0:ea85c4bb5e1f | 34 | #include "Wiconnect.h" |
dan_ackme | 17:7268f365676b | 35 | #include "StringUtil.h" |
dan_ackme | 0:ea85c4bb5e1f | 36 | #include "internal/common.h" |
dan_ackme | 0:ea85c4bb5e1f | 37 | |
dan_ackme | 0:ea85c4bb5e1f | 38 | |
dan_ackme | 0:ea85c4bb5e1f | 39 | #define CHECK_NULL_BUFFER(buf) if(buf == NULL) return WICONNECT_NULL_BUFFER |
dan_ackme | 0:ea85c4bb5e1f | 40 | #define CHECK_INITIALIZED() if(!initialized) return WICONNECT_NOT_INITIALIZED |
dan_ackme | 0:ea85c4bb5e1f | 41 | #define RESET_CMD_HEADER(header) memset(header, 0, sizeof(CommandHeader)); header->bytes_remaining = WICONNECT_HEADER_LENGTH |
dan_ackme | 0:ea85c4bb5e1f | 42 | |
dan_ackme | 0:ea85c4bb5e1f | 43 | #define DEBUG_CMD_SEND(cmd) debugLog(">> CMD: %s", cmd) |
dan_ackme | 0:ea85c4bb5e1f | 44 | #define DEBUG_CMD_LOG(res) debugLog("<< LOG: %s", res) |
dan_ackme | 0:ea85c4bb5e1f | 45 | #define DEBUG_CMD_RESPONSE(res) debugLog("<< RES: %s", res) |
dan_ackme | 0:ea85c4bb5e1f | 46 | #define DEBUG_CMD_ERROR(code) debugLog("<< ERR:(%d) %s", code, getLastCommandResponseCodeStr()) |
dan_ackme | 0:ea85c4bb5e1f | 47 | #define DEBUG_ERROR(msg, ...) debugLog(" ERR: " msg, ## __VA_ARGS__) |
dan_ackme | 0:ea85c4bb5e1f | 48 | #define DEBUG_INFO(msg, ...) debugLog(" DBG: " msg, ## __VA_ARGS__) |
dan_ackme | 0:ea85c4bb5e1f | 49 | |
dan_ackme | 0:ea85c4bb5e1f | 50 | |
dan_ackme | 0:ea85c4bb5e1f | 51 | |
dan_ackme | 0:ea85c4bb5e1f | 52 | typedef enum |
dan_ackme | 0:ea85c4bb5e1f | 53 | { |
dan_ackme | 0:ea85c4bb5e1f | 54 | WICONNECT_CMD_TYPE_NULL = 0, |
dan_ackme | 0:ea85c4bb5e1f | 55 | WICONNECT_CMD_TYPE_REPLY = 'R', |
dan_ackme | 0:ea85c4bb5e1f | 56 | WICONNECT_CMD_TYPE_LOG = 'L', |
dan_ackme | 0:ea85c4bb5e1f | 57 | WICONNECT_CMD_TYPE_SAFEMODE = 'S' |
dan_ackme | 0:ea85c4bb5e1f | 58 | } ResponseType; |
dan_ackme | 0:ea85c4bb5e1f | 59 | |
dan_ackme | 0:ea85c4bb5e1f | 60 | typedef enum |
dan_ackme | 0:ea85c4bb5e1f | 61 | { |
dan_ackme | 0:ea85c4bb5e1f | 62 | WICONNECT_CMD_CODE_NULL = 0, |
dan_ackme | 0:ea85c4bb5e1f | 63 | WICONNECT_CMD_SUCCESS = 1, // The command was successful |
dan_ackme | 0:ea85c4bb5e1f | 64 | WICONNECT_CMD_FAILED = 2, // The command failed, most likely in the firmware |
dan_ackme | 0:ea85c4bb5e1f | 65 | WICONNECT_CMD_PARSE_ERROR = 3, // Failed to parse the command |
dan_ackme | 0:ea85c4bb5e1f | 66 | WICONNECT_CMD_UNKNOWN = 4, // Unknown command |
dan_ackme | 0:ea85c4bb5e1f | 67 | WICONNECT_CMD_TOO_FEW_ARGS = 5, // Not enough command arguments |
dan_ackme | 0:ea85c4bb5e1f | 68 | WICONNECT_CMD_TOO_MANY_ARGS = 6, // Too many command arguments |
dan_ackme | 0:ea85c4bb5e1f | 69 | WICONNECT_CMD_UNKNOWN_OPTION = 7, // Unknown option (e.g. known 'set' command option) |
dan_ackme | 0:ea85c4bb5e1f | 70 | WICONNECT_CMD_BAD_ARGS = 8, // Invalid command arguments |
dan_ackme | 0:ea85c4bb5e1f | 71 | } ResponseCode; |
dan_ackme | 0:ea85c4bb5e1f | 72 | |
dan_ackme | 0:ea85c4bb5e1f | 73 | #define WICONNECT_HEADER_LENGTH 9 |
dan_ackme | 0:ea85c4bb5e1f | 74 | typedef struct |
dan_ackme | 0:ea85c4bb5e1f | 75 | { |
dan_ackme | 0:ea85c4bb5e1f | 76 | ResponseType response_type; |
dan_ackme | 0:ea85c4bb5e1f | 77 | ResponseCode response_code; |
dan_ackme | 0:ea85c4bb5e1f | 78 | uint16_t response_len; |
dan_ackme | 0:ea85c4bb5e1f | 79 | uint8_t len_buffer[WICONNECT_HEADER_LENGTH]; |
dan_ackme | 0:ea85c4bb5e1f | 80 | uint8_t *len_buffer_ptr; |
dan_ackme | 0:ea85c4bb5e1f | 81 | uint8_t bytes_remaining; |
dan_ackme | 0:ea85c4bb5e1f | 82 | } CommandHeader; |
dan_ackme | 0:ea85c4bb5e1f | 83 | |
dan_ackme | 0:ea85c4bb5e1f | 84 | typedef struct |
dan_ackme | 0:ea85c4bb5e1f | 85 | { |
dan_ackme | 0:ea85c4bb5e1f | 86 | char *responseBuffer; |
dan_ackme | 0:ea85c4bb5e1f | 87 | char *responseBufferPtr; |
dan_ackme | 0:ea85c4bb5e1f | 88 | int responseBufferLen; |
dan_ackme | 0:ea85c4bb5e1f | 89 | ReaderFunc reader; |
dan_ackme | 0:ea85c4bb5e1f | 90 | void *user; |
dan_ackme | 0:ea85c4bb5e1f | 91 | char *commandPtr; |
dan_ackme | 0:ea85c4bb5e1f | 92 | int commandLen; |
dan_ackme | 0:ea85c4bb5e1f | 93 | int bytesToWrite; |
dan_ackme | 0:ea85c4bb5e1f | 94 | int bytesToRead; |
dan_ackme | 0:ea85c4bb5e1f | 95 | int timeoutMs; |
dan_ackme | 0:ea85c4bb5e1f | 96 | Callback callback; |
dan_ackme | 0:ea85c4bb5e1f | 97 | bool nonBlocking; |
dan_ackme | 0:ea85c4bb5e1f | 98 | } CommandContext; |