read time from gps

master
Eggert Jung 6 years ago
parent 5e2934df71
commit fd31f5acd1

@ -4,6 +4,7 @@
#include <util/delay.h>
#include <avr/interrupt.h> //interrupts
#include <stdlib.h>
#include <string.h>
#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<<RXC0)) ){}; //RXC = Recive complete
char uart_Buffer[500];
char time_string[6];
char sat_string[2];
sat_string[0]='1';
sat_string[1]= '1';
for(int k = 0; k < 6; k++){
time_string[k] = '8';
}
int i = 0;
while(UDR0 != '\r' && i < 500){
uart_Buffer[i] = UDR0;
i++;
PORTB ^=STATUS_LED_B;
}
for(int j = 0; j < 500; j++){
//if(uart_Buffer[j] == '$'){
if(uart_Buffer[j+1] == 'G'){
if(uart_Buffer[j+2] == 'P'){
if(uart_Buffer[j+3] == 'Z'){
if(uart_Buffer[j+4] == 'D'){
if(uart_Buffer[j+5] == 'A'){
//j++;
sat_string[0] = uart_Buffer[1];
sat_string[1] = uart_Buffer[100];
//time_string[0] = uart_Buffer[j+36];
//time_string[1] = uart_Buffer[j+37];
//time_string[2] = uart_Buffer[j+8];
//time_string[3] = uart_Buffer[j+9];
//time_string[5] = uart_Buffer[j+10];
//time_string[6] = uart_Buffer[j+11];
}
}
}
}
}
// }
}
print_String(sat_string);
ISR(USART0_RX_vect)
{
static char async_input_buffer[RX_INPUT_BUFFER_SIZE];
static uint8_t async_buffer_pointer = 0;
*/
uint8_t data = UART_DATA_REG;
if(!(data == '\n' || data == '\r')){
async_input_buffer[async_buffer_pointer]=data;
async_buffer_pointer++;
}
else if(async_buffer_pointer>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;
}

Loading…
Cancel
Save