- int n_postfix = 0, n_type = 0;
-
- /* Does the packet have more than one multiplier? */
- if (data->flags & LCD14_NANO)
- n_postfix++;
- if (data->flags & LCD14_MICRO)
- n_postfix++;
- if (data->flags & LCD14_MILLI)
- n_postfix++;
- if (data->flags & LCD14_KILO)
- n_postfix++;
- if (data->flags & LCD14_MEGA)
- n_postfix++;
-
- if (n_postfix > 1)
- return FALSE;
-
- /* Does the packet "measure" more than one type of value? */
- if (data->flags & LCD14_HZ)
- n_type++;
- if (data->flags & LCD14_OHM)
- n_type++;
- if (data->flags & LCD14_FARAD)
- n_type++;
- if (data->flags & LCD14_AMP)
- n_type++;
- if (data->flags & LCD14_VOLT)
- n_type++;
- if (data->flags & LCD14_DUTY)
- n_type++;
- if (data->flags & LCD14_CELSIUS)
- n_type++;
- /* Do not test for hFE. hFE is not implemented and always '1'. */
- if (n_type > 1)
- return FALSE;
-
- /* Both AC and DC? */
- if ((data->flags & LCD14_AC) && (data->flags & LCD14_DC))
- return FALSE;
-
- /* OK, no duplicates. */
- return TRUE;
-}
-
-/* We "cook" a raw lcd14_pcaket into a more pallatable form, lcd14_data. */
-static void lcd14_cook_raw(const struct lcd14_packet *packet,
- struct lcd14_data *data)
-{
- int i, j;
-
- /* Get the digits out. */
- for (i = 0; i < 4; i++) {
- j = (i << 1) + 1;
- data->digit[i] = ((packet->raw[j] & ~LCD14_SYNC_MASK) << 4) |
- ((packet->raw[j + 1] & ~LCD14_SYNC_MASK));
- }
-
- /* Now extract the flags. */
- data->flags = ((packet->raw[0] & ~LCD14_SYNC_MASK) << 20) |
- ((packet->raw[9] & ~LCD14_SYNC_MASK) << 16) |
- ((packet->raw[10] & ~LCD14_SYNC_MASK) << 12) |
- ((packet->raw[11] & ~LCD14_SYNC_MASK) << 8) |
- ((packet->raw[12] & ~LCD14_SYNC_MASK) << 4) |
- ((packet->raw[13] & ~LCD14_SYNC_MASK));
-}
-
-/*
- * Since the DMM does not identify itself in any way shape, or form, we really
- * don't know for sure who is sending the data. We must use every possible
- * check to filter out bad packets, especially since the detection mechanism
- * depends on how well we can filter out bad packets packets.
- */
-SR_PRIV gboolean lcd14_is_packet_valid(const struct lcd14_packet *packet,
- struct lcd14_data *data)
-{
- struct lcd14_data placeholder;
-
- /* Callers not interested in the data, pass NULL. */
- if (data == NULL)
- data = &placeholder;
-
- if (!lcd14_is_sync_valid(packet))
- return FALSE;
-
- lcd14_cook_raw(packet, data);
-
- if (!lcd14_is_selection_good(data))
- return FALSE;
-
- /* If we made it here, this looks to be a valid packet. */
- return TRUE;
-}
-
-static uint8_t lcd14_to_digit(uint8_t raw_digit)
-{
- /* Take out the decimal point, so we can use a simple switch(). */
- raw_digit &= ~LCD14_DP_MASK;
-
- switch (raw_digit) {
- case 0x00:
- case LCD14_LCD_0:
- return 0;
- case LCD14_LCD_1:
- return 1;
- case LCD14_LCD_2:
- return 2;
- case LCD14_LCD_3:
- return 3;
- case LCD14_LCD_4:
- return 4;
- case LCD14_LCD_5:
- return 5;
- case LCD14_LCD_6:
- return 6;
- case LCD14_LCD_7:
- return 7;
- case LCD14_LCD_8:
- return 8;
- case LCD14_LCD_9:
- return 9;
- default:
- return LCD14_LCD_INVALID;
- }
-}
-
-/* Get a raw floating point value from the data. */
-static double lcdraw_to_double(struct lcd14_data *data)
-{
- double rawval;
- double multiplier = 1;
- uint8_t digit, raw_digit;
- gboolean dp_reached = FALSE;
- int i;
-
- /* We have 4 digits, and we start from the most significant. */
- for (i = 0; i < 4; i++) {
- raw_digit = data->digit[i];
- digit = lcd14_to_digit(raw_digit);
- if (digit == LCD14_LCD_INVALID) {
- rawval = NAN;
- break;
- }
-
- /*
- * Digit 1 does not have a decimal point. Instead, the decimal
- * point is used to indicate MAX, so we must avoid testing it.
- */
- if ((i > 0) && (raw_digit & LCD14_DP_MASK))
- dp_reached = TRUE;
- if (dp_reached)
- multiplier /= 10;
- rawval = rawval * 10 + digit;
- }
- rawval *= multiplier;
- if (data->digit[0] & LCD14_D0_NEG)
- rawval *= -1;
-
- /* See if we need to multiply our raw value by anything. */
- if (data->flags & LCD14_NANO)
- rawval *= 1E-9;
- else if (data->flags & LCD14_MICRO)
- rawval *= 1E-6;
- else if (data->flags & LCD14_MILLI)
- rawval *= 1E-3;
- else if (data->flags & LCD14_KILO)
- rawval *= 1E3;
- else if (data->flags & LCD14_MEGA)
- rawval *= 1E6;
-
- return rawval;