-/**
- * Parse the numerical value from a protocol packet.
- *
- * @param buf Buffer containing the 14-byte protocol packet.
- * @param result Pointer to a float variable. That variable will contain the
- * result value upon parsing success.
- *
- * @return SR_OK upon success, SR_ERR upon failure. Upon errors, the result
- * variable contents are undefined and should not be used.
- */
+static gboolean sync_nibbles_valid(const uint8_t *buf)
+{
+ int i;
+
+ /* Check the synchronization nibbles, and make sure they all match. */
+ for (i = 0; i < FS9721_PACKET_SIZE; i++) {
+ if (((buf[i] >> 4) & 0x0f) != (i + 1)) {
+ sr_err("Sync nibble in byte %d (0x%02x) is invalid.",
+ i, buf[i]);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+static gboolean flags_valid(const struct fs9721_info *info)
+{
+ int count;
+
+ /* Does the packet have more than one multiplier? */
+ count = 0;
+ count += (info->is_nano) ? 1 : 0;
+ count += (info->is_micro) ? 1 : 0;
+ count += (info->is_milli) ? 1 : 0;
+ count += (info->is_kilo) ? 1 : 0;
+ count += (info->is_mega) ? 1 : 0;
+ if (count > 1) {
+ sr_err("More than one multiplier detected in packet.");
+ return FALSE;
+ }
+
+ /* Does the packet "measure" more than one type of value? */
+ count = 0;
+ count += (info->is_hz) ? 1 : 0;
+ count += (info->is_ohm) ? 1 : 0;
+ count += (info->is_farad) ? 1 : 0;
+ count += (info->is_ampere) ? 1 : 0;
+ count += (info->is_volt) ? 1 : 0;
+ count += (info->is_percent) ? 1 : 0;
+ if (count > 1) {
+ sr_err("More than one measurement type detected in packet.");
+ return FALSE;
+ }
+
+ /* Both AC and DC set? */
+ if (info->is_ac && info->is_dc) {
+ sr_err("Both AC and DC flags detected in packet.");
+ return FALSE;
+ }
+
+ /* RS232 flag not set? */
+ if (!info->is_rs232) {
+ sr_err("No RS232 flag detected in packet.");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+