-
-
Notifications
You must be signed in to change notification settings - Fork 8
Fix ddop filename #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
572b78a
768677a
b7e6273
983c3fb
c677e8c
fccd331
547bd67
94369f9
d704409
ec80df3
69f9bf4
4287e03
ff8c863
01d2bc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -41,70 +41,109 @@ bool Application::initialize() | |||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| isobus::CANNetworkManager::CANNetwork.get_configuration().set_number_of_packets_per_cts_message(255); | ||||||
|
|
||||||
| isobus::NAME ourNAME(0); | ||||||
|
|
||||||
| //! Make sure you change these for your device!!!! | ||||||
| ourNAME.set_arbitrary_address_capable(true); | ||||||
| ourNAME.set_industry_group(2); | ||||||
| ourNAME.set_device_class(0); | ||||||
| ourNAME.set_function_code(static_cast<std::uint8_t>(isobus::NAME::Function::TaskController)); | ||||||
| ourNAME.set_identity_number(20); | ||||||
| ourNAME.set_ecu_instance(0); | ||||||
| ourNAME.set_function_instance(0); // TC #1. If you want to change the TC number, change this. | ||||||
| ourNAME.set_device_class_instance(0); | ||||||
| ourNAME.set_manufacturer_code(1407); | ||||||
|
|
||||||
| auto serverCF = isobus::CANNetworkManager::CANNetwork.create_internal_control_function(ourNAME, 0, isobus::preferred_addresses::IndustryGroup2::TaskController_MappingComputer); // The preferred address for a TC is defined in ISO 11783 | ||||||
| auto addressClaimedFuture = std::async(std::launch::async, [&serverCF]() { | ||||||
| while (!serverCF->get_address_valid()) | ||||||
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); }); | ||||||
| isobus::NAME tcNAME = ourNAME; | ||||||
| tcNAME.set_function_code(static_cast<std::uint8_t>(isobus::NAME::Function::TaskController)); | ||||||
|
|
||||||
| isobus::NAME tecuNAME = ourNAME; | ||||||
| tecuNAME.set_function_code(static_cast<std::uint8_t>(isobus::NAME::Function::TractorECU)); | ||||||
| tecuNAME.set_arbitrary_address_capable(false); // TECU address is fixed | ||||||
| tecuNAME.set_ecu_instance(0); | ||||||
|
|
||||||
| std::cout << "[Init] Creating Task Controller control function..." << std::endl; | ||||||
| auto tcCF = isobus::CANNetworkManager::CANNetwork.create_internal_control_function(tcNAME, 0, isobus::preferred_addresses::IndustryGroup2::TaskController_MappingComputer); // The preferred address for a TC is defined in ISO 11783 | ||||||
| auto tcAddressClaimedFuture = std::async(std::launch::async, [&tcCF]() { | ||||||
| while (!tcCF->get_address_valid()) | ||||||
| { | ||||||
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||||||
| isobus::CANNetworkManager::CANNetwork.update(); | ||||||
| } | ||||||
| }); | ||||||
|
|
||||||
| // If this fails, probably the update thread is not started | ||||||
| addressClaimedFuture.wait_for(std::chrono::seconds(5)); | ||||||
| if (!serverCF->get_address_valid()) | ||||||
| tcAddressClaimedFuture.wait_for(std::chrono::seconds(5)); | ||||||
| if (!tcCF->get_address_valid()) | ||||||
| { | ||||||
| std::cout << "Failed to claim address for TC server. The control function might be invalid." << std::endl; | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| tcServer = std::make_shared<MyTCServer>(serverCF); | ||||||
| // Create TECU control function | ||||||
| // TODO: Should we wait between this and TC? | ||||||
| // TODO: If there's already a TECU on the bus we should not create ours | ||||||
| if (tcCF) | ||||||
| { // Only create TECU if TC was created | ||||||
| std::cout << "[Init] Creating Tractor ECU control function..." << std::endl; | ||||||
| tecuCF = isobus::CANNetworkManager::CANNetwork.create_internal_control_function(tecuNAME, 0, isobus::preferred_addresses::IndustryGroup2::TractorECU); | ||||||
| std::cout << "[Init] Tractor ECU control function created, waiting 1.5 seconds..." << std::endl; | ||||||
|
|
||||||
| // Update the network manager to process TECU CF claiming | ||||||
| for (int i = 0; i < 15; i++) | ||||||
| { | ||||||
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||||||
| isobus::CANNetworkManager::CANNetwork.update(); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| tcServer = std::make_shared<MyTCServer>(tcCF); | ||||||
| auto &languageInterface = tcServer->get_language_command_interface(); | ||||||
| languageInterface.set_language_code("en"); // This is the default, but you can change it if you want | ||||||
| languageInterface.set_country_code("US"); // This is the default, but you can change it if you want | ||||||
| tcServer->initialize(); | ||||||
| tcServer->set_task_totals_active(true); // TODO: make this dynamic based on status in AOG | ||||||
|
|
||||||
| // Initialize speed and distance messages | ||||||
| speedMessagesInterface = std::make_unique<isobus::SpeedMessagesInterface>(serverCF, true, true, true, false); //TODO: make configurable whether to send these messages | ||||||
| speedMessagesInterface->initialize(); | ||||||
| nmea2000MessageInterface = std::make_unique<isobus::NMEA2000MessageInterface>(serverCF, false, false, false, false, false, false, false); | ||||||
| nmea2000MessageInterface->initialize(); | ||||||
| nmea2000MessageInterface->set_enable_sending_cog_sog_cyclically(true); // TODO: make configurable whether to send these messages | ||||||
|
|
||||||
| speedMessagesInterface->wheelBasedSpeedTransmitData.set_implement_start_stop_operations_state(isobus::SpeedMessagesInterface::WheelBasedMachineSpeedData::ImplementStartStopOperations::NotAvailable); | ||||||
| speedMessagesInterface->wheelBasedSpeedTransmitData.set_key_switch_state(isobus::SpeedMessagesInterface::WheelBasedMachineSpeedData::KeySwitchState::NotAvailable); | ||||||
| speedMessagesInterface->wheelBasedSpeedTransmitData.set_operator_direction_reversed_state(isobus::SpeedMessagesInterface::WheelBasedMachineSpeedData::OperatorDirectionReversed::NotAvailable); | ||||||
| speedMessagesInterface->machineSelectedSpeedTransmitData.set_speed_source(isobus::SpeedMessagesInterface::MachineSelectedSpeedData::SpeedSource::NavigationBasedSpeed); | ||||||
| if (tecuCF) | ||||||
| { | ||||||
| std::cout << "[Init] Creating Speed Messages Interface on TECU..." << std::endl; | ||||||
| speedMessagesInterface = std::make_unique<isobus::SpeedMessagesInterface>(tecuCF, true, true, true, false); //TODO: make configurable whether to send these messages | ||||||
| speedMessagesInterface->initialize(); | ||||||
| speedMessagesInterface->wheelBasedSpeedTransmitData.set_implement_start_stop_operations_state(isobus::SpeedMessagesInterface::WheelBasedMachineSpeedData::ImplementStartStopOperations::NotAvailable); | ||||||
| speedMessagesInterface->wheelBasedSpeedTransmitData.set_key_switch_state(isobus::SpeedMessagesInterface::WheelBasedMachineSpeedData::KeySwitchState::NotAvailable); | ||||||
| speedMessagesInterface->wheelBasedSpeedTransmitData.set_operator_direction_reversed_state(isobus::SpeedMessagesInterface::WheelBasedMachineSpeedData::OperatorDirectionReversed::NotAvailable); | ||||||
| speedMessagesInterface->machineSelectedSpeedTransmitData.set_speed_source(isobus::SpeedMessagesInterface::MachineSelectedSpeedData::SpeedSource::NavigationBasedSpeed); | ||||||
| std::cout << "[Init] Speed Messages Interface created and initialized." << std::endl; | ||||||
|
|
||||||
| std::cout << "[Init] Creating NMEA2000 Message Interface on TECU..." << std::endl; | ||||||
| nmea2000MessageInterface = std::make_unique<isobus::NMEA2000MessageInterface>(tecuCF, false, false, false, false, false, false, false); | ||||||
| nmea2000MessageInterface->initialize(); | ||||||
| nmea2000MessageInterface->set_enable_sending_cog_sog_cyclically(true); // TODO: make configurable whether to send these messages | ||||||
| std::cout << "[Init] NMEA2000 Message Interface created and initialized." << std::endl; | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| std::cout << "[Warning] TECU Control Function not available, Speed/NMEA interfaces not created" << std::endl; | ||||||
| } | ||||||
|
|
||||||
| std::cout << "Task controller server started." << std::endl; | ||||||
|
|
||||||
| static std::uint8_t xteSid = 0; | ||||||
| static std::uint32_t lastXteTransmit = 0; | ||||||
|
|
||||||
| auto packetHandler = [this, serverCF](std::uint8_t src, std::uint8_t pgn, std::span<std::uint8_t> data) { | ||||||
| if (src == 0x7F && pgn == 0xFE) // 254 - Steer Data | ||||||
| auto packetHandler = [this, tcCF](std::uint8_t src, std::uint8_t pgn, std::span<std::uint8_t> data) { | ||||||
| if (src == 0x7F && pgn == 0xE5) // 229 - Section Data 1 to 64 | ||||||
| { | ||||||
| // TODO: hack to get desired section states. probably want to make a new pgn later when we need more than 16 sections | ||||||
| std::vector<bool> sectionStates; | ||||||
| for (std::uint8_t i = 0; i < 8; i++) | ||||||
| { | ||||||
| sectionStates.push_back(data[6] & (1 << i)); | ||||||
| } | ||||||
| for (std::uint8_t i = 0; i < 8; i++) | ||||||
| for (std::uint8_t scb = 0; scb < 8; scb++) | ||||||
|
||||||
| for (std::uint8_t scb = 0; scb < 8; scb++) | |
| for (std::uint8_t scb = 0; scb < 8; scb++) |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name 'scb' is unclear and cryptic. Consider using a more descriptive name like 'byteIndex' or 'sectionByte' to improve code readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is missing proper capitalization at the start. It should be: "Element work state management: these act like master/override for actual sections" or split into a proper sentence structure.