![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This is car control simulation by using Mbed controller and real time operating system.
Dependencies: MCP23017 Servo WattBob_TextLCD mbed-rtos mbed
Fork of Ass3 by
Diff: CAR.cpp
- Revision:
- 9:d86a6b8cdfa4
- Parent:
- 8:6e55db96c11c
- Child:
- 10:2522e3878e1c
diff -r 6e55db96c11c -r d86a6b8cdfa4 CAR.cpp --- a/CAR.cpp Wed Apr 09 09:41:30 2014 +0000 +++ b/CAR.cpp Wed Apr 09 11:05:32 2014 +0000 @@ -1,24 +1,23 @@ #include "CAR.h" Semaphore CAR_MAIL_SEM(1); -Semaphore INPUT_SEM(2); -Semaphore SWITCH_SEM(3); +Semaphore INPUT_SEM(3); +Semaphore SWITCH_SEM(2); uint32_t Element_Counter_W = 0; uint32_t Element_Counter_R = 0; -typedef struct { - uint8_t Mail_Average_Speed; - float Mail_Accelerometer_Value; - float Mail_Brake_Value; - int Counter; - } CAR_MAIL; + static Mail<CAR_MAIL, 100> mail_box; bool LSide_Indicator_Value; bool RSide_Indicator_Value; - + // Create the local filesystem under the name "local" +LocalFileSystem local("local"); + CAR::CAR(){ Port.write_bit(1,BL_BIT); - - + FILE *fp = fopen("/local/Car_Values.csv", "w"); // Open "out.txt" on the local file system for writing + fprintf(fp, "Counter,Average_Speed,Accelerometer_Value,Brake_Value\r\n"); + fclose(fp); } + void CAR::SAVE_ODO(float value) { LPC_RTC->GPREG0 = *((uint32_t*)&value); } @@ -87,19 +86,19 @@ Thread::wait(500); } } -void CAR::SEND_CAR_VALUES (void const *args) { - +void CAR::SEND_CAR_VALUES (void const *args) { while (true) { CAR_MAIL *mail = mail_box.alloc(); CAR_MAIL_SEM.wait(); + INPUT_SEM.wait(); mail->Mail_Average_Speed = Average_Speed; mail->Mail_Accelerometer_Value = Accelerometer_Value; mail->Mail_Brake_Value = Brake_Value; mail->Counter = Element_Counter_W ; mail_box.put(mail); - printf("\n %i £ \n\r",Element_Counter_W); Element_Counter_W++; CAR_MAIL_SEM.release(); + INPUT_SEM.release(); Thread::wait(5000); } } @@ -116,11 +115,14 @@ printf("Writing \n\r"); osEvent evt = mail_box.get(10); CAR_MAIL *mail = (CAR_MAIL*)evt.value.p; - if (evt.status == osEventMail) { - printf("\nAverage_Speed: %i MPH\n\r" , mail->Mail_Average_Speed); - printf("Accelerometer_Value: %.3f %\n\r" , mail->Mail_Accelerometer_Value); - printf("Brake_Value: %.3f %\n\r", mail->Mail_Brake_Value); - printf("\nCounter: %i \n\r" , mail->Counter); + if (evt.status == osEventMail) { + FILE *fp = fopen("/local/Car_Values.csv", "a"); // Open "out.txt" on the local file system for writing + fprintf(fp,"%i ," , mail->Counter); + fprintf(fp,"%i ,", mail->Mail_Average_Speed); + fprintf(fp,"%.3f ," , mail->Mail_Accelerometer_Value); + fprintf(fp,"%.3f ", mail->Mail_Brake_Value); + fprintf(fp,"\r\n"); + fclose(fp); mail_box.free(mail); Element_Counter_R++; }