Skip to content

Instantly share code, notes, and snippets.

@jquast
Created November 9, 2012 00:44
Show Gist options
  • Save jquast/4042964 to your computer and use it in GitHub Desktop.
Save jquast/4042964 to your computer and use it in GitHub Desktop.
CM11a timeclock struct test
#include <stdio.h>
#include <time.h>
struct cm11_setclock {
char cmd; /* 0x9b */
char seconds; /* 0-60 */
char minutes; /* 0-119 */
char hours; /* 0-11 (hours/2) */
char yearday; /* really 9 bits */
char weekday; /* really 7 bits */
char house; /* 0:timer purge, 1:monitor clear, 3:battery clear */
};
int main(int argc, char **argv) {
struct tm *tm;
time_t t;
struct cm11_setclock sc;
int housecode = 0x60;
int reset;
time(&t);
tm = localtime(&t);
sc.cmd = x9b;
sc.seconds = tm->tm_sec;
sc.minutes = tm->tm_min + 60 * (tm->tm_hour & 1);
sc.hours = tm->tm_hour >> 1;
sc.yearday = tm->tm_yday;
sc.weekday = 1 << tm->tm_wday;
if(tm->tm_yday & 0x100)
sc.weekday |= 0x80;
sc.house = housecode;
sc.house |= reset;
printf("struct cm11_setclock:\n \
cmd: %x\n\
seconds: %x\n\
minutes: %x\n\
hours: %x\n\
yearday: %x\n\
weekday: %x\n\
house << 4: %x\n\
house |= 1: %x\n\
house: %x\n",
sc.cmd, sc.seconds, sc.minutes, sc.hours, sc.yearday, sc.weekday,
sc.house, sc.house &0x0f, sc.house
);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment