- /* Bytes 4-8: Value (up to 4 digits) and decimal point */
- factor = 1000;
- for (i = 0; i < 5; i++) {
- digit = buf[4 + i];
- /* Convert spaces to '0', so that we can parse them. */
- if (digit == ' ')
- digit = '0';
- if (digit == '.') {
- decimal_point = i;
- } else if (isdigit(digit)) {
- intval += (digit - '0') * factor;
- factor /= 10;
- } else {
- sr_err("Invalid digit byte: 0x%02x.", digit);
- return SR_ERR;
- }
- }
-
- floatval = (float)intval;
-
- /* Decimal point position */
- if (decimal_point == 0 || decimal_point == 4) {
- /* TODO: Doesn't happen? */
- } else if (decimal_point == 1) {
- floatval /= 1000;
- } else if (decimal_point == 2) {
- floatval /= 100;
- } else if (decimal_point == 3) {
- floatval /= 10;
- } else {
- sr_err("Invalid decimal point position: %d.", decimal_point);
- return SR_ERR;
- }
-
- /* Apply sign. */
- floatval *= sign;
+ /* Bytes 2-8: Sign, value (up to 5 digits) and decimal point */
+ sscanf((const char *)&valstr, "%f", result);