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

DO NOT MERGE - Charger Controller #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
42 changes: 41 additions & 1 deletion Datalogger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/*
* Local peripheral definitions
*/
const uint32_t CAN_FREQUENCY = 1000000;
const uint32_t CAN_FREQUENCY = 500000;
const uint32_t CAN_HEART_DATALOGGER = 0x049; // heartbeat CAN ID
const uint32_t CAN_CORE_STATUS_DATALOGGER = 0x749; // core status CAN ID

Expand Down Expand Up @@ -88,6 +88,34 @@ TimerTicker FileSyncTicker(5 * 60 * 1000 * 1000, UsTimer);
TimerTicker RemountTicker(250 * 1000, UsTimer);
TimerTicker UndismountTicker(10 * 1000 * 1000, UsTimer);

TimerTicker ChargerTicker(200 * 1000, UsTimer);
uint16_t swap16(uint16_t value)
{
uint16_t result = 0;
result |= (value & 0x00FF) << 8;
result |= (value & 0xFF00) >> 8;
return result;
}
#define CAN_CHARGER_CONTROL 0x1806E5F4
#define CAN_CHARGER_STATUS 0x18FF50E5
struct ChargerControlStruct {
uint16_t voltage_be;
uint16_t current_be;
uint8_t control;
uint8_t reserved1;
uint8_t reserved2;
uint8_t reserved3;
};
struct ChargerStatusStruct {
uint16_t voltage_be;
uint16_t current_be;
uint8_t status;
uint8_t reserved1;
uint8_t reserved2;
uint8_t reserved3;
};


TimerTicker EInkTicker(30 * 1000 * 1000, UsTimer);

//
Expand Down Expand Up @@ -632,6 +660,18 @@ int main() {
}
}


if(ChargerTicker.checkExpired()) {
ChargerControlStruct charger_control;

charger_control.control = 0;
charger_control.voltage_be = swap16(115*10 + 7);
charger_control.current_be = swap16(10*10);
CanBuffer.write(CANMessage(CAN_CHARGER_CONTROL, reinterpret_cast<const char*>(&charger_control), 8, CANData, CANExtended));

MainStatusLed.pulse(RgbActivity::kCyan);
}

MainStatusLed.update();
CanStatusLed.update();
SdStatusLed.update();
Expand Down