Switch refclock driver parameter to string
This commit is contained in:
parent
8de55124a8
commit
67c0f1c08c
4 changed files with 27 additions and 11 deletions
25
conf.c
25
conf.c
|
@ -428,10 +428,11 @@ parse_peer(const char *line)
|
||||||
static void
|
static void
|
||||||
parse_refclock(const char *line)
|
parse_refclock(const char *line)
|
||||||
{
|
{
|
||||||
int i, n, param, poll, dpoll, filter_length;
|
int i, n, poll, dpoll, filter_length;
|
||||||
unsigned long ref_id;
|
unsigned long ref_id;
|
||||||
double offset;
|
double offset;
|
||||||
char name[5], cmd[10 + 1];
|
const char *tmp;
|
||||||
|
char name[5], cmd[10 + 1], *param;
|
||||||
unsigned char ref[5];
|
unsigned char ref[5];
|
||||||
|
|
||||||
i = n_refclock_sources;
|
i = n_refclock_sources;
|
||||||
|
@ -444,12 +445,26 @@ parse_refclock(const char *line)
|
||||||
offset = 0.0;
|
offset = 0.0;
|
||||||
ref_id = 0;
|
ref_id = 0;
|
||||||
|
|
||||||
if (sscanf(line, "%4s %d%n", name, ¶m, &n) != 2) {
|
if (sscanf(line, "%4s%n", name, &n) != 1) {
|
||||||
LOG(LOGS_WARN, LOGF_Configure, "Could not read refclock driver name and parameter at line %d", line_number);
|
LOG(LOGS_WARN, LOGF_Configure, "Could not read refclock driver name at line %d", line_number);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
line += n;
|
||||||
|
|
||||||
|
while (isspace(line[0]))
|
||||||
|
line++;
|
||||||
|
tmp = line;
|
||||||
|
while (line[0] != '\0' && !isspace(line[0]))
|
||||||
|
line++;
|
||||||
|
|
||||||
|
if (line == tmp) {
|
||||||
|
LOG(LOGS_WARN, LOGF_Configure, "Could not read refclock parameter at line %d", line_number);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
line += n;
|
param = MallocArray(char, 1 + line - tmp);
|
||||||
|
strncpy(param, tmp, line - tmp);
|
||||||
|
param[line - tmp + 1] = '\0';
|
||||||
|
|
||||||
while (sscanf(line, "%10s%n", cmd, &n) == 1) {
|
while (sscanf(line, "%10s%n", cmd, &n) == 1) {
|
||||||
line += n;
|
line += n;
|
||||||
|
|
|
@ -52,7 +52,7 @@ struct MedianFilter {
|
||||||
struct RCL_Instance_Record {
|
struct RCL_Instance_Record {
|
||||||
RefclockDriver *driver;
|
RefclockDriver *driver;
|
||||||
void *data;
|
void *data;
|
||||||
int driver_parameter;
|
char *driver_parameter;
|
||||||
int driver_poll;
|
int driver_poll;
|
||||||
int driver_polled;
|
int driver_polled;
|
||||||
int poll;
|
int poll;
|
||||||
|
@ -99,6 +99,7 @@ RCL_Finalise(void)
|
||||||
inst->driver->fini(inst);
|
inst->driver->fini(inst);
|
||||||
|
|
||||||
filter_fini(&inst->filter);
|
filter_fini(&inst->filter);
|
||||||
|
Free(inst->driver_parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_sources > 0)
|
if (n_sources > 0)
|
||||||
|
@ -139,7 +140,7 @@ RCL_AddRefclock(RefclockParameters *params)
|
||||||
else {
|
else {
|
||||||
unsigned char ref[5] = { 0, 0, 0, 0, 0 };
|
unsigned char ref[5] = { 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
snprintf((char *)ref, 5, "%s%d", params->driver_name, params->driver_parameter);
|
snprintf((char *)ref, 5, "%s%s", params->driver_name, params->driver_parameter);
|
||||||
inst->ref_id = ref[0] << 24 | ref[1] << 16 | ref[2] << 8 | ref[3];
|
inst->ref_id = ref[0] << 24 | ref[1] << 16 | ref[2] << 8 | ref[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +207,7 @@ RCL_GetDriverData(RCL_Instance instance)
|
||||||
return instance->data;
|
return instance->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
char *
|
||||||
RCL_GetDriverParameter(RCL_Instance instance)
|
RCL_GetDriverParameter(RCL_Instance instance)
|
||||||
{
|
{
|
||||||
return instance->driver_parameter;
|
return instance->driver_parameter;
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char driver_name[4];
|
char driver_name[4];
|
||||||
int driver_parameter;
|
char *driver_parameter;
|
||||||
int driver_poll;
|
int driver_poll;
|
||||||
int poll;
|
int poll;
|
||||||
int filter_length;
|
int filter_length;
|
||||||
|
@ -59,7 +59,7 @@ extern void RCL_ReportSource(RPT_SourceReport *report, struct timeval *now);
|
||||||
/* functions used by drivers */
|
/* functions used by drivers */
|
||||||
extern void RCL_SetDriverData(RCL_Instance instance, void *data);
|
extern void RCL_SetDriverData(RCL_Instance instance, void *data);
|
||||||
extern void *RCL_GetDriverData(RCL_Instance instance);
|
extern void *RCL_GetDriverData(RCL_Instance instance);
|
||||||
extern int RCL_GetDriverParameter(RCL_Instance instance);
|
extern char *RCL_GetDriverParameter(RCL_Instance instance);
|
||||||
extern int RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, NTP_Leap leap_status);
|
extern int RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, NTP_Leap leap_status);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -59,7 +59,7 @@ static int shm_initialise(RCL_Instance instance) {
|
||||||
int id, param;
|
int id, param;
|
||||||
struct shmTime *shm;
|
struct shmTime *shm;
|
||||||
|
|
||||||
param = RCL_GetDriverParameter(instance);
|
param = atoi(RCL_GetDriverParameter(instance));
|
||||||
|
|
||||||
id = shmget(SHMKEY + param, sizeof (struct shmTime), IPC_CREAT | 0700);
|
id = shmget(SHMKEY + param, sizeof (struct shmTime), IPC_CREAT | 0700);
|
||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
|
|
Loading…
Reference in a new issue