usb: Add support for new GPSDO status field "Accumulated error"

Because we want to handle older firmwares too, we need to excepect
we might get a smaller structure !

(We can't get a larger one since the wLength we send is limited to
the structure we know)

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I4222bf22267f8343abf1e97546111ceb1c299846
This commit is contained in:
Sylvain Munaut 2022-10-04 20:44:16 +02:00
parent 6cd951d714
commit b7b6057e76
4 changed files with 23 additions and 4 deletions

View File

@ -67,6 +67,7 @@ enum e1d_line_stat_item {
LINE_GPSDO_TUNE_COARSE,
LINE_GPSDO_TUNE_FINE,
LINE_GPSDO_FREQ_EST,
LINE_GPSDO_ERR_ACC,
};
enum e1_ts_mode {

View File

@ -65,6 +65,7 @@ struct e1usb_gpsdo_status {
uint8_t mode; /*!< Current configured operating mode */
struct e1usb_gpsdo_tune tune; /*!< Current VCXO tuning values */
uint32_t freq_est; /*!< Latest frequency estimate measurement */
int16_t err_acc; /*!< Accumulated error (since fw icE1usb-fw-0.3 commit cfb8b0b7) */
} __attribute__((packed));

View File

@ -75,6 +75,7 @@ static const struct osmo_stat_item_desc line_stat_description[] = {
[LINE_GPSDO_TUNE_COARSE]= { "gpsdo:tune:coarse", "GSPDO Coarse Tuning" },
[LINE_GPSDO_TUNE_FINE] = { "gpsdo:tune:fine", "GSPDO Fine Tuning" },
[LINE_GPSDO_FREQ_EST] = { "gpsdo:freq_est", "GSPDO Frequency Estimate" },
[LINE_GPSDO_ERR_ACC] = { "gpsdo:err_acc", "GPSDO Accumulated Error" },
};
static const struct osmo_stat_item_group_desc line_stats_desc = {

View File

@ -706,14 +706,29 @@ _e1_usb_intf_gpsdo_status_cb(struct e1_intf *intf, const uint8_t *data, size_t l
{
struct e1_usb_intf_data *id = intf->drv_data;
struct e1usb_gpsdo_status *last_st = &id->gpsdo.last_status;
const struct e1usb_gpsdo_status *st;
struct e1usb_gpsdo_status _st, *st = &_st;
struct e1_line *line;
if (len < sizeof(*st)) {
LOGPIF(intf, DE1D, LOGL_ERROR, "GPSDO status %zu < %zu!\n", len, sizeof(*st));
return;
/*
* Because some fields can be added to the structure by newer
* firmware revisions, this means we can potentially get a shorter
* struct than what we asked for. We simply set those fields to
* zero.
*
* The opposite case (newer firmware than e1d) means the structure
* could be larger, but because we limit the wLength to the struct
* we know, we can't receive a larger one and the new fields are
* just ignored by this e1d version
*/
LOGPIF(intf, DE1D, LOGL_DEBUG,
"GPSDO status %zu < %zu ! Firmware probably outdated. "
"Some values will be zeroed\n",
len, sizeof(*st));
}
st = (const struct e1usb_gpsdo_status *) data;
memset(st, 0x00, sizeof(*st));
memcpy(st, data, len);
if (st->state != last_st->state) {
LOGPIF(intf, DE1D, LOGL_NOTICE, "GPSDO state change: %s -> %s\n",
@ -750,6 +765,7 @@ _e1_usb_intf_gpsdo_status_cb(struct e1_intf *intf, const uint8_t *data, size_t l
line_stat_set(line, LINE_GPSDO_TUNE_COARSE, libusb_le16_to_cpu(st->tune.coarse));
line_stat_set(line, LINE_GPSDO_TUNE_FINE, libusb_le16_to_cpu(st->tune.fine));
line_stat_set(line, LINE_GPSDO_FREQ_EST, osmo_load32le(&st->freq_est));
line_stat_set(line, LINE_GPSDO_ERR_ACC, (int16_t)libusb_le16_to_cpu(st->err_acc));
}
/* update our state */