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: 10df4df2de
...
head fork: tz1/HarleyJ1850GPS
compare: 1e09254cc6
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 40 additions and 12 deletions.
  1. +21 −2 harley.c
  2. +19 −10 harleyjg.c
View
23 harley.c
@@ -1,5 +1,6 @@
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
struct harley {
int rpm, vspd, full, gear, clutch, neutral, engtemp, turnsig, odoaccum, fuelaccum;
@@ -78,6 +79,21 @@ void calchog(char *outb, int mstime)
if (i < 5 || 0xc4 != j) {
sprintf(outb, "$PDERR,%d,%02x,", i, j);
strcat(outb, inb);
+#if 0
+ for( x = 0; x < i; x++) {
+ for( y = 0 ; y < 8 ; y++ ) {
+ hex[x] ^= 1 << y;
+ j = crc(hex,i);
+ if( j == 0xc4 )
+ break;
+ hex[x] ^= 1 << y;
+ }
+ if( y < 8 )
+ break;
+ }
+ if( y < 8 )
+ fprintf( stderr, "%s FIX %d %d %02x %02x %s\n", outb, x, y, hex[x], 1<<y ^hex[x] ,inb );
+#endif
return;
}
@@ -201,8 +217,10 @@ void calchog(char *outb, int mstime)
addnmeacksum(outb);
}
-unsigned char buf[4096];
-int main(int argc, char argv[]) {
+
+char buf[4096];
+
+int main(int argc, char *argv[]) {
unsigned ms;
while(!feof(stdin) ) {
@@ -214,4 +232,5 @@ int main(int argc, char argv[]) {
calchog( &buf[4], ms );
printf( "%3d %s\n", ms, &buf[4] );
}
+ return 0;
}
View
29 harleyjg.c
@@ -50,6 +50,11 @@ static void sendmid()
}
}
+/*-------------------------------------------------------------------------*/
+static unsigned lasttcnt, hightime, marktime, marklow;
+#define checkhitime(t) { if( t < lasttcnt )hightime++; lasttcnt = t;}
+
+/*-------------------------------------------------------------------------*/
static unsigned char innmea; // middle of NMEA, wait for end to add interleaved
// Received character from GPS - put to transmit buffer, but also handle other cases
ISR(USART_RX_vect)
@@ -85,19 +90,21 @@ ISR(USART_UDRE_vect)
}
/*-------------------------------------------------------------------------*/
-static unsigned hightime, marktime, marklow;
static unsigned char tsout[3];
static void timestamp(unsigned lowtime) {
unsigned long mark = marktime;
mark <<= 16;
mark |= marklow;
+ checkhitime(lowtime);
unsigned long now = hightime;
now <<= 16;
now |= lowtime;
now -= mark;
+ if( (now & 0xffff0000UL) == 0xffff0000UL )
+ now &= 0xffffUL;
if( now > (F_CPU/TIMER_PRESCALER) ) {
now -= (F_CPU/TIMER_PRESCALER);
- if( now > (F_CPU/TIMER_PRESCALER) ) { // reset mark
+ if( now > 8*(F_CPU/TIMER_PRESCALER) ) { // reset mark
marklow = TCNT1;
marktime = hightime;
now = 0;
@@ -119,7 +126,7 @@ static void timestamp(unsigned lowtime) {
digit++, now -= (F_CPU/TIMER_PRESCALER/100);
tsout[1] = digit;
digit = '0';
- while( now >= (F_CPU/TIMER_PRESCALER/1000) )
+ while( now > (F_CPU/TIMER_PRESCALER/1000) && digit < '9')
digit++, now -= (F_CPU/TIMER_PRESCALER/1000);
tsout[2] = digit;
}
@@ -155,7 +162,6 @@ ISR(INT1_vect)
// set up UART port and configuration, out of reset and deep sleep
static void uart_init()
{
-
outhead = outtail = midlen = innmea = 0;
/* turn on bluetooth */
DDRB |= _BV(PB1);
@@ -218,10 +224,9 @@ void receiver_init(void)
TCCR1B = _BV(ICES1) | _BV(ICNC1) | _BV(CS11) | _BV(CS10);
/* clear and enable Overflow and Input Capture interrupt */
- TIFR |= _BV(TOV1) | _BV(ICF1);
- TIMSK |= _BV(TOIE1) | _BV(ICIE1);
-
- OCR1A = US(VPW_EOF_MIN); /* timeout - EOD */
+ TIFR |= _BV(TOV1) | _BV(ICF1) | _BV(OCF1B);
+ TIMSK |= _BV(TOIE1) | _BV(ICIE1) | _BV(OCIE1B);
+ OCR1B = 32768;
MCUCR |= 0xC;
GIMSK |= 0x80;
@@ -303,12 +308,16 @@ void deepsleep(void)
}
/*-------------------------------------------------------------------------*/
-
+ISR(TIMER1_COMPB_vect)
+{
+ checkhitime(TCNT1);
+}
volatile unsigned inactime; /* = 0 */
// overflow - used as a coarse counter for long timeouts
ISR(TIMER1_OVF_vect)
{
- hightime++;
+ // hightime++;
+ checkhitime(TCNT1);
// downcount transparency counter if active
if (transptime) {
transptime--;

No commit comments for this range

Something went wrong with that request. Please try again.