Fix the datetime parsing for the Oceanic OC1.

This commit is contained in:
Jef Driesen 2010-04-27 11:34:05 +00:00
parent 6503ff2351
commit e803369364

View File

@ -119,20 +119,29 @@ oceanic_atom2_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
const unsigned char *p = abstract->data;
if (datetime) {
if (parser->model == 0x4258) {
// VT3
datetime->year = ((p[3] & 0xE0) >> 1) + (p[4] & 0x0F) + 2000;
datetime->month = (p[4] & 0xF0) >> 4;
datetime->day = p[3] & 0x1F;
datetime->hour = bcd2dec (p[1] & 0x7F);
} else {
// Atom 2
datetime->year = bcd2dec (((p[3] & 0xC0) >> 2) + (p[4] & 0x0F)) + 2000;
datetime->month = (p[4] & 0xF0) >> 4;
datetime->day = bcd2dec (p[3] & 0x3F);
datetime->hour = bcd2dec (p[1] & 0x1F);
switch (parser->model) {
case 0x434E: // OC1
datetime->year = ((p[5] & 0xE0) >> 5) + ((p[7] & 0xE0) >> 2) + 2000;
datetime->month = (p[3] & 0x0F);
datetime->day = ((p[0] & 0x80) >> 3) + ((p[3] & 0xF0) >> 4);
datetime->hour = bcd2dec (p[1] & 0x1F);
datetime->minute = bcd2dec (p[0] & 0x7F);
break;
case 0x4258: // VT3
datetime->year = ((p[3] & 0xE0) >> 1) + (p[4] & 0x0F) + 2000;
datetime->month = (p[4] & 0xF0) >> 4;
datetime->day = p[3] & 0x1F;
datetime->hour = bcd2dec (p[1] & 0x7F);
datetime->minute = bcd2dec (p[0]);
break;
default: // Atom 2
datetime->year = bcd2dec (((p[3] & 0xC0) >> 2) + (p[4] & 0x0F)) + 2000;
datetime->month = (p[4] & 0xF0) >> 4;
datetime->day = bcd2dec (p[3] & 0x3F);
datetime->hour = bcd2dec (p[1] & 0x1F);
datetime->minute = bcd2dec (p[0]);
break;
}
datetime->minute = bcd2dec (p[0]);
datetime->second = 0;
// Convert to a 24-hour clock.