Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit of G14 Code - beta firmware

Starting from sample code from gainspan, this is a first version of the
beta firmware
This project created using an IAR compiler 30 day trial - code size is
over the 16k kickstarter limit.
We need to refactor this code to work on CubeSuite+ with applilet3
  • Loading branch information...
commit 73b347f1b69e170f50476dc749336873a6e5a953 1 parent fc0c731
@CHIPkitReadonly CHIPkitReadonly authored
Showing with 26,826 additions and 2,651 deletions.
  1. +355 −0 Apps/App_Common.c
  2. +133 −0 Apps/App_Connect.c
  3. +44 −0 Apps/App_ProgramMode.c
  4. +669 −0 Apps/App_Startup.c
  5. +466 −0 Apps/App_Swarm.c
  6. +82 −0 Apps/Apps.h
  7. +94 −0 Apps/NVSettings.c
  8. +52 −0 Apps/NVSettings.h
  9. +5,692 −0 CmdLib/AtCmdLib.c
  10. +801 −0 CmdLib/AtCmdLib.h
  11. +517 −0 CmdLib/GainSpan_SPI.c
  12. +50 −0 CmdLib/GainSpan_SPI.h
  13. +980 −0 YRDKRL78G14/ADKRenesasG14.dep
  14. +581 −0 YRDKRL78G14/ADKRenesasG14.ewd
  15. +2,257 −0 YRDKRL78G14/ADKRenesasG14.ewp
  16. +10 −0 YRDKRL78G14/ADKRenesasG14.eww
  17. +96 −0 YRDKRL78G14/HostApp.h
  18. +156 −142 {gen → YRDKRL78G14/applilet3_src}/r_cg_adc.c
  19. +219 −197 {gen → YRDKRL78G14/applilet3_src}/r_cg_adc.h
  20. +65 −69 gen/r_cg_port_user.c → YRDKRL78G14/applilet3_src/r_cg_adc_user.c
  21. +93 −91 {gen → YRDKRL78G14/applilet3_src}/r_cg_cgc.c
  22. +208 −188 {gen → YRDKRL78G14/applilet3_src}/r_cg_cgc.h
  23. +63 −69 {gen → YRDKRL78G14/applilet3_src}/r_cg_cgc_user.c
  24. +319 −0 YRDKRL78G14/applilet3_src/r_cg_intc.c
  25. +173 −159 {gen → YRDKRL78G14/applilet3_src}/r_cg_intc.h
  26. +183 −177 gen/r_cg_intc.c → YRDKRL78G14/applilet3_src/r_cg_intc_user.c
  27. +94 −101 {gen → YRDKRL78G14/applilet3_src}/r_cg_it.c
  28. +68 −68 {gen → YRDKRL78G14/applilet3_src}/r_cg_it.h
  29. +101 −76 {gen → YRDKRL78G14/applilet3_src}/r_cg_it_user.c
  30. +92 −90 {gen → YRDKRL78G14/applilet3_src}/r_cg_macrodriver.h
  31. +87 −83 gen/r_cg_wdt.c → YRDKRL78G14/applilet3_src/r_cg_pclbuz.c
  32. +80 −0 YRDKRL78G14/applilet3_src/r_cg_pclbuz.h
  33. +50 −59 gen/r_cg_wdt.h → YRDKRL78G14/applilet3_src/r_cg_pclbuz_user.c
  34. +100 −0 YRDKRL78G14/applilet3_src/r_cg_port.c
  35. +233 −215 {gen → YRDKRL78G14/applilet3_src}/r_cg_port.h
  36. +161 −79 gen/r_cg_port.c → YRDKRL78G14/applilet3_src/r_cg_port_user.c
  37. +864 −0 YRDKRL78G14/applilet3_src/r_cg_serial.c
  38. +451 −430 {gen → YRDKRL78G14/applilet3_src}/r_cg_serial.h
  39. +690 −0 YRDKRL78G14/applilet3_src/r_cg_serial_user.c
  40. +250 −0 YRDKRL78G14/applilet3_src/r_cg_timer.c
  41. +940 −0 YRDKRL78G14/applilet3_src/r_cg_timer.h
  42. +213 −133 gen/r_cg_intc_user.c → YRDKRL78G14/applilet3_src/r_cg_timer_user.c
  43. +43 −43 {gen → YRDKRL78G14/applilet3_src}/r_cg_userdefine.h
  44. +110 −83 gen/r_cg_adc_user.c → YRDKRL78G14/applilet3_src/r_main.c
  45. +102 −99 {gen → YRDKRL78G14/applilet3_src}/r_systeminit.c
  46. +106 −0 YRDKRL78G14/drv/ADC.c
  47. +167 −0 YRDKRL78G14/drv/ADC.h
  48. +80 −0 YRDKRL78G14/drv/Glyph/Drivers/ST7579_LCD.h
  49. +41 −0 YRDKRL78G14/drv/Glyph/Drivers/YRDKRL78_SPI.h
  50. BIN  YRDKRL78G14/drv/Glyph/RL78GlyphLib_Debug.r87
  51. BIN  YRDKRL78G14/drv/Glyph/RL78GlyphLib_Debug_old.r87
  52. +280 −0 YRDKRL78G14/drv/Glyph/glyph_api.h
  53. +55 −0 YRDKRL78G14/drv/Glyph/glyph_cfg.h
  54. +151 −0 YRDKRL78G14/drv/Glyph/glyph_register.c
  55. +47 −0 YRDKRL78G14/drv/Glyph/glyph_types.h
  56. +184 −0 YRDKRL78G14/drv/Glyph/lcd.c
  57. +91 −0 YRDKRL78G14/drv/Glyph/lcd.h
  58. +418 −0 YRDKRL78G14/drv/I2C.c
  59. +162 −0 YRDKRL78G14/drv/I2C.h
  60. +101 −0 YRDKRL78G14/drv/RDKRL78_spi.c
  61. +15 −0 YRDKRL78G14/drv/RDKRL78_spi.h
  62. +469 −0 YRDKRL78G14/drv/SAU.h
  63. +446 −0 YRDKRL78G14/drv/SPI _G14.c
  64. +431 −0 YRDKRL78G14/drv/SPI.c
  65. +48 −0 YRDKRL78G14/drv/SPI.h
  66. +431 −0 YRDKRL78G14/drv/SPI_G13.c
  67. +109 −0 YRDKRL78G14/drv/Timer.c
  68. +44 −0 YRDKRL78G14/drv/Timer.h
  69. +447 −0 YRDKRL78G14/drv/UART0.c
  70. +30 −0 YRDKRL78G14/drv/UART0.h
  71. +444 −0 YRDKRL78G14/drv/UART2.c
  72. +30 −0 YRDKRL78G14/drv/UART2.h
  73. +209 −0 YRDKRL78G14/drv/led.c
  74. +31 −0 YRDKRL78G14/drv/led.h
  75. +92 −0 YRDKRL78G14/drv/r_cg_macrodriver.h
  76. +151 −0 YRDKRL78G14/init/hwsetup.c
  77. +378 −0 YRDKRL78G14/init/hwsetup.h
  78. +265 −0 YRDKRL78G14/lnkr5f104pj.xcl
  79. +292 −0 YRDKRL78G14/main.c
  80. +24 −0 YRDKRL78G14/settings/ADKRenesasG14.cspy.bat
  81. +74 −0 YRDKRL78G14/settings/ADKRenesasG14.dbgdt
  82. +125 −0 YRDKRL78G14/settings/ADKRenesasG14.dni
  83. +72 −0 YRDKRL78G14/settings/ADKRenesasG14.wsdt
  84. +15 −0 YRDKRL78G14/settings/GainSpan_RL78G13_IAR.cspy.bat
  85. +79 −0 YRDKRL78G14/settings/GainSpan_RL78G13_IAR.dbgdt
  86. +102 −0 YRDKRL78G14/settings/GainSpan_RL78G13_IAR.dni
  87. +85 −0 YRDKRL78G14/settings/GainSpan_RL78G13_IAR.wsdt
  88. +288 −0 YRDKRL78G14/system/EEPROM.c
  89. +43 −0 YRDKRL78G14/system/EEPROM.h
  90. +79 −0 YRDKRL78G14/system/GainSpan_IO.c
  91. +19 −0 YRDKRL78G14/system/GainSpan_IO.h
  92. +62 −0 YRDKRL78G14/system/Switch.c
  93. +35 −0 YRDKRL78G14/system/Switch.h
  94. +27 −0 YRDKRL78G14/system/YRDKRL78G14.h
  95. +120 −0 YRDKRL78G14/system/console.c
  96. +32 −0 YRDKRL78G14/system/console.h
  97. +120 −0 YRDKRL78G14/system/mstimer.c
  98. +26 −0 YRDKRL78G14/system/mstimer.h
  99. +67 −0 YRDKRL78G14/system/platform.h
Sorry, we could not display the entire diff because it was too big.
View
355 Apps/App_Common.c
@@ -0,0 +1,355 @@
+/*-------------------------------------------------------------------------*
+ * File: App_Common.c
+ *-------------------------------------------------------------------------*
+ * Description:
+ * Common routines used by all the Apps.
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Includes:
+ *-------------------------------------------------------------------------*/
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <HostApp.h>
+#include <HostApp.h>
+#include <system/console.h>
+#include <system/platform.h>
+#include <CmdLib/AtCmdLib.h>
+#include <CmdLib/GainSpan_SPI.h>
+#include <sensors/Temperature.h>
+#include <sensors/Potentiometer.h>
+#include <sensors/LightSensor.h>
+#include <sensors/Accelerometer.h>
+#include <system/mstimer.h>
+#include <drv/Glyph/lcd.h>
+#include "Apps.h"
+#include "HostApp.h"
+#ifndef APP_MAX_RECEIVED_DATA
+ #error "APP_MAX_RECEIVED_DATA must be defined in platform.h"
+#endif
+
+/*-------------------------------------------------------------------------*
+ * Globals:
+ *-------------------------------------------------------------------------*/
+uint8_t G_received[APP_MAX_RECEIVED_DATA + 1];
+unsigned int G_receivedCount = 0;
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_Write
+ *---------------------------------------------------------------------------*
+ * Description:
+ * ATCmdLib callback to write a string of characters to the module.
+ * Inputs:
+ * const uint8_t *txData -- string of bytes
+ * uint32_t dataLength -- Number of bytes to transfer
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_Write(const void *txData, uint16_t dataLength)
+{
+ const uint8_t *tx = (uint8_t *)txData;
+#ifdef ATLIBGS_INTERFACE_SPI
+ while (dataLength--) {
+ /* Keep trying to send this data until it goes */
+ while (!GainSpan_SPI_SendByte(*tx)) {
+ /* Process any incoming data as well */
+ GainSpan_SPI_Update(GAINSPAN_SPI_CHANNEL);
+ }
+
+ tx++;
+ }
+#else
+ while (dataLength--) {
+ /* Keep trying to send this data until it goes */
+ while (!GainSpan_UART_SendByte(*tx)) {
+ }
+ tx++;
+ }
+#endif
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_Read
+ *---------------------------------------------------------------------------*
+ * Description:
+ * ATCmdLib callback to read a string of characters from the module.
+ * This routine can block if needed until the data arrives.
+ * Inputs:
+ * uint8_t *rxData -- Pointer to a place to store a string of bytes
+ * uint16_t dataLength -- Number of bytes to transfer
+ * uint8_t blockFlag -- true/non-zero to wait for bytes, else false/zero.
+ * Outputs:
+ * bool -- true if character received, else false
+ *---------------------------------------------------------------------------*/
+bool App_Read(uint8_t *rxData, uint16_t dataLength, uint8_t blockFlag)
+{
+#ifdef ATLIBGS_INTERFACE_SPI
+ bool got_data = false;
+
+ /* Keep getting data if we have a number of bytes to fetch */
+ while (dataLength) {
+ /* Try to get a byte */
+ if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, rxData)) {
+ /* Got a byte, move up to the next position */
+ rxData++;
+ dataLength--;
+ got_data = true;
+ } else {
+ /* Did not get a byte, are we block? If not, stop here */
+ if (!blockFlag)
+ break;
+ }
+ }
+
+ return got_data;
+#else
+ bool got_data = false;
+
+ /* Keep getting data if we have a number of bytes to fetch */
+ while (dataLength) {
+ /* Try to get a byte */
+ if (GainSpan_UART_ReceiveByte(rxData)) {
+ /* Got a byte, move up to the next position */
+ rxData++;
+ dataLength--;
+ got_data = true;
+ } else {
+ /* Did not get a byte, are we block? If not, stop here */
+ if (!blockFlag)
+ break;
+ }
+ }
+
+ return got_data;
+#endif
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_RSSIReading
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Take a reading of the RSSI level with the WiFi and show it on
+ * the LCD display.
+ * Inputs:
+ * bool updateLCD (if true, LCD is updated)
+ * Outputs:
+ * int16_t rssi (return value)
+ *---------------------------------------------------------------------------*/
+int16_t App_RSSIReading(int16_t * rssi, bool updateLCD)
+{
+ char line[20];
+ int rssiFound = 0;
+
+ if (AtLibGs_IsNodeAssociated()) {
+ if (AtLibGs_GetRssi() == ATLIBGS_MSG_ID_OK) {
+ if (AtLibGs_ParseRssiResponse(rssi)) {
+ sprintf(line, "RSSI: %d", (*rssi));
+ DisplayLCD(LCD_LINE6, (const uint8_t *)line);
+ rssiFound = 1;
+ }
+ }
+ }
+ if (!rssiFound) {
+ DisplayLCD(LCD_LINE5, "RSSI: ----");
+ rssi = 0;
+ }
+ return *rssi;
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_TemperatureReadingUpdate
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Take a reading of a temperature and show it on the LCD display.
+ * Inputs:
+ * bool updateLCD (if true, LCD is updated), pointer to 2 member uint16_t
+ * array to update values in
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_TemperatureReadingUpdate(uint16_t * G_temp_int, bool updateLCD)
+{
+ char lcd_buffer[20];
+
+ // Temperature sensor reading
+ int16_t temp;
+ temp = Temperature_Get();
+ // Get the temperature and show it on the LCD
+ G_temp_int[0] = (int16_t)temp / 16;
+ G_temp_int[1] = (int16_t)((temp & 0x000F) * 10) / 16;
+
+ if(updateLCD)
+ {
+ // Display the contents of lcd_buffer onto the debug LCD
+ sprintf((char *)lcd_buffer, "TEMP: %d.%d C", G_temp_int[0], G_temp_int[1]);
+ DisplayLCD(LCD_LINE3, (const uint8_t *)lcd_buffer);
+ }
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_PotentiometerUpdate
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Take a reading of the potentiometer and show it on the LCD display.
+ * Inputs:
+ * bool updateLCD (if true, LCD is updated), pointer to 2 member uint16_t
+ * array to update values in
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_PotentiometerUpdate(int16_t * G_adc_int, bool updateLCD)
+{
+ char lcd_buffer[20];
+
+ // Potentiometer sensor reading
+ int32_t percent;
+ percent = Potentiometer_Get();
+ G_adc_int[0] = (int16_t)(percent / 10);
+ G_adc_int[1] = (int16_t)(percent % 10);
+
+ if(updateLCD)
+ {
+ sprintf((char *)lcd_buffer, " POT: %d.%d %%", G_adc_int[0], G_adc_int[1]);
+ /* Display the contents of lcd_buffer onto the debug LCD */
+ DisplayLCD(LCD_LINE4, (const uint8_t *)lcd_buffer);
+ }
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_LightSensorReadingUpdate
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Take a reading of a lightSensor and show it on the LCD display.
+ * Inputs:
+ * bool updateLCD (if true, LCD is updated), pointer to 2 member uint16_t
+ * array to update values in
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_LightSensorReadingUpdate(uint16_t * G_light_int, bool updateLCD)
+{
+ char lcd_buffer[20];
+
+ // Temperature sensor reading
+ *G_light_int = LightSensor_Get();
+
+ if(updateLCD)
+ {
+ // Display the contents of lcd_buffer onto the debug LCD
+ sprintf((char *)lcd_buffer, "Light: %d ", *G_light_int);
+ DisplayLCD(LCD_LINE5, (const uint8_t *)lcd_buffer);
+ }
+}
+
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_PrepareIncomingData
+ *---------------------------------------------------------------------------*
+ * Description:
+ * ATCmdLib callback to reset the incoming data state.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_PrepareIncomingData(void)
+{
+ G_receivedCount = 0;
+ G_received[0] = '\0';
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_ProcessIncomingData
+ *---------------------------------------------------------------------------*
+ * Description:
+ * ATCmdLib callback that is called when a byte has come in for a
+ * specific connection.
+ * Inputs:
+ * uint8_t rxData -- Byte received
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_ProcessIncomingData(uint8_t rxData)
+{
+ if (G_receivedCount < APP_MAX_RECEIVED_DATA) {
+ G_received[G_receivedCount++] = rxData;
+ G_received[G_receivedCount] = '\0';
+ }
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_Update
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Allow the AtLibGs to update its state when nothing is happening
+ * in the application.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_Update(void)
+{
+#ifdef ATLIBGS_INTERFACE_SPI
+ GainSpan_SPI_Update(GAINSPAN_SPI_CHANNEL);
+#else
+#endif
+}
+
+void readSensor(APP_STATE_E state){
+ char temp_char[2]; uint16_t temp; float ftemp; float gTemp_F;
+ char LCDString[30]; uint16_t gAmbientLight; extern int16_t gAccData[3];
+ extern int16_t *Accelerometer_Get(void);
+ ConsolePrintf("Reading sensor %d: ",state);
+ switch(state)
+ {
+ case UPDATE_TEMPERATURE:
+ // Temperature sensor reading
+ temp = Temperature_Get();
+ #if 0
+ // Get the temperature and show it on the LCD
+ temp_char[0] = (int16_t)temp / 16;
+ temp_char[1] = (int16_t)((temp & 0x000F) * 10) / 16;
+ #endif
+ temp_char[1] = (temp & 0xFF00)>>8;
+ temp_char[0] = temp & 0xFF;
+
+ ftemp = *(uint16_t *)temp_char;
+
+ gTemp_F = ((ftemp/5)*9)/128 + 22;
+
+ // Display the contents of lcd_buffer onto the debug LCD
+ //sprintf((char *)LCDString, "TEMP: %d.%d C", temp_char[0], temp_char[1]);
+ sprintf((char *)LCDString, "TEMP: %.1fF", gTemp_F);
+ ConsolePrintf("%s\r\n",LCDString);
+ DisplayLCD(LCD_LINE6, (const uint8_t *)LCDString);
+ state = UPDATE_LIGHT;
+ break;
+
+ case UPDATE_LIGHT:
+ // Light sensor reading
+ gAmbientLight = LightSensor_Get();
+ // Display the contents of lcd_buffer onto the debug LCD
+ sprintf((char *)LCDString, "Light: %d ", gAmbientLight);
+ ConsolePrintf("%s\r\n",LCDString);
+ DisplayLCD(LCD_LINE7, (const uint8_t *)LCDString);
+ state = UPDATE_ACCELEROMETER;
+ break;
+
+ case UPDATE_ACCELEROMETER:
+ // 3-axis accelerometer reading
+ Accelerometer_Get();
+ sprintf((char *)LCDString, "x%2d y%2d z%2d", gAccData[0], gAccData[1], gAccData[2]);
+ ConsolePrintf("%s\r\n",LCDString);
+ DisplayLCD(LCD_LINE8, (const uint8_t *)LCDString);
+ state = UPDATE_TEMPERATURE;
+ break;
+ }
+}
+
+
+/*-------------------------------------------------------------------------*
+ * End of File: App_Common.c
+ *-------------------------------------------------------------------------*/
View
133 Apps/App_Connect.c
@@ -0,0 +1,133 @@
+/*-------------------------------------------------------------------------*
+ * File: App_Connect.c
+ *-------------------------------------------------------------------------*
+ * Description:
+ * Routines for connecting to the network. Usually done at power up.
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Includes:
+ *-------------------------------------------------------------------------*/
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <HostApp.h>
+#include <system/platform.h>
+#include <system/console.h>
+#include <CmdLib/AtCmdLib.h>
+#include <CmdLib/GainSpan_SPI.h>
+#include <system/mstimer.h>
+#include <drv/Glyph/lcd.h>
+#include "Apps.h"
+
+/*-------------------------------------------------------------------------*
+ * Constants:
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Types:
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Prototypes:
+ *-------------------------------------------------------------------------*/
+ATLIBGS_MSG_ID_E App_Connect(ATLIBGS_WEB_PROV_SETTINGS *wp)
+{
+ ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;
+ char ip[20];
+ char subnet[20];
+ char gateway[20];
+
+ while (1) {
+ DisplayLCD(LCD_LINE7, " Connecting ");
+ DisplayLCD(LCD_LINE8, "");
+
+ AtLibGs_DisAssoc();
+
+ AtLibGs_FlushIncomingMessage();
+
+ // Set the mode of operation
+ rxMsgId = AtLibGs_Mode(wp->station);
+ if (rxMsgId != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad Mode!");
+ MSTimerDelay(2000);
+ DisplayLCD(LCD_LINE6, "");
+ continue;
+ }
+
+ // Turn on DHCP?
+ if (wp->dhcp_enable) {
+ rxMsgId = AtLibGs_DHCPSet(1);
+ if (rxMsgId != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE8, "Bad DHCP!");
+ MSTimerDelay(2000);
+ DisplayLCD(LCD_LINE6, "");
+ continue;
+ }
+ } else {
+ // Disable, set settings manually
+ DisplayLCD(LCD_LINE8, "DHCP On...");
+ rxMsgId = AtLibGs_DHCPSet(0);
+ if (rxMsgId != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE8, "Bad DHCP!");
+ MSTimerDelay(2000);
+ DisplayLCD(LCD_LINE6, "");
+ continue;
+ }
+
+ // Setup the IP address
+ AtLibGs_IPv4AddressToString(&wp->ip, ip);
+ AtLibGs_IPv4AddressToString(&wp->subnet, subnet);
+ AtLibGs_IPv4AddressToString(&wp->gateway, gateway);
+ rxMsgId = AtLibGs_IPSet(ip, subnet, gateway);
+ if (rxMsgId != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE8, "Bad IP!");
+ MSTimerDelay(2000);
+ DisplayLCD(LCD_LINE6, "");
+ continue;
+ }
+ }
+
+ if (wp->security != ATLIBGS_SMOPEN) {
+ /* Store the PSK value. This call takes might take few seconds to return */
+ do {
+ DisplayLCD(LCD_LINE8, "Setting PSK");
+ rxMsgId = AtLibGs_CalcNStorePSK(wp->ssid, wp->password);
+ if (rxMsgId != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE8, "Bad PSK!");
+ MSTimerDelay(2000);
+ DisplayLCD(LCD_LINE8, "");
+ continue;
+ }
+ } while (ATLIBGS_MSG_ID_OK != rxMsgId);
+ }
+
+ DisplayLCD(LCD_LINE8, "");
+
+ /* Associate to a particular AP specified by SSID */
+ rxMsgId = AtLibGs_Assoc(wp->ssid, "", wp->channel);
+ if (ATLIBGS_MSG_ID_OK != rxMsgId) {
+ /* Association error - we can retry */
+#ifdef ATLIBGS_DEBUG_ENABLE
+ ConsolePrintf("\n Association error - retry now \n");
+#endif
+ DisplayLCD(LCD_LINE7, "** Failed **");
+ MSTimerDelay(2000);
+ DisplayLCD(LCD_LINE7, "");
+ continue;
+ } else {
+ /* Association success */
+ AtLibGs_SetNodeAssociationFlag();
+ DisplayLCD(LCD_LINE7, " Connected");
+ MSTimerDelay(500);
+ DisplayLCD(LCD_LINE7, "");
+ }
+ break;
+ }
+ return rxMsgId;
+}
+
+/*-------------------------------------------------------------------------*
+ * End of File: App_Connect.c
+ *-------------------------------------------------------------------------*/
View
44 Apps/App_ProgramMode.c
@@ -0,0 +1,44 @@
+/*-------------------------------------------------------------------------*
+ * File: App_ProgramMode.c
+ *-------------------------------------------------------------------------*
+ * Description:
+ * This code puts the unit into a mode that allows the
+ * GainSpan Flash Program (gs_flashprogram) to program the
+ * GainSpan module through the Renesas RX62N RDK's serial port.
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Includes:
+ *-------------------------------------------------------------------------*/
+#include <stdint.h>
+#include <stdbool.h>
+#include <HostApp.h>
+#include <system/platform.h>
+#include <system/GainSpan_IO.h>
+#include <drv/Glyph/lcd.h>
+#include <drv/Timer.h>
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_ProgramMode
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Put the unit into programming mode by putting the control pin into
+ * program mode and mimicing the TX/RX lines on SCI2 with the
+ * RX/TX lines of SCI6.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_ProgramMode(void)
+{
+ DisplayLCD(LCD_LINE1, "GS PROGRAM");
+ Timer_Stop();
+
+ // Enter WAB Programming Mode - Will not exit
+ GainSpan_IO_ProgMode();
+}
+
+/*-------------------------------------------------------------------------*
+ * End of File: App_ProgramMode.c
+ *-------------------------------------------------------------------------*/
View
669 Apps/App_Startup.c
@@ -0,0 +1,669 @@
+/*-------------------------------------------------------------------------*
+ * File: App_Startup.c
+ *-------------------------------------------------------------------------*
+ * Description:
+ *
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Includes:
+ *-------------------------------------------------------------------------*/
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <system/platform.h>
+#include <Apps/NVSettings.h>
+#include <system/Switch.h>
+#include <drv/Glyph/lcd.h>
+#include <system/mstimer.h>
+#include <system/console.h>
+
+/*-------------------------------------------------------------------------*
+ * Constants:
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Types:
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Globals:
+ *-------------------------------------------------------------------------*/
+NVSettings_t G_nvsettings;
+char str_config_ssid[22];
+uint8_t wifi_channel;
+char WiFiMAC[20];
+char WiFiMACStr[13];
+void VirginCheck(void);
+/*---------------------------------------------------------------------------*
+ * Routine: App_InitModule
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Setup the mode by first checking if there is a link and either
+ * report or continue to the rest of the program.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_InitModule(void)
+{
+ ATLIBGS_MSG_ID_E r = ATLIBGS_MSG_ID_NONE;
+
+ DisplayLCD(LCD_LINE7, " Preparing");
+ DisplayLCD(LCD_LINE8, " Init Mod");
+
+ /* Give the unit a little time to start up */
+ /* (300 ms for GS1011 and 1000 ms for GS1500) */
+ MSTimerDelay(1000);
+
+ /* Check the link */
+#ifdef ATLIBGS_DEBUG_ENABLE
+ ConsolePrintf("Checking link\r\n");
+#endif
+
+ /* Wait for the banner (if any) */
+ MSTimerDelay(500);
+
+ /* Clear out the buffers */
+ AtLibGs_FlushRxBuffer();
+
+ /* Send command to check */
+ do {
+ AtLibGs_FlushIncomingMessage();
+ DisplayLCD(LCD_LINE8, "Checking...");
+ r = AtLibGs_Check();
+ } while (ATLIBGS_MSG_ID_OK != r);
+
+ /* Send command to DISABLE echo */
+ do {
+ DisplayLCD(LCD_LINE8, "Echo Off...");
+ r = AtLibGs_SetEcho(ATLIBGS_DISABLE);
+ } while (ATLIBGS_MSG_ID_OK != r);
+
+ /* Done */
+ DisplayLCD(LCD_LINE7, "");
+ DisplayLCD(LCD_LINE8, "");
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_StartupLimitedAP
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Put the unit into a limited AP mode using the configuration in the
+ * default LimitedAP settings.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_StartupLimitedAP(char *mySSID)
+{
+ ATLIBGS_MSG_ID_E r;
+
+ DisplayLCD(LCD_LINE3, "Limited AP:");
+ DisplayLCD(LCD_LINE4, (uint8_t const *)mySSID);
+
+#ifdef ATLIBGS_DEBUG_ENABLE
+ ConsolePrintf("Starting Limited AP: %s\n", ATLIBGS_LIMITED_AP_SSID);
+#endif
+
+ /* Try to disassociate if not already associated */
+ AtLibGs_DisAssoc();
+ while (1) {
+ DisplayLCD(LCD_LINE6, " Setting up");
+
+ r =AtLibGs_EnableRadio(1); // enable radio
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad Mode!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_Mode(ATLIBGS_STATIONMODE_LIMITED_AP);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad Mode!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_IPSet(ATLIBGS_LIMITED_AP_IP, ATLIBGS_LIMITED_AP_MASK,
+ ATLIBGS_LIMITED_AP_GATEWAY);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad IP!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_EnableDHCPServer();
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad DHCPSrv!");
+ AtLibGs_DisableDHCPServer();
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_Assoc(mySSID /*ATLIBGS_LIMITED_AP_SSID*/, 0,
+ ATLIBGS_LIMITED_AP_CHANNEL);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "AP Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ break;
+ }
+ DisplayLCD(LCD_LINE6, "");
+#ifdef ATLIBGS_DEBUG_ENABLE
+ ConsolePrintf("Limited AP Started\n");
+#endif
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_WebProvisioning
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Put the unit into web provisioning mode and wait for the user to
+ * connect with a web browser, change the settings, and click Save.
+ * The settings will then be parsed by the AtLibGs library and
+ * get saved into the nv settings.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_WebProvisioning(void)
+{
+ ATLIBGS_MSG_ID_E r;
+
+ /* At power up, load up the default settings */
+ if(NVSettingsLoad(&G_nvsettings))
+ NVSettingsSave(&G_nvsettings);
+
+ App_InitModule();
+ while(1)
+ {
+ r = AtLibGs_GetMAC(WiFiMAC);
+ if(r != ATLIBGS_MSG_ID_OK)
+ {
+ DisplayLCD(LCD_LINE6, "Get MAC Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ break;
+ };
+
+ if(r == ATLIBGS_MSG_ID_OK)
+ AtLibGs_ParseGetMacResponse(WiFiMACStr);
+ strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID);
+ strcat(str_config_ssid, &WiFiMACStr[6]); // concatenate last 6 digis of MAC as SSID
+
+ App_StartupLimitedAP(str_config_ssid);
+
+ /* Before going into web provisioning, provide DNS to give a link. */
+ /* The user can then go to http://webprov.gainspan.com/gsclient.html to get */
+ /* access to the web provisioning screen. */
+ while (1) {
+#if 0
+ AtLibGs_DisableDNSServer();
+ r = AtLibGs_EnableDNSServer("webprov.gainspan.com");
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad DNS!");
+ MSTimerDelay(2000);
+ continue;
+ }
+#endif
+ r = AtLibGs_WebProv(",", ",");
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad WebProv!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ break;
+ }
+ DisplayLCD(LCD_LINE6, "WebProv ON");
+ DisplayLCD(LCD_LINE7, (const uint8_t *) "192.168.240.");
+ DisplayLCD(LCD_LINE8, (const uint8_t *) "1/prov.html");
+#if 0
+ do {
+ DisplayLCD(LCD_LINE7, "IP: ???.???.");
+ DisplayLCD(LCD_LINE8, " ???.???");
+ r = AtLibGs_GetNetworkStatus(&network_status);
+ } while (ATLIBGS_MSG_ID_OK != r);
+
+ sprintf(text, "IP: " _F8_ "." _F8_ ".",
+ network_status.addr.ipv4[0], network_status.addr.ipv4[1]);
+ DisplayLCD(LCD_LINE7, (uint8_t *)text);
+ sprintf(text, " " _F8_ "." _F8_, network_status.addr.ipv4[2],
+ network_status.addr.ipv4[3]);
+ DisplayLCD(LCD_LINE8, (uint8_t *)text);
+#endif
+#ifdef ATLIBGS_DEBUG_ENABLE
+ ConsolePrintf("Web Provisioning ON\n");
+#endif
+
+ /* Now wait for a list of responses until we get a blank line */
+#ifdef ATLIBGS_DEBUG_ENABLE
+ ConsolePrintf("Waiting for web provisioning response...\n");
+#endif
+ AtLibGs_GetWebProvSettings(&G_nvsettings.webprov, 0);
+
+ /* Save the above settings */
+ NVSettingsSave(&G_nvsettings);
+#ifdef ATLIBGS_DEBUG_ENABLE
+ ConsolePrintf("Web provisioning complete.\n");
+#endif
+
+ DisplayLCD(LCD_LINE6, "WebProv Done");
+ DisplayLCD(LCD_LINE7, "");
+ DisplayLCD(LCD_LINE8, "Press RESET");
+ //while (1)
+ // {}
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_StartWPS
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Put the unit into WPS pushbutton mode. After pushing the button on the
+ * AP the unit will retrieve its SSID and pass phrase, then connect to it
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_StartWPS(void)
+{
+ ATLIBGS_MSG_ID_E rxMsgId;
+ ATLIBGS_NetworkStatus network;
+ AtLibGs_WPSResult result;
+ char text[20];
+
+ while (1) {
+ // Ensure we are not connected to any network (from previous runs)
+ AtLibGs_DisAssoc();
+
+ /* Pushbutton WPS demo */
+ /* Use Wi-Fi Protected Setup (WPS) FW */
+ /* turn on DHCP client */
+ AtLibGs_DHCPSet(1);
+
+ /* set to connect to AP mode */
+ AtLibGs_Mode(ATLIBGS_STATIONMODE_INFRASTRUCTURE);
+ DisplayLCD(LCD_LINE5, " Push the ");
+ DisplayLCD(LCD_LINE6, "button on AP");
+
+ /* push the button on the AP so the GS module can connect */
+ while (AtLibGs_StartWPSPUSH(&result) != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE8, " Not found!");
+ MSTimerDelay(1000);
+ DisplayLCD(LCD_LINE8, " Retrying...");
+ MSTimerDelay(1000);
+ DisplayLCD(LCD_LINE8, "");
+ }
+
+ /* Connect to AP (found from pushbutton) after setting pass phrase */
+ AtLibGs_SetPassPhrase(result.password);
+ AtLibGs_Assoc(result.ssid, "", result.channel);
+
+ rxMsgId = AtLibGs_GetNetworkStatus(&network);
+ if (rxMsgId != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE8, "Bad Network!");
+ MSTimerDelay(2000);
+ DisplayLCD(LCD_LINE8, "");
+ continue;
+ } else {
+ strncpy(text, network.ssid, 12);
+ DisplayLCD(LCD_LINE4, (const uint8_t *)text);
+ }
+ break;
+ }
+
+ DisplayLCD(LCD_LINE5, "");
+ DisplayLCD(LCD_LINE6, "");
+}
+/*---------------------------------------------------------------------------*
+ * Routine: App_StartupADKDemo
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Put the unit into a limited AP mode, enable XML parse, and setup mDNS
+ *
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_StartupADKDemo(void)
+{
+ ATLIBGS_MSG_ID_E r;
+
+ // DisplayLCD(LCD_LINE3, "Limited AP");
+ // DisplayLCD(LCD_LINE4, ATLIBGS_LIMITED_AP_SSID);
+ // VirginCheck();
+#if 1
+ DisplayLCD(LCD_LINE3, (const uint8_t *) "192.168.240.");
+ DisplayLCD(LCD_LINE4, (const uint8_t *) "1/rdk.html");
+#else
+ DisplayLCD(LCD_LINE3, (const uint8_t *) "192.168.1.1/");
+ DisplayLCD(LCD_LINE4, (const uint8_t *) "rdk.html");
+#endif
+
+ /* Try to disassociate if not already associated */
+ AtLibGs_DisAssoc();
+ while (1) {
+ DisplayLCD(LCD_LINE6, " Setting up");
+
+ r =AtLibGs_EnableRadio(1); // enable radio
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad Mode!");
+ MSTimerDelay(2000);
+ continue;
+ }
+#if 0
+ r = AtLibGs_ConfigAntenna(1);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Configure Antenna Fail!");
+ MSTimerDelay(2000);
+ continue;
+ }
+#endif
+ r = AtLibGs_Mode(ATLIBGS_STATIONMODE_LIMITED_AP);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad Mode!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_IPSet(ATLIBGS_ADK_IP, ATLIBGS_ADK_MASK,
+ ATLIBGS_ADK_GATEWAY);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad IP!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ AtLibGs_DisableDHCPServer();
+ r = AtLibGs_EnableDHCPServer();
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad DHCPSrv!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ #if 0
+ r = AtLibGs_SetRegulatoryDomain(ATLIBGS_REGDOMAIN_TELEC);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Set Domain Fail");
+ MSTimerDelay(2000);
+ continue;
+ }
+#endif
+ r = AtLibGs_GetMAC(WiFiMAC);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Get MAC Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+
+ if(r == ATLIBGS_MSG_ID_OK)
+ AtLibGs_ParseGetMacResponse(WiFiMACStr);
+
+ strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID);
+ strcat(str_config_ssid, &WiFiMACStr[6]); // concatenate last 6 digis of MAC as SSID
+ DisplayLCD(LCD_LINE1, (const uint8_t *)str_config_ssid);
+ #ifdef ATLIBGS_DEBUG_ENABLE
+ ConsolePrintf("Starting Limited AP: %s\n",str_config_ssid);
+ #endif
+ r = AtLibGs_Assoc(str_config_ssid /*ATLIBGS_ADK_SSID*/, 0,
+ ATLIBGS_ADK_CHANNEL);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "AP Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_WebServer(1, "", "", "", "");
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Server Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_SetXMLParse(1);;
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "XML Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+#if 1 // mDNS_ENABLED
+ // now start mNDS service
+ r = AtLibGs_StartMDNS();
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "MDNS1 Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_RegisterMDNSHost("xyz","local");
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "MDNS2 Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_RegisterMDNSService(ATLIBGS_ADK_MDNS_SERVER,"","_http","_tcp","local","80","path=/gainspan/profile/mcu");
+ // r = AtLibGs_RegisterMDNSService(ATLIBGS_ADK_MDNS_SERVER,"","_http","_tcp","local","80","path=/rdk.html");
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "MDNS3 Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ r = AtLibGs_AnnounceMDNS();
+ if (r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "MDNS4 Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+#endif
+ break;
+ }
+ DisplayLCD(LCD_LINE6, "");
+ MSTimerDelay(2000);
+ AtLibGs_FlushIncomingMessage();
+#ifdef ATLIBGS_DEBUG_ENABLE
+ ConsolePrintf("ADK Demo Started\n");
+#endif
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_OverTheAirProgramming
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Put the unit into over the air programming mode after connecting to an
+ * access point in infrastructure mode.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_OverTheAirProgramming(void)
+{
+ char buf[12] = " ";
+ int i;
+
+ /* OTA Firmware update demo */
+ /* Connect to AP first, then do FW upgrade with PC application */
+ AtLibGs_Mode(ATLIBGS_STATIONMODE_INFRASTRUCTURE); /* set to connect to AP mode */
+ AtLibGs_DHCPSet(1); /* turn on DHCP client */
+ AtLibGs_SetPassPhrase(ATLIBGS_AP_SEC_PSK);
+ AtLibGs_Assoc(ATLIBGS_AP_SSID, 0, 0);
+ AtLibGs_EnableRadio(1); /* radio always on */
+
+ DisplayLCD(LCD_LINE6, "Start Update");
+ DisplayLCD(LCD_LINE7, "on server IP");
+ /* print last 12 (of 15) char of server IP address */
+
+ for (i = 0; i < 12; i++) {
+ buf[i] = (char)ATLIBGS_FWUPGRADE_SERVER[i + 3];
+ }
+ DisplayLCD(LCD_LINE8, (uint8_t *)buf);
+
+ /* start FW update on remote port 8010 with 100 retries */
+ AtLibGs_FWUpgrade(ATLIBGS_FWUPGRADE_SERVER, 8010, 3000, "100");
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_OverTheAirProgrammingPushMetheod
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Put the unit into over the air programming mode in Push Method after connecting to an
+ * access point in infrastructure mode.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_OverTheAirProgrammingPushMetheod(void)
+{
+ ATLIBGS_MSG_ID_E r;
+
+ App_InitModule();
+
+ while(1)
+ {
+ r = AtLibGs_GetMAC(WiFiMAC);
+ if(r != ATLIBGS_MSG_ID_OK)
+ {
+ DisplayLCD(LCD_LINE6, "Get MAC Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ break;
+ };
+
+ if(r == ATLIBGS_MSG_ID_OK)
+ AtLibGs_ParseGetMacResponse(WiFiMACStr);
+ strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID);
+ strcat(str_config_ssid, &WiFiMACStr[6]); // concatenate last 6 digis of MAC as SSID
+
+ App_StartupLimitedAP(str_config_ssid);
+
+ r = AtLibGs_WebProv(",", ",");
+ while(r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Bad WebProv!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ DisplayLCD(LCD_LINE6, "Download ON");
+ DisplayLCD(LCD_LINE7, (const uint8_t *) "192.168.240.");
+ DisplayLCD(LCD_LINE8, (const uint8_t *) "1/otafu.html");
+ while(1)
+ ;
+}
+
+/*---------------------------------------------------------------------------*
+ * Routine: App_ProgramMode
+ *---------------------------------------------------------------------------*
+ * Description:
+ * Put the unit into programming mode by putting the control pin into
+ * program mode and mimicing the TX/RX lines on SCI2 with the
+ * RX/TX lines of SCI6.
+ * Inputs:
+ * void
+ * Outputs:
+ * void
+ *---------------------------------------------------------------------------*/
+void App_Startup(void)
+{
+ /* At power up, load up the default settings */
+ if(NVSettingsLoad(&G_nvsettings))
+ NVSettingsSave(&G_nvsettings);
+
+ /* Initialize the module now that a mode is chosen (above) */
+ App_InitModule();
+#if 0
+ /* Grab switch 1 state at startup before we init the module (which */
+ /* can take longer than people want to hold the button). */
+ sw1 = Switch1IsPressed();
+ sw2 = Switch2IsPressed();
+ sw3 = Switch3IsPressed();
+
+ /* Show the mode immediately before initialization */
+ if (sw1) {
+ DisplayLCD(LCD_LINE3, "SW1 Pressed!");
+ } else if (sw2) {
+ DisplayLCD(LCD_LINE3, "SW2 Pressed!");
+ } else if (sw3) {
+ DisplayLCD(LCD_LINE3, "SW3 Pressed!");
+ }
+ /* Initialize the module now that a mode is chosen (above) */
+ App_InitModule();
+
+ /* Was switch1 held? */
+ if (sw1) {
+ /* Yes, then go into Limited AP point */
+ App_StartupLimitedAP();
+
+ /* Now go into web provisioning mode */
+ App_WebProvisioning();
+ } else if (sw2) {
+ App_StartWPS();
+
+ /* Now go into web provisioning mode */
+ App_WebProvisioning();
+ } else if (sw3) {
+ /* User wants to do over the air programming */
+ App_OverTheAirProgramming();
+ }
+ else
+#endif
+ App_StartupADKDemo();
+}
+
+#if 0
+
+const uint8_t GainspanSignature[]="Gainspan";
+#define GAINSPAN_SIGNATURE_ADDR sizeof(NVSettings_t) // 0
+#define GAINSPAN_SIGNATURE_LEN 8
+
+#define GAINSPAN_SSID_MAX_LEN 20
+#define GAINSPAN_SSID_ADDR (GAINSPAN_SIGNATURE_ADDR + GAINSPAN_SIGNATURE_LEN)
+
+#define GAINSPAN_CHANNEL_ADDR (GAINSPAN_SSID_ADDR + GAINSPAN_SSID_MAX_LEN)
+#define GAINSPAN_CHANNEL_MAX_LEN 1
+
+void VirginCheck(void)
+{
+ uint8_t cBuffer[20];
+
+ //EEPROM_Test();
+ memset((uint8_t *)cBuffer, 0x00, 19);
+
+
+ // EEPROM_Write(GAINSPAN_SIGNATURE_ADDR, "12345678", GAINSPAN_SIGNATURE_LEN);
+ EEPROM_Read(GAINSPAN_SIGNATURE_ADDR, cBuffer, GAINSPAN_SIGNATURE_LEN);
+
+ EEPROM_Read(GAINSPAN_SIGNATURE_ADDR, cBuffer, GAINSPAN_SIGNATURE_LEN);
+ EEPROM_Read(98, cBuffer, GAINSPAN_SIGNATURE_LEN);
+ cBuffer[GAINSPAN_SIGNATURE_LEN+1]=0;
+
+ if(strcmp((char const *)GainspanSignature, (char const*)cBuffer)) // write signature "Gainspan"
+ {
+ EEPROM_Write(GAINSPAN_SIGNATURE_ADDR, "Gainspan", GAINSPAN_SIGNATURE_LEN);
+ EEPROM_Read(GAINSPAN_SIGNATURE_ADDR, cBuffer, GAINSPAN_SIGNATURE_LEN);
+ strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID);
+ AtLibGs_GetMAC((char *)cBuffer);
+
+ strncat(str_config_ssid, (char const*)&cBuffer[9],2);
+ strncat(str_config_ssid, (char const*)&cBuffer[12],2);
+ strncat(str_config_ssid, (char const*)&cBuffer[15],2);
+
+ EEPROM_Write(GAINSPAN_SSID_ADDR, str_config_ssid, GAINSPAN_SSID_MAX_LEN);
+ }
+#if 1
+ memset(str_config_ssid, 0x00, GAINSPAN_SSID_MAX_LEN);
+ EEPROM_Read(GAINSPAN_SSID_ADDR, str_config_ssid, GAINSPAN_SSID_MAX_LEN); // read SSID from EEPROM
+
+ EEPROM_Read(GAINSPAN_CHANNEL_ADDR, &wifi_channel, GAINSPAN_CHANNEL_MAX_LEN); // read WiFi channel from EEPROM
+
+ if(wifi_channel<1 || wifi_channel>14) // something wrong, set to default channel
+ {
+ wifi_channel = 6;
+ EEPROM_Write(GAINSPAN_CHANNEL_ADDR, &wifi_channel, GAINSPAN_CHANNEL_MAX_LEN);
+ }
+#endif
+}
+#endif
+/*-------------------------------------------------------------------------*
+ * End of File: App_Startup.c
+ *-------------------------------------------------------------------------*/
View
466 Apps/App_Swarm.c
@@ -0,0 +1,466 @@
+/*-------------------------------------------------------------------------*
+ * File: App_Swarm.c
+ *-------------------------------------------------------------------------*
+ * Description:
+ * Routines for connecting to bugswarm.
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Includes:
+ *-------------------------------------------------------------------------*/
+//TODO - remove unused imports, this was copypasta
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <HostApp.h>
+#include <system/platform.h>
+#include <system/console.h>
+#include <sensors/Accelerometer.h>
+#include <sensors/LightSensor.h>
+#include <sensors/Temperature.h>
+#include <sensors/Potentiometer.h>
+#include <CmdLib/AtCmdLib.h>
+#include <CmdLib/GainSpan_SPI.h>
+#include <system/mstimer.h>
+#include <system/Switch.h>
+#include <drv/Glyph/lcd.h>
+#include "Apps.h"
+#include <jsmn/jsmn.h>
+
+#define UPDATE_PERIOD 1000
+#define NUM_SENSOR 3
+#define CAPABILITIES_PERIOD 10000
+
+/*-------------------------------------------------------------------------*
+ * Constants:
+ *-------------------------------------------------------------------------*/
+uint16_t period = NUM_SENSOR;
+//const char SwarmHost[] = "192.168.11.231";
+const char SwarmHost[] = "107.20.250.52"; //api.bugswarm.net
+char resource_id[] = "14f762c59815e24973165668aff677659b973d62";
+const char swarm_id[] = "69df1aea11433b3f85d2ca6e9c3575a9c86f8182";
+const char participation_key[] = "bc60aa60d80f7c104ad1e028a5223e7660da5f8c";
+const char configuration_key[] = "359aff0298658552ec987b9354ea754b684a4047";
+const char password_hash[] = "cmVuZXNhczpyZW5lc2FzcHNr";
+
+const char configure_resource_header[] = "POST /renesas/configure HTTP/1.1\r\n"
+ "Host: api.bugswarm.net\r\nAccept: */*\r\nx-bugswarmapikey: %s\r\n"
+ "content-type: application/json\r\nContent-Length: %d\r\n\r\n%s\r\n";
+const char configure_resource_body[] =
+ "{\"name\":\"%s\",\"swarmid\":\"%s\",\"description\":"
+ "\"an RL78G14 board running bugswarm-renesasG14 1.0\"}";
+const char list_resources_header[] = "GET /resources HTTP/1.1\r\n"
+ "Host: api.bugswarm.net\r\nAccept: */*\r\nx-bugswarmapikey: %s\r\n\r\n";
+const char apikey_header[] = "GET /keys/configuration HTTP/1.1\r\n"
+"Authorization: Basic %s\r\nHost: api.bugswarm.net\r\nAccept: */*\r\n\r\n";
+const char produce_header[] = "POST /stream?swarm_id=%s&"
+ "resource_id=%s HTTP/1.1\r\nHost:api.bugswarm.com\r\n"
+ "x-bugswarmapikey:%s\r\ntransfer-encoding:chunked\r\nConnection:keep-alive"
+ "\r\nContent-Type: application/json\r\n\r\n1\r\n\n\r\n";
+const char feed_request[] = "{\"capabilities\": {\"feeds\": [\"Acceleration\","
+ "\"Temperature\",\"Button\",\"Light\",\"Sound Level\",\"Potentiometer\"]}}";
+const char message_header[] = "%x\r\n{\"message\": {\"payload\":%s}}\r\n\r\n";
+
+/*-------------------------------------------------------------------------*
+ * Types:
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Prototypes:
+ *-------------------------------------------------------------------------*/
+char MACaddr[20];
+char MACstr[13];
+char pkt[1500];
+char msg[512];
+bool connected;
+ATLIBGS_TCPMessage tcp_pkt;
+
+void App_RunConnector(void)
+{
+ ATLIBGS_MSG_ID_E r;
+ uint8_t cid = 0;
+
+ while(1) {
+ r = AtLibGs_GetMAC(MACaddr);
+ if(r != ATLIBGS_MSG_ID_OK) {
+ DisplayLCD(LCD_LINE6, "Get MAC Failed!");
+ MSTimerDelay(2000);
+ continue;
+ }
+ break;
+ };
+
+ if(r == ATLIBGS_MSG_ID_OK)
+ AtLibGs_ParseGetMacResponse(MACstr);
+ ConsolePrintf("Module MAC Address: %s\r\n", MACstr);
+
+ connected = false;
+ while(1){
+ if (!AtLibGs_IsNodeAssociated()) {
+ ConsolePrintf("Connecting to %s...",G_nvsettings.webprov.ssid);
+ r = App_Connect(&G_nvsettings.webprov);
+ ConsolePrintf(" %d\r\n",r);
+ //TODO - verify connection attempt against enum
+ }
+
+ //r = getAPIKey(pkt, sizeof(pkt), configuration_key);
+ r = getResourceID(MACstr, pkt, sizeof(pkt), resource_id);
+
+ //TODO DELETEME!
+ //ConsolePrintf("Test complete, quit\r\n");
+ //return;
+ MSTimerDelay(250);
+ ConsolePrintf("Creating a production session\r\n");
+ r = createProductionSession(&cid,
+ (char *)SwarmHost,
+ (char *)swarm_id,
+ (char *)resource_id,
+ (char *)participation_key);
+ if (r > 1){
+ ConsolePrintf("Unable to open production session, retrying\r\n");
+ connected = false;
+ MSTimerDelay(2000);
+ continue;
+ }
+ connected = true;
+ while(connected) {
+ r = App_SwarmProducer(cid);
+ if (r > 1){
+ ConsolePrintf("Error producing to swarm, retrying\r\n");
+ MSTimerDelay(2000);
+ connected = false;
+ continue;
+ } else if (r == 0) {
+ ConsolePrintf("Production session complete\r\n");
+ return;
+ }
+ }
+ }
+}
+
+ATLIBGS_MSG_ID_E getResourceID (char * mac_addr_str, char * buff, int bufflen, char * result){
+ ATLIBGS_MSG_ID_E r;
+ uint8_t cid = 0;
+ int len;
+// jsmn_parser parser;
+// jsmntok_t tokens[20];
+// jsmnerr_t jr;
+//
+// jsmn_init(&parser);
+// const char configure_resource_header[] = "POST /renesas/configure HTTP/1.1\r\n"
+// "Host: api.bugswarm.net\r\nAccept: */*\r\nx-bugswarmapikey: %s\r\n"
+// "content-type: application/json\r\nContent-Length: %d\r\n\r\n%s\r\n";
+// const char configure_resource_body[] =
+// "{\"name\":\"%s\",\"swarmid\":\"%s\",\"description\":"
+// "\"an RL78G14 board running bugswarm-renesasG14 1.0\"}";
+
+ //r = makeAPICall(&cid, buff, list_resources_header, configuration_key);
+ len = sprintf(msg, configure_resource_body, mac_addr_str, swarm_id);
+ r = makeAPICall(&cid, buff, configure_resource_header,
+ configuration_key, len, msg);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ ConsolePrintf("Unable to make API call:\r\n%s",buff);
+ return r;
+ }
+
+ r = readOnePacket(buff, bufflen, &len, 5000);
+ if (r != ATLIBGS_MSG_ID_OK){
+ ConsolePrintf("Error retrieving response %d\r\n", r);
+ return r;
+ }
+ ConsolePrintf("Got %d bytes\r\n",len);
+ char * respos = strstr(buff, "\r\n\r\n")+4;
+ if (strlen(respos) == 40) {
+ memcpy(resource_id, respos, 40);
+ } else {
+ ConsolePrintf("Invalid resource id from server, using default "
+ "\"UnknownDevice\"\r\n");
+ }
+ ConsolePrintf("Using resource id: %s\r\n",resource_id);
+// AtLibGs_Close(cid);
+// char * jsonpos = strstr(buff, "\r\n\r\n")+4;
+// if (jsonpos >= buff+strlen(buff)){
+// ConsolePrintf("Could not find a body to the response: %s\r\n", buff);
+// return ATLIBGS_MSG_ID_INVALID_INPUT;
+// }
+// ConsolePrintf("APIkey JSON: %s\r\n",jsonpos);
+// jr = jsmn_parse(&parser, jsonpos, tokens, 20);
+// if (jr != JSMN_SUCCESS){
+// ConsolePrintf("Error parsing json: %d\r\n", jr);
+// return ATLIBGS_MSG_ID_INVALID_INPUT;
+// }
+//
+// r = ATLIBGS_MSG_ID_INVALID_INPUT;
+//
+// for (int i=0;i<20;i++){
+// ConsolePrintf(" Token type: %d, Size: %d, Range: (%d-%d)\r\n",
+// tokens[i].type, tokens[i].size, tokens[i].start, tokens[i].end);
+// }
+// for (int i=0;i<20;i++){
+// if ((tokens[i].type == 3) && (tokens[i].size == 0) &&
+// (tokens[i].end-tokens[i].start == 3)){
+// if (strncmp(jsonpos + tokens[i].start, "key", 3) == 0){
+// ConsolePrintf("Found APIKEY \"%.40s\"\r\n",jsonpos+tokens[i+1].start);
+// r = ATLIBGS_MSG_ID_OK;
+// break;
+// }
+// }
+// }
+
+ return r;
+}
+
+ATLIBGS_MSG_ID_E getAPIKey(char * buff, int bufflen, char * result){
+ ATLIBGS_MSG_ID_E r;
+ uint8_t cid = 0;
+ int len;
+ jsmn_parser parser;
+ jsmntok_t tokens[20];
+ jsmnerr_t jr;
+
+ jsmn_init(&parser);
+
+ r = makeAPICall(&cid, buff, apikey_header, password_hash);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ ConsolePrintf("Unable to make API call\r\n");
+ return r;
+ }
+
+ r = readOnePacket(buff, bufflen, &len, 5000);
+ if (r != ATLIBGS_MSG_ID_OK){
+ ConsolePrintf("Error retrieving response %d\r\n", r);
+ return r;
+ }
+ ConsolePrintf("Got %d bytes\r\n",len);
+ AtLibGs_Close(cid);
+ char * jsonpos = strstr(buff, "\r\n\r\n")+4;
+ if (jsonpos >= buff+strlen(buff)){
+ ConsolePrintf("Could not find a body to the response: %s\r\n", buff);
+ return ATLIBGS_MSG_ID_INVALID_INPUT;
+ }
+ ConsolePrintf("APIkey JSON: %s\r\n",jsonpos);
+ jr = jsmn_parse(&parser, jsonpos, tokens, 20);
+ if (jr != JSMN_SUCCESS){
+ ConsolePrintf("Error parsing json: %d\r\n", jr);
+ return ATLIBGS_MSG_ID_INVALID_INPUT;
+ }
+
+ r = ATLIBGS_MSG_ID_INVALID_INPUT;
+
+ for (int i=0;i<20;i++){
+ if ((tokens[i].type == 3) && (tokens[i].size == 0) &&
+ (tokens[i].end-tokens[i].start == 3)){
+ if (strncmp(jsonpos + tokens[i].start, "key", 3) == 0){
+ ConsolePrintf("Found APIKEY \"%.40s\"\r\n",jsonpos+tokens[i+1].start);
+ strncpy(result, jsonpos+tokens[i+1].start, 40);
+ r = ATLIBGS_MSG_ID_OK;
+ break;
+ }
+ }
+ }
+ if (r == ATLIBGS_MSG_ID_INVALID_INPUT){
+ ConsolePrintf("Unable to find 'key' in response\r\n");
+ }
+
+ return r;
+}
+
+ATLIBGS_MSG_ID_E makeAPICall(uint8_t * cid, char * buff, const char *format, ...){
+ ATLIBGS_MSG_ID_E r;
+ int len;
+ va_list args;
+ va_start(args, format);
+
+ r = AtLibGs_TCPClientStart((char *)SwarmHost, 80, cid);
+ ConsolePrintf("Opened a socket: %d,%d\r\n",r,*cid);
+ if ((r != ATLIBGS_MSG_ID_OK) || (*cid == ATLIBGS_INVALID_CID)){
+ ConsolePrintf("Unable to connect to TCP socket\r\n");
+ return r;
+ }
+ App_PrepareIncomingData();
+ ConsolePrintf("Socket open, sending headers\r\n");
+
+ len = vsprintf((char *)buff, format, args);
+ //ConsolePrintf("Attempting to send: %s", buff);
+ r = AtLibGs_SendTCPData(*cid, (uint8_t *)buff, len);
+ //ConsolePrintf("Sent headers: %d\r\n", r);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ ConsolePrintf("Error transmitting headers to server (%d)%s\r\n", r, buff);
+ return r;
+ }
+ return ATLIBGS_MSG_ID_OK;
+}
+
+ATLIBGS_MSG_ID_E App_SwarmProducer(uint8_t cid) {
+ ATLIBGS_MSG_ID_E r;
+ uint16_t value;
+ float temp, tempF;
+ extern int16_t gAccData[3];
+ int idx = 0;
+
+ while(1) {
+ ConsolePrintf("Temp: ");
+ value = Temperature_Get();
+ //2.5 is an approximate measure of board self-heating...
+ temp = (((float)value)/128.0)-2.5;
+ //tempF = ((temp/5)*9)/128 + 22;
+ tempF = (temp*1.8)+32.0;
+ ConsolePrintf("%0.1fC %0.1fF\r\n", temp, tempF);
+ r = produce(cid, "{\"name\":\"Temperature\",\"feed\":{\"TempF\":%0.2f}}",
+ tempF);
+ if (r > 1)
+ return r;
+ readForAtLeast(cid, 200);
+
+ ConsolePrintf("Light: ");
+ value = LightSensor_Get();
+ ConsolePrintf("%u\r\n", value);
+ r = produce(cid, "{\"name\":\"Light\",\"feed\":{\"Value\":%u}}",
+ value);
+ if (r > 1)
+ return r;
+ readForAtLeast(cid, 200);
+
+ ConsolePrintf("Accel: ");
+ Accelerometer_Get();
+ ConsolePrintf("(%d, %d, %d)\r\n", gAccData[0], gAccData[1], gAccData[2]);
+ r = produce(cid, "{\"name\":\"Acceleration\","
+ "\"feed\":{\"x\":%0.2f,\"y\":%0.2f,\"z\":%0.2f}}",
+ (float)gAccData[0]/33.0, (float)gAccData[1]/33.0, (float)gAccData[2]/30.0);
+ if (r > 1)
+ return r;
+ readForAtLeast(cid, 200);
+
+ ConsolePrintf("Pot: ");
+ value = Potentiometer_Get();
+ value = Potentiometer_Get();
+ ConsolePrintf("%u, %04x\r\n", value/4, value);
+ r = produce(cid, "{\"name\":\"Potentiometer\",\"feed\":{\"Raw\":%u}}",
+ value/4);
+ if (r > 1)
+ return r;
+ readForAtLeast(cid, 200);
+
+ ConsolePrintf("Mic: ");
+ value = Microphone_Get();
+ value = Microphone_Get();
+ value = abs((int)(value/4)-493);
+ ConsolePrintf("%u, %04x\r\n", value, value);
+ r = produce(cid, "{\"name\":\"Sound Level\",\"feed\":{\"Raw\":%u}}",
+ value/4);
+ if (r > 1)
+ return r;
+ readForAtLeast(cid, 200);
+
+ if (idx++%5 == 0){
+ produce(cid, feed_request);
+ }
+ }
+}
+
+ATLIBGS_MSG_ID_E produce(uint8_t cid, const char *format, ...) {
+ va_list args;
+ int len;
+
+ va_start(args, format);
+ len = vsprintf((char *)msg, format, args);
+
+ len = sprintf(pkt, message_header, len+sizeof(message_header)-9, msg);
+ //ConsolePrintf("Sending: *%s*", pkt);
+ return AtLibGs_SendTCPData(cid, (uint8_t *)pkt, len);
+}
+
+ATLIBGS_MSG_ID_E createProductionSession(uint8_t *cid,
+ char * hostIP,
+ char * swarm_id,
+ char * resource_id,
+ char * participation_key) {
+ ATLIBGS_MSG_ID_E r;
+ int len;
+
+ if (!AtLibGs_IsNodeAssociated()) {
+ ConsolePrintf("Connecting to %s...",G_nvsettings.webprov.ssid);
+ r = App_Connect(&G_nvsettings.webprov);
+ ConsolePrintf(" %d\r\n",r);
+ //TODO - verify connection attempt against enum
+ }
+ ConsolePrintf("Attempting to connect to %s:%d ...",hostIP, 80);
+ r = AtLibGs_TCPClientStart(hostIP, 80, cid);
+ ConsolePrintf(" %d,%d\r\n",r,cid);
+ if ((r != ATLIBGS_MSG_ID_OK) || ((*cid) == ATLIBGS_INVALID_CID)){
+ ConsolePrintf("Unable to connect to TCP socket\r\n");
+ return r;
+ }
+ App_PrepareIncomingData();
+ ConsolePrintf("Socket open, sending headers\r\n");
+
+ len = sprintf(pkt, produce_header, swarm_id, resource_id, participation_key);
+ ConsolePrintf("Attempting to send: %s ...", pkt);
+ r = AtLibGs_SendTCPData((*cid), (uint8_t *)pkt, len);
+ ConsolePrintf(" %d\r\n", r);
+ if (r != ATLIBGS_MSG_ID_OK) {
+ ConsolePrintf("Error transmitting headers to server\r\n");
+ return r;
+ }
+
+ //Wait up to 5 seconds for presence messages.
+ readForAtLeast(*cid, 5000);
+
+ ConsolePrintf("Done waiting for presence, connected to swarm!\r\n");
+ return ATLIBGS_MSG_ID_OK;
+}
+
+ATLIBGS_MSG_ID_E readOnePacket(char * buff, int len, int * written, uint32_t ms){
+ ATLIBGS_MSG_ID_E r;
+
+ r = AtLibGs_WaitForTCPMessage(ms);
+ if (r != ATLIBGS_MSG_ID_DATA_RX) {
+ ConsolePrintf("Issue retrieving response: %u\r\n", r);
+ return r;
+ }
+ AtLibGs_ParseTCPData(G_received, G_receivedCount, &tcp_pkt);
+ //ConsolePrintf("*(%u)%s*",tcp_pkt.numBytes,tcp_pkt.message);
+ if (tcp_pkt.numBytes >= len){
+ tcp_pkt.numBytes = len-1;
+ ConsolePrintf("WARN: message greater than %d bytes, concatenated\r\n",len);
+ }
+ memset(buff, '\0', tcp_pkt.numBytes+1);
+ memcpy(buff, tcp_pkt.message, tcp_pkt.numBytes);
+ *written = tcp_pkt.numBytes;
+ App_PrepareIncomingData();
+ return ATLIBGS_MSG_ID_OK;
+}
+
+void readForAtLeast(uint8_t cid, uint32_t ms){
+ uint32_t end = MSTimerGet()+ms;
+ char * switches;
+ //WHILE: bytes are waiting in buffer, WaitForTCPMessage has a new message,
+ // or it hasn't been ms milliseocnds:
+ while ((G_receivedCount) ||
+ (AtLibGs_WaitForTCPMessage(10) == ATLIBGS_MSG_ID_DATA_RX) ||
+ (MSTimerGet() < end)){
+ //If no bytes are waiting in the buffer, don't attempt to parse.
+ if (!G_receivedCount) {
+ if (checkSwitches(switches)) {
+ ConsolePrintf("Switch Update Sw1: %u * SW2: %u * SW3: %u\r\n",Switch1IsPressed(), Switch2IsPressed(), Switch3IsPressed());
+ produce(cid, "{\"name\":\"Button\",\"feed\":{\"b1\":%u,\"b2\":%u,\"b3\":%u}}",
+ Switch1IsPressed(),Switch2IsPressed(),Switch3IsPressed());
+ }
+ continue;
+ }
+ AtLibGs_ParseTCPData(G_received, G_receivedCount, &tcp_pkt);
+ //ConsolePrintf("*(%u)%s*",tcp_pkt.numBytes,tcp_pkt.message);
+ if (tcp_pkt.numBytes >= sizeof(pkt)){
+ tcp_pkt.numBytes = sizeof(pkt)-1;
+ ConsolePrintf("WARN: message greater than %d bytes, concatenated\r\n",sizeof(pkt));
+ }
+ memset(pkt, '\0', sizeof(pkt));
+ memcpy(pkt, tcp_pkt.message, tcp_pkt.numBytes);
+ ConsolePrintf("*(%u)%s*",tcp_pkt.numBytes,pkt);
+ App_PrepareIncomingData();
+ }
+}
+
View
82 Apps/Apps.h
@@ -0,0 +1,82 @@
+/*-------------------------------------------------------------------------*
+ * File: Apps.h
+ *-------------------------------------------------------------------------*
+ * Description:
+ * Routines in the common file and each of the different demo
+ * Apps to run.
+ *-------------------------------------------------------------------------*/
+#ifndef APPS_H_
+#define APPS_H_
+
+/*-------------------------------------------------------------------------*
+ * Includes:
+ *-------------------------------------------------------------------------*/
+#include <stdint.h>
+#include <stdbool.h>
+#include "NVSettings.h"
+
+/*-------------------------------------------------------------------------*
+ * Constants:
+ *-------------------------------------------------------------------------*/
+
+typedef enum {
+ UPDATE_LIGHT,
+ UPDATE_TEMPERATURE,
+ UPDATE_POTENIOMETER,
+ UPDATE_ACCELEROMETER
+} APP_STATE_E;
+
+/*-------------------------------------------------------------------------*
+ * Globals:
+ *-------------------------------------------------------------------------*/
+extern uint8_t G_received[APP_MAX_RECEIVED_DATA + 1];
+extern unsigned int G_receivedCount;
+extern NVSettings_t G_nvsettings;
+
+/*-------------------------------------------------------------------------*
+ * Prototypes:
+ *-------------------------------------------------------------------------*/
+void App_Pachube(void);
+void App_UDPDemo(void);
+void App_TCPServerDemo(void);
+void App_TCPClientDemo(void);
+void App_HTTPDemo(void);
+void App_PassThroughUART(void);
+void App_PassThroughSPI(void);
+void App_ProgramMode(void);
+void App_Startup(void);
+void App_Menu(void);
+
+void App_Write(const void *txData, uint16_t dataLength);
+bool App_Read(uint8_t *rxData, uint16_t dataLength, uint8_t blockFlag);
+void App_PrepareIncomingData(void);
+void App_ProcessIncomingData(uint8_t rxData);
+void App_PotentiometerUpdate(int16_t * G_adc_int, bool updateLCD);
+void App_TemperatureReadingUpdate(uint16_t * G_temp_int, bool updateLCD);
+void App_LightSensorReadingUpdate(uint16_t * G_light_int, bool updateLCD);
+int16_t App_RSSIReading(int16_t * rssi, bool updateLCD);
+void App_Update(void);
+void readSensor(APP_STATE_E state);
+ATLIBGS_MSG_ID_E App_Connect(ATLIBGS_WEB_PROV_SETTINGS *webprov);
+
+void App_RunConnector(void);
+ATLIBGS_MSG_ID_E App_SwarmProducer(uint8_t cid);
+ATLIBGS_MSG_ID_E produce(uint8_t cid, const char *format, ...);
+ATLIBGS_MSG_ID_E createProductionSession(uint8_t *cid,
+ char * hostIP,
+ char * swarm_id,
+ char * resource_id,
+ char * participation_key);
+void readForAtLeast(uint8_t cid, uint32_t ms);
+ATLIBGS_MSG_ID_E readOnePacket(char * buff, int len, int * written, uint32_t ms);
+ATLIBGS_MSG_ID_E makeAPICall(uint8_t * cid, char * buff, const char *format, ...);
+ATLIBGS_MSG_ID_E getAPIKey(char * buff, int bufflen, char * result);
+ATLIBGS_MSG_ID_E getResourceID (char * mac_addr_str, char * buff, int bufflen, char * result);
+
+void App_InitModule(void);
+void App_StartupLimitedAP(char *mySSID);
+
+#endif // APPS_H_
+/*-------------------------------------------------------------------------*
+ * End of File: Apps.h
+ *-------------------------------------------------------------------------*/
View
94 Apps/NVSettings.c
@@ -0,0 +1,94 @@
+/*-------------------------------------------------------------------------*
+ * File: NVSettings.c
+ *-------------------------------------------------------------------------*
+ * Description:
+ *
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Includes:
+ *-------------------------------------------------------------------------*/
+#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <system/platform.h>
+#include "NVSettings.h"
+#include "HostApp.h"
+
+/*-------------------------------------------------------------------------*
+ * Constants:
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Types:
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Prototypes:
+ *-------------------------------------------------------------------------*/
+uint8_t NVSettingsLoad(NVSettings_t *settings)
+{
+ uint8_t failed;
+
+ NV_Open();
+ failed = NV_Read(0, (uint8_t *)settings, sizeof(*settings));
+ if (!failed)
+ if (NVSettingsChecksum(settings) != settings->checksum)
+ failed = 1;
+
+ // If the above fails, make sure to re-initialize the data
+ if (failed)
+ NVSettingsInit(settings);
+
+ return failed;
+}
+
+uint8_t NVSettingsSave(NVSettings_t *settings)
+{
+ uint8_t failed;
+
+ // Setup the checksum
+ settings->checksum = NVSettingsChecksum(settings);
+
+ // Open up the flash and save the settings
+ NV_Open();
+ NV_Erase(0, sizeof(*settings));
+ failed = NV_Write(0, (uint8_t *)settings, sizeof(*settings));
+
+ return failed;
+}
+
+void NVSettingsInit(NVSettings_t *settings)
+{
+ memset((void *)settings, 0, sizeof(*settings));
+ strcpy(settings->webprov.ssid, ATLIBGS_AP_SSID);
+ settings->webprov.channel = ATLIBGS_AP_CHANNEL;
+#if defined(ATLIBGS_SEC_PSK)
+ strcpy(settings->webprov.password, ATLIBGS_AP_SEC_PSK);
+ settings->webprov.security = ATLIBGS_SMWPA2PSK;
+#else
+ settings->webprov.password[0] = '\0';
+ settings->webprov.security = ATLIBGS_SMOPEN;
+#endif
+ settings->webprov.station = ATLIBGS_STATIONMODE_INFRASTRUCTURE;
+ settings->webprov.dhcp_enable = 1;
+ settings->webprov.tcpIPClientHostIP = 1;
+}
+
+uint32_t NVSettingsChecksum(const NVSettings_t *settings)
+{
+ uint32_t checksum = 0;
+ uint16_t i;
+
+ // Sum the bytes
+ for (i=0; i<sizeof(*settings)-sizeof(settings->checksum); i++)
+ checksum += ((uint8_t *)settings)[i];
+
+ // Return an inverted number
+ return ~checksum;
+}
+
+/*-------------------------------------------------------------------------*
+ * End of File: NVSettings.c
+ *-------------------------------------------------------------------------*/
View
52 Apps/NVSettings.h
@@ -0,0 +1,52 @@
+/*-------------------------------------------------------------------------*
+ * File: NVSettings.h
+ *-------------------------------------------------------------------------*
+ * Description:
+ *
+ *-------------------------------------------------------------------------*/
+#ifndef NVSETTINGS_H_
+#define NVSETTINGS_H_
+
+/*-------------------------------------------------------------------------*
+ * Includes:
+ *-------------------------------------------------------------------------*/
+#include "HostApp.h"
+#include "NVSettings.h"
+#include <system/platform.h>
+#include <CmdLib/AtCmdLib.h>
+
+/*-------------------------------------------------------------------------*
+ * Constants:
+ *-------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*
+ * Types:
+ *-------------------------------------------------------------------------*/
+typedef struct {
+ ATLIBGS_WEB_PROV_SETTINGS webprov;
+
+ // This field must be last
+ uint32_t checksum;
+} NVSettings_t ;
+
+/*-------------------------------------------------------------------------*
+ * Prototypes:
+ *-------------------------------------------------------------------------*/
+uint8_t NVSettingsLoad(NVSettings_t *settings);
+uint8_t NVSettingsSave(NVSettings_t *settings);
+uint32_t NVSettingsChecksum(const NVSettings_t *settings);
+void NVSettingsInit(NVSettings_t *settings);
+
+#define GAINSPAN_SIGNATURE_ADDR sizeof(NVSettings_t) // 0
+#define GAINSPAN_SIGNATURE_LEN 8
+
+#define GAINSPAN_SSID_MAX_LEN 20
+#define GAINSPAN_SSID_ADDR (GAINSPAN_SIGNATURE_ADDR + GAINSPAN_SIGNATURE_LEN)
+
+#define GAINSPAN_CHANNEL_ADDR (GAINSPAN_SSID_ADDR + GAINSPAN_SSID_MAX_LEN)
+#define GAINSPAN_CHANNEL_MAX_LEN 1
+
+#endif // NVSETTINGS_H_
+/*-------------------------------------------------------------------------*
+ * End of File: NVSettings.h
+ *-------------------------------------------------------------------------*/
View
5,692 CmdLib/AtCmdLib.c
5,692 additions, 0 deletions not shown
View
801 CmdLib/AtCmdLib.h
@@ -0,0 +1,801 @@
+/*-------------------------------------------------------------------------*
+ * File: AtCmdLib.h
+ *-------------------------------------------------------------------------*
+ * Description:
+ * The GainSpan AT Command Library (AtCmdLib) provides the functions
+ * that send AT commands to a GainSpan node and looks for a response.
+ * Parse commands are provided to interpret the response data.
+ *-------------------------------------------------------------------------*/
+#ifndef _GS_ATCMDLIB_H_
+#define _GS_ATCMDLIB_H_
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/* Parsing related defines */
+#define ATLIBGS_UDP_CLIENT_CID_OFFSET_BYTE (8) /* CID parameter offset in UDP connection response */
+#define ATLIBGS_RAW_DATA_STRING_SIZE_MAX (4) /* Number of octets representing the data length field in raw data transfer message*/
+#define ATLIBGS_HTTP_RESP_DATA_LEN_STRING_SIZE (4) /* Number of octets representing the data length field in HTTP data transfer message*/
+#define ATLIBGS_GSLINK_DATA_LEN_STRING_SIZE (4) /* Number of octets representing the data lenght field in GSLink data transfer message */
+
+#define ATLIBGS_INVALID_CID (0xFF) /* invalid CID */
+
+#define ATLIBGS_BSSID_MAX_LENGTH 20
+#define ATLIBGS_SSID_MAX_LENGTH 32
+#define ATLIBGS_MAC_MAX_LENGTH 18
+#define ATLIBGS_PASSWORD_MAX_LENGTH 32 // TODO: Is this correct?
+typedef enum {
+ ATLIBGS_RET_STATUS_ERROR = 0,
+ ATLIBGS_RET_STATUS_OK = 1,
+ ATLIBGS_RET_STATUS_VALID_DATA = 2,
+ ATLIBGS_RET_STATUS_CONTROL_CODE = 3,
+ ATLIBGS_RET_STATUS_MAX
+} ATLIBGS_RET_STATUS_E;
+
+typedef enum {
+ ATLIBGS_DISABLE = 0, ATLIBGS_ENABLE = 1
+} ATLIBGS_STATUS_E;
+
+typedef enum {
+ ATLIBGS_CON_TCP_SERVER,
+ ATLIBGS_CON_UDP_SERVER,
+ ATLIBGS_CON_UDP_CLIENT,
+ ATLIBGS_CON_TCP_CLIENT
+
+} ATLIBGS_CON_TYPE;
+
+typedef enum {
+ ATLIBGS_RX_STATE_START = 0,
+ ATLIBGS_RX_STATE_CMD_RESP,
+ ATLIBGS_RX_STATE_ESCAPE_START,
+ ATLIBGS_RX_STATE_DATA_HANDLE,
+ ATLIBGS_RX_STATE_BULK_DATA_HANDLE,
+ ATLIBGS_RX_STATE_HTTP_RESPONSE_DATA_HANDLE,
+ ATLIBGS_RX_STATE_RAW_DATA_HANDLE,
+
+ ATLIBGS_RX_STATE_DATA_CID,
+ ATLIBGS_RX_STATE_GLINK_DATA_LEN,
+ ATLIBGS_RX_STATE_GLINK_DATA_TYPE,
+ ATLIBGS_RX_STATE_GSLINK_DATA_HANDLE,
+
+ ATLIBGS_RX_STATE_MAX
+} ATLIBGS_RX_STATE_E;
+
+typedef enum {
+ ATLIBGS_MSG_ID_NONE = 0,
+ ATLIBGS_MSG_ID_OK = 1,
+ ATLIBGS_MSG_ID_INVALID_INPUT,
+ ATLIBGS_MSG_ID_ERROR,
+ ATLIBGS_MSG_ID_ERROR_IP_CONFIG_FAIL,
+ ATLIBGS_MSG_ID_ERROR_SOCKET_FAIL,
+ ATLIBGS_MSG_ID_DISCONNECT,
+ ATLIBGS_MSG_ID_DISASSOCIATION_EVENT,
+ ATLIBGS_MSG_ID_APP_RESET,
+ ATLIBGS_MSG_ID_OUT_OF_STBY_ALARM,
+ ATLIBGS_MSG_ID_OUT_OF_STBY_TIMER,
+ ATLIBGS_MSG_ID_UNEXPECTED_WARM_BOOT,
+ ATLIBGS_MSG_ID_OUT_OF_DEEP_SLEEP,
+ ATLIBGS_MSG_ID_WELCOME_MSG,
+ ATLIBGS_MSG_ID_STBY_CMD_ECHO,
+ ATLIBGS_MSG_ID_TCP_CON_DONE,
+ ATLIBGS_MSG_ID_RESPONSE_TIMEOUT,
+ ATLIBGS_MSG_ID_BULK_DATA_RX,
+ ATLIBGS_MSG_ID_DATA_RX,
+ ATLIBGS_MSG_ID_RAW_DATA_RX,
+ ATLIBGS_MSG_ID_ESC_CMD_OK,
+ ATLIBGS_MSG_ID_ESC_CMD_FAIL,
+ ATLIBGS_MSG_ID_HTTP_RESPONSE_DATA_RX,
+ ATLIBGS_MSG_ID_MAX,
+ ATLIBGS_MSG_ID_TCP_SERVER_CONNECT,
+ ATLIBGS_MSG_ID_GENERAL_MESSAGE
+} ATLIBGS_MSG_ID_E;
+
+typedef enum {
+ ATLIBGS_ID_INFO_OEM = 0,
+ ATLIBGS_ID_INFO_HARDWARE_VERSION = 1,
+ ATLIBGS_ID_INFO_SOFTWARE_VERSION = 2
+} ATLIBGS_ID_INFO_E;
+
+typedef enum {
+ ATLIBGS_PROFILE_ACTIVE = 0,
+ ATLIBGS_PROFILE_STORED_0 = 1,
+ ATLIBGS_PROFILE_STORED_1 = 2,
+} ATLIBGS_PROFILE_E;
+
+typedef enum {
+ ATLIBGS_REGDOMAIN_FCC = 0,
+ ATLIBGS_REGDOMAIN_ETSI = 1,
+ ATLIBGS_REGDOMAIN_TELEC = 2,
+ ATLIBGS_REGDOMAIN_UNKNOWN = -1
+} ATLIBGS_REGDOMAIN_E;
+
+typedef enum {
+ ATLIBGS_AUTHMODE_NONE_WPA = 0,
+ ATLIBGS_AUTHMODE_OPEN_WEP = 1,
+ ATLIBGS_AUTHMODE_SHARED_WEP = 2,
+ ATLIBGS_AUTHMODE_UNKNOWN = -1
+} ATLIBGS_AUTHMODE_E;
+
+typedef enum {
+ ATLIBGS_WEPKEY1 = 1,
+ ATLIBGS_WEPKEY2 = 2,
+ ATLIBGS_WEPKEY3 = 3,
+ ATLIBGS_WEPKEY4 = 4,
+ ATLIBGS_WEPKEY_UNKNOWN = -1
+} ATLIBGS_WEPKEY_E;
+
+typedef enum {
+ ATLIBGS_OAEAPFAST = 43,
+ ATLIBGS_OAEAPTLS = 13,
+ ATLIBGS_OAEAPTTLS = 21,
+ ATLIBGS_OAEAPPEAP = 25,
+ ATLIBGS_IAEAPMSCHAP = 26,
+ ATLIBGS_IAEAPGTC = 6,
+ ATLIBGS_AU_UNKNOWN = -1
+} ATLIBGS_INOUAUTH_E;
+
+typedef enum {
+ ATLIBGS_SMAUTO = 0,
+ ATLIBGS_SMOPEN = 1,
+ ATLIBGS_SMWEP = 2,
+ ATLIBGS_SMWPAPSK = 4,
+ ATLIBGS_SMWPA2PSK = 8,
+ ATLIBGS_SMWPAE = 16,
+ ATLIBGS_SMWPA2E = 32,
+ ATLIBGS_SM_UNKNOWN = -1
+} ATLIBGS_SECURITYMODE_E;
+
+typedef enum {
+ ATLIBGS_PROVSECU_OPEN = 1,
+ ATLIBGS_PROVSECU_WEP = 2,
+ ATLIBGS_PROVSECU_WPA_PER = 3,
+ ATLIBGS_PROVSECU_WPA_ENT = 4
+} ATLIBGS_PROVSECURITY_E;
+
+typedef enum {
+ ATLIBGS_HTTP_HE_AUTH = 2,
+ ATLIBGS_HTTP_HE_CONN = 3,
+ ATLIBGS_HTTP_HE_CON_ENC = 4,
+ ATLIBGS_HTTP_HE_CON_LENGTH = 5,
+ ATLIBGS_HTTP_HE_CON_RANGE = 6,
+ ATLIBGS_HTTP_HE_CON_TYPE = 7,
+ ATLIBGS_HTTP_HE_DATE = 8,
+ ATLIBGS_HTTP_HE_EXPIRES = 9,
+ ATLIBGS_HTTP_HE_FROM = 10,
+ ATLIBGS_HTTP_HE_HOST = 11,
+ ATLIBGS_HTTP_HE_IF_MODIF_SIN = 12,
+ ATLIBGS_HTTP_HE_LAST_MODIF = 13,
+ ATLIBGS_HTTP_HE_LOCATION = 14,
+ ATLIBGS_HTTP_HE_PRAGMA = 15,
+ ATLIBGS_HTTP_HE_RANGE = 16,
+ ATLIBGS_HTTP_HE_REF = 17,
+ ATLIBGS_HTTP_HE_SERVER = 18,
+ ATLIBGS_HTTP_HE_TRANS_ENC = 19,
+ ATLIBGS_HTTP_HE_USER_A = 20,
+ ATLIBGS_HTTP_HE_WWW_AUTH = 21,
+ ATLIBGS_HTTP_REQ_URL = 23,
+ ATLIBGS_HTTP_UNKNOWN = -1
+} ATLIBGS_HTTPCLIENT_E;
+
+typedef enum {
+ ATLIBGS_RAW_ETH_DIS = 0,
+ ATLIBGS_RAW_ETH_NONSNAP = 1,
+ ATLIBGS_RAW_ETH_ENABLEALL = 2,
+ ATLIBGS_RAW_ETH_UNKNOWN = -1
+} ATLIBGS_RAW_ETH_E;
+
+typedef enum {
+ ATLIBGS_ASPWMD_ACTIVE_ON = 0,
+ ATLIBGS_ASPWMD_MODE_1 = 1,
+ ATLIBGS_ASPWMD_MODE_2 = 2,
+ ATLIBGS_ASPWMD_MODE_3 = 3,
+ ATLIBGS_ASPWMD_UNKNOWN = -1
+} ATLIBGS_ASSOCPOWMODE_E;
+
+typedef enum {
+ ATLIBGS_SPI_PHASE = 0, ATLIBGS_SPI_PHASE_180 = 1,
+} ATLIBGS_SPI_PHASE_E;
+
+typedef enum {
+ ATLIBGS_SPI_POLARITY_LOW = 0, ATLIBGS_SPI_POLARITY_HIGH = 1,
+} ATLIBGS_SPI_POLARITY_E;
+
+typedef enum {
+ ATLIBGS_APP0_BIN = 1,
+ ATLIBGS_APP1_BIN = 2,
+ ATLIBGS_APP01_BINS = 3,
+ ATLIBGS_WLAN_BIN = 4,
+ ATLIBGS_ALL_BINS = 7,
+ ATLIBGS_FWBIN_UNKNOWN = -1
+} ATLIBGS_FIRMWARE_BINARIES_E;
+
+typedef enum {
+ ATLIBGS_GPIO10 = 10,
+ ATLIBGS_GPIO11 = 11,
+ ATLIBGS_GPIO30 = 30,
+ ATLIBGS_GPIO31 = 31,
+} ATLIBGS_GPIO_PIN_E;
+
+typedef enum {
+ ATLIBGS_LOW = 0, ATLIBGS_HIGH = 1,
+} ATLIBGS_GPIO_STATE_E;
+
+typedef enum {
+ ATLIBGS_FWUPPARAM_SERVERIP = 0,
+ ATLIBGS_FWUPPARAM_SERVERPORT = 1,
+ ATLIBGS_FWUPPARAM_PROXYPRESENT = 2,
+ ATLIBGS_FWUPPARAM_PROXYIP = 3,
+ ATLIBGS_FWUPPARAM_PROXYPORT = 4,
+ ATLIBGS_FWUPPARAM_SSLENABLE = 5,
+ ATLIBGS_FWUPPARAM_CACERT = 6,
+ ATLIBGS_FWUPPARAM_WLAN = 7,
+ ATLIBGS_FWUPPARAM_APP0 = 8,
+ ATLIBGS_FWUPPARAM_APP1 = 9,
+ ATLIBGS_FWUPPARAM_UNKNOWN = -1
+} ATLIBGS_FWUPGRADEPARAM_E;
+
+typedef enum {
+ ATLIBGS_EAPTLS_CAC = 0,
+ ATLIBGS_EAPTLS_CLIC = 1,
+ ATLIBGS_EAPTLS_PRK = 2,
+ ATLIBGS_EAPTLS_BIN = 0,
+ ATLIBGS_EAPTLS_HEX = 1,
+ ATLIBGS_EAPTLS_FLASH = 0,
+ ATLIBGS_EAPTLS_RAM = 1,
+ ATLIBGS_EAPTLS_UNKNOWN = -1
+} ATLIBGS_EAPTLS_E;
+
+typedef enum {
+ ATLIBGS_SOCKET_OPTION_TYPE_SOCK = 65535,
+ ATLIBGS_SOCKET_OPTION_TYPE_IP = 0,
+ ATLIBGS_SOCKET_OPTION_TYPE_TCP = 6,
+ ATLIBGS_SOCKET_OPTION_TYPE_UNKNOWN = -1
+} ATLIBGS_SOCKET_OPTION_TYPE_E;
+
+typedef enum {
+ ATLIBGS_SOCKET_OPTION_PARAM_TCP_MAXRT = 0x10,
+ ATLIBGS_SOCKET_OPTION_PARAM_TCP_KEEPALIVE = 0x4001,
+ ATLIBGS_SOCKET_OPTION_PARAM_SO_KEEPALIVE = 0x8,
+ ATLIBGS_SOCKET_OPTION_PARAM_TCP_KEEPALIVE_COUNT = 0x4005,
+ ATLIBGS_SOCKET_OPTION_PARAM_UNKNOWN = -1
+} ATLIBGS_SOCKET_OPTION_PARAM_E;
+
+typedef enum {
+ ATLIBGS_HTTPSEND_GET = 1,
+ ATLIBGS_HTTPSEND_POST = 3,
+ ATLIBGS_HTTPSEND_UNKNOWN = -1
+} ATLIBGS_HTTPSEND_E;
+
+typedef enum {
+ ATLIBGS_TRAUTO = 0,
+ ATLIBGS_TR1MBPS = 2,
+ ATLIBGS_TR2MBPS = 4,
+ ATLIBGS_TR5p5MBPS = 11,
+ ATLIBGS_TR11MBPS = 22,
+ ATLIBGS_TR_UNKNOWN = -1
+} ATLIBGS_TRANSRATE_E;
+
+typedef enum {
+ ATLIBGS_UNSOLICITEDTX_RT1 = 130,
+ ATLIBGS_UNSOLICITEDTX_RT2 = 132,
+ ATLIBGS_UNSOLICITEDTX_RT55 = 139,
+ ATLIBGS_UNSOLICITEDTX_RT11 = 150,
+ ATLIBGS_UNSOLICITEDTX_UNKNOWN = -1
+} ATLIBGS_UNSOLICITEDTX_E;
+
+typedef enum {
+ ATLIBGS_RFWAVETXSTART_RATE1 = 0,
+ ATLIBGS_RFWAVETXSTART_RATE2 = 1,
+ ATLIBGS_RFWAVETXSTART_RATE55 = 2,
+ ATLIBGS_RFWAVETXSTART_RATE11 = 3,
+ ATLIBGS_RFWAVETXSTART_UNKNOWN = -1
+} ATLIBGS_RFWAVETXSTART_E;
+
+typedef enum {
+ ATLIBGS_RFFRAMETXSTART_RATE1 = 2,
+ ATLIBGS_RFFRAMETXSTART_RATE2 = 4,
+ ATLIBGS_RFFRAMETXSTART_RATE55 = 11,
+ ATLIBGS_RFFRAMETXSTART_RATE11 = 22,
+ ATLIBGS_RFFRAMETXSTART_UNKNOWN = -1
+} ATLIBGS_RFFRAMETXSTART_E;
+
+typedef enum {
+ ATLIBGS_STATIONMODE_INFRASTRUCTURE = 0,
+ ATLIBGS_STATIONMODE_AD_HOC = 1,
+ ATLIBGS_STATIONMODE_LIMITED_AP = 2,
+ ATLIBGS_STATIONMODE_UNKNOWN = -1
+} ATLIBGS_STATIONMODE_E;
+
+typedef uint8_t ATLIBGS_IPv4[4];
+
+typedef union {
+ ATLIBGS_IPv4 ipv4;
+// ATLIBGS_IPv6 ipv6; // placeholder
+} ATLIBGS_IP;
+
+typedef struct {
+ char bssid[ATLIBGS_BSSID_MAX_LENGTH + 1];
+ char ssid[ATLIBGS_SSID_MAX_LENGTH + 1];
+ uint8_t channel;
+ ATLIBGS_STATIONMODE_E station;
+ int8_t signal;
+ ATLIBGS_SECURITYMODE_E security;
+} ATLIBGS_NetworkScanEntry;
+
+typedef struct {
+ char mac[ATLIBGS_MAC_MAX_LENGTH + 1];
+ uint8_t connected;
+ ATLIBGS_STATIONMODE_E mode;
+ char bssid[ATLIBGS_BSSID_MAX_LENGTH + 1];
+ char ssid[ATLIBGS_SSID_MAX_LENGTH + 1];
+ uint8_t channel;
+ ATLIBGS_SECURITYMODE_E security;
+ char signal;
+ ATLIBGS_IP addr;
+ ATLIBGS_IP subnet;
+ ATLIBGS_IP gateway;
+ ATLIBGS_IP dns1;
+ ATLIBGS_IP dns2;
+ uint32_t rxCount;
+ uint32_t txCount;
+} ATLIBGS_NetworkStatus;
+
+typedef struct {
+ char ssid[ATLIBGS_SSID_MAX_LENGTH + 1];
+ uint8_t channel;
+ uint8_t conn_type;
+ char password[ATLIBGS_PASSWORD_MAX_LENGTH + 1];
+ ATLIBGS_STATIONMODE_E station;
+ ATLIBGS_PROVSECURITY_E security;
+ uint8_t dhcp_enable;
+ uint8_t auto_dns_enable;
+ ATLIBGS_IPv4 ip;
+ ATLIBGS_IPv4 subnet;
+ ATLIBGS_IPv4 gateway;
+ ATLIBGS_IPv4 dns1;
+ ATLIBGS_IPv4 dns2;
+ uint8_t tcpIPClientHostIP;
+} ATLIBGS_WEB_PROV_SETTINGS;
+
+#define ATLIBGS_CR_CHAR 0x0D /* octet value in hex representing Carriage return */
+#define ATLIBGS_LF_CHAR 0x0A /* octet value in hex representing Line feed */
+#define ATLIBGS_ESC_CHAR 0x1B /* octet value in hex representing application level ESCAPE sequence */
+
+/* Special characters used for data mode handling */
+#define ATLIBGS_DATA_MODE_NORMAL_START_CHAR_S 'S'
+#define ATLIBGS_DATA_MODE_NORMAL_END_CHAR_E 'E'
+#define ATLIBGS_DATA_MODE_BULK_START_CHAR_Z 'Z'
+#define ATLIBGS_DATA_MODE_BULK_START_CHAR_H 'H'
+#define ATLIBGS_DATA_MODE_RAW_INDICATION_CHAR_COL ':'
+#define ATLIBGS_DATA_MODE_RAW_INDICATION_CHAR_R 'R'
+#define ATLIBGS_DATA_MODE_ESC_OK_CHAR_O 'O'
+#define ATLIBGS_DATA_MODE_ESC_FAIL_CHAR_F 'F'
+#define ATLIBGS_DATA_MODE_UDP_START_CHAR_u 'u'
+
+#define ATLIBGS_DATA_MODE_GSLINK_START_CHAR_K 'K'
+#define ATLIBGS_DATA_MODE_GSLINK_START_CHAR_G 'G'
+
+#define GSLINK_GET_XML 1
+#define GSLINK_GET_RAW 2
+#define GSLINK_POST_XML 3
+#define GSLINK_SET_RAW 4
+#define GSLINK_GET_RESP 6
+#define GSLINK_POST_RESP 7
+
+#define ESC_G_VALUE_INIT 0
+#define ESC_G_VALUE_ENABLE 1
+#define ESC_G_VALUE_END 2
+
+/************* Following control octets are used by SPI driver layer *****************************/
+#define ATLIBGS_SPI_ESC_CHAR (0xFB) /* Start transmission indication */
+#define ATLIBGS_SPI_IDLE_CHAR (0xF5) /* synchronous IDLE */
+#define ATLIBGS_SPI_XOFF_CHAR (0xFA) /* Stop transmission indication */
+#define ATLIBGS_SPI_XON_CHAR (0xFD) /* Start transmission indication */
+#define ATLIBGS_SPI_INVALID_CHAR_ALL_ONE (0xFF) /* Invalid character possibly recieved during reboot */
+#define ATLIBGS_SPI_INVALID_CHAR_ALL_ZERO (0x00) /* Invalid character possibly recieved during reboot */
+#define ATLIBGS_SPI_READY_CHECK (0xF3) /* SPI link ready check */
+#define ATLIBGS_SPI_READY_ACK (0xF3) /* SPI link ready response */
+#define ATLIBGS_SPI_CTRL_BYTE_MASK (0x80) /* Control byte mask */
+
+/************* End of SPI driver layer specific defines*****************************/
+#define ATLIBGS_RX_MAX_LINES 20
+
+/* this should be tied to a timer, faster processor larger the number */
+//#define ATLIBGS_RESPONSE_TIMEOUT_COUNT (0xFFFFFFFF) /* Time out value for reponse message */
+#define ATLIBGS_RESPONSE_TIMEOUT_COUNT (0x2FFFFFF) // OK for SPI
+/*************<Function prototye forward delarations >***************/
+
+ATLIBGS_MSG_ID_E AtLibGs_Check(void);
+ATLIBGS_MSG_ID_E AtLibGs_SetEcho(uint8_t mode);
+ATLIBGS_MSG_ID_E AtLibGs_SetMAC(char *pAddr);
+ATLIBGS_MSG_ID_E AtLibGs_SetMAC2(char *pAddr);