This repository has been archived by the owner on Nov 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
101 lines (90 loc) · 2.83 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>
#include <stdio.h>
#include <stdbool.h>
#include "gpsbmp.h"
int main (int argc, char * argv[])
{
/* ošetrenie argumentov */
if (argc != 6)
{
fprintf(stderr,"Nespravny pocet parametrov\n");
return (-1);
}
/* inicializacia allegro */
al_init();
al_init_image_addon();
al_init_primitives_addon();
/* ziskanie parametrov */
int params[4];
for(int i = 2; i<argc; i++) params[i-2] = stringToInt(argv[i]);
/* nastavenie velkosti stran v pixeloch */
int x = (params[3]-params[2])*60;
int y = (params[1]-params[0])*60;
ALLEGRO_BITMAP *bitmap = al_create_bitmap(abs(x),abs(y));
if (bitmap == NULL){
fprintf(stderr, "Nepodarilo sa vytvoriť bitmapu - al_create_bitmap()\n");
return (-2);
}
al_set_target_bitmap(bitmap);
al_clear_to_color(al_map_rgb(255, 255, 255));
/* max hodnoty X a Y osi */
int hX = params[3];
int hY = params[1];
char NMEA[6];
int nmeas = 0;
int lon = 0;
int lat = 0;
char c;
while((c = getchar()) != EOF)
{
//printf("%c\n",c);
if(c==' ') scanf("%[^\n]s",NMEA);
if(c=='$')
{
scanf("%5s",NMEA);
int tempLat = lat;
int tempLon = lon;
short zmena = 0;
//printf("%s\n",NMEA);
if (strcmp(NMEA,"GPRMB") == 0 )
{
nacitanie(6, &lon, &lat, &nmeas, &zmena);
}
else if(strcmp(NMEA,"GPRMC") == 0)
{
nacitanie(3, &lon, &lat, &nmeas, &zmena);
}
else if(strcmp(NMEA,"GPGGA") == 0)
{
nacitanie(2, &lon, &lat, &nmeas, &zmena);
}
/* podmienka nacitania najmenej 2 záznamov */
if (nmeas > 1)
{
/* ak sa súradnice nezmenili, nakreslí pixel na daných súradniciach */
if (lat == tempLat && lon == tempLon && zmena)
{
al_draw_pixel(x-((hX-lon/100)*60-(lon%100)), (hY-lat/100)*60-(lat%100),al_map_rgb(0, 0, 0));
}
/* vykreslí čiaru medzi dvoma bodmi */
else
{
al_draw_line(x-((hX-lon/100)*60-(lon%100)), (hY-lat/100)*60-(lat%100),
x-((hX-tempLon/100)*60-(tempLon%100)), (hY-tempLat/100)*60-(tempLat%100),
al_map_rgb(0, 0, 0), 1);
}
}
scanf("%[^\n]s",NMEA);
}
}
/* zápis a zničenie bitmapy */
if(!al_save_bitmap(argv[1], bitmap))
{
fprintf(stderr,"Neopravneny alebo zly zapis do suboru\n");
return (-3);
}
al_destroy_bitmap(bitmap);
return 0;
}