Skip to content

Commit

Permalink
With this commit the project compiles and will successfully connect t…
Browse files Browse the repository at this point in the history
…o torque and be seen as a valid ECU. However, look for next commit before it actually works properly.
  • Loading branch information
collin80 committed Mar 19, 2014
1 parent eaff95f commit 64cd251
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
25 changes: 24 additions & 1 deletion ELM327_Emu.cpp
Expand Up @@ -48,6 +48,8 @@ void ELM327Emu::setup() {
//this isn't a wifi link but the timer interval can be the same
//because it serves a similar function and has similar timing requirements
TickHandler::getInstance()->attach(this, CFG_TICK_INTERVAL_WIFI);

obd2Handler = OBD2Handler::getInstance();
}

/*
Expand Down Expand Up @@ -215,7 +217,28 @@ void ELM327Emu::processCmd() {
}
}
else { //if no AT then assume it is a PID request. This takes the form of four bytes which form the alpha hex digit encoding for two bytes

//there should be four or six characters here forming the ascii representation of the PID request. Easiest for now is to turn the ascii into
//a 16 bit number and mask off to get the bytes
if (strlen(incomingBuffer) == 4) {
uint32_t valu = strtol((char *) incomingBuffer, NULL, 16); //the pid format is always in hex
uint8_t pidnum = (uint8_t)(valu & 0xFF);
uint8_t mode = (uint8_t)((valu >> 8) & 0xFF);
Logger::debug(ELM327EMU, "Mode: %i, PID: %i", mode, pidnum);
char out[6];
char buff[10];
if (obd2Handler->processRequest(mode, pidnum, NULL, out)) {
mode += 0x40;
sprintf(buff, "%02X", mode);
retString.concat(buff);
sprintf(buff, "%02X", pidnum);
retString.concat(buff);
for (int i = 1; i <= out[0]; i++) {
sprintf(buff, "%02X", out[i]);
retString.concat(buff);
}
retString.concat("\r");
}
}
}

retString.concat(">"); //prompt to show we're ready to receive again
Expand Down
4 changes: 3 additions & 1 deletion ELM327_Emu.h
Expand Up @@ -56,6 +56,7 @@ AT RV (adapter voltage) - Send something like 14.4V
#include "DeviceManager.h"
#include "Sys_Messages.h"
#include "DeviceTypes.h"
#include "OBD2Handler.h"

extern PrefHandler *sysPrefs;

Expand Down Expand Up @@ -83,7 +84,8 @@ class ELM327Emu : public Device {
void saveConfiguration();

private:
USARTClass* serialInterface; //Allows for retargetting which serial port we use
USARTClass *serialInterface; //Allows for retargetting which serial port we use
OBD2Handler *obd2Handler;
char incomingBuffer[128]; //storage for one incoming line
int tickCounter;
int ibWritePtr;
Expand Down
4 changes: 4 additions & 0 deletions GEVCU.vcxproj
Expand Up @@ -83,6 +83,7 @@
<FileType>CppCode</FileType>
</ClInclude>
<ClInclude Include="CanHandler.h" />
<ClInclude Include="CanPIDListener.h" />
<ClInclude Include="CanThrottle.h" />
<ClInclude Include="config.h" />
<ClInclude Include="Device.h" />
Expand All @@ -102,6 +103,7 @@
<ClInclude Include="Logger.h" />
<ClInclude Include="MemCache.h" />
<ClInclude Include="MotorController.h" />
<ClInclude Include="OBD2Handler.h" />
<ClInclude Include="PotBrake.h">
<FileType>CppCode</FileType>
</ClInclude>
Expand Down Expand Up @@ -129,6 +131,7 @@
<ClCompile Include="BatteryManager.cpp" />
<ClCompile Include="BrusaMotorController.cpp" />
<ClCompile Include="CanHandler.cpp" />
<ClCompile Include="CanPIDListener.cpp" />
<ClCompile Include="CanThrottle.cpp" />
<ClCompile Include="Device.cpp" />
<ClCompile Include="DeviceManager.cpp" />
Expand All @@ -140,6 +143,7 @@
<ClCompile Include="Logger.cpp" />
<ClCompile Include="MemCache.cpp" />
<ClCompile Include="MotorController.cpp" />
<ClCompile Include="OBD2Handler.cpp" />
<ClCompile Include="PotBrake.cpp" />
<ClCompile Include="PotThrottle.cpp" />
<ClCompile Include="PrefHandler.cpp" />
Expand Down
2 changes: 1 addition & 1 deletion OBD2Handler.cpp
Expand Up @@ -35,7 +35,7 @@ OBD2Handler::OBD2Handler() {
motorController = (MotorController*) DeviceManager::getInstance()->getMotorController();
accelPedal = (Throttle*) DeviceManager::getInstance()->getAccelerator();
brakePedal = (Throttle*) DeviceManager::getInstance()->getBrake();
BMS = (*BatteryManager) DeviceManager::getInstance()->getDeviceByType(DEVICE_BMS);
BMS = (BatteryManager*) DeviceManager::getInstance()->getDeviceByType(DEVICE_BMS);
}

OBD2Handler *OBD2Handler::getInstance() {
Expand Down
2 changes: 1 addition & 1 deletion OBD2Handler.h
Expand Up @@ -39,7 +39,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class OBD2Handler {
public:
bool processRequest(uint8_t mode, uint8_t pid, char *inData, char *outData)
bool processRequest(uint8_t mode, uint8_t pid, char *inData, char *outData);
static OBD2Handler *getInstance();

protected:
Expand Down

0 comments on commit 64cd251

Please sign in to comment.