Add common refclock driver option parsing
This commit is contained in:
parent
e261278a5c
commit
a0e1154bfb
4 changed files with 41 additions and 9 deletions
|
@ -2229,8 +2229,8 @@ There are currently three drivers implemented:
|
|||
@table @code
|
||||
@item PPS
|
||||
Pulse per second (PPS) API driver. The parameter is a path to the PPS
|
||||
device. Assert events are used by default. The path can have
|
||||
:1 appended to use clear events instead.
|
||||
device. Assert events are used by default. Driver option
|
||||
@code{:clear} can be appended to the path to use clear events instead.
|
||||
|
||||
PPS refclock needs another source (NTP or non-PPS refclock) or local
|
||||
directive (@pxref{local directive}) enabled to function. For example:
|
||||
|
|
36
refclock.c
36
refclock.c
|
@ -58,6 +58,7 @@ struct RCL_Instance_Record {
|
|||
RefclockDriver *driver;
|
||||
void *data;
|
||||
char *driver_parameter;
|
||||
int driver_parameter_length;
|
||||
int driver_poll;
|
||||
int driver_polled;
|
||||
int poll;
|
||||
|
@ -169,6 +170,7 @@ RCL_AddRefclock(RefclockParameters *params)
|
|||
|
||||
inst->data = NULL;
|
||||
inst->driver_parameter = params->driver_parameter;
|
||||
inst->driver_parameter_length = 0;
|
||||
inst->driver_poll = params->driver_poll;
|
||||
inst->poll = params->poll;
|
||||
inst->missed_samples = 0;
|
||||
|
@ -181,6 +183,15 @@ RCL_AddRefclock(RefclockParameters *params)
|
|||
inst->timeout_id = -1;
|
||||
inst->source = NULL;
|
||||
|
||||
if (inst->driver_parameter) {
|
||||
int i;
|
||||
|
||||
inst->driver_parameter_length = strlen(inst->driver_parameter);
|
||||
for (i = 0; i < inst->driver_parameter_length; i++)
|
||||
if (inst->driver_parameter[i] == ':')
|
||||
inst->driver_parameter[i] = '\0';
|
||||
}
|
||||
|
||||
if (pps_source) {
|
||||
if (inst->pps_rate < 1)
|
||||
inst->pps_rate = 1;
|
||||
|
@ -278,6 +289,31 @@ RCL_GetDriverParameter(RCL_Instance instance)
|
|||
return instance->driver_parameter;
|
||||
}
|
||||
|
||||
char *
|
||||
RCL_GetDriverOption(RCL_Instance instance, char *name)
|
||||
{
|
||||
char *s, *e;
|
||||
int n;
|
||||
|
||||
s = instance->driver_parameter;
|
||||
e = s + instance->driver_parameter_length;
|
||||
n = strlen(name);
|
||||
|
||||
while (1) {
|
||||
s += strlen(s) + 1;
|
||||
if (s >= e)
|
||||
break;
|
||||
if (!strncmp(name, s, n)) {
|
||||
if (s[n] == '=')
|
||||
return s + n + 1;
|
||||
if (s[n] == '\0')
|
||||
return s + n;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, NTP_Leap leap_status)
|
||||
{
|
||||
|
|
|
@ -64,6 +64,7 @@ extern void RCL_CycleLogFile(void);
|
|||
extern void RCL_SetDriverData(RCL_Instance instance, void *data);
|
||||
extern void *RCL_GetDriverData(RCL_Instance instance);
|
||||
extern char *RCL_GetDriverParameter(RCL_Instance instance);
|
||||
extern char *RCL_GetDriverOption(RCL_Instance instance, char *name);
|
||||
extern int RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, NTP_Leap leap_status);
|
||||
extern int RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second);
|
||||
|
||||
|
|
|
@ -46,15 +46,10 @@ static int pps_initialise(RCL_Instance instance) {
|
|||
pps_params_t params;
|
||||
struct pps_instance *pps;
|
||||
int fd, edge_clear, mode;
|
||||
char *path, *s;
|
||||
char *path;
|
||||
|
||||
path = RCL_GetDriverParameter(instance);
|
||||
|
||||
edge_clear = 0;
|
||||
if ((s = strrchr(path, ':')) != NULL) {
|
||||
*s = '\0';
|
||||
edge_clear = atoi(s + 1);
|
||||
}
|
||||
edge_clear = RCL_GetDriverOption(instance, "clear") ? 1 : 0;
|
||||
|
||||
fd = open(path, O_RDWR);
|
||||
if (fd < 0) {
|
||||
|
|
Loading…
Reference in a new issue