Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
226 eqlazer 1
/**
2
 * CanGPS.
3
 *
4
 * @date    2001-01-09
5
 * @author  Erik Larsson
6
 */
7
 
8
#define DEBUG           0 /* Prints debug messages to uart, only use this function if output is not connected to GPS */
9
 
10
/*-----------------------------------------------------------------------------
11
 * Includes
12
 *---------------------------------------------------------------------------*/
13
/* system files */
14
#include <avr/io.h>
15
#include <avr/interrupt.h>
16
#include <avr/wdt.h>
17
#include <stdio.h>
18
#include <string.h>
19
/* lib files */
20
#include <can.h>
21
#include <serial.h>
22
#include <uart.h>
23
#include <timebase.h>
24
 
25
/* defines */
26
#define GPS_CMD_GET     0x1400
27
#define GPS_CMD_SEND    0x1401
28
#define STATUS_SEND_PERIOD 500 /* milliseconds */
29
 
30
#define TRUE 1
31
#define FALSE !TRUE
32
#define CR 0x0D
33
#define LF 0x0A
34
 
35
/*-------------------------------------------------------------------------
36
 * Global variables
37
 * -----------------------------------------------------------------------*/
38
 
39
/*----------------------------------------------------------------------------
40
 * Functions
41
 * -------------------------------------------------------------------------*/
42
 
43
/*----------------------------------------------------------------------------
44
 * Interrupt routines
45
 * -------------------------------------------------------------------------*/
46
ISR( PCINT2_vect )
47
{
48
}
49
 
50
/*-----------------------------------------------------------------------------
51
 * Main Program
52
 *---------------------------------------------------------------------------*/
53
int main(void) {
54
 
55
    uint32_t timeStamp = 0, timeStampTurn = 0;
56
    uint8_t buffering = FALSE, gpsMsg_received = FALSE, rxGps_element;
57
    char buffer[100], rxGps;
58
 
59
    Timebase_Init();
60
    Serial_Init();
61
 
62
    sei();
63
#if DEBUG
64
    printf("\n------------------------------------------------------------\n");
65
    printf(  "   CAN: GPS\n");
66
    printf(  "------------------------------------------------------------\n");
67
 
68
    printf("CanInit...");
69
    if (Can_Init() != CAN_OK) {
70
        printf("FAILED!\n");
71
    }else{
72
        printf("OK!\n");
73
    }
74
#else
75
    Can_Init();
76
#endif
77
 
78
    Can_Message_t txMsg;
79
    Can_Message_t rxMsg;
80
    txMsg.Id = GPS_CMD_SEND;
81
    txMsg.RemoteFlag = 0;
82
    txMsg.ExtendedFlag = 1;
83
    txMsg.DataLength = 3;
84
 
85
    /* main loop */
86
    while (1) {
87
        /* service the CAN routines */
88
        Can_Service();
89
 
90
        /* check if any messages have been received */
91
        while (Can_Receive(&rxMsg) == CAN_OK) {
92
            /* This node that control a servo is adressed */
93
            if( rxMsg.Id == GPS_CMD_GET ){
94
 
95
            }
96
        }
97
 
98
        if( Timebase_PassedTimeMillis(timeStamp) >= STATUS_SEND_PERIOD ){
99
            timeStamp = Timebase_CurrentTime();
100
            /* Send blinds status to CAN */
101
 
102
        }
103
 
104
        /* Get data from GPS */
105
        rxGps = uart_getc();
106
        while( rxGps != UART_NO_DATA ){
107
            /* '$' indicates start of message, start buffering */
108
            if( rxGps == '$' ){
109
                buffering = TRUE;
110
                rxGps_element = 0;
111
            }else if( rxGps == CR ){
112
                /* End of message */
113
                buffer[rxGps_element]='\0';
114
                buffering = FALSE;
115
                gpsMsg_received = TRUE;
116
            }
117
 
118
            if( buffering ){
119
                buffer[ rxGps_element ] = rxGps;
120
                rxGps_element++;
121
            }
122
            /* Get next character */
123
            rxGps = uart_getc();
124
        }
125
 
126
        if( gpsMsg_received ){
127
            /* One whole msg is completed, start compare and parse */
128
            if( !strncmp(buffer, "GPGGA", 5) ){
129
                /* Standard NMEA message, $GPGGA */
130
 
131
            }else if( !strncmp(buffer, "GPVTG", 5) ){
132
                /* Standard NMEA message, $GPVTG */
133
 
134
            }else if( !strncmp(buffer, "GPZDA", 5) ){
135
                /* Standard NMEA message, $GPZDA */
136
            }
137
 
138
            gpsMsg_received = FALSE; /* Get ready for next message */
139
 
140
        }
141
    }
142
    return 0;
143
}
144