Skip to content

Check Progress on FW-233/rewrite-canMppt #2

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

Merged
merged 2 commits into from
Oct 16, 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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "embedded-pio"]
path = embedded-pio
url = git@github.com:badgerloop-software/embedded-pio.git
1 change: 1 addition & 0 deletions embedded-pio
Submodule embedded-pio added at fa08e4
15 changes: 15 additions & 0 deletions include/canMppt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef __CAN_MPPT_H__
#define __CAN_MPPT_H__

#include "canmanager.h"
#include "const.h"
#include "IOManagement.h"

class CANMPPT : public CANManager {
public:
CANMPPT(CAN_TypeDef* canPort, CAN_PINS pins, int frequency = DEFAULT_CAN_FREQ);
void readHandler(CAN_message_t msg);
void sendMPPTData();
};

#endif // __CAN_MPPT_H__
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ lib_deps =
sstaub/Ticker@^4.4.0
gitlab-arduino/TimeoutCallback@^1.3.0
khoih-prog/STM32_PWM@^1.0.1
build_flags = -DHAL_CAN_MODULE_ENABLED
lib_extra_dirs = ./embedded-pio
45 changes: 45 additions & 0 deletions src/canMppt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "canMppt.h"
#include "mppt.h"


CANMPPT::CANMPPT(CAN_TypeDef* canPort, CAN_PINS pins, int frequency /*= DEFAULT_CAN_FREQ*/) : CANManager(canPort, pins, frequency) {};

void CANMPPT::readHandler(CAN_message_t msg) {
uint8_t* data = msg.buf;
switch (msg.id) {
case 0x050:
setCapDischarge(*data);
break;
case 0x051:
clearOVFaultReset(*data);
break;
case 0x101:
packCurrent = ((data[0] << 8) + data[1]) * 0.1;
packSOC = (float)(data[4]) / 2;
break;
case 0x103:
packChargeCurrentLimit = (float)(*(uint16_t*)data) * CONST_CURR_SAFETY_MULT;
break;
default:
break;
}
}

void CANMPPT::sendMPPTData() {
this->sendMessage(0x400, (void*)&boostEnabled, sizeof(boostEnabled));
this->sendMessage(0x401, (void*)&chargeMode, sizeof(ChargeMode));
// For each array, offset by 3*i since sending 3 fields voltage, current, temperature
for (int i = 0; i < NUM_ARRAYS; i++) {
this->sendMessage(0x402 + 5*i, (void*)&(arrayData[i].voltage), sizeof(float));
this->sendMessage(0x403 + 5*i, (void*)&(arrayData[i].current), sizeof(float));
this->sendMessage(0x404 + 5*i, (void*)&(arrayData[i].temp), sizeof(float));
this->sendMessage(0x405 + 5*i, (void*)&(arrayData[i].dutyCycle), sizeof(float));
if (chargeMode == ChargeMode::MPPT) {
this->sendMessage(0x406 + 5*i, (void*)&(targetVoltage[i]), sizeof(float));
} else {
float temp = -1;
this->sendMessage(0x406 + 5*i, (void*)&temp, sizeof(float));
//this->sendMessage(0x406 + 5*i, (void*)&(targetVoltage_C[i]), sizeof(float));
}
}
}