|
@@ -248,463 +248,6 @@ int set_equip_num(int num) {
|
|
|
|
|
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
-/*
|
|
|
|
|
-int get_state_info(state_info_t *_state) {
|
|
|
|
|
- FILE *fp;
|
|
|
|
|
- int ch = 1,
|
|
|
|
|
- input_idx=0,
|
|
|
|
|
- n=0,
|
|
|
|
|
- field_len=0;
|
|
|
|
|
- char buffer[LINE_BUFFER_SIZE],
|
|
|
|
|
- *chp;
|
|
|
|
|
-
|
|
|
|
|
- if (access(STATE_INFO_FILE, R_OK)!=0) {
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- memset(buffer, 0, sizeof(char)*LINE_BUFFER_SIZE);
|
|
|
|
|
-
|
|
|
|
|
- if ((fp = fopen(STATE_INFO_FILE, "r")) == NULL) {
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- while (!feof(fp)) {
|
|
|
|
|
- ch = fgetc(fp);
|
|
|
|
|
- if ((ch == '\n') || (ch == EOF)) {
|
|
|
|
|
-
|
|
|
|
|
- // ignore blank lines and comment lines
|
|
|
|
|
- // (begining with '#')
|
|
|
|
|
- //
|
|
|
|
|
- if (input_idx == 0) { continue; }
|
|
|
|
|
- if (buffer[0] == '#') { continue; }
|
|
|
|
|
-
|
|
|
|
|
- chp = strchr(buffer, ' ');
|
|
|
|
|
- if (chp != NULL) {
|
|
|
|
|
- chp++;
|
|
|
|
|
-
|
|
|
|
|
- n = chp - buffer;
|
|
|
|
|
-
|
|
|
|
|
- if (strncmp(buffer, "LAT ", n)==0) {
|
|
|
|
|
- _state->lat = atof(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "LON ", n)==0) {
|
|
|
|
|
- _state->lon = atof(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "HEADING ", n)==0) {
|
|
|
|
|
- _state->heading = atof(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "VELOCITY ", n)==0) {
|
|
|
|
|
- _state->velocity = atof(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "NUM_SATS ", n)==0) {
|
|
|
|
|
- _state->num_sats = atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "GPS_GOOD ", n)==0) {
|
|
|
|
|
- _state->gps_good = atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "STAMP ", n)==0) {
|
|
|
|
|
- _state->stamp = (time_t)atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "GPSTAMP ", n)==0) {
|
|
|
|
|
- _state->gpstime = (time_t)atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "PADDLE ", n)==0) {
|
|
|
|
|
- _state->paddle = atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "ROUTE ", n)==0) {
|
|
|
|
|
- _state->route = atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "TRIP ", n)==0) {
|
|
|
|
|
- _state->trip = atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "STOP ", n)==0) {
|
|
|
|
|
- _state->stop = atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "STOPNAME ", n)==0) {
|
|
|
|
|
- field_len = input_idx - n;
|
|
|
|
|
- if (field_len >= STATE_INFO_FIELD_SIZE) {
|
|
|
|
|
- field_len = STATE_INFO_FIELD_SIZE-1;
|
|
|
|
|
- }
|
|
|
|
|
- memcpy(_state->stopname, chp, field_len);
|
|
|
|
|
- _state->stopname[field_len] = '\0';
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncpy(buffer, "LOGGED_IN_DRIVER ", n)==0) {
|
|
|
|
|
- _state->logged_in_driver = atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncpy(buffer, "DRIVER_NAME ", n)==0) {
|
|
|
|
|
- field_len = input_idx - n;
|
|
|
|
|
- if (field_len >= STATE_INFO_FIELD_SIZE) {
|
|
|
|
|
- field_len = STATE_INFO_FIELD_SIZE-1;
|
|
|
|
|
- }
|
|
|
|
|
- memcpy(_state->driver_name, chp+1, input_idx - n + 1);
|
|
|
|
|
- _state->driver_name[field_len] = '\0';
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (strncmp(buffer, "EQUIP_NUM ", n)==0) {
|
|
|
|
|
- _state->equip_num = atoi(chp+1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- buffer[0] = '\0';
|
|
|
|
|
- input_idx = 0;
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- buffer[input_idx] = ch;
|
|
|
|
|
- input_idx++;
|
|
|
|
|
- if (input_idx >= LINE_BUFFER_SIZE) {
|
|
|
|
|
- input_idx = LINE_BUFFER_SIZE-1;
|
|
|
|
|
- }
|
|
|
|
|
- buffer[input_idx] = '\0';
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- fclose(fp);
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// save on disk state
|
|
|
|
|
-//
|
|
|
|
|
-int set_state_info(state_info_t *_state) {
|
|
|
|
|
- FILE *fp;
|
|
|
|
|
-
|
|
|
|
|
- if ((fp = fopen(STATE_INFO_TEMPFILE, "w")) == NULL) {
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "LAT %f\n", _state->lat);
|
|
|
|
|
- fprintf(fp, "LON %f\n", _state->lon);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "HEADING %f\n", _state->heading);
|
|
|
|
|
- fprintf(fp, "VELOCITY %f\n", _state->velocity);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "NUM_SATS %i\n", _state->num_sats);
|
|
|
|
|
- fprintf(fp, "GPS_GOOD %i\n", _state->gps_good);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "STAMP %i\n", (int)(_state->stamp));
|
|
|
|
|
- fprintf(fp, "GPSTAMP %i\n", (int)(_state->gpstime));
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "PADDLE %i\n", _state->paddle);
|
|
|
|
|
- fprintf(fp, "ROUTE %i\n", _state->route);
|
|
|
|
|
- fprintf(fp, "TRIP %i\n", _state->trip);
|
|
|
|
|
- fprintf(fp, "STOP %i\n", _state->stop);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "STOPNAME %s\n", _state->stopname);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "LOGGED_IN_DRIVER %i\n", _state->logged_in_driver);
|
|
|
|
|
- fprintf(fp, "DRIVER_NAME %s\n", _state->driver_name);
|
|
|
|
|
- fprintf(fp, "equip_num %i\n", _state->equip_num);
|
|
|
|
|
-
|
|
|
|
|
- fclose(fp);
|
|
|
|
|
-
|
|
|
|
|
- return rename(STATE_INFO_TEMPFILE, STATE_INFO_FILE);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// save on disk state
|
|
|
|
|
-//
|
|
|
|
|
-int print_state_info(state_info_t *_state) {
|
|
|
|
|
- FILE *fp = stdout;
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "LAT %f\n", _state->lat);
|
|
|
|
|
- fprintf(fp, "LON %f\n", _state->lon);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "HEADING %f\n", _state->heading);
|
|
|
|
|
- fprintf(fp, "VELOCITY %f\n", _state->velocity);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "NUM_SATS %i\n", _state->num_sats);
|
|
|
|
|
- fprintf(fp, "GPS_GOOD %i\n", _state->gps_good);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "STAMP %i\n", (int)(_state->stamp));
|
|
|
|
|
- fprintf(fp, "GPSTAMP %i\n", (int)(_state->gpstime));
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "PADDLE %i\n", _state->paddle);
|
|
|
|
|
- fprintf(fp, "ROUTE %i\n", _state->route);
|
|
|
|
|
- fprintf(fp, "TRIP %i\n", _state->trip);
|
|
|
|
|
- fprintf(fp, "STOP %i\n", _state->stop);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "STOPNAME %s\n", _state->stopname);
|
|
|
|
|
-
|
|
|
|
|
- fprintf(fp, "LOGGED_IN_DRIVER %i\n", _state->logged_in_driver);
|
|
|
|
|
- fprintf(fp, "DRIVER_NAME %s\n", _state->driver_name);
|
|
|
|
|
- fprintf(fp, "equip_num %i\n", _state->equip_num);
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-*/
|
|
|
|
|
-
|
|
|
|
|
-/*
|
|
|
|
|
-int get_driver_state(driver_status *_driver_stat) {
|
|
|
|
|
- FILE *fp;
|
|
|
|
|
- int input_idx=0,
|
|
|
|
|
- n=0,
|
|
|
|
|
- ch;
|
|
|
|
|
- char buffer[LINE_BUFFER_SIZE];
|
|
|
|
|
-
|
|
|
|
|
- // 0 - logged_in_driver
|
|
|
|
|
- // 1 - driver_name
|
|
|
|
|
- // 2 - equip_num
|
|
|
|
|
- //
|
|
|
|
|
- int _read_state = 0;
|
|
|
|
|
-
|
|
|
|
|
- if (access(DRIVER_STATE_FILE, R_OK)!=0) {
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- memset(buffer, 0, sizeof(char)*LINE_BUFFER_SIZE);
|
|
|
|
|
-
|
|
|
|
|
- n = DRIVER_NAME_LEN;
|
|
|
|
|
- if (LINE_BUFFER_SIZE < n) {
|
|
|
|
|
- n = LINE_BUFFER_SIZE;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- fp = fopen(DRIVER_STATE_FILE, "r");
|
|
|
|
|
- while ( (ch = fgetc(fp)) != EOF ) {
|
|
|
|
|
-
|
|
|
|
|
- if ((ch == '\n') || (ch == EOF)) {
|
|
|
|
|
-
|
|
|
|
|
- if (_read_state == 0) {
|
|
|
|
|
- _driver_stat->logged_in_driver = atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
- else if (_read_state == 1) {
|
|
|
|
|
-
|
|
|
|
|
- n = input_idx+1;
|
|
|
|
|
- if (n > DRIVER_NAME_LEN) {
|
|
|
|
|
- n = DRIVER_NAME_LEN;
|
|
|
|
|
- }
|
|
|
|
|
- buffer[n-1] = '\0';
|
|
|
|
|
-
|
|
|
|
|
- memcpy(_driver_stat->driver_name, buffer, n);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
- else if (_read_state == 2) {
|
|
|
|
|
- _driver_stat->equip_num = atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- memset(buffer, 0, sizeof(char)*LINE_BUFFER_SIZE);
|
|
|
|
|
- input_idx=0;
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- buffer[input_idx] = ch;
|
|
|
|
|
- input_idx++;
|
|
|
|
|
- if (input_idx >= LINE_BUFFER_SIZE) {
|
|
|
|
|
- input_idx = LINE_BUFFER_SIZE-1;
|
|
|
|
|
- buffer[LINE_BUFFER_SIZE-1] = 0;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- fclose(fp);
|
|
|
|
|
-
|
|
|
|
|
- if (_read_state < 3) {
|
|
|
|
|
- return -2;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-int get_stop_state(stop_status *_stop_stat) {
|
|
|
|
|
- FILE *fp;
|
|
|
|
|
- int input_idx=0,
|
|
|
|
|
- n=0,
|
|
|
|
|
- ch;
|
|
|
|
|
- char buffer[LINE_BUFFER_SIZE];
|
|
|
|
|
-
|
|
|
|
|
- // 0 - paddle
|
|
|
|
|
- // 1 - route
|
|
|
|
|
- // 2 - trip
|
|
|
|
|
- // 3 - stop
|
|
|
|
|
- // 4 - lat
|
|
|
|
|
- // 5 - lon
|
|
|
|
|
- // 6 - stopname
|
|
|
|
|
- //
|
|
|
|
|
- int _read_state = 0;
|
|
|
|
|
-
|
|
|
|
|
- if (access(STOP_STATE_FILE, R_OK)!=0) {
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- memset(buffer, 0, sizeof(char)*LINE_BUFFER_SIZE);
|
|
|
|
|
-
|
|
|
|
|
- fp = fopen(DRIVER_STATE_FILE, "r");
|
|
|
|
|
- while ( (ch = fgetc(fp)) != EOF ) {
|
|
|
|
|
-
|
|
|
|
|
- if ((ch == '\n') || (ch == EOF)) {
|
|
|
|
|
-
|
|
|
|
|
- if (_read_state == 0) {
|
|
|
|
|
- _stop_stat->paddle= atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
- else if (_read_state == 1) {
|
|
|
|
|
- _stop_stat->route = atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 2) {
|
|
|
|
|
- _stop_stat->trip = atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 3) {
|
|
|
|
|
- _stop_stat->stop= atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 4) {
|
|
|
|
|
- _stop_stat->lat = atof(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 5) {
|
|
|
|
|
- _stop_stat->lon = atof(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 6) {
|
|
|
|
|
-
|
|
|
|
|
- n = input_idx+1;
|
|
|
|
|
- if (n > STOP_NAME_LEN) {
|
|
|
|
|
- n = DRIVER_NAME_LEN;
|
|
|
|
|
- }
|
|
|
|
|
- buffer[n-1] = '\0';
|
|
|
|
|
-
|
|
|
|
|
- memcpy(_stop_stat->stopname, buffer, n);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- memset(buffer, 0, sizeof(char)*LINE_BUFFER_SIZE);
|
|
|
|
|
- input_idx=0;
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- buffer[input_idx] = ch;
|
|
|
|
|
- input_idx++;
|
|
|
|
|
- if (input_idx >= LINE_BUFFER_SIZE) {
|
|
|
|
|
- input_idx = LINE_BUFFER_SIZE-1;
|
|
|
|
|
- buffer[LINE_BUFFER_SIZE-1] = 0;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- fclose(fp);
|
|
|
|
|
-
|
|
|
|
|
- if (_read_state < 6) {
|
|
|
|
|
- return -2;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-int get_gps_state(gps_status *_gps_stat) {
|
|
|
|
|
- FILE *fp;
|
|
|
|
|
- int input_idx=0,
|
|
|
|
|
- ch;
|
|
|
|
|
- char buffer[LINE_BUFFER_SIZE];
|
|
|
|
|
-
|
|
|
|
|
- // 0 - lat
|
|
|
|
|
- // 1 - lon
|
|
|
|
|
- // 2 - heading
|
|
|
|
|
- // 3 - velocity
|
|
|
|
|
- // 4 - num_sats
|
|
|
|
|
- // 5 - gps_good
|
|
|
|
|
- // 6 - stamp
|
|
|
|
|
- // 7 - gpstime
|
|
|
|
|
- //
|
|
|
|
|
- int _read_state = 0;
|
|
|
|
|
-
|
|
|
|
|
- if (access(GPS_STATE_FILE, R_OK)!=0) {
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- memset(buffer, 0, sizeof(char)*LINE_BUFFER_SIZE);
|
|
|
|
|
-
|
|
|
|
|
- fp = fopen(DRIVER_STATE_FILE, "r");
|
|
|
|
|
- while ( (ch = fgetc(fp)) != EOF ) {
|
|
|
|
|
-
|
|
|
|
|
- if ((ch == '\n') || (ch == EOF)) {
|
|
|
|
|
-
|
|
|
|
|
- if (_read_state == 0) {
|
|
|
|
|
- _gps_stat->lat = atof(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 1) {
|
|
|
|
|
- _gps_stat->lon = atof(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 2) {
|
|
|
|
|
- _gps_stat->heading = atof(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 3) {
|
|
|
|
|
- _gps_stat->velocity = atof(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 4) {
|
|
|
|
|
- _gps_stat->num_sats = atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 5) {
|
|
|
|
|
- _gps_stat->gps_good = atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 6) {
|
|
|
|
|
- _gps_stat->stamp = (time_t)atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else if (_read_state == 7) {
|
|
|
|
|
- _gps_stat->gpstime = (time_t)atoi(buffer);
|
|
|
|
|
- _read_state++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- memset(buffer, 0, sizeof(char)*LINE_BUFFER_SIZE);
|
|
|
|
|
- input_idx=0;
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- buffer[input_idx] = ch;
|
|
|
|
|
- input_idx++;
|
|
|
|
|
- if (input_idx >= LINE_BUFFER_SIZE) {
|
|
|
|
|
- input_idx = LINE_BUFFER_SIZE-1;
|
|
|
|
|
- buffer[LINE_BUFFER_SIZE-1] = 0;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- fclose(fp);
|
|
|
|
|
-
|
|
|
|
|
- if (_read_state < 7) {
|
|
|
|
|
- return -2;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-*/
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
int get_server_desc(char *desc, int len) {
|
|
int get_server_desc(char *desc, int len) {
|
|
|
char svrname[LINE_BUFFER_SIZE];
|
|
char svrname[LINE_BUFFER_SIZE];
|
|
|
FILE *f;
|
|
FILE *f;
|