Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

incomplete sync with bluevmega.c (need to do keypress, not stdio)

  • Loading branch information...
commit 13bfd86fc1d3a7a42564c3de8fe803f239c2c5f0 1 parent 70ce2cf
@tz1 authored
Showing with 658 additions and 259 deletions.
  1. +658 −259 v1test.c
View
917 v1test.c
@@ -3,7 +3,6 @@
#include <string.h>
#include <unistd.h>
-
#define REQVERSION (1)
#define RESPVERSION (2)
#define REQSERIALNUMBER (3)
@@ -53,11 +52,58 @@
#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;
@@ -67,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];
@@ -87,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;
}
@@ -225,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;
-
- */
}

0 comments on commit 13bfd86

Please sign in to comment.
Something went wrong with that request. Please try again.