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[*] baro(file f) {
46 string l = timed_read(f, 1000);
48 File::fprintf(stderr, "read timedout\n");
52 if (String::index(l, "Altitude:") == 0)
58 string[*] find_baro(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[*]) {};
67 string[*] i = baro(f);
68 string[*] temp = find_baro(i, "Temperature");
69 string[*] alt = find_baro(i, "Altitude");
71 real temperature = string_to_integer(temp[2]) / 100.0;
72 real altitude = string_to_integer(alt[1]);
74 if (altitude < -50 || 3000 < altitude) {
75 printf ("weird altitude %f\n", altitude);
79 if (temperature < 20 || 30 < temperature) {
80 printf ("weird temperature %f\n", temperature);
84 printf ("altitude %f temperature %f\n", altitude, temperature);
90 string name = argv[1];
91 file f = open(name, "r+");