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

Committer:
dan_ackme
Date:
Mon Aug 11 09:58:24 2014 +0000
Revision:
0:ea85c4bb5e1f
Child:
1:6ec9998427ad
initial check-in

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan_ackme 0:ea85c4bb5e1f 1 /*
dan_ackme 0:ea85c4bb5e1f 2 * Copyright 2014, ACKme Networks
dan_ackme 0:ea85c4bb5e1f 3 * All Rights Reserved.
dan_ackme 0:ea85c4bb5e1f 4 *
dan_ackme 0:ea85c4bb5e1f 5 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
dan_ackme 0:ea85c4bb5e1f 6 * the contents of this file may not be disclosed to third parties, copied
dan_ackme 0:ea85c4bb5e1f 7 * or duplicated in any form, in whole or in part, without the prior
dan_ackme 0:ea85c4bb5e1f 8 * written permission of ACKme Networks.
dan_ackme 0:ea85c4bb5e1f 9 */
dan_ackme 0:ea85c4bb5e1f 10
dan_ackme 0:ea85c4bb5e1f 11 #pragma once
dan_ackme 0:ea85c4bb5e1f 12
dan_ackme 0:ea85c4bb5e1f 13
dan_ackme 0:ea85c4bb5e1f 14 #include <stdio.h>
dan_ackme 0:ea85c4bb5e1f 15 #include <stdarg.h>
dan_ackme 0:ea85c4bb5e1f 16 #include "Wiconnect.h"
dan_ackme 0:ea85c4bb5e1f 17 #include "internal/common.h"
dan_ackme 0:ea85c4bb5e1f 18 #include "StringUtil.h"
dan_ackme 0:ea85c4bb5e1f 19
dan_ackme 0:ea85c4bb5e1f 20
dan_ackme 0:ea85c4bb5e1f 21
dan_ackme 0:ea85c4bb5e1f 22 #define CHECK_NULL_BUFFER(buf) if(buf == NULL) return WICONNECT_NULL_BUFFER
dan_ackme 0:ea85c4bb5e1f 23 #define CHECK_INITIALIZED() if(!initialized) return WICONNECT_NOT_INITIALIZED
dan_ackme 0:ea85c4bb5e1f 24 #define RESET_CMD_HEADER(header) memset(header, 0, sizeof(CommandHeader)); header->bytes_remaining = WICONNECT_HEADER_LENGTH
dan_ackme 0:ea85c4bb5e1f 25
dan_ackme 0:ea85c4bb5e1f 26 #define DEBUG_CMD_SEND(cmd) debugLog(">> CMD: %s", cmd)
dan_ackme 0:ea85c4bb5e1f 27 #define DEBUG_CMD_LOG(res) debugLog("<< LOG: %s", res)
dan_ackme 0:ea85c4bb5e1f 28 #define DEBUG_CMD_RESPONSE(res) debugLog("<< RES: %s", res)
dan_ackme 0:ea85c4bb5e1f 29 #define DEBUG_CMD_ERROR(code) debugLog("<< ERR:(%d) %s", code, getLastCommandResponseCodeStr())
dan_ackme 0:ea85c4bb5e1f 30 #define DEBUG_ERROR(msg, ...) debugLog(" ERR: " msg, ## __VA_ARGS__)
dan_ackme 0:ea85c4bb5e1f 31 #define DEBUG_INFO(msg, ...) debugLog(" DBG: " msg, ## __VA_ARGS__)
dan_ackme 0:ea85c4bb5e1f 32
dan_ackme 0:ea85c4bb5e1f 33
dan_ackme 0:ea85c4bb5e1f 34
dan_ackme 0:ea85c4bb5e1f 35 typedef enum
dan_ackme 0:ea85c4bb5e1f 36 {
dan_ackme 0:ea85c4bb5e1f 37 WICONNECT_CMD_TYPE_NULL = 0,
dan_ackme 0:ea85c4bb5e1f 38 WICONNECT_CMD_TYPE_REPLY = 'R',
dan_ackme 0:ea85c4bb5e1f 39 WICONNECT_CMD_TYPE_LOG = 'L',
dan_ackme 0:ea85c4bb5e1f 40 WICONNECT_CMD_TYPE_SAFEMODE = 'S'
dan_ackme 0:ea85c4bb5e1f 41 } ResponseType;
dan_ackme 0:ea85c4bb5e1f 42
dan_ackme 0:ea85c4bb5e1f 43 typedef enum
dan_ackme 0:ea85c4bb5e1f 44 {
dan_ackme 0:ea85c4bb5e1f 45 WICONNECT_CMD_CODE_NULL = 0,
dan_ackme 0:ea85c4bb5e1f 46 WICONNECT_CMD_SUCCESS = 1, // The command was successful
dan_ackme 0:ea85c4bb5e1f 47 WICONNECT_CMD_FAILED = 2, // The command failed, most likely in the firmware
dan_ackme 0:ea85c4bb5e1f 48 WICONNECT_CMD_PARSE_ERROR = 3, // Failed to parse the command
dan_ackme 0:ea85c4bb5e1f 49 WICONNECT_CMD_UNKNOWN = 4, // Unknown command
dan_ackme 0:ea85c4bb5e1f 50 WICONNECT_CMD_TOO_FEW_ARGS = 5, // Not enough command arguments
dan_ackme 0:ea85c4bb5e1f 51 WICONNECT_CMD_TOO_MANY_ARGS = 6, // Too many command arguments
dan_ackme 0:ea85c4bb5e1f 52 WICONNECT_CMD_UNKNOWN_OPTION = 7, // Unknown option (e.g. known 'set' command option)
dan_ackme 0:ea85c4bb5e1f 53 WICONNECT_CMD_BAD_ARGS = 8, // Invalid command arguments
dan_ackme 0:ea85c4bb5e1f 54 } ResponseCode;
dan_ackme 0:ea85c4bb5e1f 55
dan_ackme 0:ea85c4bb5e1f 56 #define WICONNECT_HEADER_LENGTH 9
dan_ackme 0:ea85c4bb5e1f 57 typedef struct
dan_ackme 0:ea85c4bb5e1f 58 {
dan_ackme 0:ea85c4bb5e1f 59 ResponseType response_type;
dan_ackme 0:ea85c4bb5e1f 60 ResponseCode response_code;
dan_ackme 0:ea85c4bb5e1f 61 uint16_t response_len;
dan_ackme 0:ea85c4bb5e1f 62 uint8_t len_buffer[WICONNECT_HEADER_LENGTH];
dan_ackme 0:ea85c4bb5e1f 63 uint8_t *len_buffer_ptr;
dan_ackme 0:ea85c4bb5e1f 64 uint8_t bytes_remaining;
dan_ackme 0:ea85c4bb5e1f 65 } CommandHeader;
dan_ackme 0:ea85c4bb5e1f 66
dan_ackme 0:ea85c4bb5e1f 67 typedef struct
dan_ackme 0:ea85c4bb5e1f 68 {
dan_ackme 0:ea85c4bb5e1f 69 char *responseBuffer;
dan_ackme 0:ea85c4bb5e1f 70 char *responseBufferPtr;
dan_ackme 0:ea85c4bb5e1f 71 int responseBufferLen;
dan_ackme 0:ea85c4bb5e1f 72 ReaderFunc reader;
dan_ackme 0:ea85c4bb5e1f 73 void *user;
dan_ackme 0:ea85c4bb5e1f 74 char *commandPtr;
dan_ackme 0:ea85c4bb5e1f 75 int commandLen;
dan_ackme 0:ea85c4bb5e1f 76 int bytesToWrite;
dan_ackme 0:ea85c4bb5e1f 77 int bytesToRead;
dan_ackme 0:ea85c4bb5e1f 78 int timeoutMs;
dan_ackme 0:ea85c4bb5e1f 79 Callback callback;
dan_ackme 0:ea85c4bb5e1f 80 bool nonBlocking;
dan_ackme 0:ea85c4bb5e1f 81 } CommandContext;
dan_ackme 0:ea85c4bb5e1f 82