Skip to content

Partnered control function of VT is marked as offline when VT is started before my application #584

@tglane

Description

@tglane

Describe the bug
I have a small application where I try to display some text that I receive via MQTT on the VT. The problem is that whenever the VT is turned on before my application is started, the application will not work with the VT and indicate that the partnered control function is offline without ever responding to the address claim (See logs in the next section). If my application is started, claims its address and than the VT is turned on, everything works as expected.

As VT is used the AgIsoVirtualTerminal as well as a physical VT from my company.

I found a quick fix for my problem that I will present at the bottom of the issue, but I'm not sure if that is a correct way of handling the issue.

Supporting Documentation
Debug logging output of my applicaion:

[NM]: A control function claimed address 38 on channel 0
[AC]: Internal control function 900036002b800002 has arbitrarily claimed address 128 on channel 0
Address claim finished in async task
My name: 10376352915819331586
Claimed address: 128
[NM]: A partner with name a0001d00afe00000 has claimed address 38 on channel 0.
[TP]: New rx session for 0x0E600. Source: 38, destination: 128
[VT]: VT Server has a matching label for cff7e8a. It will be loaded and upload will be skipped.
[TP]: Session Closed
[TP]: Completed rx session for 0x0E600 from 38
[VT]: Loaded object pool version from VT non-volatile memory with no errors.
[NM]: Control function with address 38 and NAME a0001d00afe00000 is now offline on channel 0.
[VT]: Status Timeout

Environment (please complete the following information):

  • OS: [Ubuntu 22.04.5 LTS]
  • Compiler [arm-linux-gnueabi-gcc 11.4.0]
  • CAN Driver [Socket CAN]

Additional context
I took a quick look into the codebase and could "fix" the bug for my simple test setup by modifying the following function in can_network_manager.cpp by adding a single line to set claimedAddressSinceLastAddressClaimRequest to true for the address claiming control function so that it will not be pruned as inactive later.

	void CANNetworkManager::update_new_partners()
	{
		for (const auto &partner : partneredControlFunctions)
		{
			if (!partner->initialized)
			{
				// Remove any inactive CF that matches the partner's name
				for (auto currentInactiveControlFunction = inactiveControlFunctions.begin(); currentInactiveControlFunction != inactiveControlFunctions.end(); currentInactiveControlFunction++)
				{
					if ((partner->check_matches_name((*currentInactiveControlFunction)->get_NAME())) &&
					    (partner->get_can_port() == (*currentInactiveControlFunction)->get_can_port()) &&
					    (ControlFunction::Type::External == (*currentInactiveControlFunction)->get_type()))
					{
						inactiveControlFunctions.erase(currentInactiveControlFunction);
						break;
					}
				}

				for (const auto &currentActiveControlFunction : controlFunctionTable[partner->get_can_port()])
				{
					if ((nullptr != currentActiveControlFunction) &&
					    (partner->check_matches_name(currentActiveControlFunction->get_NAME())) &&
					    (ControlFunction::Type::External == currentActiveControlFunction->get_type()))
					{
						// This CF matches the filter and is not an internal or already partnered CF
						// Populate the partner's data
						partner->address = currentActiveControlFunction->get_address();
						partner->controlFunctionNAME = currentActiveControlFunction->get_NAME();
						partner->initialized = true;
						controlFunctionTable[partner->get_can_port()][partner->address] = std::shared_ptr<ControlFunction>(partner);
						controlFunctionTable[partner->get_can_port()][partner->address]->claimedAddressSinceLastAddressClaimRequest = true; // I added just this line
						process_control_function_state_change_callback(partner, ControlFunctionState::Online);

						LOG_INFO("[NM]: A partner with name %016llx has claimed address %u on channel %u.",
						         partner->get_NAME().get_full_name(),
						         partner->get_address(),
						         partner->get_can_port());
						break;
					}
				}
				partner->initialized = true;
			}
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions