2011-07-18 22:33:40 +02:00
|
|
|
/*
|
2011-07-23 21:32:08 +02:00
|
|
|
* (c) 2011 Siegen, Germany by Nils Faerber <nils.faerber@kernelconcepts.de>
|
2011-07-18 22:33:40 +02:00
|
|
|
*
|
2011-07-23 19:08:06 +02:00
|
|
|
* license LGPL
|
2011-07-18 22:33:40 +02:00
|
|
|
*/
|
2011-07-23 21:32:08 +02:00
|
|
|
|
2011-07-18 22:33:40 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2011-07-19 14:13:11 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2011-07-19 12:31:32 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2011-07-19 14:13:11 +02:00
|
|
|
#include <termios.h>
|
2011-07-23 21:32:08 +02:00
|
|
|
#include <ctype.h>
|
2011-07-18 22:33:40 +02:00
|
|
|
|
|
|
|
#include "metawatch_protocol.h"
|
2011-07-19 12:31:32 +02:00
|
|
|
#include "crc16ccitt.h"
|
|
|
|
|
|
|
|
|
2011-07-23 19:08:06 +02:00
|
|
|
#define MW_FRAME_DELAY 0x00
|
|
|
|
|
2011-07-19 12:31:32 +02:00
|
|
|
void dump_frame(unsigned char *frame, int len)
|
|
|
|
{
|
2011-07-23 17:56:24 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<len; i++)
|
|
|
|
fprintf(stderr, "0x%02x ", frame[i]);
|
|
|
|
fprintf(stderr, "\n");
|
2011-07-19 12:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-23 18:26:16 +02:00
|
|
|
int mw_send_frame(int mw_fd, unsigned char msg_type, unsigned char options, unsigned char *data, unsigned char len)
|
2011-07-19 12:31:32 +02:00
|
|
|
{
|
2011-07-23 17:56:24 +02:00
|
|
|
unsigned short crc;
|
|
|
|
unsigned char frame[64];
|
|
|
|
int tlen = len + 6; /* payload + 6 bytes frameing */
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
memset(frame, 0, 64);
|
|
|
|
frame[0] = MW_SOF;
|
|
|
|
frame[1] = len + 6;
|
|
|
|
frame[2] = msg_type;
|
|
|
|
frame[3] = options;
|
|
|
|
if (data != NULL && len > 0)
|
|
|
|
memcpy(frame+4, data, len);
|
2011-07-19 12:31:32 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
crc = crc16ccitt(frame, len+4);
|
|
|
|
*(unsigned short *)(frame+len+4) = crc;
|
2011-07-19 12:31:32 +02:00
|
|
|
|
2011-07-23 21:32:08 +02:00
|
|
|
#ifdef DEBUG
|
2011-07-23 17:56:24 +02:00
|
|
|
dump_frame(frame, tlen);
|
2011-07-23 21:32:08 +02:00
|
|
|
#endif
|
2011-07-19 14:13:11 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
while (((ret = write(mw_fd, frame, tlen)) >= 0) && (tlen > 0))
|
|
|
|
tlen -= ret;
|
|
|
|
|
2011-07-23 19:08:06 +02:00
|
|
|
if (MW_FRAME_DELAY)
|
|
|
|
usleep(MW_FRAME_DELAY);
|
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
if (tlen == 0 && ret >= 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return ret;
|
2011-07-19 12:31:32 +02:00
|
|
|
}
|
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
/*
|
|
|
|
* host to watch commands
|
|
|
|
*/
|
|
|
|
|
2011-07-19 12:31:32 +02:00
|
|
|
void mw_set_rtc(int mw_fd, unsigned char clk1224, unsigned char date_fmt)
|
|
|
|
{
|
2011-07-23 17:56:24 +02:00
|
|
|
time_t mtime;
|
|
|
|
struct tm mtm;
|
|
|
|
unsigned short year;
|
|
|
|
unsigned char data[32];
|
|
|
|
|
|
|
|
mtime = time(NULL);
|
|
|
|
localtime_r(&mtime, &mtm);
|
|
|
|
|
|
|
|
year = mtm.tm_year + 1900;
|
|
|
|
data[0] = (year & 0x0f00) >> 8;
|
|
|
|
data[1] = (year & 0x00ff);
|
|
|
|
data[2] = mtm.tm_mon + 1;
|
|
|
|
data[3] = mtm.tm_mday;
|
|
|
|
data[4] = mtm.tm_wday;
|
|
|
|
data[5] = mtm.tm_hour;
|
|
|
|
data[6] = mtm.tm_min;
|
|
|
|
data[7] = mtm.tm_sec;
|
|
|
|
data[8] = clk1224;
|
|
|
|
data[9] = date_fmt;
|
|
|
|
|
2011-07-23 18:26:16 +02:00
|
|
|
mw_send_frame(mw_fd, MW_SET_REAL_TIME_CLOCK, 0, data, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mw_set_vibrate_mode(int mw_fd, unsigned char enable, unsigned short on_time, unsigned short off_time, unsigned char cycles)
|
|
|
|
{
|
|
|
|
unsigned char mdata[7];
|
|
|
|
|
|
|
|
mdata[0] = enable;
|
|
|
|
*(unsigned short *)(mdata+1) = on_time; /* miliseconds */
|
|
|
|
*(unsigned short *)(mdata+3) = off_time; /* miliseconds */
|
|
|
|
mdata[5] = cycles;
|
|
|
|
mw_send_frame(mw_fd, MW_SET_VIBRATE_MODE, 0, mdata, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mw_configure_watch_mode(int mw_fd, unsigned char mode, unsigned char save, unsigned char timeout, unsigned char invert)
|
|
|
|
{
|
|
|
|
unsigned char mdata[3];
|
|
|
|
|
|
|
|
mdata[0] = timeout; /* seconds */
|
|
|
|
mdata[1] = invert; /* 0=normal, 1=invert */
|
2011-07-23 21:32:08 +02:00
|
|
|
mw_send_frame(mw_fd, MW_CONFIGURE_MODE, (mode & 0x0f) | ((save & 0x01) << 4), mdata, 2);
|
2011-07-23 18:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void mw_update_display(int mw_fd, unsigned char mode, unsigned char copy)
|
|
|
|
{
|
2011-07-23 21:32:08 +02:00
|
|
|
mw_send_frame(mw_fd, MW_UPDATE_DISPLAY, (mode & 0x0f) | ((copy & 0x01) << 4), NULL, 0);
|
2011-07-23 17:56:24 +02:00
|
|
|
}
|
|
|
|
|
2011-07-23 19:08:06 +02:00
|
|
|
void mw_load_template(int mw_fd, unsigned char mode, unsigned char template_select)
|
|
|
|
{
|
|
|
|
mw_send_frame(mw_fd, MW_LOAD_TEMPLATE, (mode & 0x0f), &template_select, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* send line for screen-mode mode from *buffer to watch, starting at display row row_offset
|
|
|
|
*/
|
|
|
|
void mw_write_buffer(int mw_fd,
|
|
|
|
unsigned char mode,
|
2011-07-23 21:32:08 +02:00
|
|
|
unsigned char numlines, /* number of lines, 0=two lines or 1=one line */
|
2011-07-23 19:08:06 +02:00
|
|
|
unsigned char row_offset, /* start at row_offset in display, e.g. lower part in idle @31 */
|
|
|
|
unsigned char *buffer, int buflen)
|
|
|
|
{
|
|
|
|
unsigned char mdata[32];
|
|
|
|
|
|
|
|
buflen = 12 * (buflen / 12); /* crop to 12 bytes */
|
|
|
|
if ((numlines == 0 && buflen < 12) || (numlines == 1 && buflen < 24)) {
|
|
|
|
fprintf(stderr, "mw_write_buffer: bufferlen does not match number of lines\n");
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
memset(mdata, 0, 32);
|
|
|
|
mdata[0] = row_offset;
|
|
|
|
memcpy((mdata+1), buffer, 12);
|
2011-07-23 21:32:08 +02:00
|
|
|
if (numlines == 0) {
|
|
|
|
mdata[13] = row_offset+1;
|
|
|
|
memcpy((mdata+14), (buffer+12), 12);
|
2011-07-23 19:08:06 +02:00
|
|
|
};
|
2011-07-23 21:32:08 +02:00
|
|
|
mw_send_frame(mw_fd, MW_WRITE_BUFFER, (mode & 0x0f) | (((numlines & 0x01)<< 4) & 0x10), mdata, numlines ? 13 : 26);
|
2011-07-23 19:08:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
/*
|
|
|
|
* watch responses, events or notifications
|
|
|
|
*/
|
|
|
|
void mw_get_real_time_clock_response(int mw_fd, unsigned char *rtcrsp, int len)
|
|
|
|
{
|
|
|
|
struct tm mtm;
|
|
|
|
unsigned short year;
|
|
|
|
unsigned char clk1224, date_fmt;
|
|
|
|
|
|
|
|
if (len != 10) {
|
|
|
|
fprintf(stderr, "get real time clock response too short %d != 10\n", len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
year = *(unsigned short *)rtcrsp;
|
|
|
|
mtm.tm_year = year - 1900;
|
|
|
|
mtm.tm_mon = rtcrsp[2] - 1;
|
|
|
|
mtm.tm_mday = rtcrsp[3];
|
|
|
|
mtm.tm_wday = rtcrsp[4];
|
|
|
|
mtm.tm_hour = rtcrsp[5];
|
|
|
|
mtm.tm_min = rtcrsp[6];
|
|
|
|
mtm.tm_sec = rtcrsp[7];
|
|
|
|
clk1224 = rtcrsp[8];
|
|
|
|
date_fmt = rtcrsp[9];
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
void mw_get_battery_voltage_response(int mw_fd, unsigned char *batrsp, int len)
|
|
|
|
{
|
|
|
|
unsigned short voltage = *(unsigned short *)batrsp;
|
|
|
|
unsigned char power_good = batrsp[2];
|
|
|
|
unsigned char bat_charging = batrsp[3];
|
|
|
|
|
|
|
|
fprintf(stderr, "battery is at %dV, %s and %s\n", voltage, power_good ? "power is good" : "power fault", bat_charging ? "charging" : "not charging");
|
|
|
|
}
|
|
|
|
|
2011-07-23 21:32:08 +02:00
|
|
|
void mw_status_change_event(int mw_fd, unsigned char option, unsigned char *statrsp, int len)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Status change event for mode %s: %s\n", mw_screen_mode_names[option&0x0f], mw_status_string[statrsp[0]]);
|
|
|
|
}
|
|
|
|
|
2011-07-23 19:08:06 +02:00
|
|
|
/* ---------------------------------------------------------------------- */
|
2011-07-23 18:26:16 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
int decode_frame(int mw_fd, unsigned char *buf, int len)
|
|
|
|
{
|
|
|
|
unsigned short crc;
|
|
|
|
unsigned char msglen;
|
|
|
|
unsigned char msgtype;
|
|
|
|
unsigned char msgopt;
|
|
|
|
unsigned char *msgdata;
|
|
|
|
|
|
|
|
/* check frame */
|
|
|
|
crc = *(unsigned short *)(buf+len-2);
|
|
|
|
if (crc != crc16ccitt(buf, len-2)) {
|
|
|
|
fprintf(stderr, "decode frame CRC error\n");
|
|
|
|
return 1;
|
|
|
|
} else
|
|
|
|
fprintf(stderr, "decode frame CRC OK\n");
|
|
|
|
if (buf[0] != MW_SOF) {
|
|
|
|
fprintf(stderr, "decode frame SOF not found\n");
|
|
|
|
return 1;
|
|
|
|
} else
|
|
|
|
fprintf(stderr, "decode frame found SOF\n");
|
|
|
|
|
|
|
|
msglen = buf[1];
|
|
|
|
msgtype = buf[2];
|
|
|
|
msgopt = buf[3];
|
|
|
|
msgdata = (buf+4);
|
|
|
|
|
|
|
|
switch (msgtype) {
|
|
|
|
case MW_GET_REAL_TIME_CLOCK_RSP:
|
|
|
|
mw_get_real_time_clock_response(mw_fd, msgdata, len-4-2);
|
|
|
|
break;
|
|
|
|
case MW_GET_INFORMATION_STRING_RSP:
|
|
|
|
msgdata[len-4-2] = 0;
|
|
|
|
fprintf(stderr, "Got info string '%s'\n", (msgdata+4));
|
|
|
|
break;
|
|
|
|
case MW_READ_BATTERY_VOLTAGE_RSP:
|
|
|
|
mw_get_battery_voltage_response(mw_fd, msgdata, len-4-2);
|
|
|
|
break;
|
|
|
|
case MW_LOW_BATTERY_WARNING_MSG:
|
|
|
|
fprintf(stderr, "Watch battery low, please connect charger\n");
|
|
|
|
break;
|
|
|
|
case MW_LOW_BATTERY_BT_OFF_MSG:
|
|
|
|
fprintf(stderr, "Watch battery extremely low - radio will turn off\n");
|
|
|
|
break;
|
2011-07-23 21:32:08 +02:00
|
|
|
case MW_STATUS_CHANGE_EVENT:
|
|
|
|
mw_status_change_event(mw_fd, msgopt, msgdata, len-4-2);
|
|
|
|
break;
|
2011-07-23 17:56:24 +02:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unkown msgtype 0x%02x\n", msgtype);
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
return 0;
|
2011-07-19 12:31:32 +02:00
|
|
|
}
|
|
|
|
|
2011-07-18 22:33:40 +02:00
|
|
|
|
2011-07-23 21:32:08 +02:00
|
|
|
void bitmap_test(int mw_fd)
|
|
|
|
{
|
|
|
|
/* a nice checker-board pattern */
|
|
|
|
unsigned char checkbuf[24] = {
|
|
|
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
|
|
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
|
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
|
};
|
|
|
|
mw_write_buffer(mw_fd, MW_SCREEN_MODE_IDLE, 0, 31, checkbuf, 24);
|
|
|
|
mw_write_buffer(mw_fd, MW_SCREEN_MODE_IDLE, 0, 33, checkbuf, 24);
|
|
|
|
mw_write_buffer(mw_fd, MW_SCREEN_MODE_IDLE, 0, 35, checkbuf, 24);
|
|
|
|
mw_write_buffer(mw_fd, MW_SCREEN_MODE_IDLE, 0, 37, checkbuf, 24);
|
|
|
|
|
|
|
|
mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void flip_buffer_bytes(unsigned char invert, unsigned char *buf, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char tmp;
|
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
tmp = 0;
|
|
|
|
for (i=0; i<8; i++)
|
|
|
|
tmp |= ((*buf & (1<<i)) >> i) << (7-i);
|
|
|
|
// fprintf(stderr, "0x%02x -> 0x%02x\n", *buf, tmp);
|
|
|
|
*buf = invert ? ~tmp : tmp;
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bitmap_read(int mw_fd)
|
|
|
|
{
|
|
|
|
int ffd, ret;
|
|
|
|
char rbuf[256];
|
|
|
|
unsigned int width, height, i, x, y;
|
|
|
|
unsigned int rowlength;
|
|
|
|
unsigned char *bmapbuf;
|
|
|
|
unsigned char mw_buf[24];
|
|
|
|
|
|
|
|
ffd = open("test.pbm", O_RDONLY);
|
|
|
|
if (ffd < 0) {
|
|
|
|
perror("open");
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
ret = read(ffd, rbuf, 3);
|
|
|
|
if (rbuf[0] != 'P' || rbuf[1] != '4') {
|
|
|
|
fprintf(stderr, "not a PBM file\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset(rbuf, 0, 256);
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
ret = read(ffd, (rbuf+i), 1);
|
|
|
|
} while (!isspace(rbuf[i++]));
|
|
|
|
width = atoi(rbuf);
|
|
|
|
|
|
|
|
memset(rbuf, 0, 256);
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
ret = read(ffd, (rbuf+i), 1);
|
|
|
|
} while (!isspace(rbuf[i++]));
|
|
|
|
height = atoi(rbuf);
|
|
|
|
|
|
|
|
fprintf(stderr, "bitmap resolution is %d x %d\n", width, height);
|
|
|
|
|
|
|
|
rowlength = ((width / 8) + 1);
|
|
|
|
fprintf(stderr, "row length = %d bytes\n", rowlength);
|
|
|
|
|
|
|
|
bmapbuf = malloc(rowlength * height);
|
|
|
|
|
|
|
|
ret = read(ffd, bmapbuf, rowlength * height);
|
|
|
|
close(ffd);
|
|
|
|
fprintf(stderr, "read %d of %d bytes\n", ret, rowlength * height);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
for (y=0; y<height; y++) {
|
|
|
|
for (x=0; x<rowlength; x++) {
|
|
|
|
for (i=0; i<8; i++)
|
|
|
|
fprintf(stderr, "%c", (bmapbuf[(y*rowlength)+x] & (1<<(7-i))) ? '.' : ' ');
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
flip_buffer_bytes(1, bmapbuf, rowlength * height);
|
|
|
|
|
|
|
|
for (y=0; y<height; y+=2) {
|
|
|
|
memset(mw_buf, 0, 24);
|
|
|
|
memcpy(mw_buf, (bmapbuf+(y*rowlength)), (rowlength > 12) ? 12 : rowlength);
|
|
|
|
memcpy((mw_buf+12), (bmapbuf+((y+1)*rowlength)), (rowlength > 12) ? 12 : rowlength);
|
|
|
|
mw_write_buffer(mw_fd, MW_SCREEN_MODE_IDLE, 0, 31+y, mw_buf, 24);
|
|
|
|
}
|
|
|
|
mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 1);
|
|
|
|
|
|
|
|
free(bmapbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-19 14:13:11 +02:00
|
|
|
void process_cmd(char *cmdline, int clinep, int mw_fd)
|
|
|
|
{
|
2011-07-23 17:56:24 +02:00
|
|
|
unsigned char mdata[32];
|
|
|
|
|
|
|
|
fprintf(stderr, "command: '%s'\n", cmdline);
|
|
|
|
|
|
|
|
if (strncmp(cmdline, "quit", 4) == 0) {
|
|
|
|
close(mw_fd);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(cmdline, "srtc", 4) == 0) {
|
|
|
|
fprintf(stderr, "Setting RTC from system time...");
|
|
|
|
mw_set_rtc(mw_fd, MW_RTC_CLOCK_24HR, MW_RTC_DATE_DDMM);
|
|
|
|
fprintf(stderr, "OK\n");
|
|
|
|
}
|
|
|
|
if (strncmp(cmdline, "grtc", 4) == 0) {
|
2011-07-23 18:26:16 +02:00
|
|
|
mw_send_frame(mw_fd, MW_GET_REAL_TIME_CLOCK, 0, NULL, 0);
|
2011-07-23 17:56:24 +02:00
|
|
|
}
|
|
|
|
if (strncmp(cmdline, "gistr", 5) == 0) {
|
|
|
|
mdata[0] = 0;
|
2011-07-23 18:26:16 +02:00
|
|
|
mw_send_frame(mw_fd, MW_GET_INFORMATION_STRING, 0, mdata, 1);
|
2011-07-23 17:56:24 +02:00
|
|
|
}
|
|
|
|
if (strncmp(cmdline, "gdtype", 6) == 0) {
|
2011-07-23 18:26:16 +02:00
|
|
|
mw_send_frame(mw_fd, MW_GET_DEVICE_TYPE, 0, NULL, 0);
|
2011-07-23 17:56:24 +02:00
|
|
|
}
|
|
|
|
if (strncmp(cmdline, "rvbat", 5) == 0) {
|
2011-07-23 18:26:16 +02:00
|
|
|
mw_send_frame(mw_fd, MW_READ_BATTERY_VOLTAGE_MSG, 0, NULL, 0);
|
2011-07-23 17:56:24 +02:00
|
|
|
}
|
|
|
|
if (strncmp(cmdline, "modecfg", 6) == 0) {
|
2011-07-23 18:26:16 +02:00
|
|
|
mw_configure_watch_mode(mw_fd, MW_SCREEN_MODE_IDLE, 0, 4, 1);
|
|
|
|
mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 0);
|
2011-07-23 17:56:24 +02:00
|
|
|
}
|
|
|
|
if (strncmp(cmdline, "rbtcfg", 6) == 0) {
|
|
|
|
mdata[0] = 0; /* idle screen */
|
|
|
|
mdata[1] = 1; /* button index */
|
|
|
|
mdata[2] = 2; /* button press type */
|
|
|
|
mdata[3] = 3; /* callback message type */
|
|
|
|
mdata[4] = 4; /* callback message option */
|
2011-07-23 18:26:16 +02:00
|
|
|
mw_send_frame(mw_fd, MW_READ_BUTTON_CONFIG, 0, NULL, 0);
|
2011-07-23 17:56:24 +02:00
|
|
|
}
|
|
|
|
if (strncmp(cmdline, "svib", 4) == 0) {
|
2011-07-23 18:26:16 +02:00
|
|
|
mw_set_vibrate_mode(mw_fd, 1, 300, 300, 5);
|
2011-07-23 17:56:24 +02:00
|
|
|
}
|
2011-07-23 21:32:08 +02:00
|
|
|
if (strncmp(cmdline, "tbmp", 4) == 0) {
|
|
|
|
bitmap_test(mw_fd);
|
|
|
|
}
|
|
|
|
if (strncmp(cmdline, "rbmp", 4) == 0) {
|
|
|
|
bitmap_read(mw_fd);
|
|
|
|
}
|
2011-07-19 14:13:11 +02:00
|
|
|
}
|
|
|
|
|
2011-07-23 18:26:16 +02:00
|
|
|
|
2011-07-19 14:13:11 +02:00
|
|
|
int menu(int mw_fd)
|
|
|
|
{
|
2011-07-23 17:56:24 +02:00
|
|
|
fd_set mfds;
|
|
|
|
struct termios tconfd;
|
|
|
|
char cmdline[128];
|
|
|
|
unsigned char msg_buf[64];
|
|
|
|
unsigned char clinep = 0;
|
|
|
|
int rcvd;
|
|
|
|
|
|
|
|
tcgetattr(0, &tconfd);
|
|
|
|
cfmakeraw(&tconfd);
|
|
|
|
tconfd.c_oflag |= ONLCR | OPOST;
|
|
|
|
tconfd.c_lflag |= ISIG;
|
|
|
|
tcsetattr(0, TCSANOW, &tconfd);
|
|
|
|
|
|
|
|
FD_ZERO(&mfds);
|
|
|
|
FD_SET(0, &mfds);
|
|
|
|
FD_SET(mw_fd, &mfds);
|
|
|
|
|
|
|
|
memset(cmdline, 0, 128);
|
|
|
|
|
|
|
|
do {
|
|
|
|
rcvd = 0;
|
|
|
|
if (select(mw_fd+1, &mfds, NULL, NULL, NULL) > 0) {
|
|
|
|
if (FD_ISSET(mw_fd, &mfds)) {
|
|
|
|
rcvd = read(mw_fd, msg_buf, 64);
|
|
|
|
fprintf(stderr, "read %d bytes:\n", rcvd);
|
|
|
|
if (rcvd > 0) {
|
|
|
|
dump_frame(msg_buf, rcvd);
|
|
|
|
decode_frame(mw_fd, msg_buf, rcvd);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (FD_ISSET(0, &mfds)) {
|
|
|
|
rcvd = read(0, (cmdline+clinep), 1);
|
|
|
|
if (rcvd > 0) {
|
|
|
|
if (cmdline[clinep] == '\r') {
|
|
|
|
printf("\n");
|
|
|
|
cmdline[clinep--] = '\0';
|
|
|
|
process_cmd(cmdline, clinep, mw_fd);
|
|
|
|
clinep = 0;
|
|
|
|
memset(cmdline, 0, 128);
|
|
|
|
} else {
|
|
|
|
clinep++;
|
|
|
|
if (clinep > 75)
|
|
|
|
clinep = 75;
|
|
|
|
printf("\r> %s", cmdline);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
FD_ZERO(&mfds);
|
|
|
|
FD_SET(0, &mfds);
|
|
|
|
FD_SET(mw_fd, &mfds);
|
|
|
|
} while (rcvd > 0);
|
|
|
|
|
|
|
|
return 0;
|
2011-07-19 14:13:11 +02:00
|
|
|
}
|
|
|
|
|
2011-07-18 22:33:40 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2011-07-23 17:56:24 +02:00
|
|
|
int mw_fd;
|
2011-07-18 22:33:40 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "Usage:\n\t%s <devicename>\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
};
|
2011-07-18 22:33:40 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
crc16ccitt_init();
|
2011-07-19 12:31:32 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
mw_fd = open(argv[1], O_RDWR);
|
|
|
|
if (mw_fd < 0) {
|
|
|
|
perror("open");
|
|
|
|
return 1;
|
|
|
|
};
|
2011-07-18 22:33:40 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
menu(mw_fd);
|
2011-07-19 12:31:32 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
fsync(mw_fd);
|
2011-07-19 12:31:32 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
close(mw_fd);
|
2011-07-19 12:31:32 +02:00
|
|
|
|
2011-07-23 17:56:24 +02:00
|
|
|
return 0;
|
2011-07-18 22:33:40 +02:00
|
|
|
};
|
2011-07-23 17:56:24 +02:00
|
|
|
|