summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2013-08-21 22:18:10 -0400
committerSolomon Peachy <pizza@shaftnet.org>2013-08-21 22:18:10 -0400
commit352b81d3545d0ada48b9e980b15fff4daee7d70e (patch)
tree6269a1009a0afa20f7d7be63cdf96a42281a1dca
parent65e5e28b59b2d96b322661ca38d8447d7c6675fe (diff)
downloadlinuxaldl-352b81d3545d0ada48b9e980b15fff4daee7d70e.tar.gz
linuxaldl-352b81d3545d0ada48b9e980b15fff4daee7d70e.tar.bz2
linuxaldl-352b81d3545d0ada48b9e980b15fff4daee7d70e.zip
Rework the data structure definitions to use macros. Far, far cleaner now.
-rw-r--r--src/linuxaldl.h76
-rw-r--r--src/linuxaldl_definitions.h144
2 files changed, 121 insertions, 99 deletions
diff --git a/src/linuxaldl.h b/src/linuxaldl.h
index a920f1d..21da6f9 100644
--- a/src/linuxaldl.h
+++ b/src/linuxaldl.h
@@ -32,11 +32,11 @@ LICENSING INFORMATION:
#define __MAX_REQUEST_SIZE 16 /* maximum size (bytes) of a request message to send to the ECM */
-#define LINUXALDL_MODE1_END_DEF {NULL,0,0,0,0,0,NULL}
-
-typedef enum _ALDL_OP { ALDL_OP_MULTIPLY=0, ALDL_OP_DIVIDE=1, ALDL_OP_SEPERATOR=9} ALDL_OP_t;
-
-#define _DEF_SEP(label) {label,0,0,ALDL_OP_SEPERATOR,0,0,NULL}
+enum ALDL_OP { ALDL_OP_SCALAR=0,
+ ALDL_OP_MAP,
+ ALDL_OP_BIT,
+ ALDL_OP_SEPERATOR,
+};
// ============================================================================
// ALDL DEFINITION STRUCTS
@@ -48,23 +48,54 @@ typedef enum _ALDL_OP { ALDL_OP_MULTIPLY=0, ALDL_OP_DIVIDE=1, ALDL_OP_SEPERATOR=
// byte_def_t struct
typedef struct _linuxaldl_byte_definition{
const char* label;
- unsigned int byte_offset; /* Offset from the 1st byte of the data part of the mode1 message */
- unsigned int bits; /* 8 or 16 are currently supported */
- unsigned int operation; // ALDL_OP_MULTIPLY: (X*factor)+offest
- // ALDL_OP_DIVIDE: (factor/X)+offset
- // ALDL_OP_SEPERATOR: use this for a seperator for the display,
- // not a data item. with this option no other
- // values matter except label.
- // you can also use the _DEF_SEP(label) macro like:
- // _DEF_SEP("---Basic Data---")
-
+ unsigned char byte_offset; /* Offset from the 1st byte of the data part of the mode1 message */
+ unsigned char bits; /* 8 or 16 are currently supported */
+ enum ALDL_OP operation;
+#if 0
+ union {
+ struct { /* (val*factor)+offset */
+ float factor;
+ float offset;
+ const char* units; /* Text string */
+ } scalar;
+ struct {
+ unsigned char bit;
+ const char *set; /* Display if set */
+ const char *unset; /* Display if not set*/
+ } bit;
+ } op;
+#endif
float op_factor; // factor for the operation
float op_offset; // offset for the operation
-
const char* units; /* Text string */
} byte_def_t;
-typedef struct _linuxaldl_definition{
+#define ALDL_DEF_SCALAR8(__label, __offset, __factor, __shift, __units ) \
+ { .label = __label, \
+ .byte_offset = __offset, \
+ .bits = 8, \
+ .operation = ALDL_OP_SCALAR, \
+ .op_factor = __factor, \
+ .op_offset = __shift, \
+ .units = __units, \
+ }
+#define ALDL_DEF_SCALAR16(__label, __offset, __factor, __shift, __units ) \
+ { .label = __label, \
+ .byte_offset = __offset, \
+ .bits = 16, \
+ .operation = ALDL_OP_SCALAR, \
+ .op_factor = __factor, \
+ .op_offset = __shift, \
+ .units = __units, \
+ }
+#define ALDL_DEF_SEPERATOR(__label) \
+ { .label = __label, \
+ .operation = ALDL_OP_SEPERATOR, \
+ }
+#define ALDL_DEF_END { .label = NULL }
+
+
+typedef struct _linuxaldl_definition {
const char* mask;
const char* name;
char mode1_request[__MAX_REQUEST_SIZE]; // the mode 1 request message, including the checksum
@@ -172,15 +203,4 @@ void aldl_update_sets(int flags);
// if it is ALDL_UPDATE_FLOATS then only floats will be updated, and the data_set_strings
// array will not be modified in any way.
-float aldl_raw8_to_float(unsigned char val, int operation, float op_factor, float op_offset);
-// converts the raw 8-bit data value val into a float by performing operation
-// using op_factor and op_offset.
-// see the documentation for the byte_def_t struct for more information
-
-
-float aldl_raw16_to_float(unsigned char msb, unsigned char lsb, int operation, float op_factor, float op_offset);
-// converts the raw 16-bit data value defined by lsb and msb into a float by performing operation
-// using op_factor and op_offset.
-// see the documentation for the byte_def_t struct for more information
-
#endif
diff --git a/src/linuxaldl_definitions.h b/src/linuxaldl_definitions.h
index 7d9e010..d7e86dc 100644
--- a/src/linuxaldl_definitions.h
+++ b/src/linuxaldl_definitions.h
@@ -20,24 +20,17 @@ LICENSING INFORMATION:
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <string.h>
-#include "linuxaldl.h"
-#include "sts_serial.h"
// ===================================================================
// WRITING A DEFINITION FOR LINUXALDL
// ===================================================================
-// XXX IMPORTANT NOTE: The definition format is likely to be extremely
-// volatile up until version 1.0. I don't recommend spending a lot of
-// time writing a definition. It probably wont work in the next version.
-
// Labels/names/units must not contain white space, commas, newlines,
// or double quotes.
// They may contain: a-z A-Z 0-9 ~!@#$%^&*()-=_+|\/}{:<>?.[];'
// Label/names/units may not be NULL, except for units for seperators,
// and in the last element of the mode1_def[] array. (see below)
-// The last element of the mode1_def[] array must be LINUXALDL_MODE1_END_DEF
+// The last element of the mode1_def[] array must be ALDL_DEF_END
// (which is a byte_def_t with label and units NULL and all other values 0).
// ===================================================================
@@ -47,76 +40,85 @@ LICENSING INFORMATION:
// Engine: 1991-1993 3.4 DOHC V6 (LQ1) Vin "X"
// ===========================================
byte_def_t aldl_DF_mode1[]= {
- _DEF_SEP("---Basic Data---"),
- {"Engine RPM", 11, 8, 0, 25.0, 0.0, "RPM"},
- {"Throttle Position", 10, 8, 0, 0.003906, 0.00, "%"},
- {"Vehicle Speed", 17, 8, 0, 1.0, 0.0, "MPH"},
- {"Engine Airflow", 37, 8, 0, 1.0, 0.0, "gm/sec"},
- {"Coolant Temp", 7, 8, 0, 1.35, -40.0, "Deg F"},
- {"Intake Air Temp", 30, 8, 0, 1.0, 0.0, "adc"},
- {"MAP", 29, 8, 0, 0.369, 10.354, "kPa"},
- _DEF_SEP("----Fuel----"),
- {"Desired AFR", 41, 8, 0, 0.100, 0.0, "A/F"},
- {"Narrowband O2", 19, 8, 0, 4.42, 0.0, "mV"},
- {"Final Base Pulse Width", 42, 16, 0, 0.015259, 0.0, "mSec"},
- {"Current BLM Cell", 23, 8, 0, 1.0, 0.0, ""},
- {"BLM", 22, 8, 0, 1.0, 0.0, "counts"},
- {"Integrator", 24, 8, 0, 1.0, 0.0, "counts"},
- {"Base Pulse Fine Corr.",21, 8, 0, 1.0, 0.0, "counts"},
- {"BLM Cell 0 Timer", 36, 8, 0, 1.0, 0.0, "counts"},
- _DEF_SEP("--Ignition--"),
- {"Knock Events", 51, 8, 0, 1.0, 0.0, "counts"},
- {"Spark Advance", 40, 8, 0, 0.351560, 0.0, "degrees"},
- {"Knock Retard", 46, 8, 0, 0.175781, 0.0, "degrees"},
- _DEF_SEP("--Accessory Data--"),
- {"PROM ID", 1, 16, 0, 1.0, 0.0, "ID"},
- {"TPS Voltage", 9, 8, 0, 0.019531, 0.0, "volts"},
- {"IAC Steps", 25, 8, 0, 1.0, 0.0, "steps"},
- {"IAC Min Position", 22, 8, 0, 1.0, 0.0, "steps"},
- {"Barometric Pressure", 28, 8, 0, 0.369, 10.3542,"kPa"},
- {"Engine Run Time", 48, 16, 0, 1.0, 0.0, "secs"},
- {"Catalytic Conv Temp", 50, 8, 0, 3.0, 300.0, "Deg C"},
- {"Fuel Pump Relay Volts", 31, 8, 0, 0.1, 0.0, "volts"},
- {"O2 Cross-Count", 20, 8, 0, 1.0, 0.0, "counts"},
- {"Desired Idle Speed", 27, 8, 0, 12.5, 0.0, "RPM"},
- {"Battery Voltage", 34, 8, 0, 0.1, 0.0, "volts"},
- {"CCP Duty Cycle", 45, 8, 0, 0.390650, 0.0, "% CCP"},
- {"RPM/MPH", 47, 8, 0, 1.0, 0.0, "RPM/MPH"},
- {"A/C Pressure Sensor", 33, 8, 0, 1.0, 0.0, "A/D Counts"},
- {"Corrosivity Sensor", 44, 8, 0, 0.0196, 0.0, "volts"},
- LINUXALDL_MODE1_END_DEF
+ ALDL_DEF_SEPERATOR("---Basic Data---"),
+ ALDL_DEF_SCALAR8("Engine RPM", 11, 25.0, 0.0, "RPM"),
+ ALDL_DEF_SCALAR8("Throttle Position", 10, 0.003906, 0.00, "%"),
+ ALDL_DEF_SCALAR8("Vehicle Speed", 17, 1.0, 0.0, "MPH"),
+ ALDL_DEF_SCALAR8("Engine Airflow", 37, 1.0, 0.0, "gm/sec"),
+ ALDL_DEF_SCALAR8("Coolant Temp", 7, 1.35, -40.0, "Deg F"),
+ ALDL_DEF_SCALAR8("Intake Air Temp", 30, 1.0, 0.0, "adc"),
+ ALDL_DEF_SCALAR8("MAP", 29, 0.369, 10.354, "kPa"),
+ ALDL_DEF_SEPERATOR("----Fuel----"),
+ ALDL_DEF_SCALAR8("Desired AFR", 41, 0.100, 0.0, "A/F"),
+ ALDL_DEF_SCALAR8("Narrowband O2", 19, 4.42, 0.0, "mV"),
+ ALDL_DEF_SCALAR16("Final Base Pulse Width", 42, 0.015259, 0.0, "mSec"),
+ ALDL_DEF_SCALAR8("Current BLM Cell", 23, 1.0, 0.0, ""),
+ ALDL_DEF_SCALAR8("BLM", 22, 1.0, 0.0, "counts"),
+ ALDL_DEF_SCALAR8("Integrator", 24, 1.0, 0.0, "counts"),
+ ALDL_DEF_SCALAR8("Base Pulse Fine Corr.",21, 1.0, 0.0, "counts"),
+ ALDL_DEF_SCALAR8("BLM Cell 0 Timer", 36, 1.0, 0.0, "counts"),
+ ALDL_DEF_SEPERATOR("--Ignition--"),
+ ALDL_DEF_SCALAR8("Knock Events", 51, 1.0, 0.0, "counts"),
+ ALDL_DEF_SCALAR8("Spark Advance", 40, 0.351560, 0.0, "degrees"),
+ ALDL_DEF_SCALAR8("Knock Retard", 46, 0.175781, 0.0, "degrees"),
+ ALDL_DEF_SEPERATOR("--Accessory Data--"),
+ ALDL_DEF_SCALAR16("PROM ID", 1, 1.0, 0.0, "ID"),
+ ALDL_DEF_SCALAR8("TPS Voltage", 9, 0.019531, 0.0, "volts"),
+ ALDL_DEF_SCALAR8("IAC Steps", 25, 1.0, 0.0, "steps"),
+ ALDL_DEF_SCALAR8("IAC Min Position", 22, 1.0, 0.0, "steps"),
+ ALDL_DEF_SCALAR8("Barometric Pressure", 28, 0.369, 10.3542,"kPa"),
+ ALDL_DEF_SCALAR16("Engine Run Time", 48, 1.0, 0.0, "secs"),
+ ALDL_DEF_SCALAR8("Catalytic Conv Temp", 50, 3.0, 300.0, "Deg C"),
+ ALDL_DEF_SCALAR8("Fuel Pump Relay Volts", 31, 0.1, 0.0, "volts"),
+ ALDL_DEF_SCALAR8("O2 Cross-Count", 20, 1.0, 0.0, "counts"),
+ ALDL_DEF_SCALAR8("Desired Idle Speed", 27, 12.5, 0.0, "RPM"),
+ ALDL_DEF_SCALAR8("Battery Voltage", 34, 0.1, 0.0, "volts"),
+ ALDL_DEF_SCALAR8("CCP Duty Cycle", 45, 0.390650, 0.0, "% CCP"),
+ ALDL_DEF_SCALAR8("RPM/MPH", 47, 1.0, 0.0, "RPM/MPH"),
+ ALDL_DEF_SCALAR8("A/C Pressure Sensor", 33, 1.0, 0.0, "A/D Counts"),
+ ALDL_DEF_SCALAR8("Corrosivity Sensor", 44, 0.0196, 0.0, "volts"),
+ ALDL_DEF_END,
};
byte_def_t aldl_9A_mode1[]= {
/* Label, offset, bits, operation, opfactor, opoffset, units */
- _DEF_SEP("---Basic Data---"),
- {"Engine RPM", 8, 8, 0, 25.0, 0.0, "RPM"}, /* NTRPMX */
- {"Vehicle Speed", 6, 8, 0, 1.0, 0.0, "MPH"}, /* FILTMPH */
- {"Throttle Position", 23, 8, 0, 0.39216, 0.0, "%"}, /* NTPSLD */
- _DEF_SEP("----Fuel----"),
- {"Integrator", 10, 8, 0, 1.0, 0.0, "counts"}, /* INT */
- {"Narrowband O2", 11, 8, 0, 4.425, 0.0, "mV"}, /* ADO2A */
- {"BLM", 19, 8, 0, 1.0, 0.0, "counts"}, /* BLM */
- _DEF_SEP("--Ignition--"),
- {"Knock Events", 18, 8, 0, 1.0, 0.0, "counts"}, /* OLDPA3 */
- _DEF_SEP("--Accessory Data--"),
- {"PROM ID", 2, 16, 0, 1.0, 0.0, "ID"}, /* PROMIDA + PROMIDB */
- {"IAC Steps", 4, 8, 0, 1.0, 0.0, "steps"}, /* ISSPNP */
- {"MAP Voltage", 7, 8, 0, 0.019608, 0.0, "volts"}, /* ADMAP */
- {"TPS Voltage", 9, 8, 0, 0.019608, 0.0, "volts"}, /* ADTHROT */
- {"Battery Voltage", 16, 8, 0, 0.1, 0.0, "volts"}, /* ADBAT */
- {"O2 Cross-Count", 20, 8, 0, 1.0, 0.0, "counts"}, /* ALDLCNTR */
- {"Fuel Pump Relay Volts", 21, 8, 0, 0.1, 0.0, "volts"}, /* PPSWVLT */
- {"Desired Idle Speed", 22, 8, 0, 12.5, 0.0, "RPM"}, /* DESSPD */
- LINUXALDL_MODE1_END_DEF
+ ALDL_DEF_SEPERATOR("---Basic Data---"),
+ ALDL_DEF_SCALAR8("Vehicle Speed", 6, 1.0, 0.0, "MPH"), /* FILTMPH */
+ ALDL_DEF_SCALAR8("Engine RPM", 8, 25.0, 0.0, "RPM"), /* NTRPMX */
+ ALDL_DEF_SCALAR8("Throttle Position", 23, 0.39216, 0.0, "%"), /* NTPSLD */
+ ALDL_DEF_SEPERATOR("----Fuel----"),
+ ALDL_DEF_SCALAR8("Integrator", 10, 1.0, 0.0, "counts"), /* INT */
+ ALDL_DEF_SCALAR8("Narrowband O2", 11, 4.425, 0.0, "mV"), /* ADO2A */
+ ALDL_DEF_SCALAR8("BLM", 19, 1.0, 0.0, "counts"), /* BLM */
+ ALDL_DEF_SEPERATOR("--Ignition--"),
+ ALDL_DEF_SCALAR8("Knock Events", 18, 1.0, 0.0, "counts"), /* OLDPA3 */
+ ALDL_DEF_SEPERATOR("--Accessory Data--"),
+ ALDL_DEF_SCALAR16("PROM ID", 2, 1.0, 0.0, "ID"), /* PROMIDA+PROMIDB */
+ ALDL_DEF_SCALAR8("IAC Steps", 4, 1.0, 0.0, "steps"), /* ISSPNP */
+ ALDL_DEF_SCALAR8("MAP Voltage", 7, 0.019608, 0.0, "volts"), /* ADMAP */
+ ALDL_DEF_SCALAR8("TPS Voltage", 9, 0.019608, 0.0, "volts"), /* ADTHROT */
+ ALDL_DEF_SCALAR8("Battery Voltage", 16, 0.1, 0.0, "volts"), /* ADBAT */
+ ALDL_DEF_SCALAR8("O2 Cross-Count", 20, 1.0, 0.0, "counts"), /* ALDLCNTR */
+ ALDL_DEF_SCALAR8("Fuel Pump Relay Voltage", 21, 0.1, 0.0, "volts"), /* PPSWVLT */
+ ALDL_DEF_SCALAR8("Desired Idle Speed", 22, 12.5, 0.0, "RPM"), /* DESSPD */
+ ALDL_DEF_END,
};
/* ADCOOL (table), MW2, MALFFLG1, MALFFLG2, MALFFLG3, MWAF1, MCU2IO (all bitmasks!) */
-aldl_definition aldl_DF = { "DF", "91-93 3.4 DOHC LQ1 ($DF)",
- {0xF4, 0x57, 0x01, 0x00, 0xB4}, 5, 67, 63, 3, aldl_DF_mode1,
- {0xF4, 0x56, 0x08, 0xAE}, 4,
- {0xF4, 0x56, 0x09, 0xAD}, 4,
- B9600, 8192,
+aldl_definition aldl_DF = { .mask = "DF",
+ .name = "91-93 3.4 DOHC LQ1 ($DF)",
+ .mode1_request = {0xF4, 0x57, 0x01, 0x00, 0xB4},
+ .mode1_request_length = 5,
+ .mode1_response_length = 67,
+ .mode1_data_length = 63,
+ .mode1_data_offset = 3,
+ .mode1_def = aldl_DF_mode1,
+ .mode8_request = {0xF4, 0x56, 0x08, 0xAE},
+ .mode8_request_length = 4,
+ .mode9_request = {0xF4, 0x56, 0x09, 0xAD},
+ .mode9_request_length = 4,
+ .basic_baudrate = B9600,
+ .ideal_baudrate = 8192,
};
aldl_definition aldl_9A = { .mask = "9A",