diff --git a/code/src/main.c b/code/src/main.c index f07406d..e276826 100644 --- a/code/src/main.c +++ b/code/src/main.c @@ -4,6 +4,7 @@ #include #include //interrupts #include +#include #include "pinout.h" #include "print.h" #include "adc.h" @@ -11,6 +12,7 @@ #include "i2cmaster.h" #include "DS3231.h" +#define RX_INPUT_BUFFER_SIZE 92 /*README DIP1 aktiviert Röhren-Schaltregler @@ -30,11 +32,32 @@ void check_buttons(void); void setup(void); void set_PWM_duty(int dutycycle); +uint8_t parse_nmea_gps(char input_string[RX_INPUT_BUFFER_SIZE], uint8_t output_buffer[3]){ + char* token = strsep(&input_string, ","); + if(!strcmp("$GPRMC", token)){ + char* time = strsep(&input_string, ","); + if(!strlen(time)){ + // no valid time available + return -1; + } + + // craft bcd values + output_buffer[0] = (time[0] - 48) << 4; + output_buffer[0] |= time[1] - 48; + + output_buffer[1] = (time[2] - 48) << 4; + output_buffer[1] |= time[3] - 48; + + output_buffer[2] = (time[4] - 48) << 4; + output_buffer[2] |= time[5] - 48; + + return 0; + } +} + int main(void){ setup(); - printf("test\n\r"); - while(1){ _delay_ms(500); @@ -154,10 +177,10 @@ void setup(){ TCCR1B = (0 << WGM02); - //Prescaler von 1024 - TCCR1B |= (1 << CS02) | - (0 << CS01) | - (1 << CS00) ; + ////Prescaler von 1024 + //TCCR1B |= (1 << CS02) | + // (0 << CS01) | + // (1 << CS00) ; //Output compare Regsiter (Setzt Zeit bei der Interrupt auslösen soll) @@ -186,6 +209,12 @@ void setup(){ } + +void set_PWM_duty(int dutycycle){ + OCR2A = dutycycle; + } + + //Timer 1 Interrupt ISR (TIMER1_OVF_vect) // Timer1 ISR { @@ -218,63 +247,23 @@ ISR(INT1_vect) { } -ISR (USART0_RX_vect){ - /* -//while ( !(UCSR0A & (1<0){ + async_input_buffer[async_buffer_pointer] = 0; // Null terminate string + async_buffer_pointer=0; + PORTB ^=STATUS_LED_C; + uint8_t test[3]; + if(!parse_nmea_gps(async_input_buffer, test)) + printf("parse: %x %x %x\n\r", test[0], test[1], test[2]); + } } -void set_PWM_duty(int dutycycle){ - OCR2A = dutycycle; - } -