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

Revision:
0:ea85c4bb5e1f
Child:
1:6ec9998427ad
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/internal/wiconnect/CommandCommon.h	Mon Aug 11 09:58:24 2014 +0000
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2014, ACKme Networks
+ * All Rights Reserved.
+ *
+ * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
+ * the contents of this file may not be disclosed to third parties, copied
+ * or duplicated in any form, in whole or in part, without the prior
+ * written permission of ACKme Networks.
+ */
+
+#pragma once
+
+
+#include <stdio.h>
+#include <stdarg.h>
+#include "Wiconnect.h"
+#include "internal/common.h"
+#include "StringUtil.h"
+
+
+
+#define CHECK_NULL_BUFFER(buf) if(buf == NULL) return WICONNECT_NULL_BUFFER
+#define CHECK_INITIALIZED() if(!initialized) return WICONNECT_NOT_INITIALIZED
+#define RESET_CMD_HEADER(header)  memset(header, 0, sizeof(CommandHeader)); header->bytes_remaining = WICONNECT_HEADER_LENGTH
+
+#define DEBUG_CMD_SEND(cmd)         debugLog(">> CMD: %s", cmd)
+#define DEBUG_CMD_LOG(res)          debugLog("<< LOG: %s", res)
+#define DEBUG_CMD_RESPONSE(res)     debugLog("<< RES: %s", res)
+#define DEBUG_CMD_ERROR(code)       debugLog("<< ERR:(%d) %s", code, getLastCommandResponseCodeStr())
+#define DEBUG_ERROR(msg, ...)       debugLog("   ERR: " msg, ## __VA_ARGS__)
+#define DEBUG_INFO(msg, ...)        debugLog("   DBG: " msg, ## __VA_ARGS__)
+
+
+
+typedef enum
+{
+    WICONNECT_CMD_TYPE_NULL = 0,
+    WICONNECT_CMD_TYPE_REPLY = 'R',
+    WICONNECT_CMD_TYPE_LOG = 'L',
+    WICONNECT_CMD_TYPE_SAFEMODE = 'S'
+} ResponseType;
+
+typedef enum
+{
+    WICONNECT_CMD_CODE_NULL         = 0,
+    WICONNECT_CMD_SUCCESS           = 1, // The command was successful
+    WICONNECT_CMD_FAILED            = 2, // The command failed, most likely in the firmware
+    WICONNECT_CMD_PARSE_ERROR       = 3, // Failed to parse the command
+    WICONNECT_CMD_UNKNOWN           = 4, // Unknown command
+    WICONNECT_CMD_TOO_FEW_ARGS      = 5, // Not enough command arguments
+    WICONNECT_CMD_TOO_MANY_ARGS     = 6, // Too many command arguments
+    WICONNECT_CMD_UNKNOWN_OPTION    = 7, // Unknown option (e.g. known 'set' command option)
+    WICONNECT_CMD_BAD_ARGS          = 8, // Invalid command arguments
+} ResponseCode;
+
+#define WICONNECT_HEADER_LENGTH 9
+typedef struct
+{
+    ResponseType response_type;
+    ResponseCode response_code;
+    uint16_t response_len;
+    uint8_t len_buffer[WICONNECT_HEADER_LENGTH];
+    uint8_t *len_buffer_ptr;
+    uint8_t bytes_remaining;
+} CommandHeader;
+
+typedef struct
+{
+    char *responseBuffer;
+    char *responseBufferPtr;
+    int responseBufferLen;
+    ReaderFunc reader;
+    void *user;
+    char *commandPtr;
+    int commandLen;
+    int bytesToWrite;
+    int bytesToRead;
+    int timeoutMs;
+    Callback callback;
+    bool nonBlocking;
+} CommandContext;
+