/******************************************************************* File: centauriPM.c Purpose: Parse serial messages from Ophir Centauri Power Meter Author: S. Alverson (alverson) Created: 03/29/2022 Modified: *******************************************************************/ #include #include #include #include #include /*#include */ #include #include #include static long subCentauriRangeInit(struct aSubRecord *psub) { return 0; } static long subCentauriRange(struct aSubRecord *psub) { const char *delim = " "; char range_str[10] = ""; char *range_tok; char *unit_tok; range_list = (char *) psub->a; /* Range list from waveform*/ range_index = (double) psub->b; /* Index for range in use from list */ /* Find the correct range based on index */ strcpy(range_str, range_list[range_index]); /*range_tok = strtok(range_list, delim); int i = 0; while (range_tok != NULL) { if (i == range_index) { strcpy(range_str, range_tok); break; } range_tok = strtok(NULL, delim); ++i; }*/ /* Separate value from units */ double raw_val = strtol(range_str, &unit_tok, 10); /* Scale value to standard unit (no SI prefix) */ double scale = 1; if (unit_tok[0] == 'm') { scale = 0.001; } else if (unit_tok[0] == 'u') { scale = 0.000001; } else if (unit_tok[0] == 'n') { scale = 0.000000001; } else { scale = 1; } psub->vala = raw_val * scale; psub->valb = raw_val; psub->valc = scale; psub->vald = unit_tok; return 0; }