Esempio n. 1
0
static void
send_packet(void)
{
    int rtx;

    switch (state) {
    case XDM_QUERY:
    case XDM_BROADCAST:
    case XDM_INDIRECT:
#if defined(IPv6)  && defined(AF_INET6)
    case XDM_MULTICAST:
#endif
        send_query_msg();
        break;
    case XDM_START_CONNECTION:
        send_request_msg();
        break;
    case XDM_MANAGE:
        send_manage_msg();
        break;
    case XDM_KEEPALIVE:
        send_keepalive_msg();
        break;
    default:
        break;
    }
    rtx = (XDM_MIN_RTX << timeOutRtx);
    if (rtx > XDM_MAX_RTX)
        rtx = XDM_MAX_RTX;
    timeOutTime = GetTimeInMillis() + rtx * 1000;
}
Esempio n. 2
0
File: tsip.cpp Progetto: adbor/gps
/** get gps time in utc seconds
*
*   updates the time_t referenced structure passed to method.
*

*   @return time_t 
*/
time_t tsip::get_gps_time_utc() {
	bool rc;
	
	//build a2 request - set UTC
	m_command.extended.code = COMMAND_SUPER_PACKET;
	m_command.extended.subcode = REPORT_SUPER_UTC_GPS_TIME;
	m_command.extended.data[0] = 0x3;
	m_command.extended.cmd_len = 3;
	
	rc = send_request_msg(m_command);
	
	//build ab request - request time packet
	m_command.extended.code = COMMAND_SUPER_PACKET;
	m_command.extended.subcode = REPORT_SUPER_PRIMARY_TIME;
	m_command.extended.cmd_len  = 2;
	rc = get_report_msg(m_command);
	if (!rc) {
		printf("****Failed to get GPS time****\n");
		exit (false);
    }


	struct tm time;

    time.tm_zone = "UTC";
    time.tm_wday = -1;
    time.tm_yday = -1;
    time.tm_isdst = -1;
    time.tm_year = m_primary_time.report.year - 1900;
    time.tm_mon = m_primary_time.report.month - 1;
    time.tm_mday = m_primary_time.report.day;
    time.tm_hour = m_primary_time.report.hours;
    time.tm_min = m_primary_time.report.minutes;
    time.tm_sec = m_primary_time.report.seconds;

    gps_time = timegm(&time);
    if (verbose) {
		printf("Got GPS time Year: %d, Month: %d, Day: %d, Hour: %d, Minutes: %d, Seconds: %d\n", time.tm_year, time.tm_mon, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
		printf("seconds: %d\n", gps_time);
    }

	return gps_time;
}
Esempio n. 3
0
File: tsip.cpp Progetto: adbor/gps
/** get_report_msg
*
*   send a sequence of commands to the gps.  The loop is continued until
*   the correct message id is returned.  
*
*   @return bool  
*/
bool tsip::get_report_msg(_command_packet _cmd) {
	//clear report flags
	init_rpt();
	
	// init local var
    unsigned char ch = 0;
    
    
RETRY:
	// send the commmand
    send_request_msg(m_command);
	
	// read stream and pass to encode routine untile packet complete 
	int loop_cnt=0;
	while (!is_report_found(_cmd)) {
		int rc = 0;
		while (rc == 0) {	
			rc = encode(getc(file));
		}
		loop_cnt++;
		if (loop_cnt >20) break;
	}
	
	//set flag
	bool rpt_fnd = is_report_found(_cmd);

	
	if(verbose){
		if (rpt_fnd) {
				printf("Packet %x %x found \n",m_report.report.code,m_report.extended.subcode);
			}else {
				printf("Packet for  %x %x not found \n",m_report.report.code,m_report.extended.subcode);
		}
		printf("\n");
	}
	
	return (rpt_fnd);
}