From 55b020ca55ebadfcabe830188a2b51335ad48e99 Mon Sep 17 00:00:00 2001 From: Dragon-Knight Date: Tue, 31 Dec 2024 04:18:18 +0300 Subject: [PATCH] move `CollectionStream` to `CUtils` --- include/BMSLogic.h | 10 +++--- lib/CANLibEx/CollectionStream.h | 59 --------------------------------- 2 files changed, 5 insertions(+), 64 deletions(-) delete mode 100644 lib/CANLibEx/CollectionStream.h diff --git a/include/BMSLogic.h b/include/BMSLogic.h index 4347f3a..f2681b7 100644 --- a/include/BMSLogic.h +++ b/include/BMSLogic.h @@ -2,7 +2,7 @@ #include #include #include -#include +#include extern UART_HandleTypeDef hBms1Uart; extern UART_HandleTypeDef hBms2Uart; @@ -18,8 +18,8 @@ namespace BMSLogic BMSManager Bms(BMS_UART_TX, BMS_ERROR); - void OnLowVoltageBatt1Steam(uint16_t coll_el, uint8_t idx); - void OnLowVoltageBatt2Steam(uint16_t coll_el, uint8_t idx); + void OnLowVoltageBatt1Steam(auto coll_el, uint8_t idx); + void OnLowVoltageBatt2Steam(auto coll_el, uint8_t idx); CollectionStream LowVoltageBatt1Stream(Ant1.data->cell_voltage, BMSANT::CellsNumber, OnLowVoltageBatt1Steam); CollectionStream LowVoltageBatt2Stream(Ant2.data->cell_voltage, BMSANT::CellsNumber, OnLowVoltageBatt2Steam); @@ -121,7 +121,7 @@ namespace BMSLogic //UpdateMaxTemperature(); } - void OnLowVoltageBatt1Steam(uint16_t coll_el, uint8_t idx) + void OnLowVoltageBatt1Steam(auto coll_el, uint8_t idx) { CANLib::obj_low_voltage_batt_1.SetValue(0, (idx + 1), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL); CANLib::obj_low_voltage_batt_1.SetValue(1, coll_el, CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL); @@ -129,7 +129,7 @@ namespace BMSLogic return; } - void OnLowVoltageBatt2Steam(uint16_t coll_el, uint8_t idx) + void OnLowVoltageBatt2Steam(auto coll_el, uint8_t idx) { CANLib::obj_low_voltage_batt_2.SetValue(0, (idx + 1), CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL); CANLib::obj_low_voltage_batt_2.SetValue(1, coll_el, CAN_TIMER_TYPE_NONE, CAN_EVENT_TYPE_NORMAL); diff --git a/lib/CANLibEx/CollectionStream.h b/lib/CANLibEx/CollectionStream.h deleted file mode 100644 index 57820cc..0000000 --- a/lib/CANLibEx/CollectionStream.h +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once -#include - -template -class CollectionStream -{ - using callback_ready_t = void (*)(T coll_el, uint8_t idx); - - public: - - CollectionStream(const T *collection, uint8_t count, callback_ready_t callback) : _collection(collection), _count(count), _callback_ready(callback) - {} - - void Start(uint16_t timer) - { - _timer = timer; - _last_tick = 0; - _send_idx = 0; - _is_run = true; - - return; - } - - void Stop() - { - _is_run = false; - - return; - } - - void Processing(uint32_t &time) - { - if(_is_run == false) return; - - if(time - _last_tick < _timer) return; - _last_tick = time; - - _callback_ready( _collection[_send_idx], _send_idx ); - - if(++_send_idx == _count) - { - Stop(); - } - - return; - } - - private: - - const T *_collection; - uint8_t _count; - callback_ready_t _callback_ready; - - uint16_t _timer; - bool _is_run; - uint8_t _send_idx; - - uint32_t _last_tick; -};