forked from latonita/arduino-canbus-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino-canbus-monitor.ino
72 lines (60 loc) · 2.53 KB
/
arduino-canbus-monitor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*****************************************************************************************
* This is implementation of CAN BUS ASCII protocol based on LAWICEL v1.3 serial protocol
* of CAN232/CANUSB device (http://www.can232.com/docs/can232_v3.pdf)
*
* Made for Arduino with Seeduino/ElecFreaks CAN BUS Shield based on MCP2515
*
* Copyright (C) 2015 Anton Viktorov <[email protected]>
* https://github.com/latonita/arduino-canbus-monitor
*
* This library is free software. You may use/redistribute it under The MIT License terms.
*
*****************************************************************************************/
#include <SPI.h>
#include "mcp_can.h"
#include "can-232.h"
#include "SoftwareSerial.h"
#define DEBUG_MODE
void setup() {
Serial.begin(LW232_DEFAULT_BAUD_RATE); // default COM baud rate is 115200.
// Can232::init (RATE, CLOCK)
// Rates: CAN_10KBPS, CAN_20KBPS, CAN_50KBPS, CAN_100KBPS, CAN_125KBPS, CAN_250KBPS, CAN_500KBPS, CAN_500KBPS, CAN_1000KBPS, CAN_83K3BPS
// Default is CAN_83K3BPS ;)))))))))
// Clock: MCP_16MHz or MCP_8MHz.
// Default is MCP_16MHz. Please note, not all CAN speeds supported. check big switch in mcp_can.cpp
// defaults can be changed in mcp_can.h
// Can232::init(); // rate and clock = LW232_DEFAULT_CAN_RATE and LW232_DEFAULT_CLOCK_FREQ
// Can232::init(CAN_125KBPS); // rate = 125, clock = LW232_DEFAULT_CLOCK_FREQ
Can232::init(CAN_125KBPS, MCP_16MHz); // set default rate you need here and clock frequency of CAN shield. Typically it is 16MHz, but on some MCP2515 + TJA1050 it is 8Mhz
// optional custom packet filter to reduce number of messages comingh through to canhacker
// Can232::setFilter(myCustomAddressFilter);
}
INT8U myCustomAddressFilter(INT32U addr) {
INT8U ret = LW232_FILTER_SKIP; //LW232_FILTER_PROCESS or LW232_FILTER_SKIP
switch(addr) {
// case 0x01b: //VIN
// case 0x1C8: //lights
// case 0x2C0: // pedals
case 0x3d0: // sound vol, treb..
ret = LW232_FILTER_PROCESS;
// case 0x000: // ?
// case 0x003: //shifter
// case 0x015: // dor open close affects this as well
// case 0x02c: // ???
// ret = 0;
// break;
// case 0x002:
// case 0x1a7: //fuel cons or some other
// ret = 1;
// break;
// default:
// ret = 0;
}
return ret;
}
void loop() {
Can232::loop();
}
void serialEvent() {
Can232::serialEvent();
}