5 string timed_read(file f, int timeout) {
6 thread reader = fork func() {
9 } catch Thread::signal(int i) {
14 thread killer = fork func() {
17 Thread::send_signal(reader, 1);
18 } catch Thread::signal(int i) {
23 poly v = Thread::join(reader);
24 Thread::send_signal(killer, 1);
31 void flush_input(file f) {
33 string s = timed_read(f, 200);
39 string[*] gps(file f) {
43 fprintf (f, "g\nv\n");
46 string l = timed_read(f, 1000);
48 File::fprintf(stderr, "Read timedout\n");
52 if (String::index(l, "software-version") == 0)
58 string[*] find_gps(string[*] s, string match) {
59 for (int i = 0; i < dim(s); i++)
60 if (String::index(s[i], match) >= 0)
61 return String::wordsplit(s[i], " ");
62 return (string[*]) {};
69 string[*] flags = find_gps(i, "Flags:");
70 string[*] sats = find_gps(i, "Sats:");
72 int actual_flags = string_to_integer(flags[1]);
74 while ((actual_flags & (1 << 4)) == 0) {
75 printf("Flags: %s\n", flags[1]);
76 printf("Sats: %s\n", sats[1]);
80 flags = find_gps(i, "Flags:");
81 sats = find_gps(i, "Sats:");
83 actual_flags = string_to_integer(flags[1]);
86 printf("Flags: %s\n", flags[1]);
87 printf("Sats: %s\n", sats[1]);
88 printf("GPS locked\n");
93 string name = argv[1];
94 file f = open(name, "r+");