Subversion Repositories HomeAutomation

Rev

Rev 226 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 226 Rev 227
Line 1... Line 1...
1
/**
1
/**
2
 * CanGPS.
2
 * CanGPS.
-
 
3
 *
-
 
4
 * Messages: <byte0><byte1>...<byte7>
-
 
5
 * $GPGGA: <GGA_MSG><UTC><Latitude><Latitude dec.><N/S><Longitude><Longitude dec.><E/W>
-
 
6
 * $GPVTG: <VTG_MSG><Course true><Course dec. true><Course magnetic><Course dec. magnetic><Speed km/h><Speed dec. km/h>
-
 
7
 * $GPZDA: <ZDA_MSG><hh><mm><ss><day><month><year>
3
 *
8
 *
4
 * @date    2001-01-09
9
 * @date    2001-01-09
5
 * @author  Erik Larsson
10
 * @author  Erik Larsson
6
 */
11
 */
7
 
12
 
Line 24... Line 29...
24
 
29
 
25
/* defines */
30
/* defines */
26
#define GPS_CMD_GET     0x1400
31
#define GPS_CMD_GET     0x1400
27
#define GPS_CMD_SEND    0x1401
32
#define GPS_CMD_SEND    0x1401
28
#define STATUS_SEND_PERIOD 500 /* milliseconds */
33
#define STATUS_SEND_PERIOD 500 /* milliseconds */
-
 
34
 
-
 
35
#define GGA_MSG     0x01
-
 
36
#define VTG_MSG     0x02
-
 
37
#define ZDA_MSG     0x03
-
 
38
#define GGA_MSG_BYTES 8
-
 
39
#define VTG_MSG_BYTES 7
-
 
40
#define ZDA_MSG_BYTES 7
29
 
41
 
30
#define TRUE 1
42
#define TRUE 1
31
#define FALSE !TRUE
43
#define FALSE !TRUE
32
#define CR 0x0D
44
#define CR 0x0D
33
#define LF 0x0A
45
#define LF 0x0A
-
 
46
#define GPS_MSG_DELIMITER ","
34
 
47
 
35
/*-------------------------------------------------------------------------
48
/*-------------------------------------------------------------------------
36
 * Global variables
49
 * Global variables
37
 * -----------------------------------------------------------------------*/
50
 * -----------------------------------------------------------------------*/
38
 
51
 
Line 49... Line 62...
49
 
62
 
50
/*-----------------------------------------------------------------------------
63
/*-----------------------------------------------------------------------------
51
 * Main Program
64
 * Main Program
52
 *---------------------------------------------------------------------------*/
65
 *---------------------------------------------------------------------------*/
53
int main(void) {
66
int main(void) {
54
 
-
 
55
    uint32_t timeStamp = 0, timeStampTurn = 0;
67
    uint32_t timeStamp = 0, timeStampTurn = 0;
56
    uint8_t buffering = FALSE, gpsMsg_received = FALSE, rxGps_element;
68
    uint8_t buffering = FALSE, gpsMsg_received = FALSE, rxGps_element;
57
    char buffer[100], rxGps;
69
    char buffer[100], rxGps;
-
 
70
    /* GPGGA, Global positioning system fix data */
-
 
71
    char gga_utc[7], gga_latitude[9], gga_latitude_NS, gga_longitude[10], gga_longitude_EW;
-
 
72
    /* GPVTG, Course over ground and speed */
-
 
73
    char vtg_course_true[6], vtg_course_magnetic[6], vtg_speed_kmh[6];
-
 
74
    /* GPZDA, Time & Date */
-
 
75
    char zda_time[7], zda_day[3], zda_month[3], zda_year[5];
-
 
76
 
-
 
77
    char *pch;
58
 
78
 
59
    Timebase_Init();
79
    Timebase_Init();
60
    Serial_Init();
80
    Serial_Init();
61
 
81
 
62
    sei();
82
    sei();
Line 90... Line 110...
90
        /* check if any messages have been received */
110
        /* check if any messages have been received */
91
        while (Can_Receive(&rxMsg) == CAN_OK) {
111
        while (Can_Receive(&rxMsg) == CAN_OK) {
92
            /* This node that control a servo is adressed */
112
            /* This node that control a servo is adressed */
93
            if( rxMsg.Id == GPS_CMD_GET ){
113
            if( rxMsg.Id == GPS_CMD_GET ){
94
 
114
 
95
            }
115
            }
96
        }
116
        }
97
 
117
 
98
        if( Timebase_PassedTimeMillis(timeStamp) >= STATUS_SEND_PERIOD ){
118
        if( Timebase_PassedTimeMillis(timeStamp) >= STATUS_SEND_PERIOD ){
99
            timeStamp = Timebase_CurrentTime();
119
            timeStamp = Timebase_CurrentTime();
100
            /* Send blinds status to CAN */
120
            /* Send blinds status to CAN */
101
 
121
 
102
        }
122
        }
Line 125... Line 145...
125
 
145
 
126
        if( gpsMsg_received ){
146
        if( gpsMsg_received ){
127
            /* One whole msg is completed, start compare and parse */
147
            /* One whole msg is completed, start compare and parse */
128
            if( !strncmp(buffer, "GPGGA", 5) ){
148
            if( !strncmp(buffer, "GPGGA", 5) ){
129
                /* Standard NMEA message, $GPGGA */
149
                /* Standard NMEA message, $GPGGA */
-
 
150
                strtok(buffer, GPS_MSG_DELIMITER); /* Throw away "GPGGA" */
-
 
151
 
-
 
152
                /* Get UTC */
-
 
153
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
154
                strcpy(gga_utc, pch);
-
 
155
 
-
 
156
                /* Get latitude */
-
 
157
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
158
                strcpy(gga_latitude, pch);
-
 
159
 
-
 
160
                /* Get latitude N/S */
-
 
161
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
162
                strcpy(gga_latitude_NS, pch);
-
 
163
 
-
 
164
                /* Get longitude */
-
 
165
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
166
                strcpy(gga_longitude, pch);
-
 
167
 
-
 
168
                /* Get longitude E/W */
-
 
169
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
170
                strcpy(gga_longitude_EW, pch);
130
 
171
 
131
            }else if( !strncmp(buffer, "GPVTG", 5) ){
172
            }else if( !strncmp(buffer, "GPVTG", 5) ){
132
                /* Standard NMEA message, $GPVTG */
173
                /* Standard NMEA message, $GPVTG */
-
 
174
                strtok(buffer, GPS_MSG_DELIMITER); /* Throw away "GPVTG" */
133
 
175
 
-
 
176
                /* Get course over ground, true degree */
-
 
177
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
178
                strcpy(vtg_course_true, pch);
-
 
179
 
-
 
180
                /* Get course over ground, magnetic degree */
-
 
181
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
182
                strcpy(vtg_course_magnetic, pch);
-
 
183
 
-
 
184
                /* Get speed over ground, km/h */
-
 
185
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
186
                strcpy(vtg_speed_kmh, pch);
-
 
187
 
134
            }else if( !strncmp(buffer, "GPZDA", 5) ){
188
            }else if( !strncmp(buffer, "GPZDA", 5) ){
135
                /* Standard NMEA message, $GPZDA */
189
                /* Standard NMEA message, $GPZDA */
-
 
190
                strtok(buffer, GPS_MSG_DELIMITER); /* Throw away "GPZDA" */
-
 
191
 
-
 
192
                /* Get time */
-
 
193
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
194
                strcpy(zda_time, pch);
-
 
195
 
-
 
196
                /* Get day, 0-31 */
-
 
197
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
198
                strcpy(zda_day, pch);
-
 
199
 
-
 
200
                /* Get month, 1-12 */
-
 
201
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
202
                strcpy(zda_month, pch);
-
 
203
 
-
 
204
                /* Get year */
-
 
205
                pch = strtok(NULL, GPS_MSG_DELIMITER);
-
 
206
                strcpy(zda_year, pch);
136
            }
207
            }
137
 
208
 
138
            gpsMsg_received = FALSE; /* Get ready for next message */
209
            gpsMsg_received = FALSE; /* Get ready for next message */
139
 
210
 
140
        }
211
        }