예제 #1
0
파일: main.c 프로젝트: dapryor/Embedded
void main(void){
//==============================================================================
// Main Program
// 
// Description: This function contains the while loop that runs continuously
// to act for the operating system. It also calls all the functions to
// initialize the system.
//
// Passed : no variables passed
// Locals: no variables declared
// Returned: no values returned
// Globals:     volatile unsigned int Time_Sequence;
//              volatile char one_time;
//              char* display_1
//              char* display_2
//              char* display_3
//              char* display_4
//              slow_input_down
//              control_state[CNTL_STATE_INDEX]
//              char big
//              char size_count;
//              char posL1
//              char posL2
//              char posL3
//              char posL4
//
// Author: David Pryor
// Date: Feb 2016
// Compiler: Built with IAR Embedded Workbench Version: V4.10A/W32 (6.4.1)
//==============================================================================
  Init_Ports();                             // Initialize Ports
  Init_Clocks();                            // Initialize Clock System 
  Init_Conditions();
  Time_Sequence = SWITCH_OFF;               // 
  Init_Timers();                            // Initialize Timers
  Init_LEDs();                              // Initialize LEDs
  Init_LCD();                               // Initialize LCD
  Init_ADC();                               // Initialize ADC
  Init_Serial_UCA1(0);                      // BAUD rate 9600
  Init_Serial_UCA0(1);                      // BAUD rate 9600
  Five_msec_Delay(1);
  PJOUT |= IOT_STA_MINIAP; //turning on miniap (only works this way)
  IR_LED_OFF();
  lcd_BIG_mid();
  display_1 = "  David   ";
  display_2 = "Project  8";  
  display_3 = "  Pryor   ";
  display_4 = "";
  Display_Process();



//------------------------------------------------------------------------------
// Begining of the "While" Operating System
//------------------------------------------------------------------------------
  while(ALWAYS) {                            // Can the Operating system run
    
    ADC_Process();              // call sampling function
    if(MainFG){
        Menu_Process();
    }
    else if(BaudMenuFG==TRUE){
        Baud_Menu(); 
    }
    else if(IOTMenuFG==TRUE){
        IOT_Menu();
    }
    
    if(StartCommandFG){ //StartCommandFG is true once "." has been received
        commandTree();
    }
    printMacAddress(); //prints mac address to screen
    macFG=FALSE; //turn off command to print mac address
    clearReceiveBuffer();
    parseIOTData();
  }
//------------------------------------------------------------------------------
}
예제 #2
0
void receive_command(char* command)
{
  BufferString temp_command;
  temp_command.head = command;
  temp_command.offset = START_ZERO;
  
  if(compare(command, COMMAND_AKNOWLEDGE))
  {
    uca0_transmit_message(AKNOWLEDGE_MESSAGE, NO_OFFSET);
  }
  else if(compare(command, SLOW_BAUD))
  {
    uca1_set_current_baud(BAUD_115200);
    
    uca0_transmit_message(SLOW_BAUD_MESSAGE, NO_OFFSET);  
    uca1_transmit_message(SLOW_BAUD_COMMAND, NO_OFFSET);  
    
    five_msec_delay(SECOND + SECOND);
    
    uca1_transmit_message(SAVE_COMMAND, NO_OFFSET); 
    
    
    five_msec_delay(SECOND);
    uca1_set_current_baud(BAUD_9600);
    
    uca1_transmit_message(RESET_COMMAND, NO_OFFSET);
    PJOUT &= ~IOT_RESET;
    
    five_msec_delay(QUARTER_SECOND);
    
    PJOUT |= IOT_RESET;  
    
    uca0_transmit_message(RESET_MESSAGE, NO_OFFSET);
    
    five_msec_delay(QUARTER_SECOND);
    
    uca1_transmit_message(G_MAC_COMMAND, NO_OFFSET);
  }
  else if(compare(command, FAST_BAUD))
  {
     uca1_set_current_baud(BAUD_9600);
    
    uca0_transmit_message(FAST_BAUD_MESSAGE, NO_OFFSET);  
    uca1_transmit_message(FAST_BAUD_COMMAND, NO_OFFSET);  
    
    five_msec_delay(SECOND + SECOND);
    
    uca1_transmit_message(SAVE_COMMAND, NO_OFFSET); 
    
    
    five_msec_delay(SECOND);
    uca1_set_current_baud(BAUD_115200);
    
    uca1_transmit_message(RESET_COMMAND, NO_OFFSET);
    PJOUT &= ~IOT_RESET;
    
    five_msec_delay(QUARTER_SECOND);
    
    PJOUT |= IOT_RESET;  
    
    uca0_transmit_message(RESET_MESSAGE, NO_OFFSET);
  }
  else if(compare(command, CONNECT_NCSU))
  {
    uca0_transmit_message(CONNECT_NCSU_MESSAGE, NO_OFFSET);    
    uca1_transmit_message(SET_SSID_NCSU_COMMAND, NO_OFFSET);
    uca1_transmit_message(GET_SSID_NCSU_COMMAND, NO_OFFSET);
    
    five_msec_delay(QUARTER_SECOND);
    
    uca1_transmit_message(SET_HOST_NAME_COMMAND, NO_OFFSET);
    uca1_transmit_message(GET_HOST_NAME_COMMAND, NO_OFFSET);
    
    five_msec_delay(QUARTER_SECOND);
    
    uca1_transmit_message(SET_PRIVACY_MODE_COMMAND, NO_OFFSET);
    uca1_transmit_message(GET_PRIVACY_MODE_COMMAND, NO_OFFSET);
    
    five_msec_delay(QUARTER_SECOND);
    
    uca1_transmit_message(SET_NETWORK_MODE_COMMAND, NO_OFFSET);
    uca1_transmit_message(GET_NETWORK_MODE_COMMAND, NO_OFFSET);
    
    uca1_transmit_message(SAVE_COMMAND, NO_OFFSET);
    uca1_transmit_message(GET_NETWORK_MODE_COMMAND, NO_OFFSET);
    
    uca1_transmit_message(SAVE_COMMAND, NO_OFFSET);
    
    five_msec_delay(QUARTER_SECOND);
    
    uca1_transmit_message(RESET_COMMAND, NO_OFFSET);
    PJOUT &= ~IOT_RESET;
    
    five_msec_delay(QUARTER_SECOND);    
    PJOUT |= IOT_RESET;  
    
    uca0_transmit_message(RESET_MESSAGE, NO_OFFSET);   
  }
  else if(compare(command, GET_WIFI_STATUS))
  {
    uca1_transmit_message(GET_WIFI_STATUS_COMMAND, NO_OFFSET);
  }
  else if(compare(command, GET_WIFI_IP))
  {
    uca1_transmit_message(GET_WIFI_IP_COMMAND, NO_OFFSET);
  }
  // Forward Command
  else if(find(CAR_FORWARD, temp_command))
  {
    display_1 = CLEAR_LINE;
    display_2 = command;
    display_3 = CLEAR_LINE;
    display_4 = CLEAR_LINE;
    
    set_motor_speed(R_FORWARD, (int) (MAX_SPEED * 0.87f));
    set_motor_speed(L_FORWARD, MAX_SPEED);
    
    lcd_BIG_mid();
    five_msec_delay(QUARTER_SECOND);
    Display_Process();
    
    uca0_transmit_message("SUCCESS", NO_OFFSET);    
     
    turn_on_motor(R_FORWARD);
    turn_on_motor(L_FORWARD);
    
    if(CH_TO_DIG(command[COMMAND_TIME_POS]) <= 9)
      five_msec_delay(SECOND * CH_TO_DIG(command[COMMAND_TIME_POS]) / COMMAND_TURN_RATIO);
    
    turn_off_motor(R_FORWARD);
    turn_off_motor(L_FORWARD);
    
     lcd_4line();
     
     if(command[COMMAND_LENGTH] == COMMAND_CHAR_SYMBOL)
       receive_command(command + COMMAND_LENGTH);
  }
  // Backward Command
   else if(find(CAR_BACKWARD, temp_command))
  {
    display_1 = CLEAR_LINE;
    display_2 = command;
    display_3 = CLEAR_LINE;
    display_4 = CLEAR_LINE;
    
    lcd_BIG_mid();
    five_msec_delay(QUARTER_SECOND);
    Display_Process();
    
     uca0_transmit_message("SUCCESS", NO_OFFSET);    
     
    turn_on_motor(R_REVERSE);
    turn_on_motor(L_REVERSE);
    
    five_msec_delay(SECOND * CH_TO_DIG(command[COMMAND_TIME_POS]));
    
    turn_off_motor(R_REVERSE);
    turn_off_motor(L_REVERSE);
    
     lcd_4line();
     
     if(command[COMMAND_LENGTH] == COMMAND_CHAR_SYMBOL)
       receive_command(command + COMMAND_LENGTH);
  }
  // Right Command
   else if(find(CAR_RIGHT, temp_command))
  {
    display_1 = CLEAR_LINE;
    display_2 = command;
    display_3 = CLEAR_LINE;
    display_4 = CLEAR_LINE;
    
    lcd_BIG_mid();
    five_msec_delay(QUARTER_SECOND);
    Display_Process();
    
     uca0_transmit_message("SUCCESS", NO_OFFSET);    
     
    turn_on_motor(R_REVERSE);
    turn_on_motor(L_FORWARD);
    
    if(CH_TO_DIG(command[COMMAND_TIME_POS]) <= 9)
      five_msec_delay(SECOND * CH_TO_DIG(command[COMMAND_TIME_POS]) / COMMAND_TURN_RATIO);
    
    turn_off_motor(R_REVERSE);
    turn_off_motor(L_FORWARD);
    
     lcd_4line();
     
     if(command[COMMAND_LENGTH] == COMMAND_CHAR_SYMBOL)
       receive_command(command + COMMAND_LENGTH);
  }
  // Left Command
   else if(find(CAR_LEFT, temp_command))
  {
    display_1 = CLEAR_LINE;
    display_2 = command;
    display_3 = CLEAR_LINE;
    display_4 = CLEAR_LINE;
    
    lcd_BIG_mid();
    five_msec_delay(QUARTER_SECOND);
    Display_Process();
    
    uca0_transmit_message("SUCCESS", NO_OFFSET);    
     
    turn_on_motor(R_FORWARD);
    turn_on_motor(L_REVERSE);
    
     if(CH_TO_DIG(command[COMMAND_TIME_POS]) <= 9)
      five_msec_delay(SECOND * CH_TO_DIG(command[COMMAND_TIME_POS]) / COMMAND_TURN_RATIO);
    
    turn_off_motor(R_FORWARD);
    turn_off_motor(L_REVERSE);
    
     lcd_4line();
     
     if(command[COMMAND_LENGTH] == COMMAND_CHAR_SYMBOL)
       receive_command(command + COMMAND_LENGTH);
  }
  else if(find(CAR_LINE_FOLLOW, temp_command))
  {
    is_follow_running = is_follow_running ? FALSE : TRUE;
  }
}