/* * nmeaInfo.cpp * * Created on: Oct 21, 2014 * Author: Alan Aguilar Sologuren */ #include "utils.h" #include "nmeaInfo.h" nmeaInfo::nmeaInfo() { // TODO Auto-generated constructor stub } nmeaInfo::~nmeaInfo() { // TODO Auto-generated destructor stub } void nmeaInfo::code_init_INFO() { code_time_now(); sig = NMEA_SIG_BAD; fix = NMEA_FIX_BAD; } static void nmeaInfo::code_time_now() { time_t lt; struct tm *tt; time(<); tt = gmtime(<); utc.year = tt->tm_year; utc.mon = tt->tm_mon; utc.day = tt->tm_mday; utc.hour = tt->tm_hour; utc.min = tt->tm_min; utc.sec = tt->tm_sec; utc.hsec = 0; } /** * \brief Convert position from INFO to radians position */ void nmeaInfo::code_info2pos(nmeaPOS *pos) { pos->lat = code_ndeg2radian(lat); pos->lon = code_ndeg2radian(lon); } /** * \brief Convert radians position to INFOs position */ void nmeaInfo::code_pos2info(const nmeaPOS *pos) { lat = code_radian2ndeg(pos->lat); lon = code_radian2ndeg(pos->lon); } /* * NOISE generator */ int nmeaInfo::nmea_igen_noise_init() { return 1; } int nmeaInfo::nmea_igen_noise_loop() { int it; int in_use; sig = (int)nmea_random(1, 3); PDOP = nmea_random(0, 9); HDOP = nmea_random(0, 9); VDOP = nmea_random(0, 9); fix = (int)nmea_random(2, 3); lat = nmea_random(0, 100); lon = nmea_random(0, 100); speed = nmea_random(0, 100); direction = nmea_random(0, 360); declination = nmea_random(0, 360); elv = (int)nmea_random(-100, 100); satinfo.inuse = 0; satinfo.inview = 0; for(it = 0; it < 12; ++it) { satinfo.sat[it].id = it; satinfo.sat[it].in_use = in_use = (int)nmea_random(0, 3); satinfo.sat[it].elv = (int)nmea_random(0, 90); satinfo.sat[it].azimuth = (int)nmea_random(0, 359); satinfo.sat[it].sig = (int)(in_use?nmea_random(40, 99):nmea_random(0, 40)); if(in_use) satinfo.inuse++; if(satinfo.sat[it].sig > 0) satinfo.inview++; } return 1; } int nmeaInfo::nmea_igen_noise_reset() { return 1; } /* * STATIC generator */ int nmeaInfo::nmea_igen_static_loop() { code_time_now(); return 1; }; int nmeaInfo::nmea_igen_static_reset() { satinfo.inuse = 4; satinfo.inview = 4; satinfo.sat[0].id = 1; satinfo.sat[0].in_use = 1; satinfo.sat[0].elv = 50; satinfo.sat[0].azimuth = 0; satinfo.sat[0].sig = 99; satinfo.sat[1].id = 2; satinfo.sat[1].in_use = 1; satinfo.sat[1].elv = 50; satinfo.sat[1].azimuth = 90; satinfo.sat[1].sig = 99; satinfo.sat[2].id = 3; satinfo.sat[2].in_use = 1; satinfo.sat[2].elv = 50; satinfo.sat[2].azimuth = 180; satinfo.sat[2].sig = 99; satinfo.sat[3].id = 4; satinfo.sat[3].in_use = 1; satinfo.sat[3].elv = 50; satinfo.sat[3].azimuth = 270; satinfo.sat[3].sig = 99; return 1; } int nmeaInfo::nmea_igen_static_init() { sig = 3; fix = 3; nmea_igen_static_reset(); return 1; } /* * SAT_ROTATE generator */ int nmeaInfo::nmea_igen_rotate_loop() { int it; int count = satinfo.inview; double deg = 360 / (count?count:1); double srt = (count?(satinfo.sat[0].azimuth):0) + 5; code_time_now(); for(it = 0; it < count; ++it) { satinfo.sat[it].azimuth = (int)((srt >= 360)?srt - 360:srt); srt += deg; } return 1; }; int nmeaInfo::nmea_igen_rotate_reset() { int it; double deg = 360 / 8; double srt = 0; satinfo.inuse = 8; satinfo.inview = 8; for(it = 0; it < satinfo.inview; ++it) { satinfo.sat[it].id = it + 1; satinfo.sat[it].in_use = 1; satinfo.sat[it].elv = 5; satinfo.sat[it].azimuth = (int)srt; satinfo.sat[it].sig = 80; srt += deg; } return 1; } int nmeaInfo::nmea_igen_rotate_init() { sig = 3; fix = 3; nmea_igen_rotate_reset(); return 1; } /* * POS_RANDMOVE generator */ int nmeaInfo::nmea_igen_pos_rmove_init() { sig = 3; fix = 3; direction = declination = 0; speed = 20; return 1; } int nmeaInfo::nmea_igen_pos_rmove_loop() { nmeaPOS crd; direction += nmea_random(-10, 10); speed += nmea_random(-2, 3); if(direction < 0) direction = 359 + direction; if(direction > 359) direction -= 359; if(speed > 40) speed = 40; if(speed < 1) speed = 1; code_info2pos(&crd); code_move_horz(&crd, &crd, direction, speed / 3600); code_pos2info(&crd); declination = direction; return 1; };