aldl_pi/a179.c

141 lines
3.7 KiB
C
Raw Normal View History

/*
* ALDL Dashboard, A179 stream decoder
*
* (c) 2019 Solomon Peachy <pizza@shaftnet.org>
*
* The latest version of this program can be found at:
*
* http://git.shaftnet.org/cgit/users/pizza/public/aldl_pi.git
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* [http://www.gnu.org/licenses/gpl-3.0.html]
*
* SPDX-License-Identifier: GPL-3.0+
*
*/
2019-01-27 11:13:14 -05:00
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "aldl.h"
#define STREAM A179
#define STREAM_WORDS 23
2019-02-08 19:53:02 -05:00
static const float A179_coolant_temp_table[] = {
2019-01-27 11:13:14 -05:00
[0] = 200,
[12] = 150,
[13] = 145,
[14] = 140,
2019-02-08 19:53:02 -05:00
[15] = 137.5, //
2019-01-27 11:13:14 -05:00
[16] = 135,
2019-02-08 19:53:02 -05:00
[17] = 132.5, //
2019-01-27 11:13:14 -05:00
[18] = 130,
[21] = 125,
[23] = 120,
[26] = 115,
[30] = 110,
[34] = 105,
2019-02-08 19:53:02 -05:00
[35] = 104, //
[36] = 103, //
[37] = 102, //
[38] = 101, //
2019-01-27 11:13:14 -05:00
[39] = 100,
[44] = 95,
[50] = 90,
[56] = 85,
[64] = 80,
[72] = 75,
[81] = 70,
[92] = 65,
[102] = 60,
[114] = 55,
[126] = 50,
[139] = 45,
[152] = 40,
[165] = 35,
[177] = 30,
[189] = 25,
[199] = 20,
[209] = 15,
[218] = 10,
[225] = 5,
[231] = 0,
2019-02-08 19:53:02 -05:00
// 232, 233, 234, 235, 236
2019-01-27 11:13:14 -05:00
[237] = -5,
2019-02-08 19:53:02 -05:00
// 238, 239, 240
2019-01-27 11:13:14 -05:00
[241] = -10,
2019-02-08 19:53:02 -05:00
// 242, 242, 243, 244,
2019-01-27 11:13:14 -05:00
[245] = -15,
2019-02-08 19:53:02 -05:00
[246] = -17.5, //
2019-01-27 11:13:14 -05:00
[247] = -20,
2019-02-08 19:53:02 -05:00
// 248, 249
2019-01-27 11:13:14 -05:00
[250] = -25,
[251] = -30,
2019-02-08 19:53:02 -05:00
[252] = -35, //
2019-01-27 11:13:14 -05:00
[253] = -40,
2019-02-08 19:53:02 -05:00
[254] = -50, //
[255] = -60, //
2019-01-27 11:13:14 -05:00
};
void aldl_a179_callback(uint8_t *data, int datalen)
{
/* Decode */
decoded.heartbeat = !decoded.heartbeat;
// data[0]; // MW2
decoded.idling = data[0] & 0x80 ? (data[0] & 0x40 ? 1 : 2 ) : 0;
decoded.running = data[0] & 0x04;
decoded.driving = data[0] & 0x01;
decoded.prom_id = data[1] | (data[2] << 8);
decoded.iac_steps = data[3];
decoded.coolant_temp_c = A179_coolant_temp_table[data[4]];
decoded.mph = data[5];
decoded.map_v = (float)((int)data[6] * 5) / 255;
decoded.rpm = data[7] * 25;
decoded.tps_v = (float)((int)data[8] * 5) / 255;
decoded.base_fuel = data[9];
decoded.o2_v = (float)((int)data[10] * 1000) / 226 / 1000;
decoded.mil = data[11] | (data[12] << 8) | (data[13] << 16);
// data[14]; // MWAF
decoded.learn_req = data[14] & 0x02;
decoded.closed_loop = data[14] & 0x80;
decoded.closed_loop_idle = data[14] & 0x10;
decoded.rich_lean = data[14] & 0x40;
decoded.battery_v = (float)data[15] / 10;
// data[16]; // MCU2IO
decoded.overspeed = data[6] & 0x04;
decoded.shift_req = data[6] & 0x08;
decoded.neutral = data[6] & 0x10;
decoded.top_gear = data[6] & 0x20;
decoded.ac_request = data[6] & 0x80;
decoded.knock_count = data[17];
decoded.corr_fuel = data[18];
decoded.o2_transitions = data[19];
decoded.fuelp_v = (float)data[20] / 10;
decoded.idle_tgt = (float)data[21] * 12.5;
decoded.tp = (float)data[22] / 2.55;
}