diff --git a/examples/seeder_example/section_control_implement_sim.cpp b/examples/seeder_example/section_control_implement_sim.cpp index a1c4cad3..ba70f84c 100644 --- a/examples/seeder_example/section_control_implement_sim.cpp +++ b/examples/seeder_example/section_control_implement_sim.cpp @@ -15,7 +15,7 @@ void SectionControlImplementSimulator::set_number_of_sections(std::uint8_t value std::uint8_t SectionControlImplementSimulator::get_number_of_sections() const { - return sectionStates.size(); + return static_cast(sectionStates.size()); } void SectionControlImplementSimulator::set_section_state(std::uint8_t index, bool value) @@ -127,19 +127,23 @@ bool SectionControlImplementSimulator::create_ddop(std::shared_ptr localizationData = { 'e', 'n', 0b01010000, 0x00, 0b01010101, 0b01010101, 0xFF }; // Make a pool with 1 granular product - // Set up device + // Set up device and device element retVal &= poolToPopulate->add_device("Isobus Seeder", "1.0.0", "123", "IS1.1", localizationData, std::vector(), clientName.get_full_name()); - retVal &= poolToPopulate->add_device_element("Seeder", elementCounter++, 0, isobus::task_controller_object::DeviceElementObject::Type::Device, static_cast(ImplementDDOPObjectIDs::MainDeviceElement)); + retVal &= poolToPopulate->add_device_element("Seeder", elementCounter, 0, isobus::task_controller_object::DeviceElementObject::Type::Device, static_cast(ImplementDDOPObjectIDs::MainDeviceElement)); retVal &= poolToPopulate->add_device_process_data("Actual Work State", static_cast(isobus::DataDescriptionIndex::ActualWorkState), isobus::task_controller_object::Object::NULL_OBJECT_ID, static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::OnChange), static_cast(ImplementDDOPObjectIDs::DeviceActualWorkState)); retVal &= poolToPopulate->add_device_process_data("Request Default PD", static_cast(ImplementDDOPObjectIDs::RequestDefaultProcessData), isobus::task_controller_object::Object::NULL_OBJECT_ID, 0, static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::Total), static_cast(ImplementDDOPObjectIDs::RequestDefaultProcessData)); retVal &= poolToPopulate->add_device_process_data("Total Time", static_cast(isobus::DataDescriptionIndex::EffectiveTotalTime), static_cast(ImplementDDOPObjectIDs::TimePresentation), static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet) | static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::Settable), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::Total), static_cast(ImplementDDOPObjectIDs::DeviceTotalTime)); - retVal &= poolToPopulate->add_device_element("Connector", elementCounter++, static_cast(ImplementDDOPObjectIDs::MainDeviceElement), isobus::task_controller_object::DeviceElementObject::Type::Connector, static_cast(ImplementDDOPObjectIDs::Connector)); + elementCounter++; // Increment element number. Needs to be unique for each element. + + // Set up connector element + retVal &= poolToPopulate->add_device_element("Connector", elementCounter, static_cast(ImplementDDOPObjectIDs::MainDeviceElement), isobus::task_controller_object::DeviceElementObject::Type::Connector, static_cast(ImplementDDOPObjectIDs::Connector)); retVal &= poolToPopulate->add_device_process_data("Connector X", static_cast(isobus::DataDescriptionIndex::DeviceElementOffsetX), static_cast(ImplementDDOPObjectIDs::ShortWidthPresentation), static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::Settable), 0, static_cast(ImplementDDOPObjectIDs::ConnectorXOffset)); retVal &= poolToPopulate->add_device_process_data("Connector Y", static_cast(isobus::DataDescriptionIndex::DeviceElementOffsetY), static_cast(ImplementDDOPObjectIDs::ShortWidthPresentation), static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::Settable), 0, static_cast(ImplementDDOPObjectIDs::ConnectorYOffset)); retVal &= poolToPopulate->add_device_property("Type", 9, static_cast(isobus::DataDescriptionIndex::ConnectorType), isobus::task_controller_object::Object::NULL_OBJECT_ID, static_cast(ImplementDDOPObjectIDs::ConnectorType)); + elementCounter++; // Increment element number. Needs to be unique for each element. - // Set up Boom - retVal &= poolToPopulate->add_device_element("AgIsoStack Example", elementCounter++, static_cast(ImplementDDOPObjectIDs::MainDeviceElement), isobus::task_controller_object::DeviceElementObject::Type::Function, static_cast(ImplementDDOPObjectIDs::MainBoom)); + // Set up Boom element + retVal &= poolToPopulate->add_device_element("AgIsoStack Example", elementCounter, static_cast(ImplementDDOPObjectIDs::MainDeviceElement), isobus::task_controller_object::DeviceElementObject::Type::Function, static_cast(ImplementDDOPObjectIDs::MainBoom)); retVal &= poolToPopulate->add_device_property("Offset X", 0, static_cast(isobus::DataDescriptionIndex::DeviceElementOffsetX), static_cast(ImplementDDOPObjectIDs::ShortWidthPresentation), static_cast(ImplementDDOPObjectIDs::BoomXOffset)); retVal &= poolToPopulate->add_device_property("Offset Y", 0, static_cast(isobus::DataDescriptionIndex::DeviceElementOffsetY), static_cast(ImplementDDOPObjectIDs::ShortWidthPresentation), static_cast(ImplementDDOPObjectIDs::BoomYOffset)); retVal &= poolToPopulate->add_device_property("Offset Z", 0, static_cast(isobus::DataDescriptionIndex::DeviceElementOffsetZ), static_cast(ImplementDDOPObjectIDs::ShortWidthPresentation), static_cast(ImplementDDOPObjectIDs::BoomZOffset)); @@ -147,9 +151,10 @@ bool SectionControlImplementSimulator::create_ddop(std::shared_ptradd_device_process_data("Setpoint Work State", static_cast(isobus::DataDescriptionIndex::SetpointWorkState), isobus::task_controller_object::Object::NULL_OBJECT_ID, static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet) | static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::Settable), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::OnChange), static_cast(ImplementDDOPObjectIDs::SetpointWorkState)); retVal &= poolToPopulate->add_device_process_data("Area Total", static_cast(isobus::DataDescriptionIndex::TotalArea), static_cast(ImplementDDOPObjectIDs::AreaPresentation), static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::Total), static_cast(ImplementDDOPObjectIDs::AreaTotal)); retVal &= poolToPopulate->add_device_process_data("Section Control State", static_cast(isobus::DataDescriptionIndex::SectionControlState), isobus::task_controller_object::Object::NULL_OBJECT_ID, static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet) | static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::Settable), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::OnChange) | static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::TimeInterval), static_cast(ImplementDDOPObjectIDs::SectionControlState)); + elementCounter++; // Increment element number. Needs to be unique for each element. - // Set up bin/tank - retVal &= poolToPopulate->add_device_element("Product", elementCounter++, 9, isobus::task_controller_object::DeviceElementObject::Type::Bin, static_cast(ImplementDDOPObjectIDs::GranularProduct)); + // Set up bin/tank element + retVal &= poolToPopulate->add_device_element("Product", elementCounter, 9, isobus::task_controller_object::DeviceElementObject::Type::Bin, static_cast(ImplementDDOPObjectIDs::GranularProduct)); retVal &= poolToPopulate->add_device_process_data("Bin Capacity", static_cast(isobus::DataDescriptionIndex::MaximumCountContent), static_cast(ImplementDDOPObjectIDs::CountPresentation), static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::OnChange) | static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::TimeInterval), static_cast(ImplementDDOPObjectIDs::BinCapacity)); retVal &= poolToPopulate->add_device_process_data("Bin Level", static_cast(isobus::DataDescriptionIndex::ActualCountContent), static_cast(ImplementDDOPObjectIDs::CountPresentation), static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet) | static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::Settable), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::OnChange) | static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::TimeInterval), static_cast(ImplementDDOPObjectIDs::BinLevel)); retVal &= poolToPopulate->add_device_process_data("Lifetime Total Count", static_cast(isobus::DataDescriptionIndex::LifetimeApplicationTotalCount), static_cast(ImplementDDOPObjectIDs::CountPresentation), static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::Total), static_cast(ImplementDDOPObjectIDs::LifetimeApplicationCountTotal)); @@ -157,13 +162,14 @@ bool SectionControlImplementSimulator::create_ddop(std::shared_ptradd_device_process_data("Target Rate", static_cast(isobus::DataDescriptionIndex::SetpointCountPerAreaApplicationRate), static_cast(ImplementDDOPObjectIDs::CountPerAreaPresentation), static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet) | static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::Settable), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::OnChange), static_cast(ImplementDDOPObjectIDs::TargetRate)); retVal &= poolToPopulate->add_device_process_data("Actual Rate", static_cast(isobus::DataDescriptionIndex::ActualCountPerAreaApplicationRate), static_cast(ImplementDDOPObjectIDs::CountPerAreaPresentation), static_cast(isobus::task_controller_object::DeviceProcessDataObject::PropertiesBit::MemberOfDefaultSet), static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::OnChange) | static_cast(isobus::task_controller_object::DeviceProcessDataObject::AvailableTriggerMethods::TimeInterval), static_cast(ImplementDDOPObjectIDs::ActualRate)); retVal &= poolToPopulate->add_device_property("Operation Type", 2, static_cast(isobus::DataDescriptionIndex::ActualCulturalPractice), isobus::task_controller_object::Object::NULL_OBJECT_ID, static_cast(ImplementDDOPObjectIDs::ActualCulturalPractice)); + elementCounter++; // Increment element number. Needs to be unique for each element. // Set up sections for section control // Using 7 ft sections for (std::uint_fast8_t i = 0; i < get_number_of_sections(); i++) { std::int32_t individualSectionWidth = BOOM_WIDTH / get_number_of_sections(); - retVal &= poolToPopulate->add_device_element("Section " + isobus::to_string(static_cast(i)), elementCounter++, 9, isobus::task_controller_object::DeviceElementObject::Type::Section, static_cast(ImplementDDOPObjectIDs::Section1) + i); + retVal &= poolToPopulate->add_device_element("Section " + isobus::to_string(static_cast(i)), elementCounter, 9, isobus::task_controller_object::DeviceElementObject::Type::Section, static_cast(ImplementDDOPObjectIDs::Section1) + i); retVal &= poolToPopulate->add_device_property("Offset X", -20, static_cast(isobus::DataDescriptionIndex::DeviceElementOffsetX), static_cast(ImplementDDOPObjectIDs::LongWidthPresentation), static_cast(ImplementDDOPObjectIDs::Section1XOffset) + i); retVal &= poolToPopulate->add_device_property("Offset Y", ((-BOOM_WIDTH) / 2) + (i * SECTION_WIDTH) + (SECTION_WIDTH / 2), static_cast(isobus::DataDescriptionIndex::DeviceElementOffsetY), static_cast(ImplementDDOPObjectIDs::LongWidthPresentation), static_cast(ImplementDDOPObjectIDs::Section1YOffset) + i); retVal &= poolToPopulate->add_device_property("Width", individualSectionWidth, static_cast(isobus::DataDescriptionIndex::ActualWorkingWidth), static_cast(ImplementDDOPObjectIDs::LongWidthPresentation), static_cast(ImplementDDOPObjectIDs::Section1Width) + i); @@ -171,6 +177,7 @@ bool SectionControlImplementSimulator::create_ddop(std::shared_ptradd_reference_to_child_object(static_cast(ImplementDDOPObjectIDs::Section1YOffset) + i); section->add_reference_to_child_object(static_cast(ImplementDDOPObjectIDs::Section1XOffset) + i); section->add_reference_to_child_object(static_cast(ImplementDDOPObjectIDs::Section1Width) + i); + elementCounter++; // Increment element number. Needs to be unique for each element, and each section is its own element. } std::uint16_t sectionCounter = 0; @@ -285,14 +292,16 @@ bool SectionControlImplementSimulator::request_value_command_callback(std::uint1 case static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState225_240): case static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState241_256): { - std::uint16_t sectionIndexOffset = NUMBER_SECTIONS_PER_CONDENSED_MESSAGE * (DDI - static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); + std::uint8_t sectionIndexOffset = NUMBER_SECTIONS_PER_CONDENSED_MESSAGE * (DDI - static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); value = 0; for (std::uint_fast8_t i = 0; i < NUMBER_SECTIONS_PER_CONDENSED_MESSAGE; i++) { - if ((i + (sectionIndexOffset)) < sim->get_number_of_sections()) + if ((i + sectionIndexOffset) < sim->get_number_of_sections()) { - value |= ((true == sim->get_section_state(i + sectionIndexOffset)) ? (static_cast(0x01) & sim->get_switch_state(i + sectionIndexOffset)) : static_cast(0x00)) << (2 * i); + bool sectionState = sim->get_section_state(i + sectionIndexOffset); + bool switchState = sim->get_switch_state(i + sectionIndexOffset); + value |= static_cast(sectionState && switchState) << (2 * i); } else { @@ -345,14 +354,14 @@ bool SectionControlImplementSimulator::request_value_command_callback(std::uint1 case static_cast(isobus::DataDescriptionIndex::SetpointCondensedWorkState225_240): case static_cast(isobus::DataDescriptionIndex::SetpointCondensedWorkState241_256): { - std::uint16_t sectionIndexOffset = NUMBER_SECTIONS_PER_CONDENSED_MESSAGE * (DDI - static_cast(isobus::DataDescriptionIndex::SetpointCondensedWorkState1_16)); + std::uint8_t sectionIndexOffset = NUMBER_SECTIONS_PER_CONDENSED_MESSAGE * (DDI - static_cast(isobus::DataDescriptionIndex::SetpointCondensedWorkState1_16)); value = 0; for (std::uint_fast8_t i = 0; i < NUMBER_SECTIONS_PER_CONDENSED_MESSAGE; i++) { - if ((i + (sectionIndexOffset)) < sim->get_number_of_sections()) + if ((i + sectionIndexOffset) < sim->get_number_of_sections()) { - value |= ((true == sim->get_section_setpoint_state(i + sectionIndexOffset)) ? static_cast(0x01) : static_cast(0x00)) << (2 * i); + value |= sim->get_section_setpoint_state(i + sectionIndexOffset) << (2 * i); } else { @@ -408,7 +417,7 @@ bool SectionControlImplementSimulator::value_command_callback(std::uint16_t, case static_cast(isobus::DataDescriptionIndex::SetpointCondensedWorkState225_240): case static_cast(isobus::DataDescriptionIndex::SetpointCondensedWorkState241_256): { - std::uint16_t sectionIndexOffset = NUMBER_SECTIONS_PER_CONDENSED_MESSAGE * (DDI - static_cast(isobus::DataDescriptionIndex::SetpointCondensedWorkState1_16)); + auto sectionIndexOffset = static_cast(NUMBER_SECTIONS_PER_CONDENSED_MESSAGE * (DDI - static_cast(isobus::DataDescriptionIndex::SetpointCondensedWorkState1_16))); for (std::uint_fast8_t i = 0; i < NUMBER_SECTIONS_PER_CONDENSED_MESSAGE; i++) { diff --git a/examples/seeder_example/seeder.cpp b/examples/seeder_example/seeder.cpp index 11f66a00..3e6f2aef 100644 --- a/examples/seeder_example/seeder.cpp +++ b/examples/seeder_example/seeder.cpp @@ -74,7 +74,7 @@ bool Seeder::initialize() auto PartnerVT = isobus::PartneredControlFunction::create(0, vtNameFilters); auto PartnerTC = isobus::PartneredControlFunction::create(0, tcNameFilters); - diagnosticProtocol = std::unique_ptr(new isobus::DiagnosticProtocol(InternalECU)); + diagnosticProtocol = std::make_unique(InternalECU); diagnosticProtocol->initialize(); diagnosticProtocol->set_product_identification_code("1234567890ABC"); @@ -94,7 +94,7 @@ bool Seeder::initialize() diagnosticProtocol->ControlFunctionFunctionalitiesMessageInterface.set_functionality_is_supported(isobus::ControlFunctionFunctionalities::Functionalities::TaskControllerGeoClient, 1, true); diagnosticProtocol->ControlFunctionFunctionalitiesMessageInterface.set_functionality_is_supported(isobus::ControlFunctionFunctionalities::Functionalities::TaskControllerSectionControlClient, 1, true); - VTApplication = std::unique_ptr(new SeederVtApplication(PartnerVT, PartnerTC, InternalECU)); + VTApplication = std::make_unique(PartnerVT, PartnerTC, InternalECU); VTApplication->initialize(); return retVal; @@ -107,6 +107,10 @@ void Seeder::terminate() VTApplication->VTClientInterface.terminate(); VTApplication->TCClientInterface.terminate(); } + if (nullptr != diagnosticProtocol) + { + diagnosticProtocol->terminate(); + } isobus::CANHardwareInterface::stop(); } diff --git a/examples/seeder_example/vt_application.cpp b/examples/seeder_example/vt_application.cpp index 7f7aba86..7d425fe9 100644 --- a/examples/seeder_example/vt_application.cpp +++ b/examples/seeder_example/vt_application.cpp @@ -88,7 +88,7 @@ bool SeederVtApplication::initialize() // Generate a unique version string for this object pool (this is optional, and is entirely application specific behavior) std::string objectPoolHash = isobus::IOPFileInterface::hash_object_pool_to_version(objectPool); - VTClientInterface.set_object_pool(0, isobus::VirtualTerminalClient::VTVersion::Version4, objectPool.data(), objectPool.size(), objectPoolHash); + VTClientInterface.set_object_pool(0, isobus::VirtualTerminalClient::VTVersion::Version4, objectPool.data(), static_cast(objectPool.size()), objectPoolHash); softkeyEventListener = VTClientInterface.add_vt_soft_key_event_listener([this](const isobus::VirtualTerminalClient::VTKeyEvent &event) { this->handle_vt_key_events(event); }); buttonEventListener = VTClientInterface.add_vt_button_event_listener([this](const isobus::VirtualTerminalClient::VTKeyEvent &event) { this->handle_vt_key_events(event); }); numericValueEventListener = VTClientInterface.add_vt_change_numeric_value_event_listener([this](const isobus::VirtualTerminalClient::VTChangeNumericValueEvent &event) { this->handle_numeric_value_events(event); }); @@ -122,135 +122,128 @@ bool SeederVtApplication::initialize() void SeederVtApplication::handle_vt_key_events(const isobus::VirtualTerminalClient::VTKeyEvent &event) { - switch (event.keyEvent) + if (isobus::VirtualTerminalClient::KeyActivationCode::ButtonUnlatchedOrReleased == event.keyEvent) { - case isobus::VirtualTerminalClient::KeyActivationCode::ButtonUnlatchedOrReleased: + switch (event.objectID) { - switch (event.objectID) + case home_Key: { - case home_Key: - { - set_currently_active_screen(ActiveScreen::Main); - } - break; + set_currently_active_screen(ActiveScreen::Main); + } + break; - case settings_Key: - { - set_currently_active_screen(ActiveScreen::Settings); - } - break; + case settings_Key: + { + set_currently_active_screen(ActiveScreen::Settings); + } + break; - case statistics_Key: - { - set_currently_active_screen(ActiveScreen::Statistics); - } - break; + case statistics_Key: + { + set_currently_active_screen(ActiveScreen::Statistics); + } + break; - case alarms_Key: - { - set_currently_active_screen(ActiveScreen::Alarms); - } - break; + case alarms_Key: + { + set_currently_active_screen(ActiveScreen::Alarms); + } + break; - case acknowledgeAlarm_SoftKey: + case acknowledgeAlarm_SoftKey: + { + for (auto &alarm : alarmConditions) { - for (std::size_t i = 0; i < alarmConditions.size(); i++) + if ((isobus::SystemTiming::time_expired_ms(alarm.conditionTimestamp, alarm.conditionTimeout)) && + (false == alarm.acknowledged)) { - if ((isobus::SystemTiming::time_expired_ms(alarmConditions.at(i).conditionTimestamp, alarmConditions.at(i).conditionTimeout)) && - (false == alarmConditions.at(i).acknowledged)) - { - alarmConditions.at(i).acknowledged = true; - break; - } - } - - if (previousActiveScreen != currentlyActiveScreen) - { - set_currently_active_screen(previousActiveScreen); - } - else - { - set_currently_active_screen(ActiveScreen::Main); + alarm.acknowledged = true; + break; } - break; } - break; - case autoManualToggle_Button: + if (previousActiveScreen != currentlyActiveScreen) { - sectionControl.set_is_mode_auto(!sectionControl.get_is_mode_auto()); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateAutoManual_ObjPtr)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection1Status_OutRect)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection2Status_OutRect)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection3Status_OutRect)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection4Status_OutRect)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection5Status_OutRect)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection6Status_OutRect)); + set_currently_active_screen(previousActiveScreen); } - break; - - case section1Toggle_Button: + else { - sectionControl.set_switch_state(0, !sectionControl.get_switch_state(0)); - TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection1EnableState_ObjPtr)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection1Status_OutRect)); + set_currently_active_screen(ActiveScreen::Main); } break; + } + break; - case section2Toggle_Button: - { - sectionControl.set_switch_state(1, !sectionControl.get_switch_state(1)); - TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection2EnableState_ObjPtr)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection2Status_OutRect)); - } - break; + case autoManualToggle_Button: + { + sectionControl.set_is_mode_auto(!sectionControl.get_is_mode_auto()); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateAutoManual_ObjPtr)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection1Status_OutRect)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection2Status_OutRect)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection3Status_OutRect)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection4Status_OutRect)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection5Status_OutRect)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection6Status_OutRect)); + } + break; - case section3Toggle_Button: - { - sectionControl.set_switch_state(2, !sectionControl.get_switch_state(2)); - TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection3EnableState_ObjPtr)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection3Status_OutRect)); - } - break; + case section1Toggle_Button: + { + sectionControl.set_switch_state(0, !sectionControl.get_switch_state(0)); + TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection1EnableState_ObjPtr)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection1Status_OutRect)); + } + break; - case section4Toggle_Button: - { - sectionControl.set_switch_state(3, !sectionControl.get_switch_state(3)); - TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection4EnableState_ObjPtr)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection4Status_OutRect)); - } - break; + case section2Toggle_Button: + { + sectionControl.set_switch_state(1, !sectionControl.get_switch_state(1)); + TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection2EnableState_ObjPtr)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection2Status_OutRect)); + } + break; - case section5Toggle_Button: - { - sectionControl.set_switch_state(4, !sectionControl.get_switch_state(4)); - TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection5EnableState_ObjPtr)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection5Status_OutRect)); - } - break; + case section3Toggle_Button: + { + sectionControl.set_switch_state(2, !sectionControl.get_switch_state(2)); + TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection3EnableState_ObjPtr)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection3Status_OutRect)); + } + break; - case section6Toggle_Button: - { - sectionControl.set_switch_state(5, !sectionControl.get_switch_state(5)); - TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection6EnableState_ObjPtr)); - txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection6Status_OutRect)); - } - break; + case section4Toggle_Button: + { + sectionControl.set_switch_state(3, !sectionControl.get_switch_state(3)); + TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection4EnableState_ObjPtr)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection4Status_OutRect)); + } + break; - default: - break; + case section5Toggle_Button: + { + sectionControl.set_switch_state(4, !sectionControl.get_switch_state(4)); + TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection5EnableState_ObjPtr)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection5Status_OutRect)); } - } - break; + break; - default: + case section6Toggle_Button: + { + sectionControl.set_switch_state(5, !sectionControl.get_switch_state(5)); + TCClientInterface.on_value_changed_trigger(2, static_cast(isobus::DataDescriptionIndex::ActualCondensedWorkState1_16)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection6EnableState_ObjPtr)); + txFlags.set_flag(static_cast(UpdateVTStateFlags::UpdateSection6Status_OutRect)); + } break; + + default: + break; + } } } @@ -428,7 +421,7 @@ void SeederVtApplication::processFlags(std::uint32_t flag, void *parentPointer) case UpdateVTStateFlags::UpdateSection5EnableState_ObjPtr: case UpdateVTStateFlags::UpdateSection6EnableState_ObjPtr: { - std::uint32_t sectionIndex = flag - static_cast(UpdateVTStateFlags::UpdateSection1EnableState_ObjPtr); + auto sectionIndex = static_cast(flag - static_cast(UpdateVTStateFlags::UpdateSection1EnableState_ObjPtr)); if (seeder->get_is_object_shown(SECTION_SWITCH_STATES.at(sectionIndex))) { @@ -549,7 +542,7 @@ void SeederVtApplication::processFlags(std::uint32_t flag, void *parentPointer) { if (seeder->get_is_object_shown(busload_VarNum)) { - transmitSuccessful = seeder->VTClientInterface.send_change_numeric_value(busload_VarNum, seeder->currentBusload * 100.0f); + transmitSuccessful = seeder->VTClientInterface.send_change_numeric_value(busload_VarNum, static_cast(seeder->currentBusload * 100.0f)); } } break; @@ -620,14 +613,14 @@ void SeederVtApplication::processFlags(std::uint32_t flag, void *parentPointer) case isobus::LanguageCommandInterface::DistanceUnits::Metric: { // Scale to KPH - currentSpeed = ((currentSpeed * 0.001f) * 3.6f); // Converting mm/s to m/s, then mm/s to kph + currentSpeed = static_cast((currentSpeed * 0.001f) * 3.6f); // Converting mm/s to m/s, then mm/s to kph } break; case isobus::LanguageCommandInterface::DistanceUnits::ImperialUS: { // Scale to MPH - currentSpeed = ((currentSpeed * 0.001f) * 2.23694f); // Converting mm/s to m/s, then mm/s to mph + currentSpeed = static_cast((currentSpeed * 0.001f) * 2.23694f); // Converting mm/s to m/s, then mm/s to mph } break; @@ -740,7 +733,7 @@ void SeederVtApplication::processFlags(std::uint32_t flag, void *parentPointer) case UpdateVTStateFlags::UpdateSection5Status_OutRect: case UpdateVTStateFlags::UpdateSection6Status_OutRect: { - std::uint32_t sectionIndex = flag - static_cast(UpdateVTStateFlags::UpdateSection1Status_OutRect); + auto sectionIndex = static_cast(flag - static_cast(UpdateVTStateFlags::UpdateSection1Status_OutRect)); if (seeder->get_is_object_shown(SECTION_STATUS_OUTRECTS.at(sectionIndex))) { @@ -809,7 +802,7 @@ void SeederVtApplication::processFlags(std::uint32_t flag, void *parentPointer) } } -bool SeederVtApplication::get_is_object_shown(std::uint16_t objectID) +bool SeederVtApplication::get_is_object_shown(std::uint16_t objectID) const { auto myControlFunction = VTClientInterface.get_internal_control_function(); bool retVal = false; @@ -1078,7 +1071,7 @@ void SeederVtApplication::update_alarms() { bool updateShownMask = false; - if ((VTClientInterface.get_is_connected()) && (alarmsEnabled)) + if ((VTClientInterface.get_is_connected()) && alarmsEnabled) { if ((0 == speedMessages.get_number_received_machine_selected_speed_command_sources()) && (0 == speedMessages.get_number_received_ground_based_speed_sources()) && diff --git a/examples/seeder_example/vt_application.hpp b/examples/seeder_example/vt_application.hpp index 7216c093..6f1a1734 100644 --- a/examples/seeder_example/vt_application.hpp +++ b/examples/seeder_example/vt_application.hpp @@ -153,7 +153,7 @@ class SeederVtApplication /// @brief Returns if the selected object ID is shown currently /// @param[in] objectID The object ID of the object to check the shown state of /// @returns True if the selected object ID is shown currently, otherwise false - bool get_is_object_shown(std::uint16_t objectID); + bool get_is_object_shown(std::uint16_t objectID) const; /// @brief Returns the number of active alarms /// @returns The number of currently active alarms @@ -237,9 +237,9 @@ class SeederVtApplication isobus::TaskControllerClient::Version tcVersion = isobus::TaskControllerClient::Version::Unknown; ///< Stores the TC's version for display in the object pool isobus::SpeedMessagesInterface speedMessages; ///< Interface for reading speed from the bus std::shared_ptr ddop = nullptr; ///< Stores our application's DDOP - std::shared_ptr &, const bool &)>> machineSelectedSpeedEventHandle; ///< Handle for MSS events - std::shared_ptr &, const bool &)>> groundBasedSpeedEventHandle; ///< Handle for ground based speed events - std::shared_ptr &, const bool &)>> wheelBasedSpeedEventHandle; ///< Handle for wheel based speed events + std::shared_ptr machineSelectedSpeedEventHandle; ///< Handle for MSS events + std::shared_ptr groundBasedSpeedEventHandle; ///< Handle for ground based speed events + std::shared_ptr wheelBasedSpeedEventHandle; ///< Handle for wheel based speed events std::uint32_t slowUpdateTimestamp_ms = 0; ///< A timestamp to limit some polled data to 1Hz update rate std::uint32_t lastMachineSpeed = 0; ///< Used to help track speed source timeouts std::uint8_t canAddress = 0xFE; ///< Stores our CAN address so we know if it changes and can update it in the pool diff --git a/sonar-project.properties b/sonar-project.properties index c7630aa6..fe1fa503 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -9,4 +9,4 @@ sonar.sources=isobus,examples,hardware_integration,utility sonar.tests=test # Exclude some files from the analysis. -sonar.exclusions=**/PCANBasic.h,**/libusb.h,**/InnoMakerUsb2CanLib.h,**/PCBUSB.h,**/canal.h,**/canal_a.h \ No newline at end of file +sonar.exclusions=**/PCANBasic.h,**/libusb.h,**/InnoMakerUsb2CanLib.h,**/PCBUSB.h,**/canal.h,**/canal_a.h,**/object_pool.hpp,**/objectPoolObjects.h \ No newline at end of file