Add fixes for RTC and NVAL commands from Oleg Titov - thanks!

This commit is contained in:
Nils Faerber 2011-11-09 22:06:55 +01:00
parent 681932903c
commit 201b7df50b
3 changed files with 14 additions and 19 deletions

View file

@ -105,7 +105,7 @@ int mw_send_frame(mwdevice_t *mwdevice, unsigned char msg_type, unsigned char op
* ---------------------------------------------------------------------- */ * ---------------------------------------------------------------------- */
int mw_set_rtc(mwdevice_t *mwdevice, unsigned char clk1224, unsigned char date_fmt) int mw_set_rtc(mwdevice_t *mwdevice)
{ {
time_t mtime; time_t mtime;
struct tm mtm; struct tm mtm;
@ -124,18 +124,16 @@ int mw_set_rtc(mwdevice_t *mwdevice, unsigned char clk1224, unsigned char date_f
data[5] = mtm.tm_hour; data[5] = mtm.tm_hour;
data[6] = mtm.tm_min; data[6] = mtm.tm_min;
data[7] = mtm.tm_sec; data[7] = mtm.tm_sec;
data[8] = clk1224;
data[9] = date_fmt;
return mw_send_frame(mwdevice, MW_SET_REAL_TIME_CLOCK, 0, data, 10); return mw_send_frame(mwdevice, MW_SET_REAL_TIME_CLOCK, 0, data, 8);
} }
int mw_nval_operation(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata) int mw_nval_operation(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata)
{ {
unsigned char data[32]; unsigned char data[32];
data[0] = (identifier & 0xff00) >> 8; data[0] = (identifier & 0x00ff);
data[1] = (identifier & 0x00ff); data[1] = (identifier & 0xff00) >> 8;
data[2] = size; data[2] = size;
if (size > 0 && mdata != NULL) if (size > 0 && mdata != NULL)
memcpy((data+3), mdata, size); memcpy((data+3), mdata, size);
@ -362,9 +360,8 @@ int mw_get_real_time_clock_response(mwdevice_t *mwdevice, unsigned char *rtcrsp,
{ {
struct tm mtm; struct tm mtm;
unsigned short year; unsigned short year;
unsigned char clk1224, date_fmt;
if (len != 10) { if (len != 8) {
fprintf(stderr, "get real time clock response length wrong %d != 10\n", len); fprintf(stderr, "get real time clock response length wrong %d != 10\n", len);
return -1; return -1;
} }
@ -377,11 +374,9 @@ int mw_get_real_time_clock_response(mwdevice_t *mwdevice, unsigned char *rtcrsp,
mtm.tm_hour = rtcrsp[5]; mtm.tm_hour = rtcrsp[5];
mtm.tm_min = rtcrsp[6]; mtm.tm_min = rtcrsp[6];
mtm.tm_sec = rtcrsp[7]; mtm.tm_sec = rtcrsp[7];
clk1224 = rtcrsp[8];
date_fmt = rtcrsp[9];
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "watch RTC is %s, clock format is %s, date format is %s\n", asctime(&mtm), clk1224 ? "24h" : "AM/PM", date_fmt ? "DD/MM" : "MM/DD"); fprintf(stderr, "watch RTC is %s\n", asctime(&mtm));
#endif #endif
if (mwdevice->mw_get_real_time_clock_response_cb != NULL) if (mwdevice->mw_get_real_time_clock_response_cb != NULL)
mwdevice->mw_get_real_time_clock_response_cb(mwdevice, &mtm, mwdevice->mw_grtcrsp_data); mwdevice->mw_get_real_time_clock_response_cb(mwdevice, &mtm, mwdevice->mw_grtcrsp_data);
@ -400,12 +395,13 @@ void mw_set_get_real_time_clock_response_cb(mwdevice_t *mwdevice, void (*mw_get_
int mw_get_battery_voltage_response(mwdevice_t *mwdevice, unsigned char *batrsp, int len) int mw_get_battery_voltage_response(mwdevice_t *mwdevice, unsigned char *batrsp, int len)
{ {
unsigned short voltage = *(unsigned short *)batrsp; unsigned char power_good = batrsp[0];
unsigned char power_good = batrsp[2]; unsigned char bat_charging = batrsp[1];
unsigned char bat_charging = batrsp[3]; unsigned short voltage = *(unsigned short *)(batrsp+2);
unsigned short voltage_average = *(unsigned short *)(batrsp+4);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "battery is at %dmV, %s and %s\n", voltage, power_good ? "power is good" : "power fault", bat_charging ? "charging" : "not charging"); fprintf(stderr, "battery is at %dmV (average is %dmV), %s and %s\n", voltage, voltage_average, power_good ? "power is good" : "power fault", bat_charging ? "charging" : "not charging");
#endif #endif
if (mwdevice->mw_get_battery_voltage_response_cb != NULL) if (mwdevice->mw_get_battery_voltage_response_cb != NULL)

View file

@ -40,7 +40,7 @@ void dump_frame(unsigned char *frame, int len);
int mw_send_frame(mwdevice_t *mwdevice, unsigned char msg_type, unsigned char options, unsigned char *data, unsigned char len); int mw_send_frame(mwdevice_t *mwdevice, unsigned char msg_type, unsigned char options, unsigned char *data, unsigned char len);
int mw_set_rtc(mwdevice_t *mwdevice, unsigned char clk1224, unsigned char date_fmt); int mw_set_rtc(mwdevice_t *mwdevice);
int mw_nval_operation(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata); int mw_nval_operation(mwdevice_t *mwdevice, unsigned char operation, unsigned short identifier, unsigned char size, void *mdata);

View file

@ -498,7 +498,7 @@ void process_cmd(char *cmdline, int clinep, mwdata_t *mwdata)
} }
if (strncmp(cmdline, "srtc", 4) == 0) { if (strncmp(cmdline, "srtc", 4) == 0) {
fprintf(stderr, "Setting RTC from system time..."); fprintf(stderr, "Setting RTC from system time...");
mw_set_rtc(&mwdata->mwdevice, MW_RTC_CLOCK_24HR, MW_RTC_DATE_DDMM); mw_set_rtc(&mwdata->mwdevice);
fprintf(stderr, "OK\n"); fprintf(stderr, "OK\n");
} }
if (strncmp(cmdline, "grtc", 4) == 0) { if (strncmp(cmdline, "grtc", 4) == 0) {
@ -583,8 +583,7 @@ void process_cmd(char *cmdline, int clinep, mwdata_t *mwdata)
} }
if (strncmp(cmdline, "g24", 3) == 0) { if (strncmp(cmdline, "g24", 3) == 0) {
mdata[0] = 0; mdata[0] = 0;
mdata[1] = 0; mw_nval_operation(&mwdata->mwdevice, MW_NVAL_OPERATION_READ, MW_NVAL_TIME_FORMAT, 1, mdata);
mw_nval_operation(&mwdata->mwdevice, MW_NVAL_OPERATION_READ, MW_NVAL_TIME_FORMAT, 2, mdata);
} }
} }