Example #1
0
void cmd_periodic_cont(void)
{
    long cmd_status;

    if(UARTPeek('\r') == -1)
    {
        return;
    }

    // Get the buffer
    UARTgets(input_buffer, sizeof(input_buffer));

    cmd_status = CmdLineProcess(input_buffer);

    switch(cmd_status)
    {
        case CMDLINE_BAD_CMD:
            UARTprintf("Bad command!\n");
            break;
        case CMDLINE_TOO_MANY_ARGS:
            UARTprintf("Bad arguments!\n");
            break;
        default:
            break;
    }

    UARTprintf("> ");
}
Example #2
0
//*****************************************************************************
//
// Checks to see if a new command has been received via the serial port and,
// if so, processes it.
//
//*****************************************************************************
void
LogProcessCommands(void)
{
    int nStatus;

    //
    // Check to see if there is a new serial command to process.
    //
    if(UARTPeek('\r') >= 0)
    {
        //
        // A new command has been entered so read it.
        //
        UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf));

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        nStatus = CmdLineProcess(g_cCmdBuf);

        //
        // Handle the case of bad command.
        //
        if(nStatus == CMDLINE_BAD_CMD)
        {
            UARTprintf("Bad command!\n");
        }

        //
        // Handle the case of too many arguments.
        //
        else if(nStatus == CMDLINE_TOO_MANY_ARGS)
        {
            UARTprintf("Too many arguments for command processor!\n");
        }

        //
        // Otherwise the command was executed.  Print the error
        // code if one was returned.
        //
        else if(nStatus != 0)
        {
            UARTprintf("Command returned error code %d\n", nStatus);
        }

        //
        // Print a prompt on the console.
        //
        UARTprintf("\n> ");
    }
}
Example #3
0
int main2(void)
{
    UINT8  IsDHCP = 0;
    int32_t i32CommandStatus;
    _NetCfgIpV4Args_t ipV4;

    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    int Status = 0;

    /* Stop WDT */
    stopWDT();

    /* Initialize the system clock of MCU */
    initClk();

    Board_Init();       // initialize LaunchPad I/O and PD1 LED
    ConfigureUART();    // Initialize the UART.
    UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
    UARTprintf("This application is configured to measure analog signals from Ain7=PD0\n");
    UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
    /* Initializing the CC3100 device */
    sl_Start(0, 0, 0);

    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();

    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,
            (unsigned char *)&ipV4);

    //Print the IP
    UARTprintf("This node is at IP: %d.%d.%d.%d\n",  SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));

    //
    // Loop forever waiting  for commands from PC...
    //
    while(1)
    {
        //
        // Print prompt for user.
        //
        UARTprintf("\n>");

        //
        // Peek to see if a full command is ready for processing.
        //
        while(UARTPeek('\r') == -1)
        {
            //
            // Approximately 1 millisecond delay.
            //
            ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000);
        }

        //
        // A '\r' was detected so get the line of text from the receive buffer.
        //
        UARTgets(g_cInput,sizeof(g_cInput));

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32CommandStatus = CmdLineProcess(g_cInput);

        //
        // Handle the case of bad command.
        //
        if(i32CommandStatus == CMDLINE_BAD_CMD)
        {
            UARTprintf("    Bad command. Try again.\n");
        }
        //
        // Handle the case of too many arguments.
        //
        else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS)
        {
            UARTprintf("    Too many arguments for command. Try again.\n");
        }
        //
        // Handle the case of too few arguments.
        //
        else if(i32CommandStatus == CMDLINE_TOO_FEW_ARGS)
        {
            UARTprintf("    Too few arguments for command. Try again.\n");
        }
        //
        // Handle the case of too few arguments.
        //
        else if(i32CommandStatus == CMDLINE_INVALID_ARG)
        {
            UARTprintf("    Invalid command argument(s). Try again.\n");
        }
    }
    
}
Example #4
0
//*****************************************************************************
//
// Main function performs init and manages system.
//
// Called automatically after the system and compiler pre-init sequences.
// Performs system init calls, restores state from hibernate if needed and
// then manages the application context duties of the system.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32Status;
    uint32_t ui32ResetCause;
    int32_t i32CommandStatus;

    //
    // Enable stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPUEnable();
    ROM_FPUStackingEnable();

    //
    // Set the system clock to run at 40Mhz off PLL with external crystal as
    // reference.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Enable the hibernate module
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    //
    // Enable and Initialize the UART.
    //
    ConfigureUART();

    UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n");
    UARTprintf("Type 'help' for a list of commands\n");
    UARTprintf("> ");

    //
    // Determine why system reset occurred and respond accordingly.
    //
    ui32ResetCause = SysCtlResetCauseGet();
    SysCtlResetCauseClear(ui32ResetCause);
    if(ui32ResetCause == SYSCTL_CAUSE_POR)
    {
        if(HibernateIsActive())
        {
            //
            // Read the status bits to see what caused the wake.
            //
            ui32Status = HibernateIntStatus(0);
            HibernateIntClear(ui32Status);

            //
            // Wake was due to the push button.
            //
            if(ui32Status & HIBERNATE_INT_PIN_WAKE)
            {
                UARTprintf("Hibernate Wake Pin Wake Event\n");
                UARTprintf("> ");

                //
                // Recover the application state variables from battery backed
                // hibernate memory.  Set ui32Mode to normal.
                //
                HibernateDataGet((uint32_t*) &g_sAppState,
                                 sizeof(tAppState) / 4 + 1);
                g_sAppState.ui32Mode = APP_MODE_NORMAL;
            }

            //
            // Wake was due to RTC match
            //
            else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0)
            {
                UARTprintf("Hibernate RTC Wake Event\n");
                UARTprintf("> ");
                //
                // Recover the application state variables from battery backed
                // hibernate memory. Set ui32Mode to briefly flash the RGB.
                //
                HibernateDataGet((uint32_t*) &g_sAppState,
                                sizeof(tAppState) / 4 + 1);
                g_sAppState.ui32Mode = APP_MODE_HIB_FLASH;
            }
        }

        else
        {
            //
            // Reset was do to a cold first time power up.
            //
            UARTprintf("Power on reset. Hibernate not active.\n");
            UARTprintf("> ");

            g_sAppState.ui32Mode = APP_MODE_NORMAL;
            g_sAppState.fColorWheelPos = 0;
            g_sAppState.fIntensity = APP_INTENSITY_DEFAULT;
            g_sAppState.ui32Buttons = 0;
        }
    }
    else
    {
        //
        // External Pin reset or other reset event occured.
        //
        UARTprintf("External or other reset\n");
        UARTprintf("> ");

        //
        // Treat this as a cold power up reset without restore from hibernate.
        //
        g_sAppState.ui32Mode = APP_MODE_NORMAL;
        g_sAppState.fColorWheelPos = APP_PI;
        g_sAppState.fIntensity = APP_INTENSITY_DEFAULT;
        g_sAppState.ui32Buttons = 0;

    //
        // colors get a default initialization later when we call AppRainbow.
        //
    }

    //
    // Initialize clocking for the Hibernate module
    //
    HibernateEnableExpClk(SysCtlClockGet());

    //
    // Initialize the RGB LED. AppRainbow typically only called from interrupt
    // context. Safe to call here to force initial color update because
    // interrupts are not yet enabled.
    //
    RGBInit(0);
    RGBIntensitySet(g_sAppState.fIntensity);
    AppRainbow(1);
    RGBEnable();

    //
    // Initialize the buttons
    //
    ButtonsInit();

    //
    // Initialize the SysTick interrupt to process colors and buttons.
    //
    SysTickPeriodSet(SysCtlClockGet() / APP_SYSTICKS_PER_SEC);
    SysTickEnable();
    SysTickIntEnable();
    IntMasterEnable();

    //
    // spin forever and wait for carriage returns or state changes.
    //
    while(1)
    {

        UARTprintf("\n>");


        //
        // Peek to see if a full command is ready for processing
        //
        while(UARTPeek('\r') == -1)
        {
            //
            // millisecond delay.  A SysCtlSleep() here would also be OK.
            //
            SysCtlDelay(SysCtlClockGet() / (1000 / 3));

            //
            // Check for change of mode and enter hibernate if requested.
            // all other mode changes handled in interrupt context.
            //
            if(g_sAppState.ui32Mode == APP_MODE_HIB)
            {
                AppHibernateEnter();
            }
        }

        //
        // a '\r' was detected get the line of text from the user.
        //
        UARTgets(g_cInput,sizeof(g_cInput));

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32CommandStatus = CmdLineProcess(g_cInput);

        //
        // Handle the case of bad command.
        //
        if(i32CommandStatus == CMDLINE_BAD_CMD)
        {
            UARTprintf("Bad command!\n");
        }

        //
        // Handle the case of too many arguments.
        //
        else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS)
        {
            UARTprintf("Too many arguments for command processor!\n");
        }
    }
}
Example #5
0
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
	int32_t i32CommandStatus;
	int i;
	initUart();
	UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n");
	UARTprintf("Type 'help' for a list of commands to control Moto\n");
	UARTprintf("> ");
	InitDelay();
	cSPIN_Peripherals_Init();
	cSPIN_Reset_And_Standby();
	/* Structure initialization by default values, in order to avoid blank records */
	cSPIN_Regs_Struct_Reset(&cSPIN_RegsStruct);
	//cSPIN_PWM_Enable(2000);
    //cSPIN_Delay(0x00FFFFFF);
    //cSPIN_PWM_DISABLE();
    #if 0
	/* Acceleration rate settings to cSPIN_CONF_PARAM_ACC in steps/s2, range 14.55 to 59590 steps/s2 */
	cSPIN_RegsStruct.ACC 		= AccDec_Steps_to_Par(cSPIN_CONF_PARAM_ACC);
	/* Deceleration rate settings to cSPIN_CONF_PARAM_DEC in steps/s2, range 14.55 to 59590 steps/s2 */
	cSPIN_RegsStruct.DEC 		= AccDec_Steps_to_Par(cSPIN_CONF_PARAM_DEC); 
	/* Maximum speed settings to cSPIN_CONF_PARAM_MAX_SPEED in steps/s, range 15.25 to 15610 steps/s */
	cSPIN_RegsStruct.MAX_SPEED 	= MaxSpd_Steps_to_Par(cSPIN_CONF_PARAM_MAX_SPEED);
	/* Full step speed settings cSPIN_CONF_PARAM_FS_SPD in steps/s, range 7.63 to 15625 steps/s */
	cSPIN_RegsStruct.FS_SPD 	= FSSpd_Steps_to_Par(cSPIN_CONF_PARAM_FS_SPD);
	/* Minimum speed settings to cSPIN_CONF_PARAM_MIN_SPEED in steps/s, range 0 to 976.3 steps/s */
	cSPIN_RegsStruct.MIN_SPEED	= cSPIN_CONF_PARAM_LSPD_BIT|MinSpd_Steps_to_Par(cSPIN_CONF_PARAM_MIN_SPEED);
        /* Acceleration duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_ACC in %, range 0 to 99.6% */
	cSPIN_RegsStruct.KVAL_ACC 	= Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_ACC);
        /* Deceleration duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_DEC in %, range 0 to 99.6% */
	cSPIN_RegsStruct.KVAL_DEC 	= Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_DEC);		
        /* Run duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_RUN in %, range 0 to 99.6% */
	cSPIN_RegsStruct.KVAL_RUN 	= Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_RUN);
        /* Hold duty cycle (torque) settings to cSPIN_CONF_PARAM_KVAL_HOLD in %, range 0 to 99.6% */
	cSPIN_RegsStruct.KVAL_HOLD 	= Kval_Perc_to_Par(cSPIN_CONF_PARAM_KVAL_HOLD);
	        /* Thermal compensation param settings to cSPIN_CONF_PARAM_K_THERM, range 1 to 1.46875 */
	cSPIN_RegsStruct.K_THERM 	= KTherm_to_Par(cSPIN_CONF_PARAM_K_THERM);
	/* Intersect speed settings for BEMF compensation to cSPIN_CONF_PARAM_INT_SPD in steps/s, range 0 to 3906 steps/s */
	cSPIN_RegsStruct.INT_SPD 	= IntSpd_Steps_to_Par(cSPIN_CONF_PARAM_INT_SPD);
	/* BEMF start slope settings for BEMF compensation to cSPIN_CONF_PARAM_ST_SLP in % step/s, range 0 to 0.4% s/step */
	cSPIN_RegsStruct.ST_SLP 	= BEMF_Slope_Perc_to_Par(cSPIN_CONF_PARAM_ST_SLP);
	/* BEMF final acc slope settings for BEMF compensation to cSPIN_CONF_PARAM_FN_SLP_ACC in% step/s, range 0 to 0.4% s/step */
	cSPIN_RegsStruct.FN_SLP_ACC = BEMF_Slope_Perc_to_Par(cSPIN_CONF_PARAM_FN_SLP_ACC);
	/* BEMF final dec slope settings for BEMF compensation to cSPIN_CONF_PARAM_FN_SLP_DEC in% step/s, range 0 to 0.4% s/step */
	cSPIN_RegsStruct.FN_SLP_DEC = BEMF_Slope_Perc_to_Par(cSPIN_CONF_PARAM_FN_SLP_DEC);
	/* Stall threshold settings to cSPIN_CONF_PARAM_STALL_TH in mV, range 31.25 to 1000mV */
	cSPIN_RegsStruct.STALL_TH 	= StallTh_to_Par(cSPIN_CONF_PARAM_STALL_TH);
        /* Set Config register according to config parameters */
        /* clock setting, switch hard stop interrupt mode, */
        /*  supply voltage compensation, overcurrent shutdown */
        /* UVLO threshold, VCC reg output voltage , PWM frequency */
	cSPIN_RegsStruct.CONFIG 	= (uint16_t)cSPIN_CONF_PARAM_CLOCK_SETTING | \
                                          (uint16_t)cSPIN_CONF_PARAM_SW_MODE	   | \
                                          (uint16_t)cSPIN_CONF_PARAM_VS_COMP       | \
                                          (uint16_t)cSPIN_CONF_PARAM_OC_SD         | \
                                          (uint16_t)cSPIN_CONF_PARAM_UVLOVAL       | \
                                          (uint16_t)cSPIN_CONF_PARAM_VCCVAL	   | \
                                          (uint16_t)cSPIN_CONF_PARAM_PWM_DIV       | \
                                          (uint16_t)cSPIN_CONF_PARAM_PWM_MUL;

	/* Overcurrent threshold settings to cSPIN_CONF_PARAM_OCD_TH, range 31.25 to 1000mV */
	cSPIN_RegsStruct.OCD_TH 	= cSPIN_CONF_PARAM_OCD_TH;        
        /* Alarm settings to cSPIN_CONF_PARAM_ALARM_EN */
	cSPIN_RegsStruct.ALARM_EN 	= cSPIN_CONF_PARAM_ALARM_EN;
        /* Step mode and sycn mode settings via cSPIN_CONF_PARAM_SYNC_MODE and cSPIN_CONF_PARAM_STEP_MODE */
	cSPIN_RegsStruct.STEP_MODE 	= (uint8_t)cSPIN_CONF_PARAM_SYNC_MODE | \
                                          (uint8_t)cSPIN_CONF_PARAM_STEP_MODE;
    /* Sink/source current, duration of constant current phases, duration of overboost phase settings */
    cSPIN_RegsStruct.GATECFG1       = (uint16_t)cSPIN_CONF_PARAM_IGATE | \
                                      (uint16_t)cSPIN_CONF_PARAM_TCC   | \
                                      (uint16_t)cSPIN_CONF_PARAM_TBOOST;
    /* Blank time, Dead time stiings */
     cSPIN_RegsStruct.GATECFG2       = (uint16_t)cSPIN_CONF_PARAM_TBLANK | \
                                       (uint16_t)cSPIN_CONF_PARAM_TDT;
        /* Program all cSPIN registers */
	cSPIN_Registers_Set(&cSPIN_RegsStruct);

#if defined(DEBUG)
    /* check the values of all cSPIN registers */
    cSPIN_rx_data = cSPIN_Registers_Check(&cSPIN_RegsStruct);
    
    /* get the values of all cSPIN registers and print them to the terminal I/O */
    cSPIN_Registers_Get(&cSPIN_RegsStruct);
#endif /* defined(DEBUG) */
#else
/**********************************************************************/
        /* Start example of DAISY CHAINING */
        /**********************************************************************/
        /* Structure initialization by default values, in order to avoid blank records */
        for (i=0;i<number_of_slaves;i++)
        {
	   cSPIN_Regs_Struct_Reset(&cSPIN_RegsStructArray[i]);
        }
        
        /* Setting of parameters for ALL DEVICES */
        for (i=0;i<number_of_slaves;i++)
        {
          cSPIN_RegsStructArray[i].ACC 		= AccDec_Steps_to_Par(ACC[i]);
          cSPIN_RegsStructArray[i].DEC 		= AccDec_Steps_to_Par(DEC[i]);
          cSPIN_RegsStructArray[i].MAX_SPEED 	= MaxSpd_Steps_to_Par(MAX_SPEED[i]);
          cSPIN_RegsStructArray[i].FS_SPD 	= FSSpd_Steps_to_Par(FS_SPD[i]);
          cSPIN_RegsStructArray[i].MIN_SPEED	= LSPD_BIT[i]|MinSpd_Steps_to_Par(MIN_SPEED[i]);
          cSPIN_RegsStructArray[i].KVAL_ACC 	= Kval_Perc_to_Par(KVAL_ACC[i]);
          cSPIN_RegsStructArray[i].KVAL_DEC 	= Kval_Perc_to_Par(KVAL_DEC[i]);		
          cSPIN_RegsStructArray[i].KVAL_RUN 	= Kval_Perc_to_Par(KVAL_RUN[i]);
          cSPIN_RegsStructArray[i].KVAL_HOLD 	= Kval_Perc_to_Par(KVAL_HOLD[i]);
          cSPIN_RegsStructArray[i].K_THERM 	= KTherm_to_Par(K_THERM[i]);
          cSPIN_RegsStructArray[i].INT_SPD 	= IntSpd_Steps_to_Par(INT_SPD[i]);
          cSPIN_RegsStructArray[i].ST_SLP 	= BEMF_Slope_Perc_to_Par(ST_SLP[i]);
          cSPIN_RegsStructArray[i].FN_SLP_ACC   = BEMF_Slope_Perc_to_Par(FN_SLP_ACC[i]);
          cSPIN_RegsStructArray[i].FN_SLP_DEC   = BEMF_Slope_Perc_to_Par(FN_SLP_DEC[i]);
          cSPIN_RegsStructArray[i].STALL_TH 	= StallTh_to_Par(STALL_TH[i]);
          cSPIN_RegsStructArray[i].CONFIG 	= (uint16_t)CONFIG_CLOCK_SETTING[i] |
                                                  (uint16_t)CONFIG_SW_MODE[i] | \
                                                  (uint16_t)CONFIG_VS_COMP[i] | \
                                                  (uint16_t)CONFIG_OC_SD[i]   | \
                                                  (uint16_t)CONFIG_UVLOVAL[i] | \
                                                  (uint16_t)CONFIG_VCCVAL[i]  | \
                                                  (uint16_t)CONFIG_PWM_DIV[i] | \
                                                  (uint16_t)CONFIG_PWM_MUL[i];

          cSPIN_RegsStructArray[i].OCD_TH 	= OCD_TH[i];
          cSPIN_RegsStructArray[i].ALARM_EN 	= ALARM_EN[i];
          cSPIN_RegsStructArray[i].STEP_MODE 	= (uint8_t)SYNC_MODE[i] | (uint8_t)STEP_MODE[i];
          cSPIN_RegsStructArray[i].GATECFG1     = (uint16_t)GATECFG1_WD_EN[i]  | \
                                                  (uint16_t)GATECFG1_TBOOST[i] | \
                                                  (uint16_t)GATECFG1_IGATE[i]  | \
                                                  (uint16_t)GATECFG1_TCC[i];
          cSPIN_RegsStructArray[i].GATECFG2     = (uint16_t)GATECFG2_TBLANK[i] | \
                                                  (uint16_t)GATECFG2_TDT[i];
        }

        /* Program all cSPIN registers of All Devices */
        cSPIN_All_Slaves_Registers_Set(number_of_slaves, &cSPIN_RegsStructArray[0]);
  
        /* Get status of all devices, clear FLAG pin */
        cSPIN_All_Slaves_Get_Status(number_of_slaves, responseArray);
#endif
    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {

        UARTprintf("\n>");


        //
        // Peek to see if a full command is ready for processing
        //
        while(UARTPeek('\r') == -1)
        {
            //
            // millisecond delay.  A SysCtlSleep() here would also be OK.
            //
            SysCtlDelay(SysCtlClockGet() / (1000 / 3));

            //
            // Check for change of mode and enter hibernate if requested.
            // all other mode changes handled in interrupt context.
            //
            //if(g_sAppState.ui32Mode == APP_MODE_HIB)
            //{
            //    AppHibernateEnter();
            //}
        }

        //
        // a '\r' was detected get the line of text from the user.
        //
        UARTgets(g_cInput,sizeof(g_cInput));

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32CommandStatus = CmdLineProcess(g_cInput);

        //
        // Handle the case of bad command.
        //
        if(i32CommandStatus == CMDLINE_BAD_CMD)
        {
            UARTprintf("Bad command!\n");
        }

        //
        // Handle the case of too many arguments.
        //
        else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS)
        {
            UARTprintf("Too many arguments for command processor!\n");
        }
    }
}
//*****************************************************************************
//
// Read a command line from the user and process it.
//
//*****************************************************************************
void
CommandReadAndProcess(void)
{
    int iCount;

    //
    // Check to see if there is a string available in the UART receive
    // buffer.
    //
    iCount = UARTPeek('\r');

    //
    // A negative return code indicates that there is no '\r' character in
    // the receive buffer and, hence, no complete string entered by the user
    // so just return.
    //
    if(iCount < 0)
    {
        return;
    }

    //
    // Here, we know that a string is available so read it.
    //
    iCount = UARTgets(g_pcCmdLine, COMMAND_BUFFER_LEN);

    //
    // If something sensible was entered, go ahead and process the command
    // line.
    //
    if(iCount)
    {
        //
        // Process the command entered by the user
        //
        iCount = CmdLineProcess(g_pcCmdLine);

        switch(iCount)
        {
            //
            // The command was not recognized
            //
            case CMDLINE_BAD_CMD:
            {
                UARTprintf("ERROR: Unrecognized command\n");
                break;
            }

            //
            // The command contained too many arguments for the command
            // line processor to handle.
            //
            case CMDLINE_TOO_MANY_ARGS:
            {
                UARTprintf("ERROR: Too many arguments\n");
                break;
            }
        }

        //
        // Display a prompt
        //
        UARTprintf(">");
    }
}
Example #7
0
int main(void)
{
    UINT8  IsDHCP = 0;
    int32_t i32CommandStatus;
    _NetCfgIpV4Args_t ipV4;
		SlSockAddrIn_t    Addr; 
		UINT16            AddrSize = 0; 
		INT16             SockID = 0; 
		UINT32            data; 
		long x = 0; //counter
    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    int Status = 0;
    /* Stop WDT */
    stopWDT();
    /* Initialize the system clock of MCU */
    initClk();
		Board_Init();       // initialize LaunchPad I/O and PD1 LED
    ConfigureUART();    // Initialize the UART.
    UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
    UARTprintf("This application is configured to generate text\n");
    UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
		//added code from the powerpoint slide
    /* Initializing the CC3100 device */
    sl_Start(0, 0, 0);
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    Addr.sin_family = SL_AF_INET;
    Addr.sin_port = sl_Htons((UINT16)PORT_NUM);
    Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);
    AddrSize = sizeof(SlSockAddrIn_t);
    SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
    // Loop forever waiting  for commands from PC...
    //
    while(1)
    {
        // Print prompt for user.
        UARTprintf("\n>");
        // Peek to see if a full command is ready for processing.
        while(UARTPeek('\r') == -1)
						LED_On();
            // Approximately 1 millisecond delay.
            ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000);

        }
        // A '\r' was detected so get the line of text from the receive buffer.
		while(Status >= 0){
      UARTprintf("\nSending a UDP packet ...\n");
		
			UARTgets(g_cInput,sizeof(g_cInput)); //this function receives the input from the Putty and places it in a string

			
			
			//DO NOT CHANGE ANYTHING ABOVE THIS COMMENT
			
			//WHAT WE NEED TO DO:
			//work with the g_cInput to get the array of letters typed into the Putty
			//then send that Array using UARTprintf
			uBuf[0] = ATYPE;   // defines this as an analog data type
			uBuf[1] = '='; 
			data = 1000;

			Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number
      UARTprintf(" %s ",uBuf); //this line sends a string to the receiver
      //the above 5 lines print out a = 1000;
			//everything below this is just error cases
			if( SockID < 0 ){
        UARTprintf("SockIDerror ");
        Status = -1; // error
      }else{
        LED_Toggle();
        Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0,
                           (SlSockAddr_t *)&Addr, AddrSize);
        if( Status <= 0 ){
          sl_Close(SockID);
          UARTprintf("SockIDerror %d ",Status);
        }else{
          UARTprintf("ok");
        }
      }
      ROM_SysCtlDelay(ROM_SysCtlClockGet() / 100); // 10ms
			LED_Off();
		}
   }