/*****************************************************************************
*
*  UpdateReadings
*
*  \param  None
*
*  \return None
*
*  \brief  Takes a reading of temperature and potentiometer and shows
*          on the LCD display
*
*****************************************************************************/
void UpdateReadings(void)
{
  TemperatureReading();
  PotentiometerReading();
  DisplayLCD(LCD_LINE7, "");
  DisplayLCD(LCD_LINE8, "");
}
/*****************************************************************************
*
*  ReportReadings
*
*  \param  None
*
*  \return None
*
*  \brief  Reports the sensor and customization values to Exosite cloud
*
*****************************************************************************/
void ReportReadings(void)
{
  static char content[256];

#ifdef HOST_APP_TCP_DEBUG
  if (updateError) 
  {
    sprintf(content, "temp=%d.%d&adc1=%d.%d&ping=%d&ect=%d\r\n",
                     G_temp_int[0],G_temp_int[1], G_adc_int[0], G_adc_int[1],
                     ping,parsererror);
    updateError = 0;
  } else {
    sprintf(content, "temp=%d.%d&adc1=%d.%d&ping=%d\r\n",
                     G_temp_int[0],G_temp_int[1], G_adc_int[0], G_adc_int[1],
                     ping);
  }
#else
  sprintf(content, "temp=%d.%d&adc1=%d.%d&ping=%d\r\n",
                   G_temp_int[0],G_temp_int[1], G_adc_int[0], G_adc_int[1],
                   ping);
#endif
  ping++;
  if (ping >= 100)
    ping = 0;
  DisplayLCD(LCD_LINE6, "  Exosite  ");
  DisplayLCD(LCD_LINE7, "   Write   ");
  if (Exosite_Write(content, strlen(content)))
  {
    DisplayLCD(LCD_LINE8, "     OK    ");
  }

  return;
}
/*---------------------------------------------------------------------------*
 * 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");
}
示例#4
0
/**********************************************************************************
Name:			DisplayIPAddress
Description:	Clears the LCD and displays IP address in dotted decimal format. 
                First two decimals are displyed on line 1 and the others on
                line 2.    
Parameters:		(unsigned short []) ipaddr - IP address to display
Returns:		None
**********************************************************************************/
void DisplayIPAddress(const unsigned short ipaddr[])
{
    char dis_buf[9];
    char *p = (char *)ipaddr;
    DisplayLCD(LCD_LINE1, "Exosite Demo");
    DisplayLCD(LCD_LINE3, "IP Addr =");
    sprintf(dis_buf, "%d.%d.", *p, *(p+1));
    DisplayLCD(LCD_LINE4, (const uint8_t *)dis_buf);
    sprintf(dis_buf, "%d.%d", *(p+2), *(p+3));
    DisplayLCD(LCD_LINE5, (const uint8_t *)dis_buf);
}
示例#5
0
int main(void) {
    
    //--------------
    // Initialization 
    char LCDinit[] = {0x33,0x32,0x28,0x01,0x0c,0x06,0x00}; //Array holding initialization string for LCD
    char Msg1[] = {0x84,'C','U','N','T','\0'};
    char Msg2[] = {0xC5,'R','P','S','\0'};
    char Msg3[10];          // Msg for displaying RPS to LCD (size 10 in case dealing with large numbers)
    InitApp();              // Initialize Ports
    DisplayLCD(LCDinit,1);  // Initialize LCD

    //--------------
    // Message on LCD
    DisplayLCD(Msg1,0);     // Display message on LCD
    DisplayLCD(Msg2,0);     // Display message 2

    //--------------
    // Initialize encoder variables
    CHA = PORTBbits.RB5;    // Initialize channel A
    CHB = PORTBbits.RB4;    // Initialize channel B
    OLD_ROT = 0;            // Initialize state of rotation
    CCWTurn = 0;            // Initialize CCW count
    CWTurn = 0;             // Initialize CW count
    RPS = 0.0;              // Initialize RPS value
    CHAcount = 0;           // Channel A counter

    //--------------
    // Setup PWM cycle to motor
    PR2 = 0x9B;             // Open pwm1 at period = 1 ms
    CCP1CONbits.DC1B1 = 0;  // Set duty cycle of pwm1
    CCP1CONbits.DC1B0 = 0;  // ...
    CCPR1L = 0b00000100;    // ...

    //-------------
    // Set timer and interrupts
    TMR0count = 0;          // Set counter for TMR0
    WriteTimer0(EncoderCount);// Load Timer0
    InitInterrupts();       // Initialize timer interrupts for Port B encoder
    

    //--------------
    // Loop phase: Display RPS on LCD
    while(1)
    {
        WaitHalfSec();
        WriteLCD(0xC0,5,RPS,Msg3);      // Display RPS on LCD
    }


    //--------------
    // Exit main
    CloseTimer0();
    return (EXIT_SUCCESS);
}
/*---------------------------------------------------------------------------*
 * 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
}
示例#7
0
/*
**	2.5ms毎にG/Aからくる割込み処理ルーチン1
*/
void GA_Interrupt1(void)
{
	UBYTE debug;
	
	++IntTimerCounter;

	/* 2.5ms毎に行うルーチンを記述 */
	/* 画処理 & 送信モータ制御 */
	ScannerInt();

	/* LCD/LED制御 */
#if 0 /* defined (HINOKI2) */	/* LCDドライバ変更対応 2002/05/15 T.Takagi */
	if (!SYS_IsCGRAM_Writing) {
		SYS_IsDisplayingLCD = TRUE;
		DisplayLCD();
		SYS_IsDisplayingLCD = FALSE;
	}
#else
	DisplayLCD();
#endif
	/* キースキャン */
	KeyScan();

	if (IntTimerCounter & 0x00000001) {	/* 5msに1回処理 */

#if (0) /* 1998/11/18 by T.Soneoka 以下の処理を2.5msで行うように上記に変更 */
**		/* LCD/LED制御 */
**		DisplayLCD();
**		/* キースキャン */
**		KeyScan();
#endif
		/* Thermal Printer 制御 */
		PrinterTimerInt();
		
		/*
		** 済みスタンプ保険処理
		** 150ms以上On時間があると済みスタンプが壊れるため
		** それ以上Onしている場合は強制的にOffする
		*/
		if (RelayPortStatus & IO_BIT_STAMP) {
			StampOnTime++;
		} else {
			StampOnTime = 0;
		}
		if (StampOnTime > (150/5)) {
			RelayPortStatus &= (~IO_BIT_STAMP);
			OutputWORD(GA_PGADR, RelayPortStatus);
		}
	}
}
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;
	}  
}
/*---------------------------------------------------------------------------*
 * 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, "");
}
/*****************************************************************************
*
* GPRS_SocketOpen
*
* Open a connection with a remote host.  Telit specific.
*
*****************************************************************************/
int32_t AtModem_SocketOpen(char * ip, uint8_t port, uint8_t * cid)
{
    static unsigned char socketFailures = 0;
    //TODO: review hard coded IP addresses -> perhaps swap for replaceable
    //ip via "ip" API call

    /* 30 is big enough for any IP */
    char location[30];
    uint8_t len;

    len = sprintf(location, "atdt\"%s\",%hhu\r", ip, port);

    AtModem_Write(location,len);
    int32_t result = AtModem_response_check(25000, "CONNECT", "\r\n");

    if (result == AT_REPLY_OK)
    {
        socketFailures = 0;
        ConsolePrintf("Socket Open\r\n");
        DisplayLCD(LCD_LINE7, "SOCKET: OPEN");
        *cid = 1; // we only have one connection
    }
    else
    {
        if (result == AT_REPLY_ERROR)
        {
            ConsolePrintf("Socket Error\r\n");
            DisplayLCD(LCD_LINE7, "SOCKET: ERR");
            AtModem_SocketClose(0);
        }
        else
        {
            ConsolePrintf("Socket No Response\r\n");
            DisplayLCD(LCD_LINE7, "SOCKET: DOWN");
        }
        result = -1;
        if (socketFailures++ > 5)
        {
            if( AtModem_Init() == -1)
            {
              // restart mcu
              WDTIMK = 1U;	/* disable INTWDTI interrupt, stop kicking watchdog */
              while(1);
            }
            socketFailures = 0;
        }
    }
    return result;
}
示例#11
0
/*******************************************************************************
* Outline      : CB_CMT_Thermal
* Description  : CMT interrupt callback function. This callback function is
*                executed after every period of the CMT timer. The function 
*                fetches the thermal temperature and displays it on the LCD.
* Argument     : none
* Return value : none
*******************************************************************************/
void CB_CMT_Thermal(void)
{
    bool         err = true;
    uint8_t      target_reg, target_data[2];
    uint16_t     temp;
    uint8_t      temp_int[2];

    /* Declare display buffer */
    uint8_t lcd_buffer[13];

    /* Read the temperature */
    target_reg = ADT7420_TEMP_MSB_REG;
    err = R_IIC_MasterSend( IIC_CHANNEL, PDL_NO_DATA, ADT7420_ADDR, &target_reg,
                            1, PDL_NO_FUNC, 0 );

    err = R_IIC_MasterReceive( IIC_CHANNEL, PDL_NO_DATA, ADT7420_ADDR, &target_data[0], 
                               2, PDL_NO_FUNC, 0 );    

    /* Convert the device measurement into a decimal number and insert 
       into a temporary string to be displayed */
    temp = (target_data[0]<<8)+target_data[1];
    temp = temp >> 3;
    temp_int[0] = (int16_t)temp/16;
    temp_int[1] = (int16_t)((temp&0x000F)*10)/16;

    sprintf((char *)lcd_buffer, "   %d.%d C" , temp_int[0], temp_int[1] );   

    /* Display the contents of lcd_buffer onto the debug LCD */
    DisplayLCD(LCD_LINE6, lcd_buffer);

    /* Halt in while loop when RPDL errors detected */    
    while (!err);
}
示例#12
0
// Connect to the MQTT broker.  Call this function whenever connection needs
// to be re-established.
// returns:  0 - everything OK
//          -1 - packet error
//          -2 - failed to get connack
int App_ConnectMqtt()
{  
    int packet_length;

    mqtt_init(&broker, WIO_CLIENTID);
    mqtt_init_auth(&broker, WIO_USERNAME, WIO_PASSWORD);
    mqtt_connect(&broker);
    // wait for CONNACK	
    packet_length = mqtt_read_packet(6000);

    if(packet_length < 0) 
    {
        DisplayLCD(LCD_LINE4, "MQTT packet error");
        return -1;
    }
    if(MQTTParseMessageType(rxm.message) != MQTT_MSG_CONNACK) 
    { 
        return -2;
    }  
    if(rxm.message[3] != 0x00)
    {
        return -2;
    }
    App_PrepareIncomingData();
    AtLibGs_FlushIncomingMessage();
    mqttConnected=1;
    return 0;
}
/*****************************************************************************
*
* GPRS_SocketClose
*
* Close a connection with a remote host.  Telit specific.
*
*****************************************************************************/
int AtModem_SocketClose(uint8_t cid)
{

    AtModem_Write((unsigned char *)"+++",3);
    DisplayLCD(LCD_LINE7, "SOCKET: OFF");
    return AtModem_response_check(15000, "NO CARRIER", "\r\n");
}
示例#14
0
/*******************************************************************************
* Outline       : main
* Description   : Main program function. This function first displays on the 
*                 debug LCD; then calls the async initialisation function, which
*                 configures and starts the SCI unit to transmit the numbers 0 to
*                 9 on the terminal untill the character 'z' is typed into the
*                 terminal. Any other key will resume the transfer.
* Argument      : none
* Return value  : none
*******************************************************************************/
void main(void)
{
    /* Initialise the LCD on the RSPI bus */
    YRDKRX62N_RSPI_Init(RSPI_CHANNEL_0);
    InitialiseLCD();

    /* Display instructions onto the LCD */
    DisplayLCD(LCD_LINE1, "Async   ");
    DisplayLCD(LCD_LINE2, "Serial  ");

    /* Initialise the SCI unit for asynchronous operation */
    Init_Async();

    /* Infinite while loop */
    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();
}
/*****************************************************************************
*
*  ReadCloudCommands
*
*  \param  None
*
*  \return None
*
*  \brief  Reads the commands from Exosite cloud
*
*****************************************************************************/
void ReadCloudCommands(void)
{
  char * pbuf = exo_buffer;
  DisplayLCD(LCD_LINE6, "  Exosite  ");
  DisplayLCD(LCD_LINE7, "    Read   ");
  if (Exosite_Read("led_ctrl", pbuf, EXO_BUFFER_SIZE)) {
    DisplayLCD(LCD_LINE8, "     OK    ");
    if (!strncmp(pbuf, "0", 1)) 
      led_all_off();
    else if (!strncmp(pbuf, "1", 1)) 
      led_all_on();
  }
  else show_status();
  MSTimerDelay(500);

  return;
}
示例#17
0
/*---------------------------------------------------------------------------*
 * Routine:  WIFI_Associate
 *---------------------------------------------------------------------------*
 * Description:
 *      Association and show result on the LCD
 * Inputs:
 *      void
 * Outputs:
 *      ATLIBGS_MSG_ID_E
 *---------------------------------------------------------------------------*/
ATLIBGS_MSG_ID_E WIFI_Associate(void)
{
    ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;
    static ATLIBGS_AUTHMODE_E WEPMode=ATLIBGS_AUTHMODE_OPEN_WEP;
    int retVal;

    DisplayLCD(LCD_LINE4, "wl_trycon.. ");

    /* Associate to a particular AP specified by SSID  */
    if (strlen(GNV_Setting.webprov.ssid) > 0)
    {
        rxMsgId = AtLibGs_Assoc(GNV_Setting.webprov.ssid,NULL,HOST_APP_AP_CHANNEL);
    }
    else
    {
        rxMsgId = AtLibGs_Assoc(HOST_APP_AP_SSID, NULL, HOST_APP_AP_CHANNEL);
    }
    if (ATLIBGS_MSG_ID_OK != rxMsgId) 
    {
        /* Association error - we can retry */
        if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WEP)
        {
            if(WEPMode==ATLIBGS_AUTHMODE_OPEN_WEP)
            {
                rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_SHARED_WEP);// Potenially it's a WEP shared AP
                WEPMode=ATLIBGS_AUTHMODE_SHARED_WEP;
            }
            else
            {
                rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_OPEN_WEP);// Potenially it's a WEP shared AP
                WEPMode=ATLIBGS_AUTHMODE_OPEN_WEP;         
            }
        }
        DisplayLCD(LCD_LINE4, "Assoc failed...");
        MSTimerDelay(2000);
        DisplayLCD(LCD_LINE4, "Trying again...");
    } 
    else 
    {
        /* Association success */
        AtLibGs_SetNodeAssociationFlag();
        DisplayLCD(LCD_LINE4, "wl_connect  ");
        MSTimerDelay(2000);
        retVal = App_ConnectMqtt();
        switch(retVal)
        {
        case 0:    
            DisplayLCD(LCD_LINE5, "MQTT Connected");
            break;
        case -1:    
            DisplayLCD(LCD_LINE5, "MQTT packet error");
            break;
        case -2:    
            DisplayLCD(LCD_LINE5, "MQTT connack error");
            break;      
        }
    }

    return rxMsgId;
}
/*---------------------------------------------------------------------------*
 * Routine:  WIFI_Associate
 *---------------------------------------------------------------------------*
 * Description:
 *      Association and show result on the LCD
 * Inputs:
 *      void
 * Outputs:
 *      ATLIBGS_MSG_ID_E
 *---------------------------------------------------------------------------*/
ATLIBGS_MSG_ID_E WIFI_Associate(void)
{
  ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE;

  DisplayLCD(LCD_LINE7, " Connecting ");

  /* Associate to a particular AP specified by SSID  */
  if (strlen(GNV_Setting.webprov.ssid) > 0)
  {
    DisplayLCD(LCD_LINE8, (const uint8_t *)GNV_Setting.webprov.ssid);
    rxMsgId = AtLibGs_Assoc(GNV_Setting.webprov.ssid,NULL,HOST_APP_AP_CHANNEL);
  }
  else
  {
    DisplayLCD(LCD_LINE8, HOST_APP_AP_SSID);
    rxMsgId = AtLibGs_Assoc(HOST_APP_AP_SSID, NULL, HOST_APP_AP_CHANNEL);
  }
  if (ATLIBGS_MSG_ID_OK != rxMsgId) {
    /* Association error - we can retry */
#ifdef HOST_APP_DEBUG_ENABLE
        ConsolePrintf("\n Association error - retry now \n");
#endif
    DisplayLCD(LCD_LINE7, " Connecting..");
    MSTimerDelay(2000);
    DisplayLCD(LCD_LINE7, "");
  } else {
    /* Association success */
    AtLibGs_SetNodeAssociationFlag();
    DisplayLCD(LCD_LINE7, " Connected ");
    MSTimerDelay(2000);
    DisplayLCD(LCD_LINE7, "");
  }

  return rxMsgId;
}
示例#19
0
/*!
* @brief Display data on the LCD, safely.
* @param[in] Position and data.
*/
void protected_lcd_display(uint8_t position, const uint8_t *data)
{
    OS_ERR err;
    
    OSMutexPend(&lcd_mutex, 0, OS_OPT_PEND_BLOCKING, 0, &err);
    assert(OS_ERR_NONE == err);
    DisplayLCD(position, data);
    OSMutexPost(&lcd_mutex, OS_OPT_POST_NONE, &err);
    assert(OS_ERR_NONE == err);
}
/*---------------------------------------------------------------------------*
 * 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;
}
示例#21
0
void RSSIReading(void)
{
  int16_t rssi;
  char line[20];
  int rssiFound = 0;

  if (AtLibGs_IsNodeAssociated()) {
    if (AtLibGs_GetRssi() == ATLIBGS_MSG_ID_OK) {
      if (AtLibGs_ParseRssiResponse(&rssi)) {
        sprintf(line, "wl_rssi: %d", rssi);
        DisplayLCD(LCD_LINE5, (const uint8_t *)line);
        rssiFound = 1;
      }
    }
  }

  if (!rssiFound) {
    DisplayLCD(LCD_LINE5, "RSSI: ----");
  }
}
示例#22
0
/*******************************
 * WriteLCD(int LCDstart, int dispLength, double var)
 *
 * This subroutine takes a numeric variable var, and outputs it to the LCD. Here
 * LCDstart tells the LCD where to place the desired message (hex), and len
 * dictates how long the message is that will be displayed. In order to display
 * the variable, this subroutine uses sprintf to convert the variable into a
 * string with the specified width and #sig figs. Warning: be careful if var
 * has several decimal places of precision. May overwrite other data in memory
 * passed the size of Msg. The if statement prevents displaying anything larger
 * than len+1 to the LCD
 *******************************/
void WriteLCD( int LCDstart, int len, double var, char Msg[] )
{
    char *msgptr = Msg;     // Point to message string
    int width = sprintf(msgptr+1,"%*.*g",len,len-1,var);    // Define minimum # characters as
                            // len, #significant digits len-1
    Msg[0] = LCDstart;      // Set LCD start at beginning of array
    if (width > len)        // If string is larger than desired length, len
    {                       // then output warning symbol '!' to LCD 
        Msg[len] = '!';     // and terminate string at len+1
        Msg[len+1] = '\0';
    }
    DisplayLCD(Msg,0);      // Display the message on the LCD
}
/*****************************************************************************
*
*  PotentiometerReading
*
*  \param  None
*
*  \return None
*
*  \brief  Takes a reading of potentiometer and shows it on the LCD display
*
*****************************************************************************/
void PotentiometerReading(void)
{
  char lcd_buffer[20];

  // Temperature sensor reading
  int32_t percent;
  percent = Potentiometer_Get();
  G_adc_int[0] = (int16_t)(percent / 10);
  G_adc_int[1] = (int16_t)(percent % 10);

  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(char * G_light_int, bool updateLCD)
{
    char lcd_buffer[20];

    // Temperature sensor reading
    *(int16_t *)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_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)
      ;
}
/*****************************************************************************
*
*  TemperatureReading
*
*  \param  None
*
*  \return None
*
*  \brief  Takes a reading of temperature and shows it on the LCD display
*
*****************************************************************************/
void TemperatureReading(void)
{
  char lcd_buffer[20];

  // Temperature sensor reading
  int16_t temp;
  temp = Temperature_Get()>>3;
  // Get the temperature and show it on the LCD
  G_temp_int[0] = (int16_t)temp / 16 - 2;
  G_temp_int[1] = (int16_t)((temp & 0x000F) * 10) / 16;

  /* 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);
}
/*---------------------------------------------------------------------------*/
void TestGainSpan_ATCommands(void)
{
    bool send = true;
    const uint8_t match[] = "AT\r\r\nOK\r\n\n\r\n";
    uint8_t in[sizeof(match)];
    uint8_t pos;
    uint8_t c;
    uint32_t start;

    DisplayLCD(LCD_LINE2, "GS ATCmd");

    /* Reset the connection by flushing any waiting data */
    start = MSTimerGet();
    while (MSTimerDelta(start) < 500) {
        if (GainSpan_SPI_ReceiveByte(SPI_WIFI_CHANNEL, &c)) {
            Console_UART_SendByte(c);
            start = MSTimerGet();
        }
    }

    start = MSTimerGet();
    while (1) {
        /* Infitine loop */
        if (send) {
            /* Do AT commands as fast as possible. */
            GainSpan_SPI_SendData("AT\r\n", 4);
            send = false;
            pos = 0;
            start += 10;
        }
        if (GainSpan_SPI_ReceiveByte(SPI_WIFI_CHANNEL, &c)) {
            if (c != GAINSPAN_SPI_CHAR_IDLE) {
                in[pos++] = c;
                Console_UART_SendByte(c);
                if (pos == (sizeof(match) - 1)) {
                    if (memcmp(match, in, sizeof(match) - 1) != 0) {
                        Console_UART_SendByte('_');
                        ErrorCode(3);
                    }

                    send = true;
                }
            }
        }
    }
}
示例#28
0
/*---------------------------------------------------------------------------*/
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);
    }
}
示例#29
0
/*---------------------------------------------------------------------------*/
void App_TemperatureReadingUpdate(char * 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);
    }
}
示例#30
0
/*******************************************************************************
* Outline      : Init_Thermal_Sensor
* Description  : This function configures the ADT7420 thermal device and starts
*                a timer to periodically read the temperature.
* Argument     : none
* Return value : none
*******************************************************************************/
void Init_Thermal_Sensor(void)
{
    /* Declare error flag */
    bool     err = true;
    uint8_t  target_reg, target_data;

    DisplayLCD(LCD_LINE5, "Temp:");

    /* Configure the ADT7420 */
    target_reg = ADT7420_CONFIG_REG;
    err = R_IIC_MasterSend( IIC_CHANNEL, PDL_NO_DATA, ADT7420_ADDR, &target_reg,
                            1, PDL_NO_FUNC, 0 );
    target_data = 0x00;                                     
    err = R_IIC_MasterSend( IIC_CHANNEL, PDL_NO_DATA, ADT7420_ADDR, &target_data,
                            1, PDL_NO_FUNC, 0 );

    /* Configure CMT1 to execute callback function every 250ms */
    err &=    R_CMT_Create( 1, PDL_CMT_PERIOD, 250E-3, CB_CMT_Thermal, 3 );


    /* Halt in while loop when RPDL errors detected */    
    while (!err);
}