//////////////////////////////////////////////////////////// constant Values ////////////////////////////////////////////////////////////
byte const source = 0xF1;
byte const target = 0x12;
byte const header = 0x80;
//////////////////////////////////////////////////////////// mode 1 (init) ////////////////////////////////////////////////////////////
byte const startinit[5] = {
0x81,
target,
source,
0x81,
0x05,
};
//////////////////////////////////////////////////////////// mode 2 (get Values) ////////////////////////////////////////////////////////////
byte const monitorsensordata[7] = {
header,
target,
source,
0x02,
0x21,
0x08,
0xAE,
};
//////////////////////////////////////////////////////////// not used for now ////////////////////////////////////////////////////////////
byte const keepalive[1] = {
0x01,
};
//////////////////////////////////////////////////////////// create string /////////////////////////////////////////////
data = 0;
sendbits = 0;
recievebits = 0;
if (mode) {
if (mode == 1) {
for (int x = 0; x < sizeof(startinit); x++) {
tx_data[x] = startinit[x];
sendbits++;
}
}
if (mode == 2) {
for (int x = 0; x < sizeof(monitorsensordata); x++) {
tx_data[x] = monitorsensordata[x];
sendbits++;
}
}
//////////////////////////////////////////////////////////// check read write delay //////////////////////////////////////////
time = millis();
if (time < read_write_delay + read_write_time) {
if (debug) console.print("Im 2 fast, waiting....");
}
while (time < read_write_delay + read_write_time) {
time = millis();
if (debug) console.println(".");
}
//////////////////////////////////////////////////////////// send string /////////////////////////////////////////////
for (int x = 0;x < sendbits;x++) {
sds.write(tx_data[x]);
delay (send_delay);
if (debug) {
console.print("Data tx: ");
console.println(tx_data[x], HEX);
}
}
//////////////////////////////////////////////////////////// decoding protocol values ////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////// mode 2 (read Values) ////////////////////////////////////////////////////////////
int const engine_value[9] = {
((rx_data[15] / 50.5) * 9.2) - 14.7,
(rx_data[17]*256 + rx_data[18]) / 2.56,
125*(rx_data[19]-55)/(256-55),
rx_data[20]*4*0.136,
1.1 * (rx_data[21] - 15),
1.1 * (rx_data[22] - 15),
rx_data[23] - rx_data[20]*4*0.136,
rx_data[24]/12.7,
rx_data[26],
};
String const engine_value_desc[] = {
"boost ",
"rpm ",
"tps ",
"ip ",
"ect ",
"iat ",
"iap ",
"bat ",
"gear ",
};
////////////////////////////////////////////////// print values //////////////////////////////////////////////
if (mode == 2) {
for (int x = 0;x < sizeof(engine_value);x++) {
console.print(engine_value_desc[x]);
console.print(engine_value[x]);
console.println();
}
}
/////////////////////////////////////////////////// write on sd //////////////////////////////////////////////