Skip to content

PDU Refactor#337

Open
ronakpjain wants to merge 4 commits intomasterfrom
ronak/pdu26
Open

PDU Refactor#337
ronakpjain wants to merge 4 commits intomasterfrom
ronak/pdu26

Conversation

@ronakpjain
Copy link
Copy Markdown
Contributor

Summary

  • Refactor PDU code into modular components (cooling, switches, faults, state, telemetry)
  • Add bangbang cooling controller
  • Remove legacy auto_switch and cooling modules

Copilot AI review requested due to automatic review settings April 13, 2026 18:15
@ronakpjain ronakpjain requested a review from a team as a code owner April 13, 2026 18:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the PDU node firmware (source/pdu/) into smaller, task-oriented modules (switch sensing/control, fault scanning, cooling policy, and telemetry publishing) and removes the legacy auto_switch and cooling implementations.

Changes:

  • Introduces new PDU modules: pdu_state, pdu_switches, pdu_faults, pdu_telemetry, and pdu_cooling (+ optional bang-bang backend).
  • Updates source/pdu/main.c to orchestrate initialization and start the new periodic tasks.
  • Deletes legacy source/pdu/auto_switch/ and source/pdu/cooling/ modules and documents the new layout in source/pdu/README.md.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
source/pdu/pdu_telemetry.h Declares periodic telemetry publishing entry points.
source/pdu/pdu_telemetry.c Publishes rail/current/temp and flow telemetry over CAN.
source/pdu/pdu_switches.h Defines switch IDs and switch control/sensing APIs.
source/pdu/pdu_switches.c Implements mux sampling + ADC conversions + switch/LED control.
source/pdu/pdu_state.h Defines shared g_pdu_state and cooling command/state structs.
source/pdu/pdu_state.c Initializes shared PDU state defaults.
source/pdu/pdu_faults.h Declares rail fault init/periodic APIs.
source/pdu/pdu_faults.c Implements table-driven nFAULT scanning and fault/LED updates.
source/pdu/pdu_cooling_bangbang.h Adds compile-time toggle and bang-bang cooling API.
source/pdu/pdu_cooling_bangbang.c Implements optional bang-bang cooling updates from motor temps.
source/pdu/pdu_cooling.h Declares cooling init/periodic APIs.
source/pdu/pdu_cooling.c Computes/apply/sends cooling outputs (switches + PWM + CAN).
source/pdu/main.c Wires new modules into init and periodic task schedule; updates heartbeat LED behavior.
source/pdu/cooling/cooling.h Removes legacy cooling interface.
source/pdu/cooling/cooling.c Removes legacy cooling implementation.
source/pdu/auto_switch/auto_switch.h Removes legacy auto-switch interface.
source/pdu/auto_switch/auto_switch.c Removes legacy auto-switch implementation.
source/pdu/README.md Documents responsibilities, module layout, and task model.
source/pdu/CMakeLists.txt No functional change (formatting only).

Comment thread source/pdu/telemetry.c
Comment thread source/pdu/pdu_cooling.c Outdated
Comment thread source/pdu/pdu_cooling_bangbang.c Outdated
@irvingywang
Copy link
Copy Markdown
Member

the files dont need to be named pdu_, they are already in the pdu folder

Comment thread source/pdu/pdu_switches.h Outdated
Comment thread source/pdu/cooling_bangbang.c Outdated
)

static float cooling_hottest_motor_temp_c(void) {
float front_left = can_data.motor_temps.front_left;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong

Comment thread source/pdu/cooling_bangbang.h Outdated
@@ -0,0 +1,16 @@
#ifndef PDU_COOLING_BANGBANG_H
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chat wat this header guard

Comment thread source/pdu/faults.c Outdated
update_fault(fault->fault_id, is_faulted);
LED_control(fault->led_id, is_latched(fault->fault_id) ? LED_BLINK : LED_OFF);

g_pdu_state.next_rail_fault_index = (uint8_t)((index + 1U) % (sizeof(PDU_RAIL_FAULT_MAP) / sizeof(PDU_RAIL_FAULT_MAP[0])));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use if statement instead of modulo

@irvingywang
Copy link
Copy Markdown
Member

cooling should be managed by an FSM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants