help
Tommy Prusak <[email protected]>
| Newsgroups | gmane.comp.time.chrony.user |
|---|---|
| Message-ID | <CAHu7pv84BBhBWPbcAaW85MHthortYsrPGNv-9X36sZ7MnK5MwQ@mail.gmail.com> |
Hello, I need some help using chrony with the SOCK reference clock option. I have been trying to find a solution to my problem but with no luck so hopefully someone can help me out. This is what I'm trying to do. I'm using ROS to get some timing data from my GPS/IMU and I'm trying to send it to chrony through a socket without the use of gpsd. In a way I'm just trying to do what gpsd does but with a different input. My GPS/IMU can output NMEA string but I have to use the option where it outputs its own proprietary packets so gpsd isn't an option. My file that is acting as a client, sending data to chrony is linked below and so is my .conf file. It seems like chrony doesn't like the timing data I am inputting but the only error message I get is "No suitable source for synchronization" and I can't seem to work back and find what is giving me that error log. I also think there might be an issue with the rate I am sending this data, since ROS is sending out this data as fast as it can. Any help would be greatly appreciated! For some clarification, In main, all ROS is doing is getting timing data and then calling the "callback" function every time there is new data. I then take this and set all the variables in the structure to then send it to chrony. Sincerely, Tommy Prusak
timing_node.cpp
(text/x-c++src, 2.6 KB)
#define SERVER_PATH "/var/run/chrony.ttyS0.sock"
//#define SERVER_PATH "/tmp/server.sock"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <ros/ros.h>
#include "sensor_msgs/TimeReference.h"
#include <errno.h>
#include <sys/uio.h>
#include <time.h>
extern "C"
{
#include <sys/time.h>
}
struct sock_sample
{
struct timeval tv;
double offset;
int pulse;
int leap;
int _pad;
int magic;
};
int client_socket, rc, len;
struct sockaddr_un remote;
char buf[40];
void callback(const sensor_msgs::TimeReference::ConstPtr &msg)
{
struct sock_sample sample;
int currentTime;
currentTime = time(NULL);
sample.magic = 0x534f434;
sample.pulse = 0;
sample.leap = 0;
sample._pad = 0;
double secs = msg->header.stamp.toSec();
sample.tv.tv_sec = (int)secs;
sample.tv.tv_usec = ((int)((secs - sample.tv.tv_sec) * 1000000));
double x = abs(currentTime - secs);
sample.offset = x;
rc = sendto(client_socket, (struct sock_sample *)&sample, sizeof(sample), 0, (struct sockaddr *)&remote, sizeof(remote));
if (rc == -1)
{
printf("SENDTO ERROR = %s\n", strerror(errno));
close(client_socket);
exit(1);
}
else
{
//printf("Data sent!\n");
}
printf("[%d]\n", sample.tv.tv_sec);
printf("%d\n", currentTime);
printf("%f\n", sample.offset);
exit;
}
int main(int argc, char *argv[])
{
system("sudo chmod u=rwx,g=rwx,o=rwx /var/run/chrony.ttyS0.sock");
memset(&remote, 0, sizeof(struct sockaddr_un));
/****************************************/
/* Create a UNIX domain datagram socket */
/****************************************/
client_socket = socket(AF_UNIX, SOCK_DGRAM, 0);
if (client_socket == -1)
{
printf("SOCKET ERROR");
exit(1);
}
/***************************************/
/* Set up the UNIX sockaddr structure */
/* by using AF_UNIX for the family and */
/* giving it a filepath to send to. */
/***************************************/
remote.sun_family = AF_UNIX;
strcpy(remote.sun_path, SERVER_PATH);
// This must be called before anything else ROS-related
ros::init(argc, argv, "timing");
// Create a ROS node handle
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("/imu/time_ref", 1000, callback);
// Don't exit the program.
ros::spin();
// /* Close socket. */
// close(sockfd);
// unlink(server_addr.sun_path);
// unlink(client_addr.sun_path);
/******************************/
/* Close the sockets and exit */
/******************************/
rc = close(client_socket);
return 1;
}
chrony.conf
(application/octet-stream, 1.8 KB)
# Welcome to the chrony configuration file. See chrony.conf(5) for more # information about usuable directives. # This will use (up to): # - 4 sources from ntp.ubuntu.com which some are ipv6 enabled # - 2 sources from 2.ubuntu.pool.ntp.org which is ipv6 enabled as well # - 1 source from [01].ubuntu.pool.ntp.org each (ipv4 only atm) # This means by default, up to 6 dual-stack and up to 2 additional IPv4-only # sources will be used. # At the same time it retains some protection against one of the entries being # down (compare to just using one of the lines). See (LP: #1754358) for the # discussion. # # About using servers from the NTP Pool Project in general see (LP: #104525). # Approved by Ubuntu Technical Board on 2011-02-08. # See http://www.pool.ntp.org/join.html for more information. #pool ntp.ubuntu.com iburst maxsources 4 #pool 0.ubuntu.pool.ntp.org iburst maxsources 1 #pool 1.ubuntu.pool.ntp.org iburst maxsources 1 #pool 2.ubuntu.pool.ntp.org iburst maxsources 2 #refclock SHM 0:perm=0606 noselect refclock SOCK /var/run/chrony.ttyS0.sock # This directive specify the location of the file containing ID/key pairs for # NTP authentication. keyfile /etc/chrony/chrony.keys # This directive specify the file into which chronyd will store the rate # information. driftfile /var/lib/chrony/chrony.drift # Uncomment the following line to turn logging on. #log tracking measurements statistics # Log files location. logdir /var/log/chrony # Stop bad estimates upsetting machine clock. maxupdateskew 100.0 # This directive enables kernel synchronisation (every 11 minutes) of the # real-time clock. Note that it can’t be used along with the 'rtcfile' directive. rtcsync # Step the system clock instead of slewing it if the adjustment is larger than # one second, but only in the first three clock updates. makestep 1 3