Make the bcd2dec() function available to all backends.

This commit is contained in:
Jef Driesen 2009-12-08 14:51:32 +00:00
parent 1d69b8c021
commit 97652c6c62
3 changed files with 10 additions and 11 deletions

View File

@ -132,3 +132,9 @@ array_uint16_le (const unsigned char data[])
{
return data[0] + (data[1] << 8);
}
unsigned char
bcd2dec (unsigned char value)
{
return ((value >> 4) & 0x0f) * 10 + (value & 0x0f);
}

View File

@ -61,6 +61,9 @@ array_uint16_be (const unsigned char data[]);
unsigned short
array_uint16_le (const unsigned char data[]);
unsigned char
bcd2dec (unsigned char value);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -54,16 +54,6 @@ iceil (unsigned int x, unsigned int n)
}
static unsigned char
bcd (unsigned char value)
{
unsigned char lower = (value ) & 0x0F;
unsigned char upper = (value >> 4) & 0x0F;
return lower + 10 * upper;
}
static unsigned int
get_profile_first (const unsigned char data[], const oceanic_common_layout_t *layout)
{
@ -155,7 +145,7 @@ oceanic_common_device_foreach (oceanic_common_device_t *device, const oceanic_co
device_devinfo_t devinfo;
devinfo.model = array_uint16_be (id + 8);
devinfo.firmware = 0;
devinfo.serial = bcd (id[10]) * 10000 + bcd (id[11]) * 100 + bcd (id[12]);
devinfo.serial = bcd2dec (id[10]) * 10000 + bcd2dec (id[11]) * 100 + bcd2dec (id[12]);
device_event_emit (abstract, DEVICE_EVENT_DEVINFO, &devinfo);
// Read the pointer data.