ACKme
/
wiconnect-test-console
Test serial console demonstrating various API functions of WiConnect library.
main.cpp
- Committer:
- dan_ackme
- Date:
- 2014-08-11
- Revision:
- 3:dddd476d5967
- Parent:
- 2:2f222449973a
- Child:
- 9:dddf6ed7e992
File content as of revision 3:dddd476d5967:
/* * 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. */ #include "Wiconnect.h" #include "util/log/log.h" #include "util/CommandProcessor/CommandProcessor.h" #include "tests/Tests.h" #include "target_config.h" #if TEST_NONBLOCKING_API #error 'TEST_NONBLOCKING_API = true' NOT currently supported for the mbed sdk #endif int wiconnectLogDebug(const char *str); int wiconnectLogAssert(const char *str); static const CommandListEntry commandList[] = { CMD_HELP_ENTRY, WICONNECT_TEST_CMD_LIST, NETWORK_TEST_CMD_LIST, SOCKET_TEST_CMD_LIST, FILE_TEST_CMD_LIST, CMD_LIST_TERMINATOR }; char testBuffer[TEST_BUFFER_LENGTH]; static uint8_t wiconnectInternalBuffer[WICONNECT_INTERNAL_BUFFER_SIZE]; static uint8_t wiconnectSerialRxBuffer[WICONNECT_SERIAL_RX_BUFFER_SIZE]; static const SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, WICONNECT_CTS_PIN, WICONNECT_RTS_PIN, WICONNECT_DEFAULT_BAUD, wiconnectSerialRxBuffer, WICONNECT_SERIAL_RX_BUFFER_SIZE); static Wiconnect wiconnectIfc(serialConfig, wiconnectInternalBuffer, WICONNECT_INTERNAL_BUFFER_SIZE, WICONNECT_RESET_PIN, WICONNECT_WAKE_PIN, TEST_NONBLOCKING_API); ConsoleSerial consoleSerial(SERIAL_TX, SERIAL_RX); CommandProcessor cmdProcessor(&consoleSerial, commandList); /*************************************************************************************************/ int main(int argc, char *argv[]) { WiconnectResult result; bool running = true; consoleSerial.setBaud(CONSOLE_BAUD); wiconnectIfc.setAssertLogger(LogFunc(wiconnectLogAssert)); wiconnectIfc.setCommandDefaultTimeout(5000); #ifdef ENABLE_WICONNECT_DEBUG wiconnectIfc.setDebugLogger(LogFunc(wiconnectLogDebug)); #endif initialize_loop: { LOG_INFO("\r\n\r\nInitializing WiConnect..."); if(WICONNECT_FAILED(result, wiconnectIfc.init(true))) { LOG_WICONNECT_ERROR(result, "Failed to initialize Wiconnect"); LOG_INFO("Press any key to retry initialization..."); int c = consoleSerial.getc(); goto initialize_loop; } } { if(!WICONNECT_FAILED(result, wiconnectIfc.getVersion())) { LOG_INFO("Version: %s", wiconnectIfc.getResponseBuffer()); } } LOG_INFO("WiConnect test app ready..."); while(running) { Command cmd; cmdProcessor.waitForCommand(&cmd); if(WICONNECT_FAILED(result, cmd.execute())) { LOG_WICONNECT_ERROR(result, "Failed to execute command"); if(result == WICONNECT_CMD_RESPONSE_ERROR) { LOG_ERROR("WiConnect command response code: %s", wiconnectIfc.getLastCommandResponseCodeStr()); } } } return 0; } /*************************************************************************************************/ int wiconnectLogDebug(const char *str) { logDebug(str); return 0; } /*************************************************************************************************/ int wiconnectLogAssert(const char *str) { logWrite("\r\n\r\n[ASSERT] ", 13); logWrite(str, strlen(str)); return 0; }