[chrony-users] help

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-users Archives ]



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



#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;
}

Attachment: chrony.conf
Description: Binary data



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/