well, I can decode ground speed now
This commit is contained in:
parent
6049cba9c6
commit
57b56d6e37
2 changed files with 33 additions and 4 deletions
|
@ -49,7 +49,7 @@ int main(int argc, char **argv) {
|
||||||
goto error_can_if_open;
|
goto error_can_if_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hexagram_capture_replay(capture, can_if, 1) < 0) {
|
if (hexagram_capture_replay(capture, can_if, 1.0) < 0) {
|
||||||
perror("hexagram_capture_replay()");
|
perror("hexagram_capture_replay()");
|
||||||
|
|
||||||
goto error_capture_replay;
|
goto error_capture_replay;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
@ -28,6 +29,8 @@ int main(int argc, char **argv) {
|
||||||
struct can_frame frame;
|
struct can_frame frame;
|
||||||
uint8_t last_gear = 0;
|
uint8_t last_gear = 0;
|
||||||
|
|
||||||
|
struct timeval now, last;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
return usage(argc, argv, NULL);
|
return usage(argc, argv, NULL);
|
||||||
}
|
}
|
||||||
|
@ -38,32 +41,58 @@ int main(int argc, char **argv) {
|
||||||
goto error_can_if_open;
|
goto error_can_if_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
memcpy(&last, &now, sizeof(now));
|
||||||
|
|
||||||
initscr();
|
initscr();
|
||||||
|
|
||||||
win = newwin(LINES, COLS, 0, 0);
|
win = newwin(LINES, COLS, 0, 0);
|
||||||
|
|
||||||
while (hexagram_can_if_read(can_if, &frame) >= 0) {
|
while (hexagram_can_if_read(can_if, &frame) >= 0) {
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
|
||||||
char lever_states[16] = " PRNDS ";
|
char lever_states[16] = " PRNDS ";
|
||||||
char manual_gears[16] = " 123456 ";
|
char manual_gears[16] = " 123456 ";
|
||||||
|
|
||||||
if (frame.can_id == 0x280) {
|
if (frame.can_id == 0x280) {
|
||||||
|
double rpm = 0.25 * (double)(frame.data[2] | (frame.data[3] << 8));
|
||||||
|
|
||||||
|
wmove(win, 1, 0);
|
||||||
|
|
||||||
|
wprintw(win, "%6.1lf RPM\n", rpm);
|
||||||
} else if (frame.can_id == 0x540) {
|
} else if (frame.can_id == 0x540) {
|
||||||
if (frame.data[7] != last_gear) {
|
if (frame.data[7] != last_gear) {
|
||||||
wmove(win, 0, 0);
|
wmove(win, 3, 8);
|
||||||
|
|
||||||
if ((frame.data[7] & 0xc) == 0xc) {
|
if ((frame.data[7] & 0xc) == 0xc) {
|
||||||
wprintw(win, " %c\n",
|
wprintw(win, " %c\n",
|
||||||
manual_gears[(frame.data[7] & 0xf0) >> 4]);
|
manual_gears[(frame.data[7] & 0xf0) >> 4]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
wprintw(win, "%c \n",
|
wprintw(win, "%c \n",
|
||||||
lever_states[(frame.data[7] & 0xf0) >> 4]);
|
lever_states[(frame.data[7] & 0xf0) >> 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
wrefresh(win);
|
|
||||||
|
|
||||||
last_gear = frame.data[7];
|
last_gear = frame.data[7];
|
||||||
}
|
}
|
||||||
|
} else if (frame.can_id == 0x5a0) {
|
||||||
|
/*
|
||||||
|
* Speed is expressed in units of 0.002 wheel cycles per second
|
||||||
|
*/
|
||||||
|
double rps = 0.001 * (double)(((uint16_t)frame.data[1] >> 1)
|
||||||
|
| ((uint16_t)frame.data[2] << 8));
|
||||||
|
|
||||||
|
double kph = (2.032 * rps * 3600) / 1000.0;
|
||||||
|
|
||||||
|
wmove(win, 2, 0);
|
||||||
|
|
||||||
|
wprintw(win, "%6.1lf kph", kph);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((now.tv_sec * 1000000) + now.tv_usec) - ((last.tv_sec * 1000000) + last.tv_usec) > 100000) {
|
||||||
|
memcpy(&last, &now, sizeof(now));
|
||||||
|
|
||||||
|
wrefresh(win);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue