Пример #1
0
/*---------------------------------------------------------------------------*
 * Task:  main
 *---------------------------------------------------------------------------*
 * Description:
 *      In the uEZ system, main() is a task.  Do not exit this task
 *      unless you want to the board to reset.  This function should
 *      setup the system and then run the main loop of the program.
 * Outputs:
 *      int                     -- Output error code
 *---------------------------------------------------------------------------*/
int MainTask(void)
{
#if COMPILE_OPTION_USB_SDCARD_DISK
    T_USBMSDriveCallbacks usbMSDiskCallbacks = { 0 };
#endif

    //printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner

    // Load the settings from non-volatile memory
    if (NVSettingsLoad() != UEZ_ERROR_NONE) {
        //printf("EEPROM Settings\n");
        NVSettingsInit();
        NVSettingsSave();
    }

#if COMPILE_OPTION_USB_SDCARD_DISK
    // Setup the USB MassStorage device to connect to MS1 (the SD Card)
    USBMSDriveInitialize(
        &usbMSDiskCallbacks,
        0,
        "MS1");
#endif

    // Setup any additional misc. tasks (such as the heartbeat task)
    SetupTasks();

    AudioStart();

    // Pass control to the main menu
    MainMenu();

    // We should not exit main unless we want to reset the board
    return 0;
}
Пример #2
0
/*---------------------------------------------------------------------------*/
void MainMenu(void)
{
    T_uezDevice lcd;
    char line[100];
    TUInt32 size;
    T_uezDevice flash;

    NVSettingsLoad();

    // Open the LCD and get the pixel buffer
    UEZLCDOpen("LCD", &lcd);

    // Setup the LCD, setup the window, and clear the screen
    ScreenInit();

    //Calibrate();

    //UEZQueueCreate(1, sizeof(T_uezInputEvent), &G_tsQueue);
    //UEZTSOpen("Touchscreen", &G_ts, &G_tsQueue);

    print("Clearing receive area ...\n");
    PNFClearArea(IMAGE_ADDR, IMAGE_SIZE);

    sprintf(line, "Waiting for image at 0x%08lX ... \n", IMAGE_ADDR);
    print(line);

    // Wait for an image to appear
    JLINK_MODE = 0;
    while (JLINK_MODE != 1) {
        UEZTaskDelay(10);
    }

    print("Image received.\n");

    print("Determing size ... ");
    size = PNFGetSize(IMAGE_ADDR, IMAGE_SIZE);
    sprintf(line, "%u bytes\n", size);
    print(line);

    print("Erasing ...");
    UEZFlashOpen("Flash0", &flash);
    UEZFlashBlockErase(flash, 0, size);
    print("done.\n");

    print("Writing ...");
    UEZFlashWrite(flash, 0, (void *)IMAGE_ADDR, size);
    print("done.\n");
    UEZFlashClose(flash);

    print("\n** NOR Flash Programming Complete. **\n");

    JLINK_MODE = 2;

    while (1) {
        UEZTaskDelay(10);
    }
}
Пример #3
0
/*---------------------------------------------------------------------------*
 * Task:  main
 *---------------------------------------------------------------------------*
 * Description:
 *      In the uEZ system, main() is a task.  Do not exit this task
 *      unless you want to the board to reset.  This function should
 *      setup the system and then run the main loop of the program.
 * Outputs:
 *      int                     -- Output error code
 *---------------------------------------------------------------------------*/
int MainTask(void)
{
#if COMPILE_OPTION_USB_SDCARD_DISK
    T_USBMSDriveCallbacks usbMSDiskCallbacks = { 0 };
#endif

    printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner

    // Load the settings from non-volatile memory
    if (NVSettingsLoad() != UEZ_ERROR_NONE) {
        printf("EEPROM Settings\n");
        NVSettingsInit();
        NVSettingsSave();
    }

#if COMPILE_OPTION_USB_SDCARD_DISK
    // Setup the USB MassStorage device to connect to MS1 (the SD Card)
    USBMSDriveInitialize(
        &usbMSDiskCallbacks,
        0,
        "MS1");
#endif

    // Setup any additional misc. tasks (such as the heartbeat task)
    SetupTasks();

    AudioStart();


  // initialize command console for test commands
  //UEZGUITestCmdsInit();

#include "UEZGainSpan.h"
    // Gainspan here:
    char rxBuf[128];
    void *G_UEZGUIWorkspace;
    G_UEZGUIWorkspace = 0;

   char* argv[2];
   argv[0]= "gainspan";
    argv[1] = "program";
//    argv[1] = "check";

UEZGUIGainSpan(G_UEZGUIWorkspace,
               2,
               (char **)argv,
               (char *)&rxBuf);

    // Pass control to the main menu
    MainMenu();

    // We should not exit main unless we want to reset the board
    return 0;
}
/*---------------------------------------------------------------------------*
 * 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();
}
Пример #5
0
/*---------------------------------------------------------------------------*
 * Task:  main
 *---------------------------------------------------------------------------*
 * Description:
 *      In the uEZ system, main() is a task.  Do not exit this task
 *      unless you want to the board to reset.  This function should
 *      setup the system and then run the main loop of the program.
 * Outputs:
 *      int                     -- Output error code
 *---------------------------------------------------------------------------*/
void MainTask(void)
{
#if COMPILE_OPTION_USB_SDCARD_DISK
    T_USBMSDriveCallbacks usbMSDiskCallbacks = {0};
#endif

    printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner

    // Load the settings from non-volatile memory
    if (NVSettingsLoad() != UEZ_ERROR_NONE) {
        printf("EEPROM Settings\n");
        NVSettingsInit();
        NVSettingsSave();
    }

    // Start up the heart beat of the LED
    UEZTaskCreate(Heartbeat, "Heart", 64, (void *)0, UEZ_PRIORITY_NORMAL, 0);

#if UEZ_ENABLE_USB_DEVICE_STACK
    if (G_usbIsDevice) {
        // Setup the USB MassStorage device to connect to MS1 (the SD Card)
        USBMSDriveInitialize(
                &usbMSDiskCallbacks,
                0,
                "MS1");
    }
#endif

    AudioStart();
    // Force calibration?
    Calibrate(CalibrateTestIfTouchscreenHeld());

    if(!GUIManager_Start_emWin_PF()){
        GUIManager_Create_All_Active_Windows_PF();
        //start the main window.
        if(G_SystemWindows_PF[HOME_SCREEN]){
            GUIManager_Show_Window_PF(HOME_SCREEN);
            GUI_ExecCreatedDialog(G_SystemWindows_PF[HOME_SCREEN]);
        } else {
            UEZFailureMsg("Failed to create windows!");
        }
    } else {
        UEZFailureMsg("emWin Failed to Start!");
    }
    // We should not exit main unless we want to reset the board
}
Пример #6
0
/*---------------------------------------------------------------------------*
* Task:  main
*---------------------------------------------------------------------------*
* Description:
*      In the uEZ system, main() is a task.  Do not exit this task
*      unless you want to the board to reset.  This function should
*      setup the system and then run the main loop of the program.
* Outputs:
*      int                     -- Output error code
*---------------------------------------------------------------------------*/
int MainTask(void)
{
#if COMPILE_OPTION_USB_SDCARD_DISK
     T_USBMSDriveCallbacks usbMSDiskCallbacks = {0};
#endif
     
     printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner
     
     // Load the settings from non-volatile memory
     if (NVSettingsLoad() != UEZ_ERROR_NONE) {
          printf("EEPROM Settings\n");
          NVSettingsInit();
          NVSettingsSave();
     }
#if UEZ_ENABLE_USB_DEVICE_STACK
     if (G_usbIsDevice) {
          // Setup the USB MassStorage device to connect to MS1 (the SD Card)

          USBMSDriveInitialize(
                               &usbMSDiskCallbacks,
                               0,
                               "MS1");
     }
#endif
     
     // Setup any additional misc. tasks (such as the heartbeat task)
     SetupTasks();
     
     AudioStart();
     
#if UEZGUI_EXP_DK_FCT_TEST
      // no command console so functional test can run
#else
     // initialize command console for test commands
     UEZGUITestCmdsInit();
#endif
     
     // Pass control to the main menu
     MainMenu();
     // We should not exit main unless we want to reset the board
     return 0;
}
Пример #7
0
/*---------------------------------------------------------------------------*/
int MainTask(void)
{
    // Output a start up banner
    printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n");

    // Start up the heart beat of the LED
    UEZTaskCreate(Heartbeat, "Heart", 64, (void *)0, UEZ_PRIORITY_NORMAL, 0);

    // Load any non-volatile settings from the data flash.
    NVSettingsInit();
    // Load the settings from non-volatile memory
    if (NVSettingsLoad() == UEZ_ERROR_CHECKSUM_BAD) {
        printf("EEPROM Settings\n");
        NVSettingsInit();
        NVSettingsSave();
    }

    // Setup the glyph API to the LCD and draw the title screen.
    GlyphOpen(&G_glyphLCD, 0);
    IDrawTitle();

    // Setup any additional misc. tasks (such as the heartbeat task)
    SetupTasks();

    // Play startup tones
    PlayAudio(523, 100);
    PlayAudio(659, 100);
    PlayAudio(783, 100);
    PlayAudio(1046, 100);
    PlayAudio(783, 100);
    PlayAudio(659, 100);
    PlayAudio(523, 100);

    // Wait in an infinite loop.
    while(1) {
        UEZTaskDelay(10000);
    }

    return 0;
}
Пример #8
0
/*---------------------------------------------------------------------------*
 * Task:  main
 *---------------------------------------------------------------------------*
 * Description:
 *      In the uEZ system, main() is a task.  Do not exit this task
 *      unless you want to the board to reset.  This function should
 *      setup the system and then run the main loop of the program.
 * Outputs:
 *      int                     -- Output error code
 *---------------------------------------------------------------------------*/
int MainTask(void)
{	
	printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner
	
	// Start up the heart beat of the LED
    UEZTaskCreate(Heartbeat, "Heart", 64, (void *)0, UEZ_PRIORITY_NORMAL, 0);
	
    NVSettingsInit();
    // Load the settings from non-volatile memory
    if (NVSettingsLoad() == UEZ_ERROR_CHECKSUM_BAD) {
        printf("EEPROM Settings\n");
        NVSettingsInit();
        NVSettingsSave();
    }

    // Delete old log file
    UEZFileDelete("0:/ACCELLOG.TXT");
    	
	// Setup any additional misc. tasks (such as the heartbeat task)
    SetupTasks();

    GlyphOpen(&G_glyphLCD, 0);
	IDrawTitle();

    // Play tones	
	PlayAudio(523, 100);
    PlayAudio(659, 100);
    PlayAudio(783, 100);
    PlayAudio(1046, 100);
    PlayAudio(783, 100);
    PlayAudio(659, 100);
    PlayAudio(523, 100);	
	
	while(1) {
		UEZTaskDelay(500);
	}

    return 0;
}
Пример #9
0
/*---------------------------------------------------------------------------*
 * Task:  main
 *---------------------------------------------------------------------------*
 * Description:
 *      In the uEZ system, main() is a task.  Do not exit this task
 *      unless you want to the board to reset.  This function should
 *      setup the system and then run the main loop of the program.
 * Outputs:
 *      int                     -- Output error code
 *---------------------------------------------------------------------------*/
int MainTask(void)
{	
	T_uezDevice temp;
	T_uezDevice accel;
	T_uezError tempDeviceError;
	T_uezError accelDeviceError;
	TUInt8 displayString[100];
	TInt32 tempValue;
	float tempFloatValue;
	AccelerometerReading accelReading;
	
	printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner
	
	// Start up the heart beat of the LED
    UEZTaskCreate(Heartbeat, "Heart", 64, (void *)0, UEZ_PRIORITY_NORMAL, 0);
	
    NVSettingsInit();
    // Load the settings from non-volatile memory
    if (NVSettingsLoad() == UEZ_ERROR_CHECKSUM_BAD) {
        printf("EEPROM Settings\n");
        NVSettingsInit();
        NVSettingsSave();
    }
	
	// Setup any additional misc. tasks (such as the heartbeat task)
    SetupTasks();

    GlyphOpen(&G_glyphLCD, 0);
	IDrawTitle();
	
	PlayAudio(523, 100);
    PlayAudio(659, 100);
    PlayAudio(783, 100);
    PlayAudio(1046, 100);
    PlayAudio(783, 100);
    PlayAudio(659, 100);
    PlayAudio(523, 100);	
	
	tempDeviceError = UEZTemperatureOpen("Temp0", &temp);
	if (tempDeviceError == UEZ_ERROR_NONE) {
		printf("MainTask: Temperature Device Open\n");
    } else {
        printf("MainTask: Failed to Open Temperature Device\n");
    }
	
	accelDeviceError = UEZAccelerometerOpen("Accel0", &accel);
	if (accelDeviceError == UEZ_ERROR_NONE) {
		printf("MainTask: Accelerometer Device Open\n");
    } else {
        printf("MainTask: Failed to Open Accelerometer Device\n");
    }
	
	while(1) {
		
		if ( tempDeviceError == UEZ_ERROR_NONE ) {
			if (UEZTemperatureRead(temp, &tempValue) == UEZ_ERROR_NONE) {
				tempFloatValue = tempValue/65536.0;
				sprintf((char *)displayString, "Temp: %.2f C", tempFloatValue);
				GlyphSetXY(G_glyphLCD, 0, 0);
    			GlyphString(G_glyphLCD, displayString, strlen(displayString));
            }
		}
		
		if ( accelDeviceError == UEZ_ERROR_NONE ) {
			if(UEZAccelerometerReadXYZ(accel, &accelReading, 10) == UEZ_ERROR_NONE )
			{				
				sprintf((char *)displayString, "ACCEL X: %d", accelReading.iX);
				GlyphSetXY(G_glyphLCD, 0, 16);
    			GlyphString(G_glyphLCD, displayString, strlen(displayString));
				
				sprintf((char *)displayString, "ACCEL Y: %d", accelReading.iY);
				GlyphSetXY(G_glyphLCD, 0, 24);
    			GlyphString(G_glyphLCD, displayString, strlen(displayString));
				
				sprintf((char *)displayString, "ACCEL Z: %d", accelReading.iZ);
				GlyphSetXY(G_glyphLCD, 0, 32);
    			GlyphString(G_glyphLCD, displayString, strlen(displayString));
			}
		}
		
		UEZTaskDelay(500);
	}

    return 0;
}
Пример #10
0
/*---------------------------------------------------------------------------*
 * Task:  main
 *---------------------------------------------------------------------------*
 * Description:
 *      In the uEZ system, main() is a task.  Do not exit this task
 *      unless you want to the board to reset.  This function should
 *      setup the system and then run the main loop of the program.
 * Outputs:
 *      int                     -- Output error code
 *---------------------------------------------------------------------------*/
int MainTask(void)
{	
	T_uezDevice adc;
	T_uezDevice temp;
	T_uezDevice accel;
	T_uezError adcDeviceError;
	T_uezError tempDeviceError;
	T_uezError accelDeviceError;
	ADC_RequestSingle adcRequest;
	TUInt32 adcReading;
	TUInt8 displayString[100];
	TInt32 tempValue;
	float tempFloatValue;
	AccelerometerReading accelReading;
	
	printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n");
	
	NVSettingsInit();
    // Load the settings from non-volatile memory
    if (NVSettingsLoad() == UEZ_ERROR_CHECKSUM_BAD) {
        printf("EEPROM Settings\n");
        NVSettingsInit();
        NVSettingsSave();
    }
	
	SetupTasks();

	GlyphOpen(&G_glyphLCD, 0);
	IDrawTitle();

	PlayAudio(523, 100);
    PlayAudio(659, 100);
    PlayAudio(783, 100);
    PlayAudio(1046, 100);
    PlayAudio(783, 100);
    PlayAudio(659, 100);
    PlayAudio(523, 100);	

	adcDeviceError = UEZADCOpen("ADC_S12AD", &adc);
	if (adcDeviceError == UEZ_ERROR_NONE) {
		printf("MainTask: ADC Device Open\n");
	} else {
		printf("MainTask: Failed to Open ADC Device\n");
	}
	
	tempDeviceError = UEZTemperatureOpen("Temp0", &temp);
	if (tempDeviceError == UEZ_ERROR_NONE) {
		printf("MainTask: Temperature Device Open\n");
    } else {
        printf("MainTask: Failed to Open Temperature Device\n");
    }
	
	accelDeviceError = UEZAccelerometerOpen("Accel0", &accel);
	if (accelDeviceError == UEZ_ERROR_NONE) {
		printf("MainTask: Accelerometer Device Open\n");
    } else {
        printf("MainTask: Failed to Open Accelerometer Device\n");
    }
	    
	//PORTE.PDR.BIT.B3 = 1;
	while(1) {
		if( adcDeviceError == UEZ_ERROR_NONE )
		{
			// the device opened properly
		    adcRequest.iADCChannel = 2;
		    adcRequest.iBitSampleSize = 12;
		    adcRequest.iTrigger = ADC_TRIGGER_NOW;
		    adcRequest.iCapturedData = &adcReading;
		    if (UEZADCRequestSingle(adc,&adcRequest) == UEZ_ERROR_NONE) {
				printf("MainTask: Potentiometer Reading: %d\n", adcReading);
		    } else {
		        printf("MainTask: Failed to get a Potentiometer Reading\n");
		    }
		}
		
		if ( tempDeviceError == UEZ_ERROR_NONE ) {
			if (UEZTemperatureRead(temp, &tempValue) == UEZ_ERROR_NONE) {
				tempFloatValue = tempValue/65536.0;
				sprintf((char *)displayString, "Temp: %.2f C", tempFloatValue);
				GlyphSetXY(G_glyphLCD, 0, 0);
    			GlyphString(G_glyphLCD, displayString, strlen(displayString));
            }
		}

		if ( accelDeviceError == UEZ_ERROR_NONE ) {
			if(UEZAccelerometerReadXYZ(accel, &accelReading, 10) == UEZ_ERROR_NONE )
			{				
				sprintf((char *)displayString, "ACCEL X: %d", accelReading.iX);
				GlyphSetXY(G_glyphLCD, 0, 16);
    			GlyphString(G_glyphLCD, displayString, strlen(displayString));
				
				sprintf((char *)displayString, "ACCEL Y: %d", accelReading.iY);
				GlyphSetXY(G_glyphLCD, 0, 24);
    			GlyphString(G_glyphLCD, displayString, strlen(displayString));
				
				sprintf((char *)displayString, "ACCEL Z: %d", accelReading.iZ);
				GlyphSetXY(G_glyphLCD, 0, 32);
    			GlyphString(G_glyphLCD, displayString, strlen(displayString));
			}
		}

		UEZTaskDelay(1000);
	}
    return 0;
}
Пример #11
0
int  main(void)
{
    AppMode_T AppMode; APP_STATE_E state=UPDATE_TEMPERATURE; 
    char LCDString[30], temp_char[2]; uint16_t temp; float ftemp;
  
    HardwareSetup();

    /************************initializa LCD module********************************/
    SPI2_Init();
    InitialiseLCD();
    led_init();
    MSTimerInit();

    /* Default app mode */
    AppMode = GAINSPAN_DEMO;
    
    /* If the CIK is exist, auto into the Exosite mode */
    NVSettingsLoad(&GNV_Setting);
    
    /* Determine if SW1 & SW3 is pressed at power up to enter programming mode */
    if (Switch1IsPressed() && Switch3IsPressed()) {
         AppMode = PROGRAM_MODE;
    }
    else if(Switch3IsPressed() && Switch2IsPressed())
    {
         AppMode = EXOSITE_ERASE;
    }
    else if(Switch1IsPressed())
    {
        AppMode = RUN_EXOSITE;
    }
    else if(Switch2IsPressed())
    {
        AppMode = RUN_PROVISIONING;
    }
    else if(Switch3IsPressed())
    {
        AppMode = RUN_OVER_AIR_DOWNLOAD;
    }
    
    if(AppMode == GAINSPAN_DEMO) {
        LCDDisplayLogo();
        LCDSelectFont(FONT_SMALL);
        DisplayLCD(LCD_LINE3, "RL78G14 RDK    V2.0");
        DisplayLCD(LCD_LINE4, "   Wi-Fi & Cloud   ");
        DisplayLCD(LCD_LINE5, "     demos by:     ");
        DisplayLCD(LCD_LINE6, "Gainspan           ");
        DisplayLCD(LCD_LINE7, "Exosite            ");
        DisplayLCD(LCD_LINE8, "Future Designs, Inc");
        MSTimerDelay(3500);
        ClearLCD();
        DisplayLCD(LCD_LINE1, "Demo Modes:        ");
        DisplayLCD(LCD_LINE2, "-RST no key:       ");
        DisplayLCD(LCD_LINE3, "   GS Web Server   ");
        DisplayLCD(LCD_LINE4, "-RST + SW1:        ");
        DisplayLCD(LCD_LINE5, "   Exosite Cloud   ");
        DisplayLCD(LCD_LINE6, "-RST + SW2:        ");
        DisplayLCD(LCD_LINE7, "   AP Provisioning ");
        DisplayLCD(LCD_LINE8, "-RST + SW3: OTA    ");
        MSTimerDelay(3000);
        ClearLCD();
        
        LCDSelectFont(FONT_LARGE);
        if(Exosite_GetCIK(NULL))
        {
          AppMode = RUN_EXOSITE;
        }
    }
    
    DisplayLCD(LCD_LINE1, "Starting..."); 
    /*****************************************************************************/  
    SPI_Init(GAINSPAN_SPI_RATE);  
   /* Setup LCD SPI channel for Chip Select P10, active low, active per byte  */
    SPI_ChannelSetup(GAINSPAN_SPI_CHANNEL, false, true);
    GainSpan_SPI_Start();

    PM15 &= ~(1 << 2);
    P15 &= ~(1 << 2);
    
    if(AppMode == PROGRAM_MODE) {
        App_ProgramMode();
    }
    else if (AppMode == RUN_EXOSITE)
    {          
        DisplayLCD(LCD_LINE1, " CLOUD DEMO ");
        Temperature_Init();
        Potentiometer_Init();  
        App_Exosite();
    }
    else if(AppMode == RUN_PROVISIONING)
    {
      App_WebProvisioning();
    }
     else if(AppMode == RUN_OVER_AIR_DOWNLOAD)
    {
       App_OverTheAirProgrammingPushMetheod();
    }
    else if (AppMode == EXOSITE_ERASE)
    {
       ClearLCD();
       LCDSelectFont(FONT_SMALL);
       DisplayLCD(LCD_LINE3, "EEPROM ERASING ... ");
       MSTimerDelay(2000);
       Exosite_Init("renesas", "rl78g14", IF_WIFI, 1);
       DisplayLCD(LCD_LINE3, "                   ");
       DisplayLCD(LCD_LINE4, "Please reset device");
       while(1);
    }
    else{
        UART0_Start(GAINSPAN_CONSOLE_BAUD);
       // UART2_Start(GAINSPAN_UART_BAUD);
 
        Temperature_Init();
        Potentiometer_Init();
    
       // sprintf(LCDString, "RDK Demo %s", VERSION_TEXT);
       // DisplayLCD(LCD_LINE1, (const uint8_t *)LCDString);
   
        /* Before doing any tests or apps, startup the module */
        /* and nonvolatile stettings */
        App_Startup();
        // Now connect to the system
        //App_Connect(&G_nvsettings.webprov);
     
       //  App_PassThroughSPI();
         
         /******************Start Processing Sensor data******************/
         
         uint32_t start = MSTimerGet();  uint8_t c;
         Accelerometer_Init();
         while(1) 
         { 
          // if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, &c)) 
           if(App_Read(&c, 1, 0)) 
             AtLibGs_ReceiveDataProcess(c);
                   
        /* Timeout? */
           if (MSTimerDelta(start) >= 100)     // every 100 ms, read sensor data
           {  
              led_task();
              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);
                  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);
                  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]);
                  DisplayLCD(LCD_LINE8, (const uint8_t *)LCDString); 
                  state = UPDATE_TEMPERATURE;
                break;
              }
              start = MSTimerGet();
           }
         }          
    }    
Пример #12
0
void App_WhiskerGW()
{
    char pubTopic[100];
    char pubMsg[250];
    unsigned char msgType;
    int counter=0;
    char cntStr[20];
    char commandBuffer[64];
    int commandBufferPointer=0;
    
    led_all_off();
    // Give the unit a little time to start up
    // (300 ms for GS1011 and 1000 ms for GS1500)
    MSTimerDelay(1000);

    NVSettingsLoad(&GNV_Setting);
    led_on(4);
    WIFI_init(1);  // Show MAC address and Version
    led_on(5);
    WIFI_Associate();
    led_on(6);
    DisplayLCD(LCD_LINE8, "Demo starting.");
    DisplayLCD(LCD_LINE3, (const uint8_t *)WifiMAC);
    
    
    
    // UART
    if(spiUartInitialize()!=0)
    {
        DisplayLCD(LCD_LINE7, "!! SPIUART_ERROR !!");
        while(1)
        {
              led_all_on();
              MSTimerDelay(250);
              led_all_off();
              MSTimerDelay(250);
        }
    }
    
    while (1) 
    {
        // Do we need to connect to the AP?
        if (!AtLibGs_IsNodeAssociated())
        {
            led_off(6);
            WIFI_Associate();
            led_on(6);
        }
        else
        {    
            if(mqttConnected==0)
                App_ConnectMqtt();
            int charCount = spiUartRxBytesAvailable();
            while(charCount>0)
            {
                commandBuffer[commandBufferPointer++] = spiUartGetByte();
                charCount--;
                if(charCount==0)
                  commandBufferPointer=0;
                if(commandBufferPointer>4)
                {
                  if(strstr(commandBuffer,"RMPU")==commandBuffer)
                  {
                    if(commandBufferPointer>24)
                    {
                      // process response
                      char macStr[9];
                      char lenStr[5];
                      memcpy(macStr,&commandBuffer[6],8);
                      macStr[8] = 0;
                      memcpy(lenStr,&commandBuffer[4],2);
                      lenStr[2]=0;
                      int len = (int)strtol(lenStr,0,16);
                      unsigned long mac = strtoul(macStr,NULL,16);
                      WhiskerModule *wm = findModule(mac);
                      if(wm!=0)
                      {
                          if(commandBufferPointer>len+16)
                          {
                            char rssiStr[3];
                            memcpy(rssiStr,&commandBuffer[commandBufferPointer-3],2);
                            rssiStr[2]=0;
                            int rssi = (int)strtol(rssiStr,0,16);
                            if((rssi & 0x80) == 0x80)
                              rssi-=256;
                            int puMsgPointer=14;
                            mqtt_initJsonMsg(pubMsg);
                            mqtt_addStringValToMsg("Name",wm->Name,pubMsg,0);
                            mqtt_addStringValToMsg("Mac",macStr,pubMsg,1);
                            char rstr[8];
                            sprintf(rstr,"%d dbm",rssi);
                            mqtt_addStringValToMsg("Rssi",rstr,pubMsg,1);
                            sprintf(pubMsg+strlen(pubMsg),",\"Values\":{");
                            puMsgPointer=14;
                            int comma=0;
                            while(puMsgPointer < (commandBufferPointer-3))
                            {
                              char cidStr[3];
                              memcpy(cidStr,&commandBuffer[puMsgPointer],2);
                              puMsgPointer+=2;
                              cidStr[2]=0;
                              unsigned char cid=(unsigned char)strtol(cidStr,0,16);
                              unsigned char channel = cid & 0x1f;
                              char valStr[9];
                              long valInt;
                              switch(cid)
                              {
                              case 0x21:
                                //digital input
                                memcpy(valStr,&commandBuffer[puMsgPointer],2);
                                valStr[2]=0;
                                puMsgPointer+=2;
                                valInt = (int)strtol(valStr,0,16);
                                if(valInt)
                                    mqtt_addStringValToMsg("DIN1","True",pubMsg,comma);
                                else
                                    mqtt_addStringValToMsg("DIN1","False",pubMsg,comma);
                                break;
                              case 0x22:
                                //digital input
                                memcpy(valStr,&commandBuffer[puMsgPointer],2);
                                valStr[2]=0;
                                puMsgPointer+=2;
                                valInt = (int)strtol(valStr,0,16);
                                if(valInt)
                                    mqtt_addStringValToMsg("DIN2","True",pubMsg,comma);
                                else
                                    mqtt_addStringValToMsg("DIN2","False",pubMsg,comma);
                                break;                              
                              case 0x43:
                                //battery analog in
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("Battery",valInt,pubMsg,comma);
                                break;          
                              case 0x44:
                                //battery analog in
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("Temperature",valInt,pubMsg,comma);
                                break;          
                              case 0x45:
                                //battery analog in
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("RH",valInt,pubMsg,comma);
                                break;  
                              case 0x5d:
                                //internal temperature
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("IntTemp",valInt,pubMsg,comma);
                                break;
                              case 0x57:                                
                                //air quality
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("AirQual",valInt,pubMsg,comma);
                                break;
                              case 0x58:
                                //air quality
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("AirQual",valInt,pubMsg,comma);
                                break;
                                
                              case 0x61:
                                // digital counter input
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("Count1",valInt,pubMsg,comma);
                                break;
                                
                              case 0x62:
                                // digital counter input
                                memcpy(valStr,&commandBuffer[puMsgPointer],4);
                                valStr[4]=0;
                                puMsgPointer+=4;                                
                                valInt = (int)strtol(valStr,0,16);
                                mqtt_addIntValToMsg("Count2",valInt,pubMsg,comma);
                                break;
                              }                              
                              comma=1;
                            }                            
                            sprintf(pubMsg+strlen(pubMsg),"}");
                            mqtt_finishJsonMsg(pubMsg);
                            sprintf(pubTopic, "%s/%s", WIO_DOMAIN, macStr);
                            int res=mqtt_publish(&broker, pubTopic, pubMsg,0)<0;
                            if(res<0)
                              mqttConnected=0;
                            led_on(8);
                            //spiUartResetFIFO();
                          }
                      }
                    }
                  }
                }
            }
            // Send data if
            RSSIReading();
            AtLibGs_WaitForTCPMessage(1000);
            led_off(7);
            led_off(8);
            if(G_receivedCount>0)
            {
                AtLibGs_ParseTCPData(G_received,G_receivedCount,&rxm);
                msgType = MQTTParseMessageType(rxm.message);
                switch(msgType)
                {
                case MQTT_MSG_SUBACK:
                  // todo: display subscription acknowledgement
                  break;
                case MQTT_MSG_PUBLISH:
                  App_MQTTMsgPublished();
                  break;
                case MQTT_MSG_PUBACK:
                  // todo: display publish acknowledgement
                  break;
                default:
                  break;
                }
            }
            counter++;
            sprintf(cntStr,"Counter=%d",counter);
            DisplayLCD(LCD_LINE6,cntStr);
            if(counter>30)
            {
                counter=0;
                sprintf(pubTopic, "%s/%s", WIO_DOMAIN, WifiMAC);
                mqtt_initJsonMsg(pubMsg);
                mqtt_addStringValToMsg("msg","status ok",pubMsg,0);
                mqtt_finishJsonMsg(pubMsg);
                int res1=mqtt_publish(&broker, pubTopic, pubMsg,0)<0;
                if(res1<0)
                    mqttConnected=0;
                led_on(7);
            }
        }       
    // Send data if END
    }
}
Пример #13
0
/*---------------------------------------------------------------------------*
 * 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)
        {}
}
Пример #14
0
/*****************************************************************************
*
*  App_Exosite
*
*  \param  None
*
*  \return None
*
*  \brief  Takse a reading of temperature and potentiometer and sends to
*          Exosite cloud using a TCP connection
*
*****************************************************************************/
void App_Exosite(void)
{
  int loop_time = 1000;
  unsigned char loopCount = 0;
  int wifi_init = 0;
  int badcik = 1;
  static const uint8_t geoCert[] = { 0x30, 0x82, 0x03, 0x54, 0x30, 0x82, 0x02, 0x3c, 0xa0, 0x03,
                                     0x02, 0x01, 0x02, 0x02, 0x03, 0x02, 0x34, 0x56, 0x30, 0x0d,
                                     0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
                                     0x05, 0x05, 0x00, 0x30, 0x42, 0x31, 0x0b, 0x30, 0x09, 0x06,
                                     0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x16,
                                     0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x47,
                                     0x65, 0x6f, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x49, 0x6e,
                                     0x63, 0x2e, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04,
                                     0x03, 0x13, 0x12, 0x47, 0x65, 0x6f, 0x54, 0x72, 0x75, 0x73,
                                     0x74, 0x20, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x43,
                                     0x41, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x32, 0x30, 0x35, 0x32,
                                     0x31, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d,
                                     0x32, 0x32, 0x30, 0x35, 0x32, 0x31, 0x30, 0x34, 0x30, 0x30,
                                     0x30, 0x30, 0x5a, 0x30, 0x42, 0x31, 0x0b, 0x30, 0x09, 0x06,
                                     0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x16,
                                     0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x47,
                                     0x65, 0x6f, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x49, 0x6e,
                                     0x63, 0x2e, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04,
                                     0x03, 0x13, 0x12, 0x47, 0x65, 0x6f, 0x54, 0x72, 0x75, 0x73,
                                     0x74, 0x20, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x43,
                                     0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a,
                                     0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00,
                                     0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
                                     0x82, 0x01, 0x01, 0x00, 0xda, 0xcc, 0x18, 0x63, 0x30, 0xfd,
                                     0xf4, 0x17, 0x23, 0x1a, 0x56, 0x7e, 0x5b, 0xdf, 0x3c, 0x6c,
                                     0x38, 0xe4, 0x71, 0xb7, 0x78, 0x91, 0xd4, 0xbc, 0xa1, 0xd8,
                                     0x4c, 0xf8, 0xa8, 0x43, 0xb6, 0x03, 0xe9, 0x4d, 0x21, 0x07,
                                     0x08, 0x88, 0xda, 0x58, 0x2f, 0x66, 0x39, 0x29, 0xbd, 0x05,
                                     0x78, 0x8b, 0x9d, 0x38, 0xe8, 0x05, 0xb7, 0x6a, 0x7e, 0x71,
                                     0xa4, 0xe6, 0xc4, 0x60, 0xa6, 0xb0, 0xef, 0x80, 0xe4, 0x89,
                                     0x28, 0x0f, 0x9e, 0x25, 0xd6, 0xed, 0x83, 0xf3, 0xad, 0xa6,
                                     0x91, 0xc7, 0x98, 0xc9, 0x42, 0x18, 0x35, 0x14, 0x9d, 0xad,
                                     0x98, 0x46, 0x92, 0x2e, 0x4f, 0xca, 0xf1, 0x87, 0x43, 0xc1,
                                     0x16, 0x95, 0x57, 0x2d, 0x50, 0xef, 0x89, 0x2d, 0x80, 0x7a,
                                     0x57, 0xad, 0xf2, 0xee, 0x5f, 0x6b, 0xd2, 0x00, 0x8d, 0xb9,
                                     0x14, 0xf8, 0x14, 0x15, 0x35, 0xd9, 0xc0, 0x46, 0xa3, 0x7b,
                                     0x72, 0xc8, 0x91, 0xbf, 0xc9, 0x55, 0x2b, 0xcd, 0xd0, 0x97,
                                     0x3e, 0x9c, 0x26, 0x64, 0xcc, 0xdf, 0xce, 0x83, 0x19, 0x71,
                                     0xca, 0x4e, 0xe6, 0xd4, 0xd5, 0x7b, 0xa9, 0x19, 0xcd, 0x55,
                                     0xde, 0xc8, 0xec, 0xd2, 0x5e, 0x38, 0x53, 0xe5, 0x5c, 0x4f,
                                     0x8c, 0x2d, 0xfe, 0x50, 0x23, 0x36, 0xfc, 0x66, 0xe6, 0xcb,
                                     0x8e, 0xa4, 0x39, 0x19, 0x00, 0xb7, 0x95, 0x02, 0x39, 0x91,
                                     0x0b, 0x0e, 0xfe, 0x38, 0x2e, 0xd1, 0x1d, 0x05, 0x9a, 0xf6,
                                     0x4d, 0x3e, 0x6f, 0x0f, 0x07, 0x1d, 0xaf, 0x2c, 0x1e, 0x8f,
                                     0x60, 0x39, 0xe2, 0xfa, 0x36, 0x53, 0x13, 0x39, 0xd4, 0x5e,
                                     0x26, 0x2b, 0xdb, 0x3d, 0xa8, 0x14, 0xbd, 0x32, 0xeb, 0x18,
                                     0x03, 0x28, 0x52, 0x04, 0x71, 0xe5, 0xab, 0x33, 0x3d, 0xe1,
                                     0x38, 0xbb, 0x07, 0x36, 0x84, 0x62, 0x9c, 0x79, 0xea, 0x16,
                                     0x30, 0xf4, 0x5f, 0xc0, 0x2b, 0xe8, 0x71, 0x6b, 0xe4, 0xf9,
                                     0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x53, 0x30, 0x51, 0x30,
                                     0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04,
                                     0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03,
                                     0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xc0, 0x7a, 0x98,
                                     0x68, 0x8d, 0x89, 0xfb, 0xab, 0x05, 0x64, 0x0c, 0x11, 0x7d,
                                     0xaa, 0x7d, 0x65, 0xb8, 0xca, 0xcc, 0x4e, 0x30, 0x1f, 0x06,
                                     0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14,
                                     0xc0, 0x7a, 0x98, 0x68, 0x8d, 0x89, 0xfb, 0xab, 0x05, 0x64,
                                     0x0c, 0x11, 0x7d, 0xaa, 0x7d, 0x65, 0xb8, 0xca, 0xcc, 0x4e,
                                     0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
                                     0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
                                     0x35, 0xe3, 0x29, 0x6a, 0xe5, 0x2f, 0x5d, 0x54, 0x8e, 0x29,
                                     0x50, 0x94, 0x9f, 0x99, 0x1a, 0x14, 0xe4, 0x8f, 0x78, 0x2a,
                                     0x62, 0x94, 0xa2, 0x27, 0x67, 0x9e, 0xd0, 0xcf, 0x1a, 0x5e,
                                     0x47, 0xe9, 0xc1, 0xb2, 0xa4, 0xcf, 0xdd, 0x41, 0x1a, 0x05,
                                     0x4e, 0x9b, 0x4b, 0xee, 0x4a, 0x6f, 0x55, 0x52, 0xb3, 0x24,
                                     0xa1, 0x37, 0x0a, 0xeb, 0x64, 0x76, 0x2a, 0x2e, 0x2c, 0xf3,
                                     0xfd, 0x3b, 0x75, 0x90, 0xbf, 0xfa, 0x71, 0xd8, 0xc7, 0x3d,
                                     0x37, 0xd2, 0xb5, 0x05, 0x95, 0x62, 0xb9, 0xa6, 0xde, 0x89,
                                     0x3d, 0x36, 0x7b, 0x38, 0x77, 0x48, 0x97, 0xac, 0xa6, 0x20,
                                     0x8f, 0x2e, 0xa6, 0xc9, 0x0c, 0xc2, 0xb2, 0x99, 0x45, 0x00,
                                     0xc7, 0xce, 0x11, 0x51, 0x22, 0x22, 0xe0, 0xa5, 0xea, 0xb6,
                                     0x15, 0x48, 0x09, 0x64, 0xea, 0x5e, 0x4f, 0x74, 0xf7, 0x05,
                                     0x3e, 0xc7, 0x8a, 0x52, 0x0c, 0xdb, 0x15, 0xb4, 0xbd, 0x6d,
                                     0x9b, 0xe5, 0xc6, 0xb1, 0x54, 0x68, 0xa9, 0xe3, 0x69, 0x90,
                                     0xb6, 0x9a, 0xa5, 0x0f, 0xb8, 0xb9, 0x3f, 0x20, 0x7d, 0xae,
                                     0x4a, 0xb5, 0xb8, 0x9c, 0xe4, 0x1d, 0xb6, 0xab, 0xe6, 0x94,
                                     0xa5, 0xc1, 0xc7, 0x83, 0xad, 0xdb, 0xf5, 0x27, 0x87, 0x0e,
                                     0x04, 0x6c, 0xd5, 0xff, 0xdd, 0xa0, 0x5d, 0xed, 0x87, 0x52,
                                     0xb7, 0x2b, 0x15, 0x02, 0xae, 0x39, 0xa6, 0x6a, 0x74, 0xe9,
                                     0xda, 0xc4, 0xe7, 0xbc, 0x4d, 0x34, 0x1e, 0xa9, 0x5c, 0x4d,
                                     0x33, 0x5f, 0x92, 0x09, 0x2f, 0x88, 0x66, 0x5d, 0x77, 0x97,
                                     0xc7, 0x1d, 0x76, 0x13, 0xa9, 0xd5, 0xe5, 0xf1, 0x16, 0x09,
                                     0x11, 0x35, 0xd5, 0xac, 0xdb, 0x24, 0x71, 0x70, 0x2c, 0x98,
                                     0x56, 0x0b, 0xd9, 0x17, 0xb4, 0xd1, 0xe3, 0x51, 0x2b, 0x5e,
                                     0x75, 0xe8, 0xd5, 0xd0, 0xdc, 0x4f, 0x34, 0xed, 0xc2, 0x05,
                                     0x66, 0x80, 0xa1, 0xcb, 0xe6, 0x33};

  bool isTimeSync = false;

  // wait 1 sec for LCD messages display
  MSTimerDelay(1000);
  NVSettingsLoad(&GNV_Setting);

#ifdef SHOW_VERSION
  DisplayLCD(LCD_LINE2, (const uint8_t *)ExositeAppVersion);
#endif

  // must initialize one time for mac address prepare..
  WIFI_init(1);
  if (!Exosite_Init("renesas", "rl78g14", IF_WIFI, 0))
  {
    show_status();
    while(1);
  }

  while(AtLibGs_AddCert(  EXOSITE_CA_NAME,
                          true,
                          geoCert,
                          sizeof(geoCert)) != ATLIBGS_MSG_ID_OK)
  {
    DisplayLCD(LCD_LINE4, "Add CA FAILED");
  }

  while (1)
  {
    if (!checkWiFiConnected(wifi_init))
    {
      wifi_init = 0;
    }
    else
    {
      if(!isTimeSync)
      {
        if(Exosite_SyncTime() == 0)
          isTimeSync = true;
      }
      
      UpdateReadings();

      int code = Exosite_StatusCode();
      if (code == EXO_STATUS_OK)
      {
        badcik = 0;
        wifi_init = 1;

        ReadCloudCommands();

        if (loopCount++ >= WRITE_INTERVAL) 
        {
          // POST the Sensor and templature values
          ReportReadings();
          loopCount = 0;
        }
        loop_time = 500; //delay 0.5 seconds before next turn..
      }
      else if (1 == badcik || EXO_STATUS_BAD_CIK == code || EXO_STATUS_NOAUTH == code)
      {
        DisplayLCD(LCD_LINE6, "  Exosite  ");
        DisplayLCD(LCD_LINE7, " Connecting");
        DisplayLCD(LCD_LINE8, "           ");

        if (!Exosite_Activate())
        {
          badcik = 1;
          loop_time = 3000; // delay 3 seconds
        }
        else
        {
          DisplayLCD(LCD_LINE7, " Connected ");
        }
      }
      show_status();
    }

    MSTimerDelay(loop_time);  //delay before looping again
  }
}
Пример #15
0
int main(void)
{
    AppMode_T AppMode;
    WDTIMK = 0U;	/* enable INTWDTI interrupt */
   
    
    HardwareSetup();
    MSTimerInit();
    
    /************************initializa LCD module********************************/
    SPI2_Init();
    InitialiseLCD();
    led_init();
    
    /* Default app mode */
    AppMode = RUN_EXOSITE;

    /* Determine if SW1 & SW3 is pressed at power up to enter nvm erase mode */
    if (Switch1IsPressed() && Switch3IsPressed())
    {

        DisplayLCD(LCD_LINE1, "*NVM ERASED*");
        DisplayLCD(LCD_LINE2, "Reboot      ");
        DisplayLCD(LCD_LINE3, "  Device    ");
        while(1)
        {
            // wait here
        }
    }
    else if(Switch1IsPressed())
    {
        AppMode = ACTIVATE_MODEM;
    }
    
    DisplayLCD(LCD_LINE1, "Initializing");
    DisplayLCD(LCD_LINE2, "  Novatel   ");
    DisplayLCD(LCD_LINE3, "   Modem    ");
        
    // reset the modem
    P8 &= ~(1<<POWER_OFF_PIN); //SET LOW
    PM8 &= ~(1<<POWER_OFF_PIN); //SET AS OUTPUT
    P8 |= (1<<POWER_OFF_PIN);  //SET HIGH
    MSTimerDelay(500); //pulse
    P8 &= ~(1<<POWER_OFF_PIN); //SET LOW


    // pulse the phone pin as well
    ADPC = 0x09U;   //DEFAULT is all AINx pins are Analog, change 8-15
                    // to digital
    P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
    PM15 &= ~(1<<MODEM_PHON_PIN); //SET AS OUTPUT
    P15 |= (1<<MODEM_PHON_PIN);  //SET HIGH
    MSTimerDelay(500); //pulse
    P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
    PM15 |= (1<<MODEM_PHON_PIN); //SET AS INPUT
    
    // wait for modem to power up
    DisplayLCD(LCD_LINE1, "Waiting for ");
    DisplayLCD(LCD_LINE2, "  Modem to  ");
    DisplayLCD(LCD_LINE3, " Initialize ");
    DisplayLCD(LCD_LINE4, "      3     ");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE4, "      2     ");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE4, "      1     ");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE4, "");
    // Start UART0 for Novatel modem
    UART0_Start(NOVATEL_UART_BAUD_RATE);

   

    /* If the CIK is exist, auto into the Exosite mode */
    NVSettingsLoad(&GNV_Setting);
    
    
   

    if(AppMode == RUN_EXOSITE)
    {
        LCDDisplayLogo();
        LCDSelectFont(FONT_SMALL);
        DisplayLCD(LCD_LINE3, "RL78G14 RDK    V2.0");
        DisplayLCD(LCD_LINE4, "   Cellular        ");
        DisplayLCD(LCD_LINE5, "     demos by:     ");
        DisplayLCD(LCD_LINE6, "Novatel            ");
        DisplayLCD(LCD_LINE7, "Exosite            ");
        MSTimerDelay(3500);
        ClearLCD();
        DisplayLCD(LCD_LINE1, "Demo Modes:        ");
        DisplayLCD(LCD_LINE2, "-RST no key:       ");
        DisplayLCD(LCD_LINE3, "   ExoSite App     ");
        DisplayLCD(LCD_LINE4, "-RST + SW1 & SW3:  ");
        DisplayLCD(LCD_LINE5, "   Reset NVM       ");
        DisplayLCD(LCD_LINE6, "-RST + SW1:        ");
        DisplayLCD(LCD_LINE7, "   Cell Activate   ");
        MSTimerDelay(3000);
        ClearLCD();

        LCDSelectFont(FONT_LARGE);
        DisplayLCD(LCD_LINE1, "Exosite DEMO");
        
        Temperature_Init();
        Potentiometer_Init();
        
        App_Exosite();
    }
    else if (AppMode == ACTIVATE_MODEM)
    {
        ATModem_CellActivate();
    }

   

    return 0;
}