Skip to content

Commit 13755b9

Browse files
author
Luca Toniolo
committed
Parse new configs from a comment, to allow 2.9 halscope to open new configs
1 parent c2a4427 commit 13755b9

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/hal/utils/scope.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ static int read_samples_from_config(const char *filename)
112112
return 0; /* file doesn't exist, use default */
113113
}
114114
while (fgets(buf, sizeof(buf), fp) != NULL) {
115+
/* Support both "SAMPLES nnn" and "# SAMPLES nnn" for backward compatibility */
116+
/* Older halscope versions will ignore "# SAMPLES" as a comment */
115117
if (strncasecmp(buf, "SAMPLES ", 8) == 0) {
116118
samples = atoi(buf + 8);
117119
break;
120+
} else if (strncasecmp(buf, "# SAMPLES ", 10) == 0) {
121+
samples = atoi(buf + 10);
122+
break;
118123
}
119124
}
120125
fclose(fp);

src/hal/utils/scope_files.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@
6060
*/
6161

6262
/*
63+
# SAMPLES <int> total sample buffer size (written as comment for compatibility)
6364
THREAD <string> name of thread to sample in
64-
MAXCHAN <int> 1,2,4,8,16, maximum channel count
65+
MAXCHAN <int> 1,2,4,8,16, maximum channel count (ignored, kept for compatibility)
6566
HMULT <int> multiplier, sample every N runs of thread
6667
HZOOM <int> 1-9, horizontal zoom setting
6768
HPOS <float> 0.0-1.0, horizontal position setting
@@ -467,6 +468,8 @@ static char *samples_cmd(void * arg)
467468
int *argp;
468469
/* SAMPLES is handled early in main() before scope_rt is loaded */
469470
/* Here we just store it in requested_samples so it gets saved back */
471+
/* This handles both "SAMPLES nnn" from config files */
472+
/* The "# SAMPLES nnn" comment version is handled by read_samples_from_config() */
470473
argp = (int *)(arg);
471474
ctrl_usr->horiz.requested_samples = *argp;
472475
return NULL;

src/hal/utils/scope_horiz.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,12 @@ void write_horiz_config(FILE *fp)
320320
/* save requested_samples if set, otherwise current buf_len */
321321
samples_to_save = (horiz->requested_samples > 0) ?
322322
horiz->requested_samples : ctrl_shm->buf_len;
323-
fprintf(fp, "SAMPLES %d\n", samples_to_save);
323+
/* Write SAMPLES as a comment for backward compatibility with old halscope */
324+
/* Old versions will ignore "# SAMPLES", new versions parse it in read_samples_from_config() */
325+
fprintf(fp, "# SAMPLES %d\n", samples_to_save);
326+
/* Also write MAXCHAN for backward compatibility with old halscope */
327+
/* Old versions use MAXCHAN, new versions ignore it (always use 16 channels) */
328+
fprintf(fp, "MAXCHAN 16\n");
324329
fprintf(fp, "THREAD %s\n", horiz->thread_name);
325330
fprintf(fp, "HMULT %d\n", ctrl_shm->mult);
326331
fprintf(fp, "HZOOM %d\n", horiz->zoom_setting);

0 commit comments

Comments
 (0)