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/HarleyJ1850GPS
base: f4669933c5
...
head fork: tz1/HarleyJ1850GPS
compare: 10df4df2de
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 238 additions and 4 deletions.
  1. +6 −1 Makefile
  2. +217 −0 harley.c
  3. +15 −3 harleyjg.c
View
7 Makefile
@@ -9,6 +9,8 @@ DUDE_PORT = usb
DEFS =
LIBS =
+HOSTCC = gcc -Wall -O6
+
CC = avr-gcc
CFLAGS = --std=c99 -g -Wall $(OPTIMIZE) -mmcu=$(MCU) $(DEFS)
@@ -17,11 +19,14 @@ LDFLAGS = -Wl,-Map,$(PRG).map
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
-all: $(PRG).elf lst text eeprom size
+all: $(PRG).elf lst text eeprom size harley
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
+harley: harley.c
+ $(HOSTCC) harley.c -o $@
+
harleyjg.o: harleyjg.c
clean:
View
217 harley.c
@@ -0,0 +1,217 @@
+#include <string.h>
+#include <stdio.h>
+
+struct harley {
+ int rpm, vspd, full, gear, clutch, neutral, engtemp, turnsig, odoaccum, fuelaccum;
+ int odolastms, fuellastms;
+ int odolastval, fuellastval;
+};
+
+void addnmeacksum(char *c)
+{
+ int i = 0;
+ char *d = c;
+ d += strlen(d);
+ *d++ = '*';
+ *d = 0;
+ c++;
+ while (*c && *c != '*')
+ i ^= *c++;
+ i &= 0xff;
+ sprintf(++c, "%02X", i);
+}
+
+static int crc(int *data, int len)
+{
+ unsigned char crc, dimg;
+ unsigned char poly;
+ int i;
+
+ crc = 0xff;
+ while (len--) {
+ dimg = *data++;
+ // printf("%02x ", dimg);
+ for (i = 0; i < 8; i++) {
+ poly = 0;
+ if (0x80 & (crc ^ dimg ))
+ poly = 0x1d;
+ crc = (crc << 1) ^ poly;
+ dimg <<= 1;
+ }
+ }
+ //printf("= %02x\n", crc);
+ return crc;
+}
+
+static unsigned short odolast = 0, fuellast = 0;
+
+struct harley hstat;
+
+void calchog(char *outb, int mstime)
+{
+ int i, j, x;
+ unsigned short y;
+ int hex[8];
+ char inb[4096], *c, *d;
+
+ c = outb;
+ while( *c && (*c < '0' || *c > 'F') ) // remove leading J or whatever
+ c++;
+ d = inb;
+ while( *c ) {
+ if( (*c >= '0' && *c <= 'F') )
+ *d++ = *c;
+ c++;
+ }
+ *d++ = 0;
+ if( strlen(inb) < 10 )
+ return;
+#if 0
+ // obdpros
+ i = sscanf(inb, "%02x %02x %02x %02x %02x %02x %02x %02x",
+ );
+#endif
+ // AVR
+ i = sscanf(inb, "%02x%02x%02x%02x%02x%02x%02x%02x",
+ &hex[0], &hex[1], &hex[2], &hex[3], &hex[4], &hex[5], &hex[6], &hex[7]);
+ j = crc(hex, i);
+ if (i < 5 || 0xc4 != j) {
+ sprintf(outb, "$PDERR,%d,%02x,", i, j);
+ strcat(outb, inb);
+ return;
+ }
+
+ i--;
+ x = hex[0] << 24;
+ x |= hex[1] << 16;
+ x |= hex[2] << 8;
+ x |= hex[3];
+
+ y = hex[4] << 8 | hex[5];
+
+ if (x == 0x281b1002) { // rpm * 4
+ sprintf(outb, "$PDRPM,%d.%02d,", y / 4, y % 4 * 25);
+ hstat.rpm = y * 250;
+ } else if (x == 0x48291002) { // kph*128
+ sprintf(outb, "$PDSPD,%d.%03d,", y / 200, y % 200 * 5);
+ hstat.vspd = y * 5;
+ } else if (x == 0xa8491010) { // temp, deg F
+ sprintf(outb, "$PDHOT,%d,", hex[4]);
+ hstat.engtemp = hex[4];
+ } else if (x == 0xa83b1003) { // gear
+ y = hex[4];
+ j = 0;
+ if (y)
+ while (y >>= 1)
+ j++;
+ else
+ j = -1;
+ sprintf(outb, "$PDGER,%d,", j);
+ hstat.gear = j;
+ } else if (x == 0x48da4039 && (hex[4] & 0xfc) == 0) { // turn signals
+ char turns[] = "NRLB";
+ sprintf(outb, "$PDSGN,%c,", turns[hex[4]]);
+ hstat.turnsig = hex[4];
+ } else if ((x & 0xffffff7f) == 0xa8691006) { // odo, 40cm/tick,
+ if (!(x & 0x80)) {
+ hstat.odolastval = y;
+ hstat.odolastval -= odolast;
+ if( hstat.odolastval < 0 )
+ hstat.odolastval += 65536;
+ hstat.odoaccum += hstat.odolastval;
+ if (mstime >= hstat.odolastms)
+ hstat.odolastms = mstime - hstat.odolastms;
+ else
+ hstat.odolastms = 100000 + mstime - hstat.odolastms;
+ sprintf(outb, "$PDODO,%d,%d,", hstat.odolastval, hstat.odolastms);
+ odolast = y;
+ hstat.odolastms = mstime;
+ } else { // count overflow
+ odolast = 0;
+ hstat.odolastms = mstime;
+ hstat.odoaccum = 0;
+ sprintf(outb, "$PDODO,-0,-0,");
+ }
+ } else if ((x & 0xffffff7f) == 0xa883100a) { // fuel, 0.04ml/tick
+ if (!(x & 0x80)) {
+ hstat.fuellastval = y;
+ hstat.fuellastval -= fuellast;
+ if( hstat.fuellastval < 0 )
+ hstat.fuellastval += 65536;
+ hstat.fuelaccum += hstat.fuellastval;
+ if (mstime >= hstat.fuellastms)
+ hstat.fuellastms = mstime - hstat.fuellastms;
+ else
+ hstat.fuellastms = 100000 + mstime - hstat.fuellastms;
+ sprintf(outb, "$PDFUL,%d,%d,", hstat.fuellastval, hstat.fuellastms);
+ fuellast = y;
+ hstat.fuellastms = mstime;
+ } else {
+ fuellast = 0;
+ hstat.fuellastms = mstime;
+ hstat.fuelaccum = 0;
+ sprintf(outb, "$PDFUL,-0,-0,");
+ }
+ } else if (x == 0xa8836112 && (hex[4] & 0xd0) == 0xd0) { // fuel gauge, level
+ sprintf(outb, "$PDGAS,%d,", hex[4] & 0x0f);
+ hstat.full = hex[4] & 0x0f;
+ } else if ((x & 0xffffff5d) == 0x483b4000) { // clutch, neutral
+ sprintf(outb, "$PDCLU,");
+ hstat.neutral = !!(hex[3] & 0x20); // ! & 0x02
+ hstat.clutch = !!(hex[3] & 0x80);
+ switch (hex[3]) {
+ case 0x02:
+ sprintf(outb, "$PDCLU,xx,");
+ break;
+ case 0x82:
+ sprintf(outb, "$PDCLU,xC,");
+ break;
+ case 0x20:
+ sprintf(outb, "$PDCLU,Nx,");
+ break;
+ case 0xA0:
+ sprintf(outb, "$PDCLU,NC,");
+ break;
+ }
+ } else if (x == 0x68881003
+ || x == 0x68FF1003 || x == 0x68FF4003 || x == 0x68FF6103 || x == 0xC888100E || x == 0xC8896103 || x == 0xE889610E) {
+ sprintf(outb, "$PDPNG,");
+ } else if ((x & 0xffffff7f) == 0x4892402a || (x & 0xffffff7f) == 0x6893612a) {
+ sprintf(outb, "$PDOFF,"); // shutdown - lock
+ } else if (x == 0x68881083) {
+ sprintf(outb, "$PDMIL,"); // check engine
+ } else {
+ sprintf(outb, "$PDMSG,");
+ }
+
+ c = inb;
+ while (*c) {
+ if (*c == ' ')
+ *c = ',';
+ c++;
+ }
+
+ strcat(outb, inb);
+ c = outb;
+ while( *c )
+ if( *c < ' ' )
+ *c = 0;
+ else
+ c++;
+ addnmeacksum(outb);
+
+}
+unsigned char buf[4096];
+int main(int argc, char argv[]) {
+ unsigned ms;
+
+ while(!feof(stdin) ) {
+ memset(buf,0,256);
+ gets(buf);
+ if( buf[3] != 'J' )
+ continue;
+ ms = atoi(buf);
+ calchog( &buf[4], ms );
+ printf( "%3d %s\n", ms, &buf[4] );
+ }
+}
View
18 harleyjg.c
@@ -86,7 +86,7 @@ ISR(USART_UDRE_vect)
/*-------------------------------------------------------------------------*/
static unsigned hightime, marktime, marklow;
-static unsigned char tsout[2];
+static unsigned char tsout[3];
static void timestamp(unsigned lowtime) {
unsigned long mark = marktime;
mark <<= 16;
@@ -108,6 +108,8 @@ static void timestamp(unsigned lowtime) {
marktime = mark >> 16;
}
}
+ while( now >= (F_CPU/TIMER_PRESCALER) )
+ now -= (F_CPU/TIMER_PRESCALER);
unsigned char digit = '0';
while( now >= (F_CPU/TIMER_PRESCALER/10) )
digit++, now -= (F_CPU/TIMER_PRESCALER/10);
@@ -116,6 +118,10 @@ static void timestamp(unsigned lowtime) {
while( now >= (F_CPU/TIMER_PRESCALER/100) )
digit++, now -= (F_CPU/TIMER_PRESCALER/100);
tsout[1] = digit;
+ digit = '0';
+ while( now >= (F_CPU/TIMER_PRESCALER/1000) )
+ digit++, now -= (F_CPU/TIMER_PRESCALER/1000);
+ tsout[2] = digit;
}
// PPS on the UTC second mark
@@ -125,6 +131,11 @@ ISR(INT1_vect)
return;
// PORTB |= _BV(PB2);
unsigned t = TCNT1;
+
+ timestamp(t);
+ midbuf[midlen++] = tsout[0];
+ midbuf[midlen++] = tsout[1];
+ midbuf[midlen++] = tsout[2];
midbuf[midlen++] = '=';
marktime = hightime;
marklow = t;
@@ -363,11 +374,12 @@ ISR(TIMER1_CAPT_vect)
/* doesn't quite do IFRs - normalization bit, crc? */
if (!polarity && width >= US(VPW_SOF_MIN)) {
#if 1
- jmsglen = 3;
+ jmsglen = 4;
timestamp(now);
jmsgbuf[0] = tsout[0];
jmsgbuf[1] = tsout[1];
- jmsgbuf[2] = 'J';
+ jmsgbuf[2] = tsout[2];
+ jmsgbuf[3] = 'J';
#else
jmsglen = 1;
jmsgbuf[0] = 'J';

No commit comments for this range

Something went wrong with that request. Please try again.