The DIF (DDEC Interface) application is a C++ MFC (Microsoft Foundation Classes) Win32 desktop application for communicating with Detroit Diesel Electronic Controls (DDEC) engine control modules. It connects to ECMs via J1708/J1587 serial bus protocol to monitor engine parameters, read/clear fault codes, and perform calibration operations.
Technology: C++ / MFC / Win32
Source: /mnt/d/source/repos/ddec/dif/src/
Files: 83 total (41 .cpp, 42 .h)
| File | Class | Responsibility |
|---|---|---|
| DIF.cpp/h | CDIFApp | MFC application entry point |
| DIFDoc.cpp/h | CDIFDoc | Document: owns worker thread, ECM data, task manager |
| DIFView.cpp/h | CDIFView | View: live data display, menu handling |
| MainFrm.cpp/h | CMainFrame | Main frame window |
| DIFDefines.h | (constants) | All message IDs, timer IDs, constants |
| DIFCmdLine.cpp/h | CDIFCmdLine | Command-line argument parsing |
| File | Class | Responsibility |
|---|---|---|
| CMC.cpp/h | CCMC | J1708 message I/O wrapper |
| RP1210Wrapper.cpp/h | CRP1210Wrapper | RP1210A driver abstraction |
| MJ1708.H | (structs) | J1708 protocol structures (J1708MSG, J1708CONFIG) |
| File | Class | Responsibility |
|---|---|---|
| ecmdata.cpp/h | CEcmData, CPIDInfo, CPIDData | ECM parameter database |
| extractdata.cpp/h | CExtractData | J1587 message parser |
| enginfo.cpp/h | CEngInfo | Engine identification |
| ptrdb.cpp/h | CPowerTekRDB | PowerTek real-time database interface |
| logfile.cpp/h | CLogFile | Data logging to files |
| File | Class | Responsibility |
|---|---|---|
| TaskManager.cpp/h | CTaskManager | Central task scheduler |
| ECMTASK.CPP/H | CEcmTask | Base task class (pure virtual) |
| HPAdjustTask.cpp/h | CHPAdjustTask | PWM/horsepower adjustment |
| GovGainTask.cpp/h | CGovGainTask | Governor gain read/set |
| InjCalTask1.cpp/h | CInjCalTask | Injector calibration |
| VSGTask.cpp/h | CVSGTask | Variable speed governor |
| RatingTask.cpp/h | CRatingTask | Engine rating |
| CodesTask.cpp/h | CCodesTask | Diagnostic codes get/clear |
| SlewTask.CPP/H | CSlewTask | Parameter slewing |
| ResetTask.cpp/h | CResetTask | ECM reset operations |
| SetChannelTask.cpp/h | CSetChannelTask | I/O channel configuration |
| SetAckTask.CPP/H | CSetAckTask | Acknowledgement setting |
| ccotask.cpp/h | CCCOTask | Cylinder cutout |
| File | Class | Responsibility |
|---|---|---|
| SlewingDlg.cpp/h | CSlewingDlg | Slewing test scheduling dialog |
| slewmanager.cpp/h | CSlewManager | Slew schedule management |
| GovGainDlg.cpp/h | CGovGainDlg | Governor gain UI |
| InjCalDlg1.cpp/h | CInjCalDlg | Injector calibration UI |
| VSGDlg.cpp/h | CVSGDlg | VSG settings UI |
| RatingDlg.cpp/h | CRatingDlg | Rating selection UI |
| CodesDlg.cpp/h | CCodesDlg | Diagnostic codes UI |
| CutOut.cpp/h, CCODlg.h | CCutOutDlg | Cylinder cutout UI |
| ChooseTable.cpp/h | CChooseTableDlg | Table selection |
| EditTable.cpp/h | CEditTableDlg | Calibration table editing |
| PerfConfigDlg.cpp/h | CPerfConfigDlg | Performance configuration |
| ReadMem.cpp/h | CReadMemDlg | Memory read utility |
| PWMult.cpp/h | CPWMultDlg | PWM multiplier UI |
| BenchMark.cpp/h | CBenchMark | Performance benchmarking |
| TimedMsgbox.cpp/h | CTimedMsgBox | Auto-closing message boxes |
| Splash.cpp/h | CSplashDlg | Splash screen |
| File | Responsibility |
|---|---|
| ECtl.cpp/h | Enhanced edit control |
| StdAfx.cpp/h | Precompiled headers |
| resource.h | Resource IDs |
Central coordinator. Creates and owns:
CEcmData[3] - Parameter databases for Master + 2 ReceiversCCMC or CRP1210Wrapper - Hardware communicationCExtractData - Message parserCTaskManager - Task schedulerCEngInfo - Engine identificationCPowerTekRDB - Test system database connectionManages the worker thread with event handles for start/stop/kill signals.
J1708 message I/O wrapper with 40-byte read/write buffers.
Key methods:
Read_Message() - Read one J1708 message from hardwareWrite_Message() - Send a formatted J1587 requestSend_Message() - Send raw bytes on the busConfiguration: 9600 baud default, 20ms read timeout, 3 retry limit.
Each ECM has arrays of CPIDInfo (definitions) and CPIDData (runtime values), loaded from CSV files. Three instances: Master (MID 128), Receiver 1 (MID 175), Receiver 2 (MID 183).
Processes J1587 messages by PID range:
Maintains a CObList of active tasks with CRITICAL_SECTION protection. Each task type has its own Windows timer for timeout management. Routes incoming PIDs to tasks via WorkerProcessPID().
Pure virtual base class. All tasks implement:
Retry() - Called on timeoutProcessPid() - Handle incoming responseRemove() - Clean up and deletePostAcknowledge() - Notify owning dialog of resultCDIFDoc::OnNewDocument()
└─── AfxBeginThread(WorkerThreadProc)
│
├── Initialization
│ ├── Allocate CCMC instance
│ ├── Create CExtractData parser
│ └── Request all initial PIDs
│
├── Main Loop (continuous)
│ ├── CCMC::Read_Message() ← Poll J1708 bus
│ ├── Route by MID to ECM (128/175/183)
│ ├── CExtractData::ProcessJ1587() ← Parse PIDs
│ ├── CPowerTekRDB::RDBWrite() ← Update test DB
│ ├── CTaskManager::WorkerProcessPID() ← Check tasks
│ └── Sleep(100ms)
│
└── Cleanup on kill event
Timer-based operations:
1. User initiates operation (menu/dialog)
└── CTaskManager::GovernorGain() / VSG() / Rating() / etc.
└── new CTask(params)
└── GUIAddTask(task) ← Enter CRITICAL_SECTION
2. Worker thread processes messages
└── WorkerProcessPID(pid, mid, data)
└── For each task: task->ProcessPid()
└── If handled: task->Remove(), PostAcknowledge()
3. Timeout occurs (Windows timer)
└── OnTimer(timerID)
└── task->Retry() or timeout error
| Task Type | Timer ID | Timeout (ms) |
|---|---|---|
| PWM Adjust | 2 | 12000 |
| Governor Gain | 3 | 12000 |
| Injector Cal | 4 | 12000 |
| VSG | 5 | 12000 |
| Rating | 6 | 12000 |
| Codes | 7 | 12000 |
| Set Channel | 8 | 12000 |
| Cylinder Cutout | 9 | 2000 |
Each task type uses a base value for status code ranges:
| Task | Base | Meaning: Base+0=Success |
|---|---|---|
| Slew | 1000 | 1000=OK, 1001+=error codes |
| HP Adjust | 2000 | |
| InjCal | 3000 | |
| CCO | 4000 | |
| GovGain | 5000 | |
| VSG | 6000 | |
| Rating | 7000 | |
| Clear Codes | 8000 | |
| Get Codes | 9000 |
15-column format, one row per PID parameter:
| Column | Content | Example |
|---|---|---|
| 1 | PID number | 190 |
| 2 | Full description | "Engine Speed" |
| 3 | EDMS name | "EC1_RPM" |
| 4 | Units | "RPM" |
| 5 | Bit size | 16 |
| 6 | Bit offset | 0 |
| 7 | Scale factor | 0.25 |
| 8 | Data type | Uns16 |
| 9 | On-request flag | 0 or 1 |
| 10 | Request-once flag | 0 or 1 |
| 11 | Min value | 0 |
| 12 | Max value | 3000 |
| 13 | Slewable param | 0 (not slewable) or index |
| 14 | Conversion multiplier | 1.0 |
| 15 | Conversion add | 0.0 |
Three files: Ddec3ec1.csv (Master), Ddec3ec2.csv (Receiver 1), Ddec3ec3.csv (Receiver 2).
One parameter name per line, 83 total. Format: EC[n]_[PARAM]
Examples: EC1_RPM, EC1_BVOLT, EC1_CLTO, EC1_GOP, EC1_FUEL_RATE, EC1_IMP, EC1_OT, EC1_TP, EC1_CL
Format: Code number, description, fault type (SID/PID), FMI.
Format: Channel number, name, type (input/output), function description.
| Name | Value | Description |
|---|---|---|
| THE_APP_MID | 180 | DIF application |
| cMASTER_MID | 128 (0x80) | Master ECM |
| cRECEIVER_1_MID | 175 (0xAF) | Receiver 1 |
| cRECEIVER_2_MID | 183 (0xB7) | Receiver 2 |
| Name | Value |
|---|---|
| MSG_SIZE | 128 bytes |
| MAX_J1708_MSG_SIZE | 26 bytes |
| STR_SIZE | 40 bytes |
| MATRIX_SIZE | 153 (17x9) |
| Name | Value |
|---|---|
| TIMER_REQUEST_PIDS_UPDATE_TIME | 11500ms |
| CHECK_ON_INTERFACE_STATUS_TIME | 1500ms |
| CONFIG_WORKER_DEFAULT_SLEEP_PER_CYCLE | 100ms |
| CONFIG_WORKER_DEFAULT_UPDATE_INTERVAL | 500ms |
| CONFIG_DEFAULT_CMC_TIMEOUT | 20ms |
| Name | Value |
|---|---|
| MAX_ECMS | 3 |
| MAX_CYLINDERS | 24 |
| MAX_CYLINDERS_PER_ECM | 8 |
| MAX_RETRIES | 3 |
| Code | Meaning |
|---|---|
| 0 | Success, action acknowledged |
| 1 | Failed - initialization message not received |
| 2 | Failed - engineering bit not set |
| 3 | Failed - invalid data |
| 4 | Failed - EEPROM busy |
| 5 | Failed - invalid conditions (engine running) |
| 6 | Failed - EEPROM failure |
| 7 | Failed - wrong engine type (DDEC IV) |
| 8 | Failed - reset lockout set (DDEC IV) |
| Code | Meaning |
|---|---|
| 0 | Success, acknowledged |
| 1 | Failed - engine hours exceed maximum |
| 2 | Failed - invalid data |
| 3 | Failed - invalid password |
| 4 | Failed - invalid condition |
| 5 | Failed - EEPROM failure |
| 6 | Failed - EEPROM busy |
| ID | Type | Scale Factor |
|---|---|---|
| 128/129 | Overall (read/set) | x16 |
| 130/131 | Proportional (read/set) | x16384 |
| 132/133 | Integral (read/set) | x1024 |
| 134/135 | Differential (read/set) | x1048576 |