Skip to content

Commit

Permalink
Use OneWire library & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Knight committed Dec 27, 2024
1 parent 4cf91b2 commit 6422dce
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 899 deletions.
74 changes: 68 additions & 6 deletions include/BMSLogic.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#pragma once

#include "BMS_low_level_abstraction.h"

#include <bms_ant_data.h>

#include <BMSManager.h>
#include <drivers/BMSAnt.h>
#include <drivers/BMSOther.h>
Expand Down Expand Up @@ -48,6 +43,73 @@ namespace BMSLogic
{
DEBUG_LOG_TOPIC("BMS-ERR", "idx: %d, code: %d\n", idx, code);
}


void UpdateCANObjects_BMS1(const BMSANT::packet_raw_reverse_t *data)
{
timer_type_t timer_type = CAN_TIMER_TYPE_NORMAL;
event_type_t event_type = CAN_EVENT_TYPE_NONE;



CANLib::obj_high_current_1.SetValue(0, data->total_current, CAN_TIMER_TYPE_NORMAL);


timer_type = CAN_TIMER_TYPE_NORMAL;
if (data->capacity_percent < 15)
{
timer_type = CAN_TIMER_TYPE_CRITICAL;
}
else if (data->capacity_percent < 30)
{
timer_type = CAN_TIMER_TYPE_WARNING;
}
CANLib::obj_battery_percent_1.SetValue(0, data->capacity_percent, timer_type);



CANLib::obj_battery_power_1.SetValue(0, data->total_power, CAN_TIMER_TYPE_NORMAL);
//CANLib::obj_battery_state_1.SetValue(0, data->, CAN_TIMER_TYPE_NORMAL);
CANLib::obj_high_voltage_1.SetValue(0, data->total_voltage, CAN_TIMER_TYPE_NORMAL);



timer_type = CAN_TIMER_TYPE_NORMAL;
event_type = CAN_EVENT_TYPE_NONE;
if(data->cell_vmin_volt >= 2700 && data->cell_vmin_volt <= 3000)
{
timer_type = CAN_TIMER_TYPE_WARNING;
}
else if(data->cell_vmin_volt < 2700 || data->cell_vmax_volt > 4200)
{
timer_type = CAN_TIMER_TYPE_CRITICAL;
event_type = CAN_EVENT_TYPE_ERROR;
}
CANLib::obj_low_voltage_min_max_delta_1.SetValue(0, data->cell_vmin_volt, timer_type, event_type);
CANLib::obj_low_voltage_min_max_delta_1.SetValue(1, data->cell_vmax_volt, timer_type, event_type);
CANLib::obj_low_voltage_min_max_delta_1.SetValue(2, (data->cell_vmax_volt - data->cell_vmin_volt), timer_type, event_type);



//CANLib::obj_low_voltage_batt_1.SetValue(0, data->total_voltage, CAN_TIMER_TYPE_NORMAL);
//CANLib::obj_max_temperature_1.SetValue(0, data->total_voltage, CAN_TIMER_TYPE_NORMAL);
//CANLib::obj_temperature_1.SetValue(0, data->total_voltage, CAN_TIMER_TYPE_NORMAL);














//UpdateMaxTemperature();
}


inline void Setup()
Expand All @@ -57,7 +119,7 @@ namespace BMSLogic
uart_data[BMS_1].hal = &hBms1Uart;
uart_data[BMS_2].hal = &hBms2Uart;

Ant1.SetReadyCallback( CANLib::UpdateCANObjects_BMS );
Ant1.SetReadyCallback( UpdateCANObjects_BMS1 );
//Ant2.SetReadyCallback();

Bms.SetModel(BMS_1, Ant1);
Expand Down
12 changes: 6 additions & 6 deletions include/CANLogic.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <EasyPinD.h>
#include <CANLibrary.h>
#include "BMS_low_level_abstraction.h"
#include <drivers/BMSAnt_Data.h>

extern CAN_HandleTypeDef hcan;
Expand Down Expand Up @@ -347,7 +346,7 @@ namespace CANLib
}
for (uint8_t i = 0; i < 7; i++)
{
curr_temp = obj_temperature_3.GetValue(i);
//curr_temp = obj_temperature_3.GetValue(i);
if (curr_temp > max_temp)
max_temp = curr_temp;
}
Expand All @@ -365,10 +364,11 @@ namespace CANLib
}

// TODO: надо ещё обсудить по event_type и его присваивать
obj_max_temperature.SetValue(0, max_temp, timer_type, event_type);
//obj_max_temperature.SetValue(0, max_temp, timer_type, event_type);
}

void UpdateCANObjects_BMS(const BMSANT::packet_raw_reverse_t *data)
/*
void UpdateCANObjects_BMS1(const BMSANT::packet_raw_reverse_t *data)
{
//packet_structure_t *bms_packet_struct = (packet_structure_t *)bms_raw_packet_data;
Expand Down Expand Up @@ -578,7 +578,7 @@ namespace CANLib
// Максимально зафиксированная температура.
UpdateMaxTemperature();
}

*/
void UpdateCANObjects_ExternalTemperature(int8_t *temperature_data, uint8_t data_count)
{
if (temperature_data == nullptr)
Expand Down Expand Up @@ -618,7 +618,7 @@ namespace CANLib
{
if (data_index >= data_count)
return;
obj_temperature_3.SetValue(i, temperature_data[data_index++]);
//obj_temperature_3.SetValue(i, temperature_data[data_index++]);
}

// 0x0046 MaxTemperature
Expand Down
38 changes: 38 additions & 0 deletions include/OneWire.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
#include <OneWireTSensEx.h>

extern TIM_HandleTypeDef htim1;

namespace OneWire
{
OneWireDriver oneWire(GPIOB, GPIO_PIN_9, &htim1);
OneWireTSensEx<16> sensors(oneWire);


inline void Setup()
{
sensors.RegReadyCallback([](OneWireTSensEx<16>::sensor_t *obj, uint8_t count) -> void
{
for(uint8_t i = 0; i < count; ++i)
{
Logger.Printf("Rom: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X, Temp: %05d°C, Valid: %d, Min: %d, Mid: %d, Max: %d",
obj[i].rom->raw[0], obj[i].rom->raw[1], obj[i].rom->raw[2], obj[i].rom->raw[3],
obj[i].rom->raw[4], obj[i].rom->raw[5], obj[i].rom->raw[6], obj[i].rom->raw[7],
obj[i].temp, obj[i].valid, sensors.GetMinTemp(), sensors.GetMidTemp(), sensors.GetMaxTemp()).PrintNewLine();
}
});

return;
}

inline void Loop(uint32_t &current_time)
{
sensors.Processing(current_time);


// При выходе обновляем время
current_time = HAL_GetTick();

return;
}
};
121 changes: 0 additions & 121 deletions lib/PixelBMSLibrary/src/bms_ant.h

This file was deleted.

Loading

0 comments on commit 6422dce

Please sign in to comment.