Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tz1/bluev
base: d2739b0602
...
head fork: tz1/bluev
compare: 27631cf81f
  • 6 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
15 ArduinoMega.HOWTO.txt
@@ -64,12 +64,15 @@ information and reconfigure your V1.
You will need the IDE from arduino.cc to compile and flash the
program. It is available for the PC, Mac, and Linux.
-The files bluev.ino, bluevirq, and bluevmega.c can be copied into a
-folder named "bluev" in the arduino sketchbook folder, and opened as a
-sketch (that is what it calls protrams) and compiled and uploaded by
-pressing the "play" button. Remember to set the COM port and the
-board type (it should work with any Mega compatible, but older boards
-use a 1280, newer ones use a 2560, so check which one you have.
+Copy the bluev_sketch folder to the sketchbook folder for the Arduino.
+
+You can open it using the IDE directly or double-click on the
+bluev_sketch.ino file in the folder.
+
+The program can then be compiled and uploaded by pressing the "play"
+button. Remember to set the COM port and the board type (it should
+work with any Mega compatible, but older boards use a 1280, newer ones
+use a 2560, so check which one you have.
You can use the serial monitor and use the top box to send the command
characters, but a terminal program might be easier.
View
16 Makefile.ArduMega → bluev_sketch/Makefile
@@ -1,7 +1,7 @@
HOSTCC = gcc -Wall -O6
PRG = bluevmega
-OBJ = bluevmega.o
+OBJ = bluevmega.o bluevirq.o
MCU = atmega1280
OPTIMIZE = -Os
@@ -19,28 +19,20 @@ LDFLAGS = -Wl,-Map,$(PRG).map
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
-all: $(PRG).elf lst text eeprom size v1reShark v1send v1test
-
-v1reShark: v1reShark.c
- $(HOSTCC) v1reShark.c -o $@
-
-v1send: v1send.c
- $(HOSTCC) v1send.c -o $@
-
-v1test: v1test.c
- $(HOSTCC) v1test.c -o $@
+all: $(PRG).elf lst text eeprom size
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
bluevmega.o: bluevmega.c
+bluevirq.o: bluevirq.c
+
clean:
rm -rf *.o
rm -rf $(PRG).elf $(PRG).bin $(PRG).hex $(PRG).srec
rm -rf $(PRG)_eeprom.bin $(PRG)_eeprom.hex $(PRG)_eeprom.srec
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
- rm -rf v1reShark v1send v1test
lst: $(PRG).lst
View
0  bluev.ino → bluev_sketch/bluev_sketch.ino 100755 → 100644
File renamed without changes
View
0  bluevirq.c → bluev_sketch/bluevirq.c
File renamed without changes
View
374 bluevmega.c → bluev_sketch/bluevmega.c
@@ -5,6 +5,7 @@
/*========================================================================*/
// V1 Command, Response, and Info packet Processing
+
/*========================================================================*/
static unsigned char cmdslice = 4;
extern volatile unsigned char v1head, v1tail, inhead, intail;
@@ -32,14 +33,23 @@ static void printser(char *str)
}
}
-// print string from progmem
-static void printser_P(const char *p)
+static char localstr[128];
+static char *pullp(const char *p)
{
- char c;
- while ((c = pgm_read_byte(p++))) {
- while (!(UCSR0A & _BV(UDRE0)));
- UDR0 = c;
- }
+ strcpy_P(localstr, p);
+ return localstr;
+}
+
+static int readpkt(unsigned char *);
+static unsigned char respget[];
+static int getkey() {
+ while (inhead == intail)
+ readpkt(respget);
+ return inbuf[intail++];
+}
+
+static int keypress() {
+ return( inhead != intail);
}
#define REQVERSION (1)
@@ -87,7 +97,7 @@ static void printser_P(const char *p)
#define REQVEHICLESPEED (0x73)
#define RESPVEHICLESPEED (0x74)
#define REQOVERRIDETHUMBWHEEL (0x75)
-#define REQSETSAVVYMUTEENABLE (0x76)
+#define REQSETSAVVYUNMUTEENABLE (0x76)
#define NORESPONSE (0xfe)
@@ -144,34 +154,34 @@ static int readpkt(unsigned char *buf)
while (buf[0] != 0xaa) // SOF
{
buf[0] = readv1rx();
- //sprintf( serbuf, "%02x", buf[0] );
+ //sprintf( serbuf, pullp(PSTR("%02x")), buf[0] );
//printser( serbuf );
}
- buf[1] = readv1rx();
+ buf[1] = readv1rx(); // destination
if ((buf[1] & 0xf0) != 0xd0)
continue;
- buf[2] = readv1rx();
+ buf[2] = readv1rx(); // source
if ((buf[2] & 0xf0) != 0xe0)
continue;
- if ((buf[2] & 15) == 0xa)
+ if ((buf[2] & 15) == 0xa) // check if checksum or nonchecksum
tstnocks = 0;
else if ((buf[2] & 15) == 9)
tstnocks = 1;
- buf[3] = readv1rx();
- buf[4] = readv1rx();
+ buf[3] = readv1rx(); // packet ID
+ buf[4] = readv1rx(); // length
len = 5;
for (ix = 0; ix < buf[4]; ix++) {
buf[len] = readv1rx();
len++;
}
- if (!tstnocks) {
+ if (!tstnocks) { // checksum if present
unsigned char cks = 0;
for (ix = 0; ix < len - 1; ix++)
cks += buf[ix];
if (buf[len - 1] != (cks & 0xff))
return -2; // continue; ???
}
- buf[len] = readv1rx();
+ buf[len] = readv1rx(); // EOF
if (buf[len++] != 0xab)
continue;
@@ -181,8 +191,9 @@ static int readpkt(unsigned char *buf)
v1idd++;
memcpy(v1infdisplaydata, buf + 5, 8);
}
+ // alerts
else if (buf[3] == RESPALERTDATA) {
- //sprintf(serbuf, "a: %d\n", buf[1] & 0xf);
+ //sprintf( serbuf, pullp(PSTR("a: %d\n")), buf[1] & 0xf);
//printser(serbuf);
// copy to temp until index == total, then move to out and inc
if (!buf[5]) { // no alerts
@@ -191,6 +202,7 @@ static int readpkt(unsigned char *buf)
v1alerts++;
}
}
+ // v1 alertout is updated when a full set of alerts is received and accumulated.
else { // accumulate and copy block
memcpy(v1alerttemp[(buf[5] >> 4) - 1], buf + 5, 7);
if (buf[5] >> 4 == (buf[5] & 15)) {
@@ -199,19 +211,20 @@ static int readpkt(unsigned char *buf)
}
}
}
+ // concealed display
else if (buf[3] == RESPDATARECEIVED) {
cddr++;
}
else {
#if 0
// show nonstream traffic
- sprintf(serbuf, "r: %d:", len);
+ sprintf(serbuf, pullp(PSTR("r: %d:")), len);
printser(serbuf);
for (ix = 1; ix < len - 1; ix++) {
- sprintf(serbuf, " %02x", buf[ix]);
+ sprintf(serbuf, pullp(PSTR(" %02x")), buf[ix]);
printser(serbuf);
}
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
#endif
}
return len;
@@ -221,10 +234,10 @@ static int readpkt(unsigned char *buf)
// send a command, wait until it goes out, then look for a response packet (by ID), placing it in buf.
static int sendcmd(unsigned char *thiscmd, unsigned char resp, unsigned char *buf)
{
- unsigned char ix;
+ unsigned char ix, iy;
int ret;
- memcpy(inmsgbuf, thiscmd, thiscmd[4] + 6); // This queues the message for transmission
+ memcpy(inmsgbuf, thiscmd, thiscmd[4] + 6); // This queues the message for transmission
inmsglen = thiscmd[4] + 6;
inmsgstate = 4;
@@ -232,53 +245,55 @@ static int sendcmd(unsigned char *thiscmd, unsigned char resp, unsigned char *bu
#define ECHOTIME 8
for (ix = 0; ix < ECHOTIME; ix++) { // look for command on bus
ret = readpkt(buf);
- // sprintf( serbuf, "%d: %02x %02x %02x %02x %02x %02x %02x\r\n", ret, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6] );
+ // sprintf( serbuf, pullp(PSTR("%d: %02x %02x %02x %02x %02x %02x %02x\r\n")), ret, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6] );
if (ret < thiscmd[4] + 6)
continue;
if (!memcmp(thiscmd, buf, ret))
break;
}
- if (ix == ECHOTIME)
+ if (ix == ECHOTIME) // can't transmit for some reason - TS holdoff?
return -1;
-
- if (resp == NORESPONSE)
+ if (resp == NORESPONSE) // no response required for this
return 0;
-
- // FIXME - we don't check that the destination is our ID.
// look for response, max packets to wait - busy will reset.
#define RESPTIME 20
for (ix = 0; ix < RESPTIME; ix++) {
ret = readpkt(buf);
if (ret < 6)
continue;
+ // FIXME - we don't check the source or destination ID.
switch (buf[3]) {
case RESPUNSUPPORTEDPACKET:
- sprintf(serbuf, "Unsupported Packet\r\n");
- printser(serbuf);
+ // print, but don't exit because it may not be our request.
+ printser(pullp(PSTR("Unsupported Packet\r\n")));
break;
case RESPREQUESTNOTPROCESSED:
- sprintf(serbuf, "Request Not Processed %02x\r\n", buf[5]);
+ // if our packet ID, return error
+ sprintf(serbuf, pullp(PSTR("Request Not Processed %02x\r\n")), buf[5]);
printser(serbuf);
- // maybe abort, return -3?
+ if (buf[5] == thiscmd[3])
+ return -3;
break;
case INFV1BUSY:
- // FIXME, we don't check packet ID
#if 0
- printser_P(PSTR("V1Busy:"));
- for (ix = 0; ix < buf[4] - 1; ix++) {
- sprintf(serbuf, " %02x", buf[5 + ix]);
+ printser(pullp(PSTR("V1Busy:")));
+ for (iy = 0; iy < buf[4] - 1; iy++) {
+ sprintf(serbuf, pullp(PSTR(" %02x")), buf[5 + iy]);
printser(serbuf);
}
- printser(serbuf, "\r\n"));
+ printser(serbuf, "\r\n")));
#endif
- ix = 0; // reset timer
+ for (iy = 0; iy < buf[4] - 1; iy++)
+ if (buf[5 + iy] == thiscmd[3])
+ ix = 0; // reset timer since it is still processing our packet
break;
case RESPDATAERROR:
- sprintf(serbuf, "Data Error %02x\r\n", buf[5]);
+ sprintf(serbuf, pullp(PSTR("Data Error %02x\r\n")), buf[5]);
printser(serbuf);
+ if (buf[5] == thiscmd[3])
+ return -4;
break;
}
-
if (buf[3] == resp)
break;
}
@@ -313,17 +328,17 @@ static void sweep1() {
// Sweep Sections and Definitions
makecmd(cmdsend, cmdslice, 0xa, REQSWEEPSECTIONS, 0, NULL);
sendcmd(cmdsend, RESPSWEEPSECTIONS, respget);
- printser_P(PSTR("SweepSections:\r\n"));
- sprintf(serbuf, "+%d/%d %5u - %5u\r\n", respget[5] >> 4, respget[5] & 15, respget[8] << 8 | respget[9],
+ printser(pullp(PSTR("SweepSections:\r\n")));
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u - %5u\r\n")), respget[5] >> 4, respget[5] & 15, respget[8] << 8 | respget[9],
respget[6] << 8 | respget[7]);
printser(serbuf);
if (respget[4] > 6) {
- sprintf(serbuf, "+%d/%d %5u -:%5u\r\n", respget[10] >> 4, respget[10] & 15, respget[13] << 8 | respget[14],
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u -:%5u\r\n")), respget[10] >> 4, respget[10] & 15, respget[13] << 8 | respget[14],
respget[11] << 8 | respget[12]);
printser(serbuf);
}
if (respget[4] > 11) {
- sprintf(serbuf, "+%d/%d %5u - %5u\r\n", respget[15] >> 4, respget[15] & 15, respget[18] << 8 | respget[19],
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u - %5u\r\n")), respget[15] >> 4, respget[15] & 15, respget[18] << 8 | respget[19],
respget[16] << 8 | respget[17]);
printser(serbuf);
}
@@ -336,17 +351,17 @@ static void sweep1() {
if (respget[3] != 0x23)
continue;
ix++;
- sprintf(serbuf, "+%d/%d %5u - %5u\r\n", respget[5] >> 4, respget[5] & 15, respget[8] << 8 | respget[9],
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u - %5u\r\n")), respget[5] >> 4, respget[5] & 15, respget[8] << 8 | respget[9],
respget[6] << 8 | respget[7]);
printser(serbuf);
if (respget[4] > 6) {
- sprintf(serbuf, "+%d/%d %5u -:%5u\r\n", respget[10] >> 4, respget[10] & 15, respget[13] << 8 | respget[14],
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u -:%5u\r\n")), respget[10] >> 4, respget[10] & 15, respget[13] << 8 | respget[14],
respget[11] << 8 | respget[12]);
printser(serbuf);
}
if (respget[4] > 11) {
- sprintf(serbuf, "+%d/%d %5u - %5u\r\n", respget[15] >> 4, respget[15] & 15, respget[18] << 8 | respget[19],
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u - %5u\r\n")), respget[15] >> 4, respget[15] & 15, respget[18] << 8 | respget[19],
respget[16] << 8 | respget[17]);
printser(serbuf);
}
@@ -354,7 +369,7 @@ static void sweep1() {
// sweep definitions must stay within the sections above
makecmd(cmdsend, cmdslice, 0xa, REQMAXSWEEPINDEX, 0, NULL);
sendcmd(cmdsend, RESPMAXSWEEPINDEX, respget);
- sprintf(serbuf, "MaxSweepIndex: %d (+1 for number of definitions)\r\n", respget[5]);
+ sprintf(serbuf, pullp(PSTR("MaxSweepIndex: %d (+1 for number of definitions)\r\n")), respget[5]);
printser(serbuf);
maxswp = respget[5];
}
@@ -365,8 +380,8 @@ static void sweep2() {
// read sweep sections
makecmd(cmdsend, cmdslice, 0xa, REQALLSWEEPDEFINITIONS, 0, NULL);
sendcmd(cmdsend, RESPSWEEPDEFINITION, respget);
- printser_P(PSTR("SweepDefinitions:\r\n"));
- sprintf(serbuf, "+%d/%d Low:%5u High:%5u\r\n", 1 + (respget[5] & 63), 1 + maxswp, respget[8] << 8 | respget[9],
+ printser(pullp(PSTR("SweepDefinitions:\r\n")));
+ sprintf(serbuf, pullp(PSTR("+%d/%d Low:%5u High:%5u\r\n")), 1 + (respget[5] & 63), 1 + maxswp, respget[8] << 8 | respget[9],
respget[6] << 8 | respget[7]);
printser(serbuf);
for (ix = 0; ix < maxswp;) {
@@ -376,7 +391,7 @@ static void sweep2() {
if (respget[3] != 0x17)
continue;
ix++;
- sprintf(serbuf, "+%d/%d Low:%5u High:%5u\r\n", 1 + (respget[5] & 63), 1 + maxswp, respget[8] << 8 | respget[9],
+ sprintf(serbuf, pullp(PSTR("+%d/%d Low:%5u High:%5u\r\n")), 1 + (respget[5] & 63), 1 + maxswp, respget[8] << 8 | respget[9],
respget[6] << 8 | respget[7]);
printser(serbuf);
}
@@ -385,14 +400,11 @@ static void sweep2() {
// user interactive program to get a 16 bit unsigned word (frequency to write sweep)
static unsigned getword() {
unsigned ret = 0;
- unsigned char c;
for (;;) {
- while (inhead == intail)
- readpkt(respget);
- c = inbuf[intail++];
+ unsigned char c = getkey();
if (c >= ' ' && c < 127) {
- while (!(UCSR0A & 0x20));
- UDR0 = c;
+ sprintf( serbuf, "%c", c );
+ printser(serbuf);
}
switch (c) {
case '0':
@@ -411,13 +423,13 @@ static unsigned getword() {
case 127:
case 8:
ret /= 10;
- printser_P(PSTR("\b \b"));
+ printser(pullp(PSTR("\b \b")));
break;
case '\r':
return ret;
case 0x15:
ret = 0;
- printser_P(PSTR("\r \r"));
+ printser(pullp(PSTR("\r \r")));
break;
case 0x1b:
return 0;
@@ -436,18 +448,18 @@ static void sweepset() {
sweep1();
sweep2();
- printser_P(PSTR("Enter Definition Ranges, low and high, 0 to end\r\n"));
+ printser(pullp(PSTR("Enter Definition Ranges, low and high, 0 to end\r\n")));
for (ix = 0; ix <= maxswp; ix++) {
- sprintf(serbuf, "Def %d Low:\r\n", ix + 1);
+ sprintf(serbuf, pullp(PSTR("Def %d Low:\r\n")), ix + 1);
printser(serbuf);
low[ix] = getword();
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
if (low[ix] == 0)
break;
- sprintf(serbuf, "Def %d High:\r\n", ix + 1);
+ sprintf(serbuf, pullp(PSTR("Def %d High:\r\n")), ix + 1);
printser(serbuf);
high[ix] = getword();
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
if (high[ix] == 0)
break;
}
@@ -456,17 +468,13 @@ static void sweepset() {
return;
for (iy = 0; iy < ix; iy++) {
- sprintf(serbuf, "%2d: %5u - %5u\r\n", iy + 1, low[iy], high[iy]);
+ sprintf(serbuf, pullp(PSTR("%2d: %5u - %5u\r\n")), iy + 1, low[iy], high[iy]);
printser(serbuf);
}
- printser_P(PSTR("Write to V1? (Y/N):"));
- while (inhead == intail)
- readpkt(respget);
- if (inbuf[intail] != 'Y' && inbuf[intail] != 'y') {
- intail++;
+ printser(pullp(PSTR("Write to V1? (Y/N):")));
+ char c = getkey();
+ if (c != 'Y' && c != 'y')
return;
- }
- intail++;
for (iy = 0; iy < ix; iy++) {
unsigned char wrsbuf[5];
// write, commit on the last.
@@ -479,7 +487,7 @@ static void sweepset() {
wrsbuf[4] = low[iy];
makecmd(cmdsend, cmdslice, 0xa, REQWRITESWEEPDEFINITIONS, 5, wrsbuf);
sendcmd(cmdsend, NORESPONSE, respget);
- sprintf(serbuf, "Wrote %2d: %5u - %5u\r\n", iy + 1, low[iy], high[iy]);
+ sprintf(serbuf, pullp(PSTR("Wrote %2d: %5u - %5u\r\n")), iy + 1, low[iy], high[iy]);
printser(serbuf);
}
// get write response and decode errors.
@@ -491,11 +499,11 @@ static void sweepset() {
break;
}
if (respget[5]) {
- sprintf(serbuf, "Write Error in index %d\r\n", respget[5] - 1);
+ sprintf(serbuf, pullp(PSTR("Write Error in index %d\r\n")), respget[5] - 1);
printser(serbuf);
}
else
- printser_P(PSTR("Write Successfup\r\n"));
+ printser(pullp(PSTR("Write Successfup\r\n")));
sweep2();
}
@@ -504,40 +512,40 @@ static void defaultsweeps() {
syncresp();
makecmd(cmdsend, cmdslice, 0xa, REQDEFAULTSWEEPS, 0, NULL);
sendcmd(cmdsend, NORESPONSE, respget);
- printser_P(PSTR("Default Sweeps Done, Please use infoscan to confirm\r\n"));
+ printser(pullp(PSTR("Default Sweeps Done, Please use infoscan to confirm\r\n")));
}
static char userset[] = "12345678AbCdEFGHJuUtL ";
// show user bytes
static void userprint() {
int ix;
- printser_P(PSTR("UserSet: (default) "));
+ printser(pullp(PSTR("UserSet: (default) ")));
for (ix = 0; ix < 8; ix++) {
- sprintf(serbuf, "%c", (respget[5] >> ix) & 1 ? userset[ix] : '_');
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[5] >> ix) & 1 ? userset[ix] : '_');
printser(serbuf);
}
for (ix = 0; ix < 8; ix++) {
- sprintf(serbuf, "%c", (respget[6] >> ix) & 1 ? userset[ix + 8] : '_');
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[6] >> ix) & 1 ? userset[ix + 8] : '_');
printser(serbuf);
}
for (ix = 0; ix < 8; ix++) {
- sprintf(serbuf, "%c", (respget[7] >> ix) & 1 ? userset[ix + 16] : '_');
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[7] >> ix) & 1 ? userset[ix + 16] : '_');
printser(serbuf);
}
- printser_P(PSTR("\r\nUserSet: (changed) "));
+ printser(pullp(PSTR("\r\nUserSet: (changed) ")));
for (ix = 0; ix < 8; ix++) {
- sprintf(serbuf, "%c", (respget[5] >> ix) & 1 ? '_' : userset[ix]);
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[5] >> ix) & 1 ? '_' : userset[ix]);
printser(serbuf);
}
for (ix = 0; ix < 8; ix++) {
- sprintf(serbuf, "%c", (respget[6] >> ix) & 1 ? '_' : userset[ix + 8]);
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[6] >> ix) & 1 ? '_' : userset[ix + 8]);
printser(serbuf);
}
for (ix = 0; ix < 8; ix++) {
- sprintf(serbuf, "%c", (respget[7] >> ix) & 1 ? '_' : userset[ix + 16]);
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[7] >> ix) & 1 ? '_' : userset[ix + 16]);
printser(serbuf);
}
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
}
static void usershow() {
@@ -551,33 +559,33 @@ static void usershow() {
static void infoscan() {
int ix;
- // sprintf( serbuf, "VN: %d: %02x %02x %02x %02x %02x %02x %02x\r\n", ix, cmdsend[0], cmdsend[1], cmdsend[2], cmdsend[3], cmdsend[4], cmdsend[5], cmdsend[6] );
- printser_P(PSTR("=====INFOSCAN=====\r\n"));
+ // sprintf( serbuf, pullp(PSTR("VN: %d: %02x %02x %02x %02x %02x %02x %02x\r\n")), ix, cmdsend[0], cmdsend[1], cmdsend[2], cmdsend[3], cmdsend[4], cmdsend[5], cmdsend[6] );
+ printser(pullp(PSTR("=====INFOSCAN=====\r\n")));
syncresp();
// do commands
makecmd(cmdsend, cmdslice, 0xa, REQVERSION, 0, NULL);
sendcmd(cmdsend, RESPVERSION, respget);
- printser_P(PSTR("V1 Version: "));
+ printser(pullp(PSTR("V1 Version: ")));
for (ix = 0; ix < respget[4] - 1; ix++) {
- sprintf(serbuf, "%c", respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
printser(serbuf);
}
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
makecmd(cmdsend, cmdslice, 0xa, REQSERIALNUMBER, 0, NULL);
sendcmd(cmdsend, RESPSERIALNUMBER, respget);
- printser_P(PSTR("V1 SerialNo: "));
+ printser(pullp(PSTR("V1 SerialNo: ")));
for (ix = 0; ix < respget[4] - 1; ix++) {
- sprintf(serbuf, "%c", respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
printser(serbuf);
}
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
makecmd(cmdsend, cmdslice, 0xa, REQBATTERYVOLTAGE, 0, NULL);
sendcmd(cmdsend, RESPBATTERYVOLTAGE, respget);
- sprintf(serbuf, "BattVolt: %d.%02d\r\n", respget[5], respget[6]);
+ sprintf(serbuf, pullp(PSTR("BattVolt: %d.%02d\r\n")), respget[5], respget[6]);
printser(serbuf);
usershow();
@@ -588,51 +596,51 @@ static void infoscan() {
// Concealed Display
makecmd(cmdsend, cmdslice, 0, REQVERSION, 0, NULL);
sendcmd(cmdsend, RESPVERSION, respget);
- printser_P(PSTR("CD Version: "));
+ printser(pullp(PSTR("CD Version: ")));
for (ix = 0; ix < respget[4] - 1; ix++) {
- sprintf(serbuf, "%c", respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
printser(serbuf);
}
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
// Remote Audio
makecmd(cmdsend, cmdslice, 1, REQVERSION, 0, NULL);
sendcmd(cmdsend, RESPVERSION, respget);
- printser_P(PSTR("RA Version: "));
+ printser(pullp(PSTR("RA Version: ")));
for (ix = 0; ix < respget[4] - 1; ix++) {
- sprintf(serbuf, "%c", respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
printser(serbuf);
}
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
// Savvy
makecmd(cmdsend, cmdslice, 2, REQVERSION, 0, NULL);
sendcmd(cmdsend, RESPVERSION, respget);
- printser_P(PSTR("SV Version: "));
+ printser(pullp(PSTR("SV Version: ")));
for (ix = 0; ix < respget[4] - 1; ix++) {
- sprintf(serbuf, "%c", respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
printser(serbuf);
}
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
makecmd(cmdsend, cmdslice, 2, REQSERIALNUMBER, 0, NULL);
sendcmd(cmdsend, RESPSERIALNUMBER, respget);
- printser_P(PSTR("SV SerialNo: "));
+ printser(pullp(PSTR("SV SerialNo: ")));
for (ix = 0; ix < respget[4] - 1; ix++) {
- sprintf(serbuf, "%c", respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
printser(serbuf);
}
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
makecmd(cmdsend, cmdslice, 2, REQSAVVYSTATUS, 0, NULL);
sendcmd(cmdsend, RESPSAVVYSTATUS, respget);
- sprintf(serbuf, "SavvyStat: ThreshKPH:%d (unmu ena: throvrd):%d\r\n", respget[5], respget[6]);
+ sprintf(serbuf, pullp(PSTR("SavvyStat: ThreshKPH:%d (unmu ena: throvrd):%d\r\n")), respget[5], respget[6]);
printser(serbuf);
makecmd(cmdsend, cmdslice, 2, REQVEHICLESPEED, 0, NULL);
sendcmd(cmdsend, RESPVEHICLESPEED, respget);
- sprintf(serbuf, "SavvyVehSpd: %d kph\r\n", respget[5]);
+ sprintf(serbuf, pullp(PSTR("SavvyVehSpd: %d kph\r\n")), respget[5]);
printser(serbuf);
- printser_P(PSTR("=====END INFOSCAN=====\r\n"));
+ printser(pullp(PSTR("=====END INFOSCAN=====\r\n")));
}
// Ask for and Display (decoded) alerts
@@ -640,88 +648,80 @@ static const unsigned char typ[] = "LAKXU^-v", t;
static void alerts() {
int ix;
syncresp();
- printser_P(PSTR("=====ALERTS=====\r\n"));
+ printser(pullp(PSTR("=====ALERTS=====\r\n")));
makecmd(cmdsend, cmdslice, 0xa, REQSTARTALERTDATA, 0, NULL);
sendcmd(cmdsend, NORESPONSE, respget);
for (;;) {
- if (inhead != intail) {
- intail = inhead;
+ if( keypress() ) {
+ getkey();
break;
}
- printser_P(PSTR("===\r\n"));
+ printser(pullp(PSTR("===\r\n")));
ix = v1alerts;
while (ix == v1alerts)
readpkt(respget);
for (ix = 0; ix < (v1alertout[0][0] & 15); ix++) {
unsigned char *b = v1alertout[ix], t;
- sprintf(serbuf, "%2d/%2d %5u %3d ^v %3d ", b[0] >> 4, b[0] & 15, b[1] << 8 | b[2], b[3], b[4]);
+ sprintf(serbuf, pullp(PSTR("%2d/%2d %5u %3d ^v %3d ")), b[0] >> 4, b[0] & 15, b[1] << 8 | b[2], b[3], b[4]);
printser(serbuf);
for (t = 0; t < 8; t++)
if ((b[5] >> t) & 1) {
- sprintf(serbuf, "%c", typ[t]);
+ sprintf(serbuf, pullp(PSTR("%c")), typ[t]);
printser(serbuf);
}
- if (b[6] & 0x80) {
- sprintf(serbuf, "!");
- printser(serbuf);
- }
- printser_P(PSTR("\r\n"));
+ if (b[6] & 0x80)
+ printser(pullp(PSTR("!")));
+ printser(pullp(PSTR("\r\n")));
}
}
makecmd(cmdsend, cmdslice, 0xa, REQSTOPALERTDATA, 0, NULL);
sendcmd(cmdsend, NORESPONSE, respget);
- printser_P(PSTR("=====END ALERTS=====\r\n"));
+ printser(pullp(PSTR("=====END ALERTS=====\r\n")));
}
-const prog_char sevs2ascii[] PROGMEM = {
- " ~'...17_...j..]"
- "........l...uvJ."
- "`\".^............"
- "|.......LC...GU0"
- "-.......=#.....3"
- "r./.....c..2o.d."
- "....\\.4......5y9"
- ".F.Ph.HAtE..b6.8"
- };
-
+// convert 7 segment to ASCII or something close
+static const prog_char sevs2ascii[] PROGMEM = {
+" ~'...17_...j..]........l...uvJ.`\".^............|.......LC...GU0-.......=#.....3r./.....c..2o.d.....\\.4......5y9.F.Ph.HAtE..b6.8"
+};
+//bit 0-7: Mute, TSHold, SysUp, DispOn, Euro, Custom, -, -
+static const unsigned char inf2[] = "MHUDEC-=";
static void showinfdisp() {
int ix;
- sprintf(serbuf, "%c%c %02x %02x ", pgm_read_byte(sevs2ascii + (respget[5] & 0x7f)), respget[5] & 0x80 ? 'o' : ' ', respget[5],
- respget[6] ^ respget[5]);
+ sprintf(serbuf, pullp(PSTR("%c%c %02x %02x ")), pgm_read_byte(sevs2ascii + (respget[5] & 0x7f)), respget[5] & 0x80 ? 'o' : ' ',
+ respget[5], respget[6] ^ respget[5]);
printser(serbuf);
for (ix = 0; ix < 8; ix++) {
- sprintf(serbuf, "%c", (respget[7] >> ix) & 1 ? '*' : '.');
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[7] >> ix) & 1 ? '*' : '.');
printser(serbuf);
}
printser(" ");
-
+
for (ix = 0; ix < 8; ix++)
if ((respget[8] >> ix) & 1) {
- sprintf(serbuf, "%c", typ[ix]);
+ sprintf(serbuf, pullp(PSTR("%c")), typ[ix]);
printser(serbuf);
}
else
printser("_");
printser(" ");
-
+
for (ix = 0; ix < 8; ix++)
if (((respget[8] ^ respget[9]) >> ix) & 1) {
- sprintf(serbuf, "%c", typ[ix]);
+ sprintf(serbuf, pullp(PSTR("%c")), typ[ix]);
printser(serbuf);
}
else
printser("_");
printser(" ");
- const unsigned char inf2[] = "MHUDEC-=";
- //bit 0-7: Mute, TSHold, SysUp, DispOn, Euro, Custom, -, -
+
for (ix = 0; ix < 8; ix++)
if ((respget[10] >> ix) & 1) {
- sprintf(serbuf, "%c", inf2[ix]);
+ sprintf(serbuf, pullp(PSTR("%c")), inf2[ix]);
printser(serbuf);
}
else
printser("_");
- printser_P(PSTR("\r\n"));
+ printser(pullp(PSTR("\r\n")));
}
// This setup can be used for Savvy override and unmute setting, by changing the command
@@ -733,6 +733,20 @@ static void setmode(unsigned char mode) {
sendcmd(cmdsend, NORESPONSE, respget);
}
+static void savvyunmute(unsigned char enable) {
+ syncresp();
+ enable = ! !enable; // make 0 or 1
+ makecmd(cmdsend, cmdslice, 0xa, REQSETSAVVYUNMUTEENABLE, 1, &enable);
+ sendcmd(cmdsend, NORESPONSE, respget);
+}
+
+// 0 - never, 0xff - always, else kph.
+static void savvyoverride(unsigned char speed) {
+ syncresp();
+ makecmd(cmdsend, cmdslice, 0xa, REQOVERRIDETHUMBWHEEL, 1, &speed);
+ sendcmd(cmdsend, NORESPONSE, respget);
+}
+
// no param command without response
static void quickcommand(unsigned char cmd) {
syncresp();
@@ -743,42 +757,40 @@ static void quickcommand(unsigned char cmd) {
// prototype - need to add set/reset dialog and edit the buffer
static void userbytes() {
syncresp();
- printser_P(PSTR("Current:\r\n"));
+ printser(pullp(PSTR("Current:\r\n")));
usershow();
- printser_P(PSTR("Use one of the above letters/numbers to change,\r\n"
- " or Q to quit, W to write changes to the V1\r\n"));
+ printser(pullp(PSTR("Use one of the above letters/numbers to change,\r\n" " or Q to quit, W to write changes to the V1\r\n")));
unsigned char ub[6];
- memcpy( ub,respget+5,6);
- for(;;) {
- while (inhead == intail)
- readpkt(respget);
- char c = inbuf[intail++];
- if( c <= ' ' )
+ memcpy(ub, respget + 5, 6);
+ for (;;) {
+ char c = getkey();
+ if (c <= ' ')
continue;
- if( c == 'Q' || c == 'q' )
- return;
- if( c == 'w' || c == 'w' )
- break;
+ if (c == 'Q' || c == 'q')
+ return;
+ if (c == 'w' || c == 'w')
+ break;
int ix;
- for( ix=0; ix < 24; ix++ )
- if( userset[ix] == c )
+ for (ix = 0; ix < 24; ix++)
+ if (userset[ix] == c)
break;
- if( ix < 24 )
+ if (ix < 24)
ub[ix >> 3] ^= 1 << (ix & 7);
- memcpy( respget+5,ub,6 );
+ memcpy(respget + 5, ub, 6);
userprint();
}
- memcpy( respget+5,ub,6 );
+ memcpy(respget + 5, ub, 6);
userprint();
- printser_P(PSTR("Updating\r\n"));
+ printser(pullp(PSTR("Updating\r\n")));
makecmd(cmdsend, cmdslice, 0xa, REQWRITEUSERBYTES, 6, ub);
sendcmd(cmdsend, NORESPONSE, respget);
- printser_P(PSTR("New:\r\n"));
+ printser(pullp(PSTR("New:\r\n")));
usershow();
}
extern void hwsetup(void);
+
/*========================================================================*/
#ifdef STANDALONE
int main()
@@ -791,10 +803,10 @@ void init()
int ret;
unsigned char lastdisp[12];
-
- printser_P(PSTR("V1MegaTool\r\n"));
- for(;;) {
- for (;;) { // get at least one inf packet
+
+ printser(pullp(PSTR("V1MegaTool\r\n")));
+ for (;;) {
+ for (;;) { // get at least one inf packet
ret = readpkt(respget);
if (ret < 5)
continue;
@@ -802,13 +814,10 @@ void init()
break;
}
// should give Not Ready message if timecmdslice holdoff.
- printser_P(PSTR("A-alerts, I-infoscan, D-DefaultSweep, S-SetSweeps. T-transparent, U-userbytes V-ViewDisplay\r\n"));
- printser_P(PSTR("#-FactDefault 1-DispOff 2-DispOn 3-MuteOn 4-Muteoff 5-AllBogeys 6-Logic 7-Advanced-Logic\r\n"));
- while (inhead == intail)
- readpkt(respget);
-
- switch (inbuf[intail++]) {
-
+ printser(pullp(PSTR("A-alerts, I-infoscan, D-DefaultSweep, S-SetSweeps. T-transparent, U-userbytes V-ViewDisplay\r\n")));
+ printser(pullp(PSTR("#-FactDefault 1-DispOff 2-DispOn 3-MuteOn 4-Muteoff 5-AllBogeys 6-Logic 7-Advanced-Logic\r\n")));
+ char c = getkey();
+ switch (c) {
case '#':
quickcommand(REQFACTORYDEFAULT);
break;
@@ -825,13 +834,13 @@ void init()
quickcommand(REQMUTEOFF);
break;
case '5':
- setmode(1); // all bogeys
+ setmode(1); // all bogeys
break;
case '6':
- setmode(2); // logic
+ setmode(2); // logic
break;
case '7':
- setmode(3); // advanced logic
+ setmode(3); // advanced logic
break;
case 'A':
case 'a':
@@ -855,23 +864,24 @@ void init()
break;
case 'T':
case 't':
- transp = 1; // act like bluetooth port
+ transp = 1; // act like bluetooth port
while (transp)
sleep_mode();
break;
case 'V':
case 'v':
- printser_P(PSTR("Mute (ESP)Hold systemUp mainDisp Euro Custom\r\n"));
+ printser(pullp(PSTR("Mute (ESP)Hold systemUp mainDisp Euro Custom\r\n")));
lastdisp[0] = 0;
- while( inhead == intail ) {
+ while (!keypress()) {
ret = readpkt(respget);
if (ret < 5)
continue;
- if (respget[3] == INFDISPLAYDATA && memcmp( lastdisp, respget, 12 )) {
+ if (respget[3] == INFDISPLAYDATA && memcmp(lastdisp, respget, 12)) {
showinfdisp();
- memcpy( lastdisp, respget, 12 );
+ memcpy(lastdisp, respget, 12);
}
}
+ c = getkey();
break;
default:
break;
View
43 v1prepackets.txt
@@ -1,43 +0,0 @@
-Precalculated packets for time slot 4. Alter checksum if slot altered.
-
-{ 0xaa, 0xda, 0xe4, 0x01, 0x01, 0x6a, 0xab} // software version
-{ 0xaa, 0xda, 0xe4, 0x03, 0x01, 0x6c, 0xab} // serial number
-{ 0xaa, 0xda, 0xe4, 0x11, 0x01, 0x7a, 0xab} // user bytes
-{ 0xaa, 0xda, 0xe4, 0x14, 0x01, 0x7d, 0xab} // factory defaults
-{ 0xaa, 0xda, 0xe4, 0x16, 0x01, 0x7f, 0xab} // sweep definitions
-{ 0xaa, 0xda, 0xe4, 0x18, 0x01, 0x81, 0xab} // default sweeps
-{ 0xaa, 0xda, 0xe4, 0x19, 0x01, 0x82, 0xab} // max sweep index
-{ 0xaa, 0xda, 0xe4, 0x22, 0x01, 0x8b, 0xab} // sweep sections
-{ 0xaa, 0xda, 0xe4, 0x32, 0x01, 0x9b, 0xab} // main display off
-{ 0xaa, 0xda, 0xe4, 0x33, 0x01, 0x9c, 0xab} // main display on
-{ 0xaa, 0xda, 0xe4, 0x34, 0x01, 0x9d, 0xab} // mute on
-{ 0xaa, 0xda, 0xe4, 0x35, 0x01, 0x9e, 0xab} // mute off
-{ 0xaa, 0xda, 0xe4, 0x41, 0x01, 0xaa, 0xab} // alert data on
-{ 0xaa, 0xda, 0xe4, 0x42, 0x01, 0xab, 0xab} // alert data off
-{ 0xaa, 0xda, 0xe4, 0x62, 0x01, 0xcb, 0xab} // battery voltage
-{ 0xaa, 0xda, 0xe4, 0x36, 0x02, 0x01, 0xa1, 0xab} // all bogeys mode
-o{ 0xaa, 0xda, 0xe4, 0x36, 0x02, 0x02, 0xa2, 0xab} // logic mode
-{ 0xaa, 0xda, 0xe4, 0x36, 0x02, 0x03, 0xa3, 0xab} // advanced logic mode
-
-{ 0xaa, 0xd0, 0xe4, 0x01, 0x01, 0x60, 0xab} // CD software version
-
-{ 0xaa, 0xd1, 0xe4, 0x01, 0x01, 0x61, 0xab} // RA software version
-
-{ 0xaa, 0xd2, 0xe4, 0x01, 0x01, 0x62, 0xab} // savvy software version
-{ 0xaa, 0xd2, 0xe4, 0x03, 0x01, 0x64, 0xab} // savvy serial number
-{ 0xaa, 0xd2, 0xe4, 0x71, 0x01, 0xda, 0xab} // savvy status
-{ 0xaa, 0xd2, 0xe4, 0x73, 0x01, 0xdc, 0xab} // savvy vehicle speed
-
-//cks not verified
-{ 0xaa, 0xd2, 0xe4, 0x76, 0x02, 0x00, 0xe0, 0xab} // savvy disable unmute
-{ 0xaa, 0xd2, 0xe4, 0x76, 0x02, 0x01, 0xe1, 0xab} // savvy enable unmute
-
-// one byte param
-{ 0xaa, 0xd2, 0xe4, 0x75, 0x02, 0x00, 0xdf, 0xab} // savvy thumbwheel override
-// mute threshold speed, KPH, 0=never 0xff=always, fix cks
-
-// complex param
-{ 0xaa, 0xda, 0xe4, 0x13, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x--, 0xab} // write user bytes
-{ 0xaa, 0xda, 0xe4, 0x15, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x--, 0xab} // write sweep definition
-
-// Note - an 0xaa 0xd4 0xe? packet for version or serial number might be responded to
View
920 v1test.c
@@ -10,7 +10,7 @@
#define REQUSERBYTES (0x11)
#define RESPUSERBYTES (0x12)
-#define REQWRITEUSERBYTES (0x11)
+#define REQWRITEUSERBYTES (0x13)
#define REQFACTORYDEFAULT (0x14)
#define REQWRITESWEEPDEFINITIONS (0x15)
@@ -48,15 +48,62 @@
#define REQVEHICLESPEED (0x73)
#define RESPVEHICLESPEED (0x74)
#define REQOVERRIDETHUMBWHEEL (0x75)
-#define REQSETSAVVYMUTEENABLE (0x76)
+#define REQSETSAVVYUNMUTEENABLE (0x76)
#define NORESPONSE (0xfe)
+
+/*========================================================================*/
+// V1 Command, Response, and Info packet Processing
+
+/*========================================================================*/
+static unsigned char cmdslice = 4;
+
+// Read one character from the V1 data stream
FILE *fp = NULL;
-unsigned char nochecksum = 0;
-unsigned char slice = 4;
-int makecmd(unsigned char *buf, unsigned char src, unsigned char dst, unsigned char pkt, unsigned char len, unsigned char *param)
+static int readv1rx(void)
+{
+ unsigned char retchar;
+ fread( &retchar,1,1,fp );
+ return retchar;
+}
+
+static char serbuf[256];
+// print out strings to the main (USB) serial port
+static void printser(char *str)
+{
+ printf( "%s", str );
+}
+
+#define PSTR(x) (x)
+
+static char *pullp(const char *p)
+{
+ return (char *)p;
+}
+
+static int readpkt(unsigned char *);
+static unsigned char respget[];
+static int getkey() {
+ return getchar();
+}
+
+static int keypress() {
+ return 0;//getchar();
+}
+
+
+static unsigned char tstnocks = 0; // is this a checksummed V1?
+
+// Create a valid V1 command in BUF, return length. Returns 0 if something is invalid
+// Note it permits source and dest 0-15, not just a source of 3,4,5.
+// pkt is the ID of the command.
+// len is size of param, param points to the bytes to go after the length
+// (before and not including the optional checksum which will be handled
+// according to what the infDisplay is doing.
+static int makecmd(unsigned char *buf, unsigned char src, unsigned char dst, unsigned char pkt,
+ unsigned char len, unsigned char *param)
{
if (len > 16)
return 0;
@@ -66,17 +113,17 @@ int makecmd(unsigned char *buf, unsigned char src, unsigned char dst, unsigned c
return 0;
unsigned char *b = buf, l = len;
*b++ = 0xaa;
- if (nochecksum && dst == 0x0a)
+ if (tstnocks && dst == 0x0a)
dst = 9;
- if (dst == 9 && !nochecksum)
+ if (dst == 9 && !tstnocks)
dst = 0x0a;
*b++ = 0xd0 + dst;
*b++ = 0xe0 + src;
*b++ = pkt;
- *b++ = len + !nochecksum;
+ *b++ = len + !tstnocks;
while (l--)
*b++ = *param++;
- if (!nochecksum) {
+ if (!tstnocks) {
unsigned char cks = 0, ix = 0;
for (ix = 0; ix < len + 5; ix++)
cks += buf[ix];
@@ -86,136 +133,158 @@ int makecmd(unsigned char *buf, unsigned char src, unsigned char dst, unsigned c
return b - buf;
};
-unsigned char v1idd = 0, v1infdisplaydata[8];
-unsigned char v1alerts = 0, v1alerttemp[16][7], v1alertout[16][7];
-unsigned char cddr = 0;
+static unsigned char v1idd = 0, v1infdisplaydata[8];
+static unsigned char v1alerts = 0, v1alerttemp[16][7], v1alertout[16][7];
+static unsigned char cddr = 0;
-int readpkt(unsigned char *buf)
+// Get a full, valid packet from the V1 - SOF, EOF, source, destination, and length bytes checked.
+// For unsolicited packets (infdisp, respalert, respdatarx), process internally
+static int readpkt(unsigned char *buf)
{
unsigned char len, ix;
- int ret;
buf[0] = 0;
for (;;) {
while (buf[0] != 0xaa) // SOF
- while (1 != (ret = fread(&buf[0], 1, 1, fp)))
- if (ret < 0)
- return ret;
- while (1 != fread(&buf[1], 1, 1, fp)); // target
+ {
+ buf[0] = readv1rx();
+ //sprintf( serbuf, pullp(PSTR("%02x")), buf[0] );
+ //printser( serbuf );
+ }
+ buf[1] = readv1rx(); // destination
if ((buf[1] & 0xf0) != 0xd0)
continue;
- while (1 != fread(&buf[2], 1, 1, fp)); // source
+ buf[2] = readv1rx(); // source
if ((buf[2] & 0xf0) != 0xe0)
continue;
- if ((buf[2] & 15) == 0xa)
- nochecksum = 0;
+ if ((buf[2] & 15) == 0xa) // check if checksum or nonchecksum
+ tstnocks = 0;
else if ((buf[2] & 15) == 9)
- nochecksum = 1;
- while (1 != fread(&buf[3], 1, 1, fp)); // packet id
- while (1 != fread(&buf[4], 1, 1, fp)); // length
- if (buf[4] > 16)
- continue;
-
+ tstnocks = 1;
+ buf[3] = readv1rx(); // packet ID
+ buf[4] = readv1rx(); // length
len = 5;
for (ix = 0; ix < buf[4]; ix++) {
- while (1 != fread(&buf[len], 1, 1, fp));
+ buf[len] = readv1rx();
len++;
}
- if (!nochecksum) {
+ if (!tstnocks) { // checksum if present
unsigned char cks = 0;
for (ix = 0; ix < len - 1; ix++)
cks += buf[ix];
if (buf[len - 1] != (cks & 0xff))
return -2; // continue; ???
}
- while (1 != fread(&buf[len], 1, 1, fp));
+ buf[len] = readv1rx(); // EOF
if (buf[len++] != 0xab)
continue;
// save off current alert or inf packet separately
if (buf[3] == INFDISPLAYDATA) {
- // maybe verify rest of packet
- v1idd++;
- memcpy( v1infdisplaydata, buf+5, 8 );
+ // maybe verify rest of packet
+ v1idd++;
+ memcpy(v1infdisplaydata, buf + 5, 8);
}
+ // alerts
else if (buf[3] == RESPALERTDATA) {
- // copy to temp until index == total, then move to out and inc
- if( !buf[5] ) { // no alerts
- memset( v1alertout, 0, 7 );
- v1alerts++;
- }
- else { // accumulate and copy block
- memcpy( v1alerttemp[(buf[5]>>4)-1], buf+5, 7 );
- if( buf[5]>>4 == (buf[5] & 15) ) {
- memcpy( v1alertout, v1alerttemp, 7*(buf[5]&15) );
- v1alerts++;
- }
- }
+ //sprintf( serbuf, pullp(PSTR("a: %d\n")), buf[1] & 0xf);
+ //printser(serbuf);
+ // copy to temp until index == total, then move to out and inc
+ if (!buf[5]) { // no alerts
+ if (!v1alertout[0][0]) { // already zero?
+ memset(v1alertout, 0, 7);
+ v1alerts++;
+ }
+ }
+ // v1 alertout is updated when a full set of alerts is received and accumulated.
+ else { // accumulate and copy block
+ memcpy(v1alerttemp[(buf[5] >> 4) - 1], buf + 5, 7);
+ if (buf[5] >> 4 == (buf[5] & 15)) {
+ memcpy(v1alertout, v1alerttemp, 7 * (buf[5] & 15));
+ v1alerts++;
+ }
+ }
}
+ // concealed display
else if (buf[3] == RESPDATARECEIVED) {
- cddr++;
+ cddr++;
}
else {
#if 0
- // show nonstream traffic
- printf("r: %d:", len );
- for( ix = 1 ; ix < len - 1 ; ix++ )
- printf( " %02x", buf[ix]);
- printf( "\n" );
+ // show nonstream traffic
+ sprintf(serbuf, pullp(PSTR("r: %d:")), len);
+ printser(serbuf);
+ for (ix = 1; ix < len - 1; ix++) {
+ sprintf(serbuf, pullp(PSTR(" %02x")), buf[ix]);
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("\r\n")));
#endif
- }
+ }
return len;
}
}
-int sendcmd(unsigned char *thiscmd, unsigned char resp, unsigned char *buf)
+// send a command, wait until it goes out, then look for a response packet (by ID), placing it in buf.
+static int sendcmd(unsigned char *thiscmd, unsigned char resp, unsigned char *buf)
{
- unsigned char ix;
+ unsigned char ix, iy;
int ret;
- fwrite(thiscmd, thiscmd[4] + 6, 1, fp); // write command
+ fwrite( thiscmd, thiscmd[4] + 6 , 1, fp );
+
+ // wait this many packets max for the command to go out on the bus
#define ECHOTIME 8
for (ix = 0; ix < ECHOTIME; ix++) { // look for command on bus
ret = readpkt(buf);
- // printf( "%d: %02x %02x %02x %02x %02x %02x %02x\n", ret, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6] );
+ // sprintf( serbuf, pullp(PSTR("%d: %02x %02x %02x %02x %02x %02x %02x\r\n")), ret, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6] );
if (ret < thiscmd[4] + 6)
continue;
if (!memcmp(thiscmd, buf, ret))
break;
}
- if (ix == ECHOTIME)
+ if (ix == ECHOTIME) // can't transmit for some reason - TS holdoff?
return -1;
-
- if (resp == NORESPONSE)
+ if (resp == NORESPONSE) // no response required for this
return 0;
-
- // look for response
+ // look for response, max packets to wait - busy will reset.
#define RESPTIME 20
for (ix = 0; ix < RESPTIME; ix++) {
ret = readpkt(buf);
if (ret < 6)
continue;
+ // FIXME - we don't check the source or destination ID.
switch (buf[3]) {
case RESPUNSUPPORTEDPACKET:
- printf("Unsupported Packet\n");
+ // print, but don't exit because it may not be our request.
+ printser(pullp(PSTR("Unsupported Packet\r\n")));
break;
case RESPREQUESTNOTPROCESSED:
- printf("Request Not Processed %02x\n", buf[5]);
- // maybe abort, return -3?
+ // if our packet ID, return error
+ sprintf(serbuf, pullp(PSTR("Request Not Processed %02x\r\n")), buf[5]);
+ printser(serbuf);
+ if (buf[5] == thiscmd[3])
+ return -3;
break;
case INFV1BUSY:
#if 0
- printf("V1Busy:");
- for (ix = 0; ix < buf[4] - 1; ix++)
- printf(" %02x", buf[5 + ix]);
- printf("\n");
+ printser(pullp(PSTR("V1Busy:")));
+ for (iy = 0; iy < buf[4] - 1; iy++) {
+ sprintf(serbuf, pullp(PSTR(" %02x")), buf[5 + iy]);
+ printser(serbuf);
+ }
+ printser(serbuf, "\r\n")));
#endif
- ix = 0; // reset timer
+ for (iy = 0; iy < buf[4] - 1; iy++)
+ if (buf[5 + iy] == thiscmd[3])
+ ix = 0; // reset timer since it is still processing our packet
break;
case RESPDATAERROR:
- printf("Data Error %02x\n", buf[5]);
+ sprintf(serbuf, pullp(PSTR("Data Error %02x\r\n")), buf[5]);
+ printser(serbuf);
+ if (buf[5] == thiscmd[3])
+ return -4;
break;
}
-
if (buf[3] == resp)
break;
}
@@ -224,221 +293,552 @@ int sendcmd(unsigned char *thiscmd, unsigned char resp, unsigned char *buf)
return 0;
}
-/*========================================================================*/
-int main(int argc, char *argv[])
-{
- unsigned char buf[22], sendbuf[22], ix;
- int ret;
- fp = fopen("/dev/ttyUSB0", "a+b");
- if (!fp)
- fp = fopen("/dev/rfcomm0", "a+b");
- if (!fp)
- return -1;
-
- // need to flush input
- fseek(fp, 0, SEEK_END);
-
- for (;;) { // get at least one inf packet
- ret = readpkt(buf);
- if (ret < 5)
- continue;
- if (buf[3] == INFDISPLAYDATA)
- break;
- }
- // should worry about timeslice holdoff.
-
- // printf( "VN: %d: %02x %02x %02x %02x %02x %02x %02x\n", ix, sendbuf[0], sendbuf[1], sendbuf[2], sendbuf[3], sendbuf[4], sendbuf[5], sendbuf[6] );
-#if 0
- unsigned char cmparm[] = { 3 };
- ix = makecmd(sendbuf, slice, 0xa, REQCHANGEMODE, 1, cmparm);
- sendcmd(sendbuf, NORESPONSE, buf);
-#endif
- // send one request version to clear out the incoming packet buffer
- makecmd(sendbuf, slice, 0xa, REQVERSION, 0, NULL);
- sendcmd(sendbuf, NORESPONSE, buf);
+// command and response buffers
+static unsigned char respget[22], cmdsend[22];
+static unsigned int maxswp = 5;
+
+// make sure the buffer is clear by getting an echo.
+// FIXME - should have long timeout and return status.
+static void syncresp() {
+ int iy;
+ // send one request version to clear out the incoming packet respgetfer
+ makecmd(cmdsend, cmdslice, 0xa, REQVERSION, 0, NULL);
+ sendcmd(cmdsend, NORESPONSE, respget);
for (;;) {
- ret = readpkt(buf);
- if (ret < 6)
+ iy = readpkt(respget);
+ if (iy < 6)
continue;
- if( buf[3] == RESPVERSION )
- break;
+ if (respget[3] == RESPVERSION)
+ break;
}
+}
- // do commands
- makecmd(sendbuf, slice, 0xa, REQVERSION, 0, NULL);
- sendcmd(sendbuf, RESPVERSION, buf);
- printf("Version: ");
- for (ix = 0; ix < buf[4] - 1; ix++)
- printf("%c", buf[5 + ix] < 127 && buf[5 + ix] > 31 ? buf[5 + ix] : '.');
- printf("\n");
-
- makecmd(sendbuf, slice, 0xa, REQSERIALNUMBER, 0, NULL);
- sendcmd(sendbuf, RESPSERIALNUMBER, buf);
- printf("SerialNo: ");
- for (ix = 0; ix < buf[4] - 1; ix++)
- printf("%c", buf[5 + ix] < 127 && buf[5 + ix] > 31 ? buf[5 + ix] : '.');
- printf("\n");
-
- makecmd(sendbuf, slice, 0xa, REQBATTERYVOLTAGE, 0, NULL);
- sendcmd(sendbuf, RESPBATTERYVOLTAGE, buf);
- printf("BattVolt: %d.%02d\n", buf[5], buf[6]);
-
- // User settings
- makecmd(sendbuf, slice, 0xa, REQUSERBYTES, 0, NULL);
- sendcmd(sendbuf, RESPUSERBYTES, buf);
- char userset[] = "12345678AbCdEFGHJuUtL ";
- printf("UserSet: (default) ");
- for (ix = 0; ix < 8; ix++)
- printf("%c", (buf[5] >> ix) & 1 ? userset[ix] : '_');
- for (ix = 0; ix < 8; ix++)
- printf("%c", (buf[6] >> ix) & 1 ? userset[ix + 8] : '_');
- for (ix = 0; ix < 8; ix++)
- printf("%c", (buf[7] >> ix) & 1 ? userset[ix + 16] : '_');
- printf("\nUserSet: (changed) ");
- for (ix = 0; ix < 8; ix++)
- printf("%c", (buf[5] >> ix) & 1 ? '_' : userset[ix]);
- for (ix = 0; ix < 8; ix++)
- printf("%c", (buf[6] >> ix) & 1 ? '_' : userset[ix + 8]);
- for (ix = 0; ix < 8; ix++)
- printf("%c", (buf[7] >> ix) & 1 ? '_' : userset[ix + 16]);
- printf("\n");
-
+// This is the first part of the sweep probe getting the sections and maximum index
+static void sweep1() {
+ int ix, ret;
// Sweep Sections and Definitions
- makecmd(sendbuf, slice, 0xa, REQSWEEPSECTIONS, 0, NULL);
- sendcmd(sendbuf, RESPSWEEPSECTIONS, buf);
- printf("SweepSct:\n");
- printf("+%d/%d %5d - %5d\n", buf[5] >> 4, buf[5] & 15, buf[8] << 8 | buf[9], buf[6] << 8 | buf[7]);
- if (buf[4] > 6)
- printf("+%d/%d %5d -:%5d\n", buf[10] >> 4, buf[10] & 15, buf[13] << 8 | buf[14], buf[11] << 8 | buf[12]);
- if (buf[4] > 11)
- printf("+%d/%d %5d - %5d\n", buf[15] >> 4, buf[15] & 15, buf[18] << 8 | buf[19], buf[16] << 8 | buf[17]);
- unsigned int nswppkt = (buf[5] & 15);
+ makecmd(cmdsend, cmdslice, 0xa, REQSWEEPSECTIONS, 0, NULL);
+ sendcmd(cmdsend, RESPSWEEPSECTIONS, respget);
+ printser(pullp(PSTR("SweepSections:\r\n")));
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u - %5u\r\n")), respget[5] >> 4, respget[5] & 15, respget[8] << 8 | respget[9],
+ respget[6] << 8 | respget[7]);
+ printser(serbuf);
+ if (respget[4] > 6) {
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u -:%5u\r\n")), respget[10] >> 4, respget[10] & 15, respget[13] << 8 | respget[14],
+ respget[11] << 8 | respget[12]);
+ printser(serbuf);
+ }
+ if (respget[4] > 11) {
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u - %5u\r\n")), respget[15] >> 4, respget[15] & 15, respget[18] << 8 | respget[19],
+ respget[16] << 8 | respget[17]);
+ printser(serbuf);
+ }
+ unsigned int nswppkt = (respget[5] & 15);
for (ix = 1; ix < nswppkt / 3;) {
// read additional 0x23 packet, print it out
- ret = readpkt(buf);
+ ret = readpkt(respget);
if (ret < 5)
continue;
- if (buf[3] != 0x23)
+ if (respget[3] != 0x23)
continue;
ix++;
- printf("+%d/%d %5d - %5d\n", buf[5] >> 4, buf[5] & 15, buf[8] << 8 | buf[9], buf[6] << 8 | buf[7]);
- if (buf[4] > 6)
- printf("+%d/%d %5d -:%5d\n", buf[10] >> 4, buf[10] & 15, buf[13] << 8 | buf[14], buf[11] << 8 | buf[12]);
- if (buf[4] > 11)
- printf("+%d/%d %5d - %5d\n", buf[15] >> 4, buf[15] & 15, buf[18] << 8 | buf[19], buf[16] << 8 | buf[17]);
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u - %5u\r\n")), respget[5] >> 4, respget[5] & 15, respget[8] << 8 | respget[9],
+ respget[6] << 8 | respget[7]);
+ printser(serbuf);
+
+ if (respget[4] > 6) {
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u -:%5u\r\n")), respget[10] >> 4, respget[10] & 15, respget[13] << 8 | respget[14],
+ respget[11] << 8 | respget[12]);
+ printser(serbuf);
+ }
+ if (respget[4] > 11) {
+ sprintf(serbuf, pullp(PSTR("+%d/%d %5u - %5u\r\n")), respget[15] >> 4, respget[15] & 15, respget[18] << 8 | respget[19],
+ respget[16] << 8 | respget[17]);
+ printser(serbuf);
+ }
}
// sweep definitions must stay within the sections above
- makecmd(sendbuf, slice, 0xa, REQMAXSWEEPINDEX, 0, NULL);
- sendcmd(sendbuf, RESPMAXSWEEPINDEX, buf);
- printf("SweepMax: %d\n", buf[5]);
- unsigned int maxswp = buf[5];
+ makecmd(cmdsend, cmdslice, 0xa, REQMAXSWEEPINDEX, 0, NULL);
+ sendcmd(cmdsend, RESPMAXSWEEPINDEX, respget);
+ sprintf(serbuf, pullp(PSTR("MaxSweepIndex: %d (+1 for number of definitions)\r\n")), respget[5]);
+ printser(serbuf);
+ maxswp = respget[5];
+}
+
+// This is the second part of the sweep probe which gets the actual sweep definitions
+static void sweep2() {
+ int ix, ret;
// read sweep sections
- makecmd(sendbuf, slice, 0xa, REQALLSWEEPDEFINITIONS, 0, NULL);
- sendcmd(sendbuf, RESPSWEEPDEFINITION, buf);
- printf("SweepDef: %d Top:%5d Bot:%5d\n", buf[5] & 63, buf[6] << 8 | buf[7], buf[8] << 8 | buf[9]);
+ makecmd(cmdsend, cmdslice, 0xa, REQALLSWEEPDEFINITIONS, 0, NULL);
+ sendcmd(cmdsend, RESPSWEEPDEFINITION, respget);
+ printser(pullp(PSTR("SweepDefinitions:\r\n")));
+ sprintf(serbuf, pullp(PSTR("+%d/%d Low:%5u High:%5u\r\n")), 1 + (respget[5] & 63), 1 + maxswp, respget[8] << 8 | respget[9],
+ respget[6] << 8 | respget[7]);
+ printser(serbuf);
for (ix = 0; ix < maxswp;) {
- ret = readpkt(buf);
+ ret = readpkt(respget);
if (ret < 5)
continue;
- if (buf[3] != 0x17)
+ if (respget[3] != 0x17)
continue;
ix++;
- printf("SweepDef: %d Top:%5d Bot:%5d\n", buf[5] & 63, buf[6] << 8 | buf[7], buf[8] << 8 | buf[9]);
+ sprintf(serbuf, pullp(PSTR("+%d/%d Low:%5u High:%5u\r\n")), 1 + (respget[5] & 63), 1 + maxswp, respget[8] << 8 | respget[9],
+ respget[6] << 8 | respget[7]);
+ printser(serbuf);
+ }
+}
+
+// user interactive program to get a 16 bit unsigned word (frequency to write sweep)
+static unsigned getword() {
+ unsigned ret = 0;
+ scanf( "%u", &ret );
+ return ret;
+}
+
+// Set a new set of sweep definitions
+static void sweepset() {
+ int ix, iy;
+ unsigned low[20], high[20];
+
+ syncresp();
+
+ sweep1();
+ sweep2();
+ printser(pullp(PSTR("Enter Definition Ranges, low and high, 0 to end\r\n")));
+ for (ix = 0; ix <= maxswp; ix++) {
+ sprintf(serbuf, pullp(PSTR("Def %d Low:\r\n")), ix + 1);
+ printser(serbuf);
+ low[ix] = getword();
+ printser(pullp(PSTR("\r\n")));
+ if (low[ix] == 0)
+ break;
+ sprintf(serbuf, pullp(PSTR("Def %d High:\r\n")), ix + 1);
+ printser(serbuf);
+ high[ix] = getword();
+ printser(pullp(PSTR("\r\n")));
+ if (high[ix] == 0)
+ break;
}
+ // print and ask to commit
+ if (!ix)
+ return;
+
+ for (iy = 0; iy < ix; iy++) {
+ sprintf(serbuf, pullp(PSTR("%2d: %5u - %5u\r\n")), iy + 1, low[iy], high[iy]);
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("Write to V1? (Y/N):")));
+
+ char c = getkey();
+ if (c != 'Y' && c != 'y')
+ return;
+ for (iy = 0; iy < ix; iy++) {
+ unsigned char wrsbuf[5];
+ // write, commit on the last.
+ wrsbuf[0] = 0x80 | iy;
+ if (iy == ix - 1)
+ wrsbuf[0] |= 0x40;
+ wrsbuf[1] = high[iy] >> 8;
+ wrsbuf[2] = high[iy];
+ wrsbuf[3] = low[iy] >> 8;
+ wrsbuf[4] = low[iy];
+ makecmd(cmdsend, cmdslice, 0xa, REQWRITESWEEPDEFINITIONS, 5, wrsbuf);
+ sendcmd(cmdsend, NORESPONSE, respget);
+ sprintf(serbuf, pullp(PSTR("Wrote %2d: %5u - %5u\r\n")), iy + 1, low[iy], high[iy]);
+ printser(serbuf);
+ }
+ // get write response and decode errors.
+ for (;;) {
+ iy = readpkt(respget);
+ if (iy < 6)
+ continue;
+ if (respget[3] == RESPSWEEPWRITERESULT)
+ break;
+ }
+ if (respget[5]) {
+ sprintf(serbuf, pullp(PSTR("Write Error in index %d\r\n")), respget[5] - 1);
+ printser(serbuf);
+ }
+ else
+ printser(pullp(PSTR("Write Successfup\r\n")));
+ sweep2();
+}
+
+// set default sweeps
+static void defaultsweeps() {
+ syncresp();
+ makecmd(cmdsend, cmdslice, 0xa, REQDEFAULTSWEEPS, 0, NULL);
+ sendcmd(cmdsend, NORESPONSE, respget);
+ printser(pullp(PSTR("Default Sweeps Done, Please use infoscan to confirm\r\n")));
+}
+
+static char userset[] = "12345678AbCdEFGHJuUtL ";
+// show user bytes
+static void userprint() {
+ int ix;
+ printser(pullp(PSTR("UserSet: (default) ")));
+ for (ix = 0; ix < 8; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[5] >> ix) & 1 ? userset[ix] : '_');
+ printser(serbuf);
+ }
+ for (ix = 0; ix < 8; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[6] >> ix) & 1 ? userset[ix + 8] : '_');
+ printser(serbuf);
+ }
+ for (ix = 0; ix < 8; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[7] >> ix) & 1 ? userset[ix + 16] : '_');
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("\r\nUserSet: (changed) ")));
+ for (ix = 0; ix < 8; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[5] >> ix) & 1 ? '_' : userset[ix]);
+ printser(serbuf);
+ }
+ for (ix = 0; ix < 8; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[6] >> ix) & 1 ? '_' : userset[ix + 8]);
+ printser(serbuf);
+ }
+ for (ix = 0; ix < 8; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[7] >> ix) & 1 ? '_' : userset[ix + 16]);
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("\r\n")));
+}
+
+static void usershow() {
+ // User settings
+ makecmd(cmdsend, cmdslice, 0xa, REQUSERBYTES, 0, NULL);
+ sendcmd(cmdsend, RESPUSERBYTES, respget);
+ userprint();
+}
+
+// Scan for everything I could find in the spec for all devices
+static void infoscan() {
+ int ix;
+
+ // sprintf( serbuf, pullp(PSTR("VN: %d: %02x %02x %02x %02x %02x %02x %02x\r\n")), ix, cmdsend[0], cmdsend[1], cmdsend[2], cmdsend[3], cmdsend[4], cmdsend[5], cmdsend[6] );
+ printser(pullp(PSTR("=====INFOSCAN=====\r\n")));
+ syncresp();
+
+ // do commands
+ makecmd(cmdsend, cmdslice, 0xa, REQVERSION, 0, NULL);
+ sendcmd(cmdsend, RESPVERSION, respget);
+ printser(pullp(PSTR("V1 Version: ")));
+
+ for (ix = 0; ix < respget[4] - 1; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("\r\n")));
+
+ makecmd(cmdsend, cmdslice, 0xa, REQSERIALNUMBER, 0, NULL);
+ sendcmd(cmdsend, RESPSERIALNUMBER, respget);
+ printser(pullp(PSTR("V1 SerialNo: ")));
+ for (ix = 0; ix < respget[4] - 1; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("\r\n")));
+
+ makecmd(cmdsend, cmdslice, 0xa, REQBATTERYVOLTAGE, 0, NULL);
+ sendcmd(cmdsend, RESPBATTERYVOLTAGE, respget);
+ sprintf(serbuf, pullp(PSTR("BattVolt: %d.%02d\r\n")), respget[5], respget[6]);
+ printser(serbuf);
+
+ usershow();
+
+ sweep1();
+ sweep2();
// Concealed Display
- makecmd(sendbuf, slice, 0, REQVERSION, 0, NULL);
- sendcmd(sendbuf, RESPVERSION, buf);
- printf("CD Version: ");
- for (ix = 0; ix < buf[4] - 1; ix++)
- printf("%c", buf[5 + ix] < 127 && buf[5 + ix] > 31 ? buf[5 + ix] : '.');
- printf("\n");
+ makecmd(cmdsend, cmdslice, 0, REQVERSION, 0, NULL);
+ sendcmd(cmdsend, RESPVERSION, respget);
+ printser(pullp(PSTR("CD Version: ")));
+ for (ix = 0; ix < respget[4] - 1; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("\r\n")));
// Remote Audio
- makecmd(sendbuf, slice, 1, REQVERSION, 0, NULL);
- sendcmd(sendbuf, RESPVERSION, buf);
- printf("RA Version: ");
- for (ix = 0; ix < buf[4] - 1; ix++)
- printf("%c", buf[5 + ix] < 127 && buf[5 + ix] > 31 ? buf[5 + ix] : '.');
- printf("\n");
+ makecmd(cmdsend, cmdslice, 1, REQVERSION, 0, NULL);
+ sendcmd(cmdsend, RESPVERSION, respget);
+ printser(pullp(PSTR("RA Version: ")));
+ for (ix = 0; ix < respget[4] - 1; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("\r\n")));
// Savvy
- makecmd(sendbuf, slice, 2, REQVERSION, 0, NULL);
- sendcmd(sendbuf, RESPVERSION, buf);
- printf("SV Version: ");
- for (ix = 0; ix < buf[4] - 1; ix++)
- printf("%c", buf[5 + ix] < 127 && buf[5 + ix] > 31 ? buf[5 + ix] : '.');
- printf("\n");
-
- makecmd(sendbuf, slice, 2, REQSERIALNUMBER, 0, NULL);
- sendcmd(sendbuf, RESPSERIALNUMBER, buf);
- printf("SV SerialNo: ");
- for (ix = 0; ix < buf[4] - 1; ix++)
- printf("%c", buf[5 + ix] < 127 && buf[5 + ix] > 31 ? buf[5 + ix] : '.');
- printf("\n");
-
- makecmd(sendbuf, slice, 2, REQSAVVYSTATUS, 0, NULL);
- sendcmd(sendbuf, RESPSAVVYSTATUS, buf);
- printf("SavvyStat: ThreshKPH:%d (unmu ena: throvrd):%d\n", buf[5], buf[6]);
- makecmd(sendbuf, slice, 2, REQVEHICLESPEED, 0, NULL);
- sendcmd(sendbuf, RESPVEHICLESPEED, buf);
- printf("SavvyVehSpd: %d kph\n", buf[5]);
-
- makecmd(sendbuf, slice, 0xa, REQSTARTALERTDATA, 0, NULL);
- sendcmd(sendbuf, NORESPONSE, buf);
- for(;;) {
- printf( "===\n" );
- ix = v1alerts;
- while( ix == v1alerts ) {
- usleep(10000);
- readpkt(buf);
- }
- for( ix = 0 ; ix < (v1alertout[0][0] & 15); ix++ ) {
- unsigned char *b = v1alertout[ix];
- unsigned char typ[]="LAKXU^-v", t;
- printf("%2d/%2d %5d %3d ^v %3d ", b[0] >> 4, b[0] & 15, b[1] << 8 | b[2], b[3], b[4]);
- for( t = 0 ; t < 8; t++ )
- if( (b[5] >> t ) & 1)
- printf( "%c", typ[t] );
- if( b[6] & 0x80 )
- printf( "!" );
- printf( "\n" );
+ makecmd(cmdsend, cmdslice, 2, REQVERSION, 0, NULL);
+ sendcmd(cmdsend, RESPVERSION, respget);
+ printser(pullp(PSTR("SV Version: ")));
+ for (ix = 0; ix < respget[4] - 1; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("\r\n")));
+
+ makecmd(cmdsend, cmdslice, 2, REQSERIALNUMBER, 0, NULL);
+ sendcmd(cmdsend, RESPSERIALNUMBER, respget);
+ printser(pullp(PSTR("SV SerialNo: ")));
+ for (ix = 0; ix < respget[4] - 1; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), respget[5 + ix] < 127 && respget[5 + ix] > 31 ? respget[5 + ix] : '.');
+ printser(serbuf);
+ }
+ printser(pullp(PSTR("\r\n")));
+
+ makecmd(cmdsend, cmdslice, 2, REQSAVVYSTATUS, 0, NULL);
+ sendcmd(cmdsend, RESPSAVVYSTATUS, respget);
+ sprintf(serbuf, pullp(PSTR("SavvyStat: ThreshKPH:%d (unmu ena: throvrd):%d\r\n")), respget[5], respget[6]);
+ printser(serbuf);
+ makecmd(cmdsend, cmdslice, 2, REQVEHICLESPEED, 0, NULL);
+ sendcmd(cmdsend, RESPVEHICLESPEED, respget);
+ sprintf(serbuf, pullp(PSTR("SavvyVehSpd: %d kph\r\n")), respget[5]);
+ printser(serbuf);
+ printser(pullp(PSTR("=====END INFOSCAN=====\r\n")));
+}
+
+// Ask for and Display (decoded) alerts
+static const unsigned char typ[] = "LAKXU^-v", t;
+static void alerts() {
+ int ix;
+ syncresp();
+ printser(pullp(PSTR("=====ALERTS=====\r\n")));
+ makecmd(cmdsend, cmdslice, 0xa, REQSTARTALERTDATA, 0, NULL);
+ sendcmd(cmdsend, NORESPONSE, respget);
+ for (;;) {
+ if( keypress() ) {
+ getkey();
+ break;
}
+ printser(pullp(PSTR("===\r\n")));
+ ix = v1alerts;
+ while (ix == v1alerts)
+ readpkt(respget);
+ for (ix = 0; ix < (v1alertout[0][0] & 15); ix++) {
+ unsigned char *b = v1alertout[ix], t;
+ sprintf(serbuf, pullp(PSTR("%2d/%2d %5u %3d ^v %3d ")), b[0] >> 4, b[0] & 15, b[1] << 8 | b[2], b[3], b[4]);
+ printser(serbuf);
+ for (t = 0; t < 8; t++)
+ if ((b[5] >> t) & 1) {
+ sprintf(serbuf, pullp(PSTR("%c")), typ[t]);
+ printser(serbuf);
+ }
+ if (b[6] & 0x80)
+ printser(pullp(PSTR("!")));
+ printser(pullp(PSTR("\r\n")));
+ }
+ }
+ makecmd(cmdsend, cmdslice, 0xa, REQSTOPALERTDATA, 0, NULL);
+ sendcmd(cmdsend, NORESPONSE, respget);
+ printser(pullp(PSTR("=====END ALERTS=====\r\n")));
+}
+
+const char sevs2ascii[] = {
+" ~'...17_...j..]........l...uvJ.`\".^............|.......LC...GU0-.......=#.....3r./.....c..2o.d.....\\.4......5y9.F.Ph.HAtE..b6.8"};
+
+static void showinfdisp() {
+ int ix;
+ sprintf(serbuf, pullp(PSTR("%c%c %02x %02x ")), sevs2ascii[respget[5] & 0x7f], respget[5] & 0x80 ? 'o' : ' ',
+ respget[5], respget[6] ^ respget[5]);
+ printser(serbuf);
+ for (ix = 0; ix < 8; ix++) {
+ sprintf(serbuf, pullp(PSTR("%c")), (respget[7] >> ix) & 1 ? '*' : '.');
+ printser(serbuf);
+ }
+ printser(" ");
+
+ for (ix = 0; ix < 8; ix++)
+ if ((respget[8] >> ix) & 1) {
+ sprintf(serbuf, pullp(PSTR("%c")), typ[ix]);
+ printser(serbuf);
+ }
+ else
+ printser("_");
+ printser(" ");
+
+ for (ix = 0; ix < 8; ix++)
+ if (((respget[8] ^ respget[9]) >> ix) & 1) {
+ sprintf(serbuf, pullp(PSTR("%c")), typ[ix]);
+ printser(serbuf);
+ }
+ else
+ printser("_");
+ printser(" ");
+ const unsigned char inf2[] = "MHUDEC-=";
+ //bit 0-7: Mute, TSHold, SysUp, DispOn, Euro, Custom, -, -
+ for (ix = 0; ix < 8; ix++)
+ if ((respget[10] >> ix) & 1) {
+ sprintf(serbuf, pullp(PSTR("%c")), inf2[ix]);
+ printser(serbuf);
+ }
+ else
+ printser("_");
+ printser(pullp(PSTR("\r\n")));
+}
+
+// This setup can be used for Savvy override and unmute setting, by changing the command
+// set scan mode
+// 1=AllBogeys, 2=Logic, 3=AdvancedLogic
+static void setmode(unsigned char mode) {
+ syncresp();
+ makecmd(cmdsend, cmdslice, 0xa, REQCHANGEMODE, 1, &mode);
+ sendcmd(cmdsend, NORESPONSE, respget);
+}
+
+static void savvyunmute(unsigned char enable) {
+ syncresp();
+ enable = ! !enable; // make 0 or 1
+ makecmd(cmdsend, cmdslice, 0xa, REQSETSAVVYUNMUTEENABLE, 1, &enable);
+ sendcmd(cmdsend, NORESPONSE, respget);
+}
+
+// 0 - never, 0xff - always, else kph.
+static void savvyoverride(unsigned char speed) {
+ syncresp();
+ makecmd(cmdsend, cmdslice, 0xa, REQOVERRIDETHUMBWHEEL, 1, &speed);
+ sendcmd(cmdsend, NORESPONSE, respget);
+}
+
+// no param command without response
+static void quickcommand(unsigned char cmd) {
+ syncresp();
+ makecmd(cmdsend, cmdslice, 0xa, cmd, 0, NULL);
+ sendcmd(cmdsend, NORESPONSE, respget);
+}
+
+// prototype - need to add set/reset dialog and edit the buffer
+static void userbytes() {
+ syncresp();
+ printser(pullp(PSTR("Current:\r\n")));
+ usershow();
+ printser(pullp(PSTR("Use one of the above letters/numbers to change,\r\n" " or Q to quit, W to write changes to the V1\r\n")));
+ unsigned char ub[6];
+ memcpy(ub, respget + 5, 6);
+ for (;;) {
+ char c = getkey();
+ if (c <= ' ')
+ continue;
+ if (c == 'Q' || c == 'q')
+ return;
+ if (c == 'w' || c == 'w')
+ break;
+ int ix;
+ for (ix = 0; ix < 24; ix++)
+ if (userset[ix] == c)
+ break;
+ if (ix < 24)
+ ub[ix >> 3] ^= 1 << (ix & 7);
+ memcpy(respget + 5, ub, 6);
+ userprint();
+ }
+ memcpy(respget + 5, ub, 6);
+ userprint();
+
+ printser(pullp(PSTR("Updating\r\n")));
+ makecmd(cmdsend, cmdslice, 0xa, REQWRITEUSERBYTES, 6, ub);
+ sendcmd(cmdsend, NORESPONSE, respget);
+ printser(pullp(PSTR("New:\r\n")));
+ usershow();
+}
+
+extern void hwsetup(void);
+
+/*========================================================================*/
+int main(int argc, char *argv[])
+{
+ int ret;
+ unsigned char lastdisp[12];
+
+ fp = fopen("/dev/ttyUSB0", "a+b");
+ if (!fp)
+ fp = fopen("/dev/rfcomm0", "a+b");
+ if (!fp)
+ return -1;
+
+ // need to flush input
+ fseek(fp, 0, SEEK_END);
+
+ printser(pullp(PSTR("V1MegaTool\r\n")));
+ for (;;) {
+ for (;;) { // get at least one inf packet
+ ret = readpkt(respget);
+ if (ret < 5)
+ continue;
+ if (respget[3] == INFDISPLAYDATA)
+ break;
+ }
+ // should give Not Ready message if timecmdslice holdoff.
+ printser(pullp(PSTR("A-alerts, I-infoscan, D-DefaultSweep, S-SetSweeps. U-userbytes V-ViewDisplay\r\n")));
+ printser(pullp(PSTR("#-FactDefault 1-DispOff 2-DispOn 3-MuteOn 4-Muteoff 5-AllBogeys 6-Logic 7-Advanced-Logic\r\n")));
+
+ char c = getkey();
+
+ switch (c) {
+
+ case '#':
+ quickcommand(REQFACTORYDEFAULT);
+ break;
+ case '1':
+ quickcommand(REQTURNOFFMAINDISPLAY);
+ break;
+ case '2':
+ quickcommand(REQTURNONMAINDISPLAY);
+ break;
+ case '3':
+ quickcommand(REQMUTEON);
+ break;
+ case '4':
+ quickcommand(REQMUTEOFF);
+ break;
+ case '5':
+ setmode(1); // all bogeys
+ break;
+ case '6':
+ setmode(2); // logic
+ break;
+ case '7':
+ setmode(3); // advanced logic
+ break;
+ case 'A':
+ case 'a':
+ alerts();
+ break;
+ case 'U':
+ case 'u':
+ userbytes();
+ break;
+ case 'I':
+ case 'i':
+ infoscan();
+ break;
+ case 'S':
+ case 's':
+ sweepset();
+ break;
+ case 'D':
+ case 'd':
+ defaultsweeps();
+ break;
+ case 'V':
+ case 'v':
+ printser(pullp(PSTR("Mute (ESP)Hold systemUp mainDisp Euro Custom\r\n")));
+ lastdisp[0] = 0;
+ while( !keypress() ) {
+ ret = readpkt(respget);
+ if (ret < 5)
+ continue;
+ if (respget[3] == INFDISPLAYDATA && memcmp(lastdisp, respget, 12)) {
+ showinfdisp();
+ memcpy(lastdisp, respget, 12);
+ }
+ }
+ getkey();
+ break;
+ default:
+ break;
+ }
}
- fclose(fp);
- return 0;
- /*
-
- char sevs2ascii[] = {
- ' ', '~', '.', '.', '.', '.', '1', '7',
- '_', '.', '.', '.', 'j', '.', '.', ']',
- '.', '.', '.', '.', '.', '.', '.', '.',
- 'l', '.', '.', '.', 'u', 'v', 'J', '.',
-
- '.', '.', '.', '^', '.', '.', '.', '.',
- '.', '.', '.', '.', '.', '.', '.', '.',
- '|', '.', '.', '.', '.', '.', '.', '.',
- 'L', 'C', '.', '.', '.', 'G', 'U', '0',
-
- '-', '.', '.', '.', '.', '.', '.', '.',
- '=', '#', '.', '.', '.', '.', '.', '3',
- 'r', '.', '/', '.', '.', '.', '.', '.',
- 'c', '.', '.', '2', 'o', '.', 'd', '.',
-
- '.', '.', '.', '.', '\\', '.', '4', '.',
- '.', '.', '.', '.', '.', '5', 'y', '9',
- '.', 'F', '.', 'P', 'h', '.', 'H', 'A',
- 't', 'E', '.', '.', 'b', '6', '.', '8'
- };
- printf("Disp: %c%c %02x %02x ", sevs2ascii[buf[5] & 0x7f], buf[5] & 0x80 ? 'o' : ' ', buf[5], buf[6] ^ buf[5]);
- for (ix = 0; ix < 8; ix++)
- printf("%c", (buf[7] >> ix) & 1 ? '*' : '.');
-
- //bit 0-7: Laser, Ka, K, X, -, Front, Side, Rear
- printf(" %02x %02x", buf[8], buf[9] ^ buf[8]);
- //bit 0-7: Mute, TSHold, SysUp, DispOn, Euro, Custom, -, -
- printf(" %02x\n", buf[10]);
- break;
-
- */
}

No commit comments for this range

Something went wrong with that request. Please try again.