-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiatee.ino
More file actions
155 lines (120 loc) · 3.05 KB
/
Fiatee.ino
File metadata and controls
155 lines (120 loc) · 3.05 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "WiFi.h"
#include "mcp_can.h"
#include <SPI.h>
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128]; // Array to store serial string
String dashSoc;
String miles;
String charging;
String locked;
#define CAN0_INT 5 // Set INT to pin 5
MCP_CAN CAN0(4); // Set CS to pin 4
#define CAN1_INT 22 // Set INT to pin 22
MCP_CAN CAN1(21); // Set CS to pin 21
void setup() {
Serial.begin(115200);
if(CAN0.begin(MCP_ANY, CAN_50KBPS, MCP_8MHZ) == CAN_OK)
Serial.println("CAN0 Initialized Successfully!");
else
Serial.println("Error Initializing CAN0");
if(CAN1.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK)
Serial.println("CAN1 Initialized Successfully!");
else
Serial.println("Error Initializing CAN1");
CAN0.setMode(MCP_NORMAL);
pinMode(CAN0_INT, INPUT);
CAN1.setMode(MCP_NORMAL);
pinMode(CAN1_INT, INPUT);
}
void lockCar() {
INT32U canId = 0xC41401F;
byte data[8] = {};
data[0] = 0x6C;
CAN0.sendMsgBuf(canId, 1, 8, data);
delay(100);
CAN0.sendMsgBuf(canId, 1, 8, data);
}
void unlockCar() {
INT32U canId = 0xC41401F;
byte data[8] = {};
data[0] = 0x74;
CAN0.sendMsgBuf(canId, 1, 8, data);
delay(100);
CAN0.sendMsgBuf(canId, 1, 8, data);
}
void beep() {
INT32U canId = 0xC41401F;
byte data[8] = {};
data[0] = 0x2;
CAN0.sendMsgBuf(canId, 1, 8, data);
delay(100);
CAN0.sendMsgBuf(canId, 1, 8, data);
}
void chargingOff() {
INT32U canId = 0xC41401F;
byte data[8] = {};
data[0] = 0x40;
CAN0.sendMsgBuf(canId, 1, 8, data);
delay(100);
CAN0.sendMsgBuf(canId, 1, 8, data);
}
void chargingOn() {
INT32U canId = 0xC41401F;
byte data[8] = {};
data[0] = 0x20;
CAN0.sendMsgBuf(canId, 1, 8, data);
delay(100);
CAN0.sendMsgBuf(canId, 1, 8, data);
}
void climateOff() {
INT32U canId = 0xE194031;
byte data[8] = {};
data[0] = 0x40;
data[1] = 0x64;
CAN0.sendMsgBuf(canId, 1, 8, data);
delay(100);
CAN0.sendMsgBuf(canId, 1, 8, data);
}
void climateOn() {
INT32U canId = 0xE194031;
byte data[8] = {};
data[0] = 0x20;
data[1] = 0x64;
CAN0.sendMsgBuf(canId, 1, 8, data);
delay(100);
CAN0.sendMsgBuf(canId, 1, 8, data);
}
void loop() {
if(!digitalRead(CAN0_INT)) {
//CAN-B
CAN0.readMsgBuf(&rxId, &len, rxBuf);
if ((rxId & 0x1FFFFFFF) == 0x06414000) {
if (rxBuf[3] == 0x17) {
locked = "No";
} else {
locked = "Yes";
}
}
}
if(!digitalRead(CAN1_INT)) {
//CAN-C
CAN1.readMsgBuf(&rxId, &len, rxBuf);
if ((rxId & 0x1FFFFFFF) == 0x0C10A040) {
sprintf(msgString, "0x%.2X", rxBuf[1]);
dashSoc = msgString;
}
if ((rxId & 0x1FFFFFFF) == 0x0C10A040) {
sprintf(msgString, "0x%.2X", rxBuf[0]);
miles = msgString;
}
if ((rxId & 0x1FFFFFFF) == 0x0C50A049) {
if (rxBuf[1] == 0x00) {
charging = "No";
} else {
charging = "Yes";
}
}
}
}