int main(void) { // Initialize all hardware PLL_Init(); eStopInit(); encoderInit(actlPos); motorInit(); lightsInit(); lightsUpdate(COLOR_RED); UART_Init(); Timer1_Init(); softRun(); // Send welcome message to UART terminal UART_OutChar('W');UART_OutChar('e');UART_OutChar('l');UART_OutChar('c'); UART_OutChar('o');UART_OutChar('m');UART_OutChar('e'); UART_OutChar(CR);UART_OutChar(LF); // Spin forever while(1) { parse(UART_InUDec()); // read commands from UART // All other functions performed by Timer 1 interrupt handler } }
//------------cmdCAN----------------- // Control CAN. void cmdCAN(void){ printf("Choose a command for CAN:\n\r"); printf(" (1) Get Data - Get the data received in FIFO.\n\r"); printf(" (2) Send Data - Send four bytes of data.\n\r"); printf(" (3) Lost Packets - Display how many packets were lost.\n\r"); printf("--Enter Command #--> "); uint32_t selection = UART_InUDec(); printf("\n\r"); switch(selection){ // View data case(1):{ uint8_t data[8]; unsigned long counter = 1; printf("The data in the CAN0 fifo is as follows:\n\r"); if(CAN0PutPt!=CAN0GetPt){//if there is one do{//for all data in fifo data[0] = CAN0_Fifo_Get();//Byte 0 data[1] = CAN0_Fifo_Get();//Byte 1 data[2] = CAN0_Fifo_Get();//Byte 2 data[3] = CAN0_Fifo_Get();//Byte 3 data[4] = CAN0_Fifo_Get();//Byte 4 data[5] = CAN0_Fifo_Get();//Byte 5 data[6] = CAN0_Fifo_Get();//Byte 6 // data[7] = CAN0_Fifo_Get();//Byte 7 //get data and print it printf("Output %lu IR0 = %u\n\r", counter, data[0]); printf("Output %lu IR1 = %u\n\r", counter, data[1]); printf("Output %lu IR2 = %u\n\r", counter, data[2]); printf("Output %lu IR3 = %u\n\r", counter, data[3]); printf("Output %lu Ping1 = %u\n\r", counter, data[4]); printf("Output %lu Bumper0 = %u\n\r", counter, data[5]); printf("Output %lu Bumper1 = %u\n\r", counter, data[6]); // printf("Output %lu Start = %u\n\r\n\r", counter, data[7]); counter++;//increment counter }while(CAN0PutPt!=CAN0GetPt); } else{//if there is none printf("none"); printf("\n\r"); } break; } // Send data case(2):{ uint8_t data[8]; uint32_t input; for(int i = 0; i < 8; i++){//for Bytes 0-7 switch(i){//for every different sensor case 0: printf("What is the input from IR0 (0-255): "); break; case 1: printf("\n\rWhat is the input from IR1 (0-255): "); break; case 2: printf("\n\rWhat is the input from IR2 (0-255): "); break; case 3: printf("\n\rWhat is the input from IR3 (0-255): "); break; case 4: printf("\n\rWhat is the input from Ping1 (0-255): "); break; case 5: printf("\n\rWhat is the input from Bumper0 (0-255): "); break; case 6: printf("\n\rWhat is the input from Bumper1 (0-255): "); break; // case 7: // printf("\n\rWhat is the input from Start (0-255): "); // break; } input=UART_InUDec(); if(input>255){ printf("\n\rImproper selection\n\r"); return; } else{ data[i] = input&0x000000FF;//store the byte } } CAN0_SendData(data);//send 8 bytes of data printf("\n\rYour inputs were sent.\n\r"); break; } // Lost packets case(3):{ printf("\n\r%lu packets have been lost.\n\r", PacketLost); break; } default: { printf("Improper selection\n\r"); return; } } }
void Interpreter(void) // just a prototype, link to your interpreter { uint32_t stringSize; uint32_t adcVoltage; uint8_t deviceChosen; uint8_t taskAddedBefore = 0; uint8_t commandChosen = -1; char message[MESSAGELENGTH] = ""; OutCRLF(); UART_OutString("Input Command: "); while(1){ OutCRLF(); //UART_OutString("Commands: 0 - ADC, 1 - LCD, 2 - Time"); OutCRLF(); commandChosen = UART_InChar(); switch(commandChosen) { case '0': OutCRLF(); UART_OutString("ADC Voltage = "); //ADC_Open(4); adcVoltage = (ADC_In() *3300) / 4095; //convert to mV UART_OutUDec(adcVoltage); OutCRLF(); break; case '1': OutCRLF(); UART_OutString("Enter LCD device 0 or 1: "); deviceChosen = UART_InUDec(); OutCRLF(); UART_OutString("Enter message: "); UART_InString(message, MESSAGELENGTH); OutCRLF(); stringSize = strlen(message); if(stringSize > 20) { OutCRLF(); UART_OutString("String too long..."); OutCRLF(); } LCD_test(deviceChosen, message); //prints to lcd OutCRLF(); break; case '2': if(!taskAddedBefore){ OS_AddPeriodicThread(dummy, 5, 1); taskAddedBefore = 1; } OutCRLF(); UART_OutUDec(OS_ReadPeriodicTime()); OutCRLF(); break; case '3': UART_OutString("NumSamples: "); UART_OutUDec(NumSamples); OutCRLF(); break; case '4': UART_OutString("Jitter: "); UART_OutUDec(MaxJitter); OutCRLF(); break; case '5': UART_OutString("DataLost: "); UART_OutUDec(DataLost); OutCRLF(); break; case '6': UART_OutString("FilterWork: "); UART_OutUDec(FilterWork); OutCRLF(); break; case '7': UART_OutString("NumCreated: "); UART_OutUDec(NumCreated); OutCRLF(); break; case '8': for(int i = 0; i<64; i++) { UART_OutUDec(x[i]); OutCRLF(); } break; default: UART_OutString("Incorrect command!"); break; } //adcSample = ADC_In(); //ST7735_SetCursor(0,0); //ST7735_OutUDec(adcSample); } }