diff --git a/emBODY/eBcode/arch-arm/board/amc/application/v1/cfg/theApplication_config.h b/emBODY/eBcode/arch-arm/board/amc/application/v1/cfg/theApplication_config.h index 69471170b..d0fb98f2b 100644 --- a/emBODY/eBcode/arch-arm/board/amc/application/v1/cfg/theApplication_config.h +++ b/emBODY/eBcode/arch-arm/board/amc/application/v1/cfg/theApplication_config.h @@ -38,8 +38,8 @@ namespace embot { namespace app { namespace eth { .property = { Process::eApplication, - {1, 8}, - {2023, Month::Dec, Day::fourteen, 18, 45} + {1, 9}, + {2024, Month::Jan, Day::eight, 18, 00} }, .OStick = 1000*embot::core::time1microsec, .OSstacksizeinit = 10*1024, diff --git a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Inc/BAT_B.h b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Inc/BAT_B.h index 3e79a0dd4..bcf5c37b9 100644 --- a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Inc/BAT_B.h +++ b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Inc/BAT_B.h @@ -99,6 +99,8 @@ extern uint16_t time_delay; extern uint8_t can_message; +extern uint8_t TX_ENABLED; + extern __IO ITStatus UartReady; extern uint32_t VTH[7]; diff --git a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Inc/global_var.h b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Inc/global_var.h index d55481c71..284638141 100644 --- a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Inc/global_var.h +++ b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Inc/global_var.h @@ -115,4 +115,6 @@ extern uint16_t time_delay; extern uint8_t can_message; +extern uint8_t TX_ENABLED; + #endif diff --git a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/BAT_B.c b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/BAT_B.c index f62e454bd..3b71d4ee9 100644 --- a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/BAT_B.c +++ b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/BAT_B.c @@ -11,7 +11,7 @@ char Firmware_vers = 1; char Revision_vers = 3; -char Build_number = 2; +char Build_number = 3; uint32_t vtol=100; // voltage tolerance for hysteresis uint32_t vhyst=0; // voltage hysteresis @@ -73,6 +73,8 @@ int32_t Current_board_in_fault = 0; int32_t Current_HSM_in_fault = 0; int32_t Current_motor_in_fault = 0; +uint8_t TX_ENABLED = 0; + uint8_t V12board_bdc = 1; // +++++++++++++++++++++++++++++++++++++++++++++ da cambiare logica ++++++++++++++++++ uint8_t V12motor_bdc = 1; // +++++++++++++++++++++++++++++++++++++++++++++ da cambiare logica ++++++++++++++++++ diff --git a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/can_utility.c b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/can_utility.c index 2e973c1ab..1cef7b1f8 100644 --- a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/can_utility.c +++ b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/can_utility.c @@ -25,7 +25,7 @@ uint32_t TxMailbox; // in the struct we can define the data, which have the same type for all the packets, // what changes is only the value // then there'll be a getInstance() sort of method for retrieving the struct -// following the signleton usage in OOP +// following the singleton usage in OOP // this will help to make code cleaner and avoid duplications // Instantiate data regarding info of battery pack CAN_TxHeaderTypeDef TxHeader_620; @@ -145,6 +145,15 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) /* Reception Error */ Error_Handler(); } + + /* Enable - Disable CAN Transmission from EMS */ + if( (RxHeader.IDE == CAN_ID_STD) && ((RxHeader.StdId & 0x700) >> 8) == 2 ) // GOT MESSAGE FROM CLASS ICUBCANPROTO_CLASS_POLLING_ANALOGSENSOR + { + if((RxData[0] & 0x7F) == 7) // GOT MESSAGE OF TYPE ICUBCANPROTO_POL_AS_CMD__SET_TXMODE + { + TX_ENABLED = (RxData[1] == 0) ? 1 : 0; + } + } /* Display LEDx */ if ((RxHeader.StdId == 0x621) && (RxHeader.IDE == CAN_ID_STD) && (RxHeader.DLC == 8)) @@ -152,4 +161,5 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) //LED_Display(RxData[0]); //ubKeyNumber = RxData[0]; } + } diff --git a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/main.c b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/main.c index bb294dc4e..223837123 100644 --- a/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/main.c +++ b/emBODY/eBcode/arch-arm/board/bat/BAT_Rev_B/Src/main.c @@ -303,6 +303,8 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){ } if(htim->Instance==TIM16){ // timer 100ms toggle_100ms = toggle_100ms^1; + if(TX_ENABLED == 0) + return; CANBUS(); } if(htim->Instance==TIM17){ // timer 1s diff --git a/emBODY/eBcode/arch-arm/board/ems004/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h b/emBODY/eBcode/arch-arm/board/ems004/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h index 21373b806..b5dab523a 100644 --- a/emBODY/eBcode/arch-arm/board/ems004/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h +++ b/emBODY/eBcode/arch-arm/board/ems004/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h @@ -81,21 +81,21 @@ extern "C" { #define EOMTHEEMSAPPLCFG_VERSION_MAJOR (VERSION_MAJOR_OFFSET+3) // minor <0-255> // minor <0-255> -#define EOMTHEEMSAPPLCFG_VERSION_MINOR 82 +#define EOMTHEEMSAPPLCFG_VERSION_MINOR 83 // version // build date // year <2010-2030> -#define EOMTHEEMSAPPLCFG_BUILDDATE_YEAR 2023 +#define EOMTHEEMSAPPLCFG_BUILDDATE_YEAR 2024 // month <1-12> -#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 11 +#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 1 // day <1-31> -#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 29 +#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 8 // hour <0-23> -#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 13 +#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 18 // minute <0-59> -#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 49 +#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 00 // build date // Info diff --git a/emBODY/eBcode/arch-arm/board/ems004/appl/v2/src/eoappservices/embot_app_eth_theBATservice.cpp b/emBODY/eBcode/arch-arm/board/ems004/appl/v2/src/eoappservices/embot_app_eth_theBATservice.cpp index 2c232d86f..08c532b0a 100644 --- a/emBODY/eBcode/arch-arm/board/ems004/appl/v2/src/eoappservices/embot_app_eth_theBATservice.cpp +++ b/emBODY/eBcode/arch-arm/board/ems004/appl/v2/src/eoappservices/embot_app_eth_theBATservice.cpp @@ -81,19 +81,21 @@ struct embot::app::eth::theBATservice::Impl { const eOmn_serv_configuration_t *tmpservcfg{nullptr}; // theBATnetvariables[i] holds pointer to the network variable of the whole - // eOas_battery_t w/ i index theFTboards[i] contains the relevant board type + // eOas_battery_t w/ i index + // theBATboards[i] contains the relevant board type std::array theBATnetvariables{nullptr}; - std::array theBATboards{eobrd_cantype_bms}; + std::array theBATboards{eobrd_cantype_none}; // this object performs the monitoring of presence of CAN boards CANmonitor canmonitor{}; static constexpr CANmonitor::Config defaultcanmonitorconfig{ {}, // the map is left empty - 100 * embot::core::time1millisec, + 250 * embot::core::time1millisec, CANmonitor::Report::ALL, 10 * embot::core::time1second, s_eobj_ownname, - eomn_serv_category_battery}; + eomn_serv_category_battery + }; embot::core::Time debugtimeft{0}; @@ -152,8 +154,10 @@ struct embot::app::eth::theBATservice::Impl { void debug_CANMAPPING(EOconstarray *carray); }; -eOresult_t embot::app::eth::theBATservice::Impl::initialise() { - if (true == initted) { +eOresult_t embot::app::eth::theBATservice::Impl::initialise() +{ + if (true == initted) + { return eores_OK; } @@ -181,26 +185,24 @@ eOresult_t embot::app::eth::theBATservice::Impl::initialise() { service.active = eobool_false; service.started = eobool_false; service.state = eomn_serv_state_idle; - eo_service_hid_SynchServiceState(eo_services_GetHandle(), - eomn_serv_category_battery, service.state); + eo_service_hid_SynchServiceState(eo_services_GetHandle(), eomn_serv_category_battery, service.state); // clear data used by this class - for (auto &item : theBATnetvariables) - item = nullptr; - for (auto &item : theBATboards) - item = eobrd_cantype_bms; + for (auto &item : theBATnetvariables) item = nullptr; + for (auto &item : theBATboards) item = eobrd_cantype_none; initted = true; return eores_OK; } eOresult_t embot::app::eth::theBATservice::Impl::Tick() { - if (eobool_false == - service.active) { // nothing to do because object must be first activated + if (eobool_false == service.active) + { // nothing to do because object must be first activated return (eores_OK); } - if (eobool_false == service.started) { // not running, thus we do nothing + if (eobool_false == service.started) + { // not running, thus we do nothing return (eores_OK); } @@ -210,12 +212,11 @@ eOresult_t embot::app::eth::theBATservice::Impl::Tick() { return eores_OK; } -eOresult_t embot::app::eth::theBATservice::Impl::SendReport() { - eo_errman_Error(eo_errman_GetHandle(), diagnostics.errorType, NULL, - s_eobj_ownname, &diagnostics.errorDescriptor); +eOresult_t embot::app::eth::theBATservice::Impl::SendReport() +{ + eo_errman_Error(eo_errman_GetHandle(), diagnostics.errorType, NULL, s_eobj_ownname, &diagnostics.errorDescriptor); - eOerror_value_t errorvalue = - eoerror_code2value(diagnostics.errorDescriptor.code); + eOerror_value_t errorvalue = eoerror_code2value(diagnostics.errorDescriptor.code); switch (errorvalue) { case eoerror_value_CFG_bat_failed_candiscovery: { @@ -230,26 +231,27 @@ eOresult_t embot::app::eth::theBATservice::Impl::SendReport() { return eores_OK; } -eOresult_t embot::app::eth::theBATservice::Impl::Verify( - const eOmn_serv_configuration_t *servcfg, - eOservice_onendofoperation_fun_t onverify, bool activateafterverify) { +eOresult_t embot::app::eth::theBATservice::Impl::Verify(const eOmn_serv_configuration_t *servcfg, eOservice_onendofoperation_fun_t onverify, bool activateafterverify) +{ eo_errman_Trace(eo_errman_GetHandle(), "::Verify()", s_eobj_ownname); - if (NULL == servcfg) { + if (NULL == servcfg) + { service.state = eomn_serv_state_failureofverify; - eo_service_hid_SynchServiceState(eo_services_GetHandle(), - eomn_serv_category_battery, service.state); - if (NULL != onverify) { + eo_service_hid_SynchServiceState(eo_services_GetHandle(), eomn_serv_category_battery, service.state); + if (NULL != onverify) + { onverify(nullptr, eobool_false); } return (eores_NOK_nullpointer); } - if (eomn_serv_AS_battery != servcfg->type) { + if (eomn_serv_AS_battery != servcfg->type) + { service.state = eomn_serv_state_failureofverify; - eo_service_hid_SynchServiceState(eo_services_GetHandle(), - eomn_serv_category_battery, service.state); - if (NULL != onverify) { + eo_service_hid_SynchServiceState(eo_services_GetHandle(), eomn_serv_category_battery, service.state); + if (NULL != onverify) + { onverify(nullptr, eobool_false); } return (eores_NOK_generic); @@ -260,8 +262,7 @@ eOresult_t embot::app::eth::theBATservice::Impl::Verify( } service.state = eomn_serv_state_verifying; - eo_service_hid_SynchServiceState(eo_services_GetHandle(), - eomn_serv_category_battery, service.state); + eo_service_hid_SynchServiceState(eo_services_GetHandle(), eomn_serv_category_battery, service.state); // make sure the timer is not running eo_timer_Stop(diagnostics.reportTimer); @@ -270,10 +271,10 @@ eOresult_t embot::app::eth::theBATservice::Impl::Verify( service.activateafterverify = activateafterverify; service.state = eomn_serv_state_verified; - eo_service_hid_SynchServiceState(eo_services_GetHandle(), - eomn_serv_category_battery, service.state); + eo_service_hid_SynchServiceState(eo_services_GetHandle(), eomn_serv_category_battery, service.state); - if (eobool_true == service.activateafterverify) { + if (eobool_true == service.activateafterverify) + { Activate(servcfg); } @@ -283,19 +284,16 @@ eOresult_t embot::app::eth::theBATservice::Impl::Verify( diagnostics.errorDescriptor.par64 = 0; EOaction_strg astrg = {0}; EOaction *act = (EOaction *)&astrg; - eo_action_SetCallback(act, s_send_periodic_error_report, this, - eov_callbackman_GetTask(eov_callbackman_GetHandle())); + eo_action_SetCallback(act, s_send_periodic_error_report, this, eov_callbackman_GetTask(eov_callbackman_GetHandle())); diagnostics.errorType = eo_errortype_debug; - diagnostics.errorDescriptor.code = - eoerror_code_get(eoerror_category_Config, eoerror_value_CFG_bat_ok); - eo_errman_Error(eo_errman_GetHandle(), diagnostics.errorType, NULL, - s_eobj_ownname, &diagnostics.errorDescriptor); + diagnostics.errorDescriptor.code = eoerror_code_get(eoerror_category_Config, eoerror_value_CFG_bat_ok); + eo_errman_Error(eo_errman_GetHandle(), diagnostics.errorType, NULL, s_eobj_ownname, &diagnostics.errorDescriptor); - if ((0 != diagnostics.repetitionOKcase) && (0 != diagnostics.reportPeriod)) { + if ((0 != diagnostics.repetitionOKcase) && (0 != diagnostics.reportPeriod)) + { diagnostics.errorCallbackCount = diagnostics.repetitionOKcase; - eo_timer_Start(diagnostics.reportTimer, eok_abstimeNOW, - diagnostics.reportPeriod, eo_tmrmode_FOREVER, act); + eo_timer_Start(diagnostics.reportTimer, eok_abstimeNOW, diagnostics.reportPeriod, eo_tmrmode_FOREVER, act); } if (NULL != service.onverify) { @@ -305,8 +303,8 @@ eOresult_t embot::app::eth::theBATservice::Impl::Verify( return eores_OK; } -eOresult_t embot::app::eth::theBATservice::Impl::Activate( - const eOmn_serv_configuration_t *servcfg) { +eOresult_t embot::app::eth::theBATservice::Impl::Activate(const eOmn_serv_configuration_t *servcfg) +{ eo_errman_Trace(eo_errman_GetHandle(), "::Activate()", s_eobj_ownname); if (NULL == servcfg) { @@ -337,7 +335,8 @@ eOresult_t embot::app::eth::theBATservice::Impl::Activate( // - init the theBATnetvariables // we must load all the boards into can mapping, entities etc - for (uint8_t s = 0; s < numofsensors; s++) { + for (uint8_t s = 0; s < numofsensors; s++) + { const eOas_battery_sensordescriptor_t *sd = reinterpret_cast( eo_constarray_At(carray, s)); @@ -383,21 +382,21 @@ eOresult_t embot::app::eth::theBATservice::Impl::Activate( service.active = eobool_true; service.state = eomn_serv_state_activated; - eo_service_hid_SynchServiceState(eo_services_GetHandle(), - eomn_serv_category_battery, service.state); + eo_service_hid_SynchServiceState(eo_services_GetHandle(), eomn_serv_category_battery, service.state); return (eores_OK); } -eOresult_t embot::app::eth::theBATservice::Impl::Deactivate() { +eOresult_t embot::app::eth::theBATservice::Impl::Deactivate() +{ eo_errman_Trace(eo_errman_GetHandle(), "::Deactivate()", s_eobj_ownname); - if (eobool_false == service.active) { + if (eobool_false == service.active) + { // i force to eomn_serv_state_idle because it may be that state was // eomn_serv_state_verified or eomn_serv_state_failureofverify service.state = eomn_serv_state_idle; - eo_service_hid_SynchServiceState(eo_services_GetHandle(), - eomn_serv_category_battery, service.state); + eo_service_hid_SynchServiceState(eo_services_GetHandle(), eomn_serv_category_battery, service.state); return (eores_OK); } @@ -405,27 +404,24 @@ eOresult_t embot::app::eth::theBATservice::Impl::Deactivate() { // entity-can-mapping and the board-can-mapping, reset all things inside this // object - if (eobool_true == service.started) { + if (eobool_true == service.started) + { Stop(); } SetRegulars(nullptr, nullptr); // deconfig EOtheCANmapping - eo_canmap_DeconfigEntity(eo_canmap_GetHandle(), eoprot_endpoint_analogsensors, - eoprot_entity_as_battery, - sharedcan.entitydescriptor); + eo_canmap_DeconfigEntity(eo_canmap_GetHandle(), eoprot_endpoint_analogsensors, eoprot_entity_as_battery, sharedcan.entitydescriptor); eo_canmap_UnloadBoards(eo_canmap_GetHandle(), sharedcan.boardproperties); // clear data used by this class for (auto &item : theBATnetvariables) { if (nullptr != item) { // i reset the status to its default value - std::memmove(&item->status, &defaultBATstatus, - sizeof(eOas_battery_status_t)); + std::memmove(&item->status, &defaultBATstatus, sizeof(eOas_battery_status_t)); // i reset the config to its default value - std::memmove(&item->config, &defaultFTconfig, - sizeof(eOas_battery_config_t)); + std::memmove(&item->config, &defaultBATconfig, sizeof(eOas_battery_config_t)); } item = nullptr; @@ -446,8 +442,7 @@ eOresult_t embot::app::eth::theBATservice::Impl::Deactivate() { service.active = eobool_false; service.state = eomn_serv_state_idle; - eo_service_hid_SynchServiceState(eo_services_GetHandle(), - eomn_serv_category_battery, service.state); + eo_service_hid_SynchServiceState(eo_services_GetHandle(), eomn_serv_category_battery, service.state); return (eores_OK); } @@ -479,14 +474,16 @@ eOresult_t embot::app::eth::theBATservice::Impl::Start() { CANmonitor::Config cfg = defaultcanmonitorconfig; // use ... cfg.target.clear(); - cfg.periodofcheck = - embot::core::time1millisec * - service.servconfig.data.as.battery.canmonitorconfig.periodofcheck; - cfg.periodofreport = - embot::core::time1millisec * - service.servconfig.data.as.battery.canmonitorconfig.periodofreport; - cfg.reportmode = static_cast( - service.servconfig.data.as.battery.canmonitorconfig.reportmode); +// this if condition should be used to check if canmonitor config is passed by the configuration files +// currently it is not woring properly since we are discussing the udpates related to this for the icub-main part +// therefore we are keeping it commented for now and using the default configuration for the canmonitor +// if(service.servconfig.data.as.battery.canmonitorconfig.periodofcheck != 0) +// { +// cfg.periodofcheck = embot::core::time1millisec * service.servconfig.data.as.battery.canmonitorconfig.periodofcheck; +// cfg.periodofreport = embot::core::time1millisec * service.servconfig.data.as.battery.canmonitorconfig.periodofreport; +// cfg.reportmode = static_cast(service.servconfig.data.as.battery.canmonitorconfig.reportmode); +// } + canmonitor.configure(cfg); canmonitor.start(); @@ -512,8 +509,7 @@ eOresult_t embot::app::eth::theBATservice::Impl::Stop() { service.started = eobool_false; service.state = eomn_serv_state_activated; - eo_service_hid_SynchServiceState(eo_services_GetHandle(), - eomn_serv_category_battery, service.state); + eo_service_hid_SynchServiceState(eo_services_GetHandle(), eomn_serv_category_battery, service.state); // we dont remove all regulars related to ft entity because Deactivate() does // that. @@ -521,24 +517,23 @@ eOresult_t embot::app::eth::theBATservice::Impl::Stop() { return eores_OK; } -eOresult_t embot::app::eth::theBATservice::Impl::SetRegulars( - eOmn_serv_arrayof_id32_t *arrayofid32, uint8_t *numberofthem) { +eOresult_t embot::app::eth::theBATservice::Impl::SetRegulars(eOmn_serv_arrayof_id32_t *arrayofid32, uint8_t *numberofthem) +{ eo_errman_Trace(eo_errman_GetHandle(), "::SetRegulars()", s_eobj_ownname); - if (eobool_false == - service.active) { // nothing to do because object must be first activated + if (eobool_false == service.active) + { // nothing to do because object must be first activated return (eores_OK); } - return (eo_service_hid_SetRegulars(id32ofregulars, arrayofid32, - s_battery_isID32relevant, numberofthem)); + return (eo_service_hid_SetRegulars(id32ofregulars, arrayofid32, s_battery_isID32relevant, numberofthem)); } -eOresult_t embot::app::eth::theBATservice::Impl::AcceptCANframe( - const canFrameDescriptor &cfd) { +eOresult_t embot::app::eth::theBATservice::Impl::AcceptCANframe(const canFrameDescriptor &cfd) { // object must be first activated otherwise we cannot use EOtheCANmapping, // theBATnetvariables, theFTboards - if (eobool_false == service.active) { + if (eobool_false == service.active) + { return (eores_OK); } @@ -659,47 +654,50 @@ embot::app::eth::theBATservice::Impl::GetServiceState() const { return service.state; } -eOresult_t -embot::app::eth::theBATservice::Impl::process(const eOropdescriptor_t *rd, - const EOnv *nv) { - if ((nullptr == rd) || (nullptr == rd->data)) { - return eores_NOK_nullpointer; +eOresult_t embot::app::eth::theBATservice::Impl::process(const eOropdescriptor_t *rd, const EOnv *nv) +{ + + if ((nullptr == rd) || (nullptr == rd->data)) + { + return eores_NOK_nullpointer; } eOprotIndex_t index = eoprot_ID2index(rd->id32); - eOprot_tag_as_battery_t tag = - static_cast(eoprot_ID2tag(rd->id32)); - - switch (tag) { - case eoprot_tag_as_battery_config: { - // in here we need to get the configuration and assign it - eOas_battery_config_t *cfg = - reinterpret_cast(rd->data); - set(index, cfg); - } break; + eOprot_tag_as_battery_t tag = static_cast(eoprot_ID2tag(rd->id32)); - case eoprot_tag_as_battery_cmmnds_enable: { - // in here we either start or stop depending on value 1 or 0 of ... - // eOas_battery_commands_t::enable - uint8_t *cmdenable = reinterpret_cast(rd->data); - enable(index, cmdenable); - } break; + switch (tag) + { + case eoprot_tag_as_battery_config: + { + // in here we need to get the configuration and assign it + eOas_battery_config_t *cfg = reinterpret_cast(rd->data); + set(index, cfg); + } break; - default: { + case eoprot_tag_as_battery_cmmnds_enable: + { + // in here we either start or stop depending on value 1 or 0 of ... + // eOas_battery_commands_t::enable + uint8_t *cmdenable = reinterpret_cast(rd->data); + enable(index, cmdenable); + } break; - } break; + default: + { + + } break; } return eores_OK; } -bool embot::app::eth::theBATservice::Impl::set( - eOprotIndex_t index, const eOas_battery_config_t *ftc) { +bool embot::app::eth::theBATservice::Impl::set(eOprotIndex_t index, const eOas_battery_config_t *ftc) +{ // NOTE-x: // ... the ETH protocol mechanism already writes inside the relevant memory // the new values inside ftc we just have have them, which are also inside // theBATnetvariables[index]->config however, ... if the method process() - // whuich calls set() is called by theServiceValidator and not by the ETH + // which calls set() is called by theServiceValidator and not by the ETH // callbacks, we also must copy what inside ftc but ... beware of nullptr if (nullptr == ftc) { @@ -710,16 +708,17 @@ bool embot::app::eth::theBATservice::Impl::set( return false; } - eOas_battery_config_t *theNVptr = (nullptr != theBATnetvariables[index]) - ? &theBATnetvariables[index]->config - : nullptr; + eOas_battery_config_t *theNVptr = (nullptr != theBATnetvariables[index]) ? &theBATnetvariables[index]->config : nullptr; - if (nullptr == theNVptr) { + if (nullptr == theNVptr) + { return false; } - if (ftc != theNVptr) { // in this case the caller was not the ETH handler, so - // we must update the internal memory + if (ftc != theNVptr) + { + // in this case the caller was not the ETH handler, so + // we must update the internal memory std::memmove(theNVptr, ftc, sizeof(eOas_battery_config_t)); } @@ -764,11 +763,9 @@ bool embot::app::eth::theBATservice::Impl::enable(eOprotIndex_t index, // NOTE: i do that only for FT, not for temperature because it is FT che // comanda eObrd_canlocation_t loc{}; - eOprotID32_t id32 = - eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, - index, eoprot_tag_none); - if (eores_OK == eo_canmap_GetEntityLocation(eo_canmap_GetHandle(), id32, &loc, - NULL, NULL)) { + eOprotID32_t id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, index, eoprot_tag_none); + if (eores_OK == eo_canmap_GetEntityLocation(eo_canmap_GetHandle(), id32, &loc, NULL, NULL)) + { if (true == on) { canmonitor.add(loc); // // i adjust rate according to actual rate w/ a safety factor @@ -822,18 +819,56 @@ embot::app::eth::theBATservice::Impl::s_battery_isID32relevant(uint32_t id32) { return (eobool_false); } -void embot::app::eth::theBATservice::Impl::can_battery_Config( - eOprotIndex_t index, uint8_t ratemillisec) { - // For now do nothing for BMS +void embot::app::eth::theBATservice::Impl::can_battery_Config(eOprotIndex_t index, uint8_t ratemillisec) +{ +// uint8_t datarate = ratemillisec; +// sharedcan.command.clas = eocanprot_msgclass_pollingAnalogSensor; +// sharedcan.command.type = ICUBCANPROTO_POL_AS_CMD__SET_CANDATARATE; +// sharedcan.command.value = &datarate; +// eOprotID32_t id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, index, eoprot_tag_none); +// eo_canserv_SendCommandToEntity(eo_canserv_GetHandle(), &sharedcan.command, id32); + + // Notihing to do for now } -void embot::app::eth::theBATservice::Impl::can_battery_TX(eOprotIndex_t index, - bool on) { - // For now do nothing for BMS +void embot::app::eth::theBATservice::Impl::can_battery_TX(eOprotIndex_t index, bool on) +{ + if(nullptr == theBATnetvariables[index]) + { + return; + } + + // now, depending on the pair {transmit, mode} we choose the eOas_batterymode_t value to send to the bat / bms board + // amongst these two: + // eoas_batterymode_txdatacontinuously + // eoas_batterymode_acquirebutdonttx + + eOas_batterymode_t batterymode = (true == on ) ? eoas_batterymode_txdatacontinuously : eoas_batterymode_acquirebutdonttx; + + sharedcan.command.clas = eocanprot_msgclass_pollingAnalogSensor; + sharedcan.command.type = ICUBCANPROTO_POL_AS_CMD__SET_TXMODE; + sharedcan.command.value = &batterymode; + eOprotID32_t id32 = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, index, eoprot_tag_none); + eo_canserv_SendCommandToEntity(eo_canserv_GetHandle(), &sharedcan.command, id32); } void embot::app::eth::theBATservice::Impl::can_battery_TXstop() { - // For now do nothing for BMS + // set txmode + eOenum08_t mode = eoas_batterymode_acquirebutdonttx; + sharedcan.command.clas = eocanprot_msgclass_pollingAnalogSensor; + sharedcan.command.type = ICUBCANPROTO_POL_AS_CMD__SET_TXMODE; + sharedcan.command.value = &mode; + + for(uint8_t protindex = 0; protindexenable(index, cmdenable); } -const embot::app::eth::theServiceTester::Config & -embot::app::eth::theBATservice::servicetesterconfig() const { +const embot::app::eth::theServiceTester::Config &embot::app::eth::theBATservice::servicetesterconfig() const +{ return pImpl->servicetesterconfig(); } @@ -934,29 +969,27 @@ embot::app::eth::theBATservice::servicetesterconfig() const { extern "C" { -extern void eoprot_fun_UPDT_as_battery_config(const EOnv *nv, - const eOropdescriptor_t *rd) { +extern void eoprot_fun_UPDT_as_battery_config(const EOnv *nv, const eOropdescriptor_t *rd) +{ embot::app::eth::theBATservice::getInstance().process(rd, nv); } extern void -eoprot_fun_UPDT_as_battery_cmmnds_enable(const EOnv *nv, - const eOropdescriptor_t *rd) { +eoprot_fun_UPDT_as_battery_cmmnds_enable(const EOnv *nv, const eOropdescriptor_t *rd) +{ embot::app::eth::theBATservice::getInstance().process(rd, nv); } -extern void eoprot_fun_INIT_as_battery_config(const EOnv *nv) { - eOas_battery_config_t *config = - reinterpret_cast(eo_nv_RAM(nv)); - std::memmove(config, &embot::app::eth::theBATservice::defaultFTconfig, - sizeof(eOas_battery_config_t)); +extern void eoprot_fun_INIT_as_battery_config(const EOnv *nv) +{ + eOas_battery_config_t *config = reinterpret_cast(eo_nv_RAM(nv)); + std::memmove(config, &embot::app::eth::theBATservice::defaultBATconfig, sizeof(eOas_battery_config_t)); } -extern void eoprot_fun_INIT_as_battery_status(const EOnv *nv) { - eOas_battery_status_t *status = - reinterpret_cast(eo_nv_RAM(nv)); - std::memmove(status, &embot::app::eth::theBATservice::defaultBATstatus, - sizeof(eOas_battery_status_t)); +extern void eoprot_fun_INIT_as_battery_status(const EOnv *nv) +{ + eOas_battery_status_t *status = reinterpret_cast(eo_nv_RAM(nv)); + std::memmove(status, &embot::app::eth::theBATservice::defaultBATstatus, sizeof(eOas_battery_status_t)); } } // extern "C" diff --git a/emBODY/eBcode/arch-arm/board/ems004/appl/v2/src/eoappservices/embot_app_eth_theBATservice.h b/emBODY/eBcode/arch-arm/board/ems004/appl/v2/src/eoappservices/embot_app_eth_theBATservice.h index a3e48dcc8..287c37b3d 100644 --- a/emBODY/eBcode/arch-arm/board/ems004/appl/v2/src/eoappservices/embot_app_eth_theBATservice.h +++ b/emBODY/eBcode/arch-arm/board/ems004/appl/v2/src/eoappservices/embot_app_eth_theBATservice.h @@ -84,6 +84,12 @@ class theBATservice { // function eOresult_t process(const eOropdescriptor_t *rd, const EOnv *nv = nullptr); eOresult_t SendReport(); + +// // we can call them if _Activate() was called. they are used by the callbacks of eth protocol +// eOresult_t eo_battery_GetFullScale(eOservice_onendofoperation_fun_t overrideonfullscaleready); +// eOresult_t eo_battery_Set(eOas_battery_config_t *cfg); +// eOresult_t eo_battery_SetDataRate(uint8_t datarate); +// uint8_t eo_battery_GetDataRate(); // default status of the BAT sensors static constexpr eOas_battery_status_t defaultBATstatus{ @@ -94,7 +100,7 @@ class theBATservice { .current = 0, .charge = 0}}; // default configuration of the BAT sensors - static constexpr eOas_battery_config_t defaultFTconfig{ + static constexpr eOas_battery_config_t defaultBATconfig{ .period = 100, }; diff --git a/emBODY/eBcode/arch-arm/board/mc2plus/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h b/emBODY/eBcode/arch-arm/board/mc2plus/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h index 2fde0c7f8..dddd54d91 100644 --- a/emBODY/eBcode/arch-arm/board/mc2plus/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h +++ b/emBODY/eBcode/arch-arm/board/mc2plus/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h @@ -75,21 +75,21 @@ extern "C" { #define EOMTHEEMSAPPLCFG_VERSION_MAJOR 3 // minor <0-255> // minor <0-255> -#define EOMTHEEMSAPPLCFG_VERSION_MINOR 64 +#define EOMTHEEMSAPPLCFG_VERSION_MINOR 65 // version // build date // year <2010-2030> -#define EOMTHEEMSAPPLCFG_BUILDDATE_YEAR 2023 +#define EOMTHEEMSAPPLCFG_BUILDDATE_YEAR 2024 // month <1-12> -#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 11 +#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 1 // day <1-31> -#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 29 +#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 8 // hour <0-23> -#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 14 +#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 18 // minute <0-59> -#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 34 +#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 00 // build date // Info diff --git a/emBODY/eBcode/arch-arm/board/mc4plus/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h b/emBODY/eBcode/arch-arm/board/mc4plus/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h index ccb676b01..c3d695e4a 100644 --- a/emBODY/eBcode/arch-arm/board/mc4plus/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h +++ b/emBODY/eBcode/arch-arm/board/mc4plus/appl/v2/cfg/eoemsappl/EOMtheEMSapplCfg_cfg.h @@ -84,21 +84,21 @@ extern "C" { #define EOMTHEEMSAPPLCFG_VERSION_MAJOR (VERSION_MAJOR_OFFSET+3) // minor <0-255> -#define EOMTHEEMSAPPLCFG_VERSION_MINOR 85 +#define EOMTHEEMSAPPLCFG_VERSION_MINOR 86 // version // build date // year <2010-2030> -#define EOMTHEEMSAPPLCFG_BUILDDATE_YEAR 2023 +#define EOMTHEEMSAPPLCFG_BUILDDATE_YEAR 2024 // month <1-12> -#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 11 +#define EOMTHEEMSAPPLCFG_BUILDDATE_MONTH 1 // day <1-31> -#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 29 +#define EOMTHEEMSAPPLCFG_BUILDDATE_DAY 8 // hour <0-23> -#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 14 +#define EOMTHEEMSAPPLCFG_BUILDDATE_HOUR 18 // minute <0-59> -#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 33 +#define EOMTHEEMSAPPLCFG_BUILDDATE_MIN 00 // build date diff --git a/emBODY/eBcode/arch-arm/embobj/plus/can/EOtheCANmapping.c b/emBODY/eBcode/arch-arm/embobj/plus/can/EOtheCANmapping.c index edd1fd3e1..4e5043fcd 100644 --- a/emBODY/eBcode/arch-arm/embobj/plus/can/EOtheCANmapping.c +++ b/emBODY/eBcode/arch-arm/embobj/plus/can/EOtheCANmapping.c @@ -24,7 +24,6 @@ #include "stdlib.h" #include "EoCommon.h" - #include "EOtheMemoryPool.h" // -------------------------------------------------------------------------------------------------------------------- @@ -275,12 +274,18 @@ extern EOtheCANmapping * eo_canmap_Initialise(const eOcanmap_cfg_t *canmapcfg) s_eo_canmap_singleton.arrayOfBRDEXTptr[m][n] = eo_array_New(eocanmap_ft_boards_maxnumberof, sizeof(eOcanmap_board_extended_t*), NULL); } + m = eocanmap_posOfEPEN(eoprot_endpoint_analogsensors, eoprot_entity_as_battery); + for(uint8_t n=0; n