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/TimeoutTimer.h"
38 #include "types/PeriodicTimer.h"
39 #include "types/Gpio.h"
40 #include "types/WiconnectSerial.h"
41 
42 #ifdef WICONNECT_ASYNC_TIMER_ENABLED
43 #include "types/QueuedCommand.h"
44 #include "types/CommandQueue.h"
45 #endif
46 
47 #include "NetworkInterface.h"
48 #include "SocketInterface.h"
49 #include "FileInterface.h"
50 #include "GhmInterface.h"
51 
52 
53 #ifdef WICONNECT_ENABLE_MALLOC
54 #define WICONNECT_MALLOC_ARGS , void* (*malloc_)(size_t) = WICONNECT_DEFAULT_MALLOC, void (*free_)(void*) = WICONNECT_DEFAULT_FREE
56 #else
57 #define WICONNECT_MALLOC_ARGS
58 #endif
59 
60 
64 namespace wiconnect {
65 
66 
78 class Wiconnect : public NetworkInterface,
79  public SocketInterface,
80  public FileInterface,
81  public GhmInterface
82 {
83 public:
84 
100  Wiconnect(const SerialConfig &serialConfig, Pin reset = PIN_NC, Pin wake = PIN_NC, bool nonBlocking = WICONNECT_DEFAULT_NONBLOCKING WICONNECT_MALLOC_ARGS);
101 
118  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);
119  ~Wiconnect();
120 
121 
122  // ------------------------------------------------------------------------
123 
124 
132  static Wiconnect* getInstance();
133 
144  WiconnectResult init(bool bringNetworkUp=false);
145 
151  void deinit();
152 
161  bool isInitialized();
162 
172  bool updateRequired();
173 
187 
200 
212  void flush(int delayMs = 500);
213 
224  WiconnectResult getVersion(char *versionBuffer = NULL, int versionBufferSize = 0, const Callback &completeCallback = Callback());
225 
226 
237  WiconnectResult updateFirmware(bool forced = false, const char *versionStr = NULL, const Callback &completeCallback = Callback());
238 
239 
240  // ------------------------------------------------------------------------
241 
242 
260  WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen,
261  TimerTimeout timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, va_list vaList);
278  WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, TimerTimeout timeoutMs, const ReaderFunc &reader,
279  void *user, const char *cmd, va_list vaList);
280 
297  WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, TimerTimeout timeoutMs, const ReaderFunc &reader,
298  void *user, const char *cmd, ...);
299 
316  WiconnectResult sendCommand(TimerTimeout timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, ...);
317 
334  WiconnectResult sendCommand(const ReaderFunc &reader, void *user, const char *cmd, ...);
335 
350  WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, TimerTimeout timeoutMs, const char *cmd, ...);
351 
366  WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen, const char *cmd, ...);
367 
381  WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, const char *cmd, ...);
382 
398  WiconnectResult sendCommand(const Callback &completeCallback, const char *cmd, ...);
399 
414  WiconnectResult sendCommand(const char *cmd, ...);
415 
429  WiconnectResult sendCommand(const Callback &completeCallback, TimerTimeout timeoutMs, const char *cmd, ...);
430 
445  WiconnectResult sendCommand(TimerTimeout timeoutMs, const char *cmd, ...);
446 
459  WiconnectResult sendCommand(const char *cmd, va_list vaList);
460 
473 
481  void stopCurrentCommand();
482 
483 
484  // ------------------------------------------------------------------------
485 
486 
496  const char* getLastCommandResponseCodeStr();
497 
505  uint16_t getLastCommandResponseLength();
506 
514  char* getResponseBuffer();
515 
526  WiconnectResult responseToUint32(uint32_t *uint32Ptr);
527 
538  WiconnectResult responseToInt32(int32_t *int32Ptr);
539 
540 
541  // ------------------------------------------------------------------------
542 
556  WiconnectResult setSetting(const char *settingStr, uint32_t value);
557 
571  WiconnectResult setSetting(const char *settingStr, const char *value);
572 
586  WiconnectResult getSetting(const char *settingStr, uint32_t *valuePtr);
587 
601  WiconnectResult getSetting(const char *settingStr, char **valuePtr);
602 
617  WiconnectResult getSetting(const char *settingStr, char *valueBuffer, uint16_t valueBufferLen);
618 
619 
627  void setBlockingEnabled(bool blockingEnabled);
628 
634  bool getBlockingEnabled(void);
635 
646  void setCommandDefaultTimeout(TimerTimeout timeoutMs);
647 
656 
664  void setPinToGpioMapper(PinToGpioMapper mapper);
665 
673  void setDebugLogger(LogFunc logFunc);
674 
684  void setAssertLogger(LogFunc assertLogFunc);
685 
686  // ------------------------------------------------------------------------
687 
688 
689 #ifdef WICONNECT_ASYNC_TIMER_ENABLED
690 
701  WiconnectResult enqueueCommand(QueuedCommand *command, const Callback &commandCompleteHandler = Callback());
702 
712  void setCommandProcessingPeriod(uint32_t periodMs);
713 #endif
714 
715 
724  static const char* getWiconnectResultStr(WiconnectResult wiconnectResult);
725 
734  static uint32_t wiconnectVersionToInt(char *versionStr);
735 
736 protected:
737 
738 #ifdef WICONNECT_ENABLE_MALLOC
739  void* (*_malloc)(size_t);
740  void (*_free)(void *);
741  friend class QueuedCommand;
742  friend class WiconnectSerial;
743  friend class ScanResult;
744 #endif
745 
746  wiconnect::WiconnectSerial serial;
747  wiconnect::Gpio resetGpio;
748  wiconnect::Gpio wakeGpio;
749 
750  volatile bool commandExecuting;
751  bool initialized;
752  bool needUpdate;
753  bool nonBlocking;
754 
755  PinToGpioMapper pinToGpioMapper;
756 
757  char *internalBuffer;
758  int internalBufferSize;
759  bool internalBufferAlloc;
760  uint8_t internalProcessingState;
761  void *currentCommandId;
762 
763  wiconnect::TimeoutTimer timeoutTimer;
764  TimerTimeout defaultTimeoutMs;
765 
766  uint8_t commandHeaderBuffer[32];
767  char commandFormatBuffer[WICONNECT_MAX_CMD_SIZE];
768  uint8_t commandContext[96];
769 
770  void prepare(void *internalBuffer, int internalBufferSize, bool nonBlocking);
771  bool configureModuleDataBus(void);
772  WiconnectResult inline receiveResponse();
773  WiconnectResult inline receivePacket();
774  void issueCommandCallback(WiconnectResult result);
775 
776 #ifdef WICONNECT_ENABLE_DEBUGGING
777  LogFunc debugLogger;
778 #endif
779  LogFunc assertLogger;
780 
781  void debugLog(const char *msg, ...);
782 
783 #ifdef WICONNECT_ASYNC_TIMER_ENABLED
784  wiconnect::PeriodicTimer commandProcessorTimer;
785  uint32_t commandProcessingPeriod;
786  CommandQueue commandQueue;
787  wiconnect::QueuedCommand *currentQueuedCommand;
788 
789  void commandProcessingTimerHandler(void);
790  void processNextQueuedCommand();
791  void checkQueuedCommandTimeout();
792 #endif
793 
794  friend class NetworkInterface;
795  friend class SocketInterface;
796  friend class FileInterface;
797  friend class GhmInterface;
798  friend class GhmMessageList;
799  friend class GhmMessage;
800  friend class ScanResultList;
801  friend class WiconnectFile;
802  friend class WiconnectSocket;
803  friend class WiconnectUdpServer;
804 };
805 
806 }
807 
808 
809 #include "sdkTypes.h"
810 
Wiconnect(const SerialConfig &serialConfig, Pin reset=NC, Pin wake=NC, bool nonBlocking=false, void *(*malloc_)(size_t)=malloc, void(*free_)(void *)=free)
WiConnect class constructor.
static const char * getWiconnectResultStr(WiconnectResult wiconnectResult)
Converts a WiconnectResult to string representation.
Contains single entry from goHACK.me message listing.
Definition: GhmMessage.h:46
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.
void setBlockingEnabled(bool blockingEnabled)
Sets if API calls are blocking or non-blocking.
UDP Server Listening socket.
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.
static uint32_t wiconnectVersionToInt(char *versionStr)
Converts wiconnect version string to uint32_t representation.
Host<->Wiconnect Module serial configuration.
Definition: sdk.h:148
TimerTimeout getCommandDefaultTimeout()
Returns the current default maximum API execution time.
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.
List of goHACK.me messages.
WiConnect WiFi module file object.
Definition: WiconnectFile.h:44
The provides an interface for http://goHACK.me.
Definition: GhmInterface.h:81
void setCommandDefaultTimeout(TimerTimeout timeoutMs)
Sets the default maximum time an API method may execute before terminating and return a timeout error...
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.
WiconnectResult setSetting(const char *settingStr, uint32_t value)
Set a module setting.
void setCommandProcessingPeriod(uint32_t periodMs)
Set the period at which an asynchronous command should be processed.
Class which contains command for asynchronous processing.
Definition: QueuedCommand.h:43
PinName Pin
Pin name on HOST.
Definition: sdk.h:142
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.
WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen, TimerTimeout timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, va_list vaList)
Send command to WiConnect WiFi module.
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.
unsigned long TimerTimeout
Timeout type.
Connection object to remote server.
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...
The root WiConnect library class. This class inheriets all WiConnect functionality.
WiconnectResult enqueueCommand(QueuedCommand *command, const Callback &commandCompleteHandler=Callback())
Add user command to be executed asynchronously.
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:113
#define delayMs(ms)
Function to stop processor for specified number of milliseconds.
Definition: sdk.h:199
#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:136
WiconnectResult getVersion(char *versionBuffer=NULL, int versionBufferSize=0, const Callback &completeCallback=Callback())
Return current version of WiConnect WiFi module.
bool updateRequired()
Return TRUE if the WiFi module's firmware supports the SDK version, FALSE if the WiFi module's firmwa...
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.
bool getBlockingEnabled(void)
Gets if API calls are blocking or non-blocking.