ACKme Logo WiConnect Host Library- API Reference Guide
 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
WiconnectInterface.h
1 
29 #pragma once
30 
31 #include "WiconnectTypes.h"
32 
33 
34 #include "types/LogFunc.h"
35 #include "types/ReaderFunc.h"
36 #include "types/Callback.h"
37 #include "types/QueuedCommand.h"
38 #include "types/CommandQueue.h"
39 #include "types/TimeoutTimer.h"
40 #include "types/PeriodicTimer.h"
41 #include "types/Gpio.h"
42 #include "types/WiconnectSerial.h"
43 
44 #include "NetworkInterface.h"
45 #include "SocketInterface.h"
46 #include "FileInterface.h"
47 
48 
49 #ifdef WICONNECT_ENABLE_MALLOC
50 #define WICONNECT_MALLOC_ARGS , void* (*malloc_)(size_t) = WICONNECT_DEFAULT_MALLOC, void (*free_)(void*) = WICONNECT_DEFAULT_FREE
52 #else
53 #define WICONNECT_MALLOC_ARGS
54 #endif
55 
56 
60 namespace wiconnect {
61 
62 
74 class Wiconnect : public NetworkInterface,
75  public SocketInterface,
76  public FileInterface
77 {
78 public:
79 
95  Wiconnect(const SerialConfig &serialConfig, Pin reset = PIN_NC, Pin wake = PIN_NC, bool nonBlocking = WICONNECT_DEFAULT_NONBLOCKING WICONNECT_MALLOC_ARGS);
96 
113  Wiconnect(const SerialConfig &serialConfig, int internalBufferSize, void *internalBuffer = NULL, Pin reset = PIN_NC, Pin wake = PIN_NC, bool nonBlocking = WICONNECT_DEFAULT_NONBLOCKING WICONNECT_MALLOC_ARGS);
114  ~Wiconnect();
115 
116 
117  // ------------------------------------------------------------------------
118 
119 
127  static Wiconnect* getInstance();
128 
139  WiconnectResult init(bool bringNetworkUp=false);
140 
146  void deinit();
147 
156  bool isInitialized();
157 
171 
184 
196  void flush(int delayMs = 500);
197 
208  WiconnectResult getVersion(char *versionBuffer = NULL, int versionBufferSize = 0, const Callback &completeCallback = Callback());
209 
210 
221  WiconnectResult updateFirmware(bool forced = false, const char *versionStr = NULL, const Callback &completeCallback = Callback());
222 
223 
224  // ------------------------------------------------------------------------
225 
226 
244  WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen,
245  int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, va_list vaList);
262  WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const ReaderFunc &reader,
263  void *user, const char *cmd, va_list vaList);
264 
281  WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const ReaderFunc &reader,
282  void *user, const char *cmd, ...);
283 
300  WiconnectResult sendCommand( int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, ...);
301 
318  WiconnectResult sendCommand(const ReaderFunc &reader, void *user, const char *cmd, ...);
319 
334  WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const char *cmd, ...);
335 
350  WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen, const char *cmd, ...);
351 
365  WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, const char *cmd, ...);
366 
382  WiconnectResult sendCommand(const Callback &completeCallback, const char *cmd, ...);
383 
398  WiconnectResult sendCommand(const char *cmd, ...);
399 
413  WiconnectResult sendCommand(const Callback &completeCallback, int timeoutMs, const char *cmd, ...);
414 
429  WiconnectResult sendCommand(int timeoutMs, const char *cmd, ...);
430 
443  WiconnectResult sendCommand(const char *cmd, va_list vaList);
444 
457 
465  void stopCurrentCommand();
466 
467 
468  // ------------------------------------------------------------------------
469 
470 
480  const char* getLastCommandResponseCodeStr();
481 
489  uint16_t getLastCommandResponseLength();
490 
498  char* getResponseBuffer();
499 
510  WiconnectResult responseToUint32(uint32_t *uint32Ptr);
511 
522  WiconnectResult responseToInt32(int32_t *int32Ptr);
523 
524 
525  // ------------------------------------------------------------------------
526 
540  WiconnectResult setSetting(const char *settingStr, uint32_t value);
541 
555  WiconnectResult setSetting(const char *settingStr, const char *value);
556 
570  WiconnectResult getSetting(const char *settingStr, uint32_t *valuePtr);
571 
585  WiconnectResult getSetting(const char *settingStr, char **valuePtr);
586 
601  WiconnectResult getSetting(const char *settingStr, char *valueBuffer, uint16_t valueBufferLen);
602 
603 
614  void setCommandDefaultTimeout(int timeoutMs);
615 
624 
632  void setPinToGpioMapper(PinToGpioMapper mapper);
633 
641  void setDebugLogger(LogFunc logFunc);
642 
652  void setAssertLogger(LogFunc assertLogFunc);
653 
654 
655  // ------------------------------------------------------------------------
656 
657 
658 #ifdef WICONNECT_ASYNC_TIMER_ENABLED
659 
670  WiconnectResult enqueueCommand(QueuedCommand *command, const Callback &commandCompleteHandler = Callback());
671 
681  void setCommandProcessingPeriod(uint32_t periodMs);
682 #endif
683 
684 
693  static const char* getWiconnectResultStr(WiconnectResult wiconnectResult);
694 
695 protected:
696 
697 #ifdef WICONNECT_ENABLE_MALLOC
698  void* (*_malloc)(size_t);
699  void (*_free)(void *);
700  friend class QueuedCommand;
701  friend class WiconnectSerial;
702  friend class ScanResult;
703  friend class ScanResultList;
704  friend class WiconnectSocket;
705  friend class WiconnectFile;
706 #endif
707 
708  wiconnect::WiconnectSerial serial;
709  wiconnect::Gpio resetGpio;
710  wiconnect::Gpio wakeGpio;
711 
712  volatile bool commandExecuting;
713  bool initialized;
714  bool nonBlocking;
715 
716  PinToGpioMapper pinToGpioMapper;
717 
718  char *internalBuffer;
719  int internalBufferSize;
720  bool internalBufferAlloc;
721  uint8_t internalProcessingState;
722  void *currentCommandId;
723 
724  wiconnect::TimeoutTimer timeoutTimer;
725  int defaultTimeoutMs;
726 
727  uint8_t commandHeaderBuffer[32];
728  char commandFormatBuffer[WICONNECT_MAX_CMD_SIZE];
729  uint8_t commandContext[96];
730 
731  void prepare(void *internalBuffer, int internalBufferSize, bool nonBlocking);
732  WiconnectResult inline receiveResponse();
733  WiconnectResult inline receivePacket();
734  void issueCommandCallback(WiconnectResult result);
735 
736  LogFunc debugLogger;
737  LogFunc assertLogger;
738  void debugLog(const char *msg, ...);
739 
740 #ifdef WICONNECT_ASYNC_TIMER_ENABLED
741  wiconnect::PeriodicTimer commandProcessorTimer;
742  uint32_t commandProcessingPeriod;
743  CommandQueue commandQueue;
744  wiconnect::QueuedCommand *currentQueuedCommand;
745 
746  void commandProcessingTimerHandler(void);
747  void processNextQueuedCommand();
748  void checkQueuedCommandTimeout();
749 #endif
750 
751  friend class NetworkInterface;
752  friend class SocketInterface;
753  friend class FileInterface;
754 };
755 
756 }
757 
758 
759 #include "sdkTypes.h"
760 
static const char * getWiconnectResultStr(WiconnectResult wiconnectResult)
Converts a WiconnectResult to string representation.
void setAssertLogger(LogFunc assertLogFunc)
Sets callback used when Wiconnect Library hits and internal assertion.
const char * getLastCommandResponseCodeStr()
When the WiConnect WiFi module returns a response, it contains a response code in the header...
int8_t(* PinToGpioMapper)(Pin pin)
Function pointer for mapping from a host pin to a WiConnect Module GPIO.
The provides an interface for joining and/or creating a network. It provides other utilities such as ...
WiconnectResult
API Result code.
WiconnectResult reset()
Toggle the WiConnect WiFi module reset signal.
void flush(int delayMs=500)
Flush any received data in serial RX buffer and terminate any commands on WiConnect WiFi module...
Generic callback function.
Definition: Callback.h:49
WiconnectResult wakeup()
Toggle the WiConnect WiFi moduel wakeup signal.
Host<->Wiconnect Module serial configuration.
Definition: sdk.h:129
WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen, int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, va_list vaList)
Send command to WiConnect WiFi module.
void setDebugLogger(LogFunc logFunc)
Sets callback function used to debug WiConnect WiFi module RX/TX serial data.
static Wiconnect * getInstance()
Get instance of previously instantiated Wiconnect Library.
WiconnectResult checkCurrentCommand()
Check the status of the currently executing command.
WiConnect WiFi module file object.
Definition: WiconnectFile.h:44
WiconnectResult responseToUint32(uint32_t *uint32Ptr)
Helper method to convert previous response to uint32.
Generic data reading callback function.
Definition: ReaderFunc.h:45
void deinit()
De-initialize library.
char * getResponseBuffer()
Return pointer to internal response buffer.
void setCommandDefaultTimeout(int timeoutMs)
Sets the default maximum time an API method may execute before terminating and return a timeout error...
WiconnectResult setSetting(const char *settingStr, uint32_t value)
Set a module setting.
Class which contains command for asynchronous processing.
Definition: QueuedCommand.h:43
PinName Pin
Pin name on HOST.
Definition: sdk.h:123
WiconnectResult init(bool bringNetworkUp=false)
Initialize library and communication link with WiConnect WiFi module.
WiconnectResult getSetting(const char *settingStr, uint32_t *valuePtr)
Get a module setting.
void setPinToGpioMapper(PinToGpioMapper mapper)
Sets a mapping function used to convert from a host Pin to WiConnect WiFi module GPIO.
Logging callback function.
Definition: LogFunc.h:45
void stopCurrentCommand()
Stop the currently executing command.
WiconnectResult responseToInt32(int32_t *int32Ptr)
Helper method to convert previous response to int32.
Connection object to remote server.
Wiconnect(const SerialConfig &serialConfig, Pin reset=PIN_NC, Pin wake=PIN_NC, bool nonBlocking=WICONNECT_DEFAULT_NONBLOCKING WICONNECT_MALLOC_ARGS)
WiConnect class constructor.
uint16_t getLastCommandResponseLength()
Return the length in bytes of the previous response.
List of WiFi network scan results.
The provides an interface for creating TCP/UDP/TLS/HTTP client sockets. A client socket connects to a...
int getCommandDefaultTimeout()
Returns the current default maximum API execution time.
The root WiConnect library class. This class inheriets all WiConnect functionality.
The provides an interface for creating TCP/UDP/TLS/HTTP client sockets. A client socket connects to a...
Definition: FileInterface.h:68
#define WICONNECT_DEFAULT_NONBLOCKING
The default blocking mode of the Library.
Definition: sdk.h:99
#define delayMs(ms)
Function to stop processor for specified number of milliseconds.
Definition: sdk.h:180
#define WICONNECT_MAX_CMD_SIZE
The maximum command size that may be sent to the WiConnect WiFi module.
#define PIN_NC
Default value for a pin, Not connected.
Definition: sdk.h:117
WiconnectResult getVersion(char *versionBuffer=NULL, int versionBufferSize=0, const Callback &completeCallback=Callback())
Return current version of WiConnect WiFi module.
bool isInitialized()
Return TRUE if library is able to communicated with WiConnect WiFi module. FALSE else.
Contains single entry from WiFi scan results.
Definition: ScanResult.h:46
WiconnectResult updateFirmware(bool forced=false, const char *versionStr=NULL, const Callback &completeCallback=Callback())
Update the wifi module's internal firmware.