Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaf Updates 241113 #124

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/leafinv.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LeafINV: public Inverter
void SetTorque(float torque);
float GetMotorTemperature() { return motor_temp; }
float GetInverterTemperature() { return inv_temp; }
float GetInverterVoltage() { return voltage / 2; }
float GetInverterVoltage() { return voltage; }
float GetMotorSpeed() { return speed; }
int GetInverterState() { return error; }
void SetCanInterface(CanHardware* c);
Expand Down
104 changes: 84 additions & 20 deletions src/NissanPDM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ static uint8_t counter_55b=0;
static uint8_t counter_1d4=0;
static uint8_t OBCpwrSP=0;
static uint8_t OBCpwr=0;
static bool OBCwake = false;
static bool PPStat = false;
static uint8_t OBCVoltStat=0;
static uint8_t PlugStat=0;
static uint16_t calcBMSpwr=0;
static bool BMSspoof = true;
static uint8_t OBCAvailPwr = 0;
static uint8_t OBCActPwr = 0;

/*Info on running Leaf Gen 2,3 PDM
IDs required :
Expand Down Expand Up @@ -93,42 +94,99 @@ void NissanPDM::DecodeCAN(int id, uint32_t data[2])
{
uint8_t* bytes = (uint8_t*)data;// arrgghhh this converts the two 32bit array into bytes. See comments are useful:)

if (id == 0x679)// THIS MSG FIRES ONCE ON CHARGE PLUG INSERT
{
uint8_t dummyVar = bytes[0];
dummyVar = dummyVar;
OBCwake = true; //0x679 is received once when we plug in if pdm is asleep so wake wakey...
}

else if (id == 0x390)// THIS MSG FROM PDM
if (id == 0x390)// THIS MSG FROM PDM
{
OBCVoltStat = (bytes[3] >> 3) & 0x03;

if(OBCVoltStat == 0x1)
{
Param::SetInt(Param::AC_Volts,110);
}
else if(OBCVoltStat == 0x2)
{
Param::SetInt(Param::AC_Volts,230);
}
else
{
Param::SetInt(Param::AC_Volts,0);
}

OBCActPwr = bytes[1]; //Power in 0.1kW
OBCAvailPwr = bytes[6]; //Power in 0.1kW

PlugStat = bytes[5] & 0x0F;
if(PlugStat == 0x08) PPStat = true; //plug inserted
if(PlugStat == 0x00) PPStat = false; //plug not inserted

Param::SetInt(Param::PlugDet,PPStat);
}
}

bool NissanPDM::ControlCharge(bool RunCh, bool ACReq)
bool NissanPDM::ControlCharge(bool RunCh, bool ACReq) //Modeled off of Outlander Charger
{
bool dummy=RunCh;
dummy=dummy;

int opmode = Param::GetInt(Param::opmode);
if(opmode != MOD_CHARGE)
int chgmode = Param::GetInt(Param::interface);
switch(chgmode)
{
if(ACReq && OBCwake)
case Unused:
if(PPStat && ACReq)
{
//OBCwake = false;//reset obc wake for next time
return true;
}
}
else
{
return false;
}

break;

case i3LIM:
if(RunCh && ACReq)//we have a startup request to AC charge from a charge interface
{
return true;
}
else
{
return false;
}
break;

case CPC:
if(RunCh && ACReq)//we have a startup request to AC charge from a charge interface
{
return true;
}
else
{
return false;
}
break;

case Focci:
if(RunCh && ACReq)//we have a startup request to AC charge from a charge interface
{
return true;
}
else
{
return false;
}
break;

case Chademo:
if (RunCh && ACReq)
{
return true;
}
else
{
return false;
}

break;

if(PPStat && ACReq) return true;
if(!PPStat || !ACReq)
{
OBCwake = false;
return false;
}
return false;
}
Expand All @@ -150,6 +208,9 @@ void NissanPDM::Task10Ms()

if (opmode == MOD_CHARGE) //ONLY send when charging else sent by leafinv.cpp
{



/////////////////////////////////////////////////////////////////////////////////////////////////
// CAN Message 0x1D4: Target Motor Torque

Expand Down Expand Up @@ -412,6 +473,9 @@ void NissanPDM::Task100Ms()

can->Send(0x5bc, (uint32_t*)bytes, 8);
}

Param::SetInt(Param::PilotLim,float(OBCAvailPwr/2.25));

}


Expand Down