Closed mennolodder closed 9 months ago
Quoted from https://github.com/sharpbrick/powered-up/issues/58#issuecomment-1891022068 :
This should not be. Either we discover the device OR use static port inform messages. Do not remember why the behavior is like that. Device enumeration not necessarily need to discover the devices but my just pretty print our existing knowledge.
When doing device dump-static-port -p 0
. I see that the first message we receive is:
< 0F-00-04-00-01-2E-00-00-10-00-00-00-10-00-00
Which is HubAttachedIOForAttachedDeviceMessage
. This message is handled in the KnowledgeManager
in ApplyDynamicProtocolKnowledge
(called from LegoWirelessProtocol.ConnectAsync()
. This is implemented as follows:
case HubAttachedIOForAttachedDeviceMessage msg:
hub = knowledge.Hub(msg.HubId);
port = knowledge.Port(msg.HubId, msg.PortId);
ResetProtocolKnowledgeForPort(msg.HubId, port.PortId, knowledge);
port.IsDeviceConnected = true;
port.IOTypeId = msg.IOTypeId;
port.HardwareRevision = msg.HardwareRevision;
port.SoftwareRevision = msg.SoftwareRevision;
AddCachePortAndPortModeInformation(msg.IOTypeId, msg.HardwareRevision, msg.SoftwareRevision, hub, port, knowledge, deviceFactory);
Which loads the static information.
I don't know much about this part yet, but for port / device discovery it would be clean to not load the static information. However we could also make this more robust by making sure the info is overwritten when never info is received (that might lead to a less consistent state though).
The first option seems best, we could make that a protocol feature (use dumps or discover)
Discovery should start fresh. And an explicit operation. The protocol is IMHO from LEGO itself used without discovering the knowledge. Discovery takes far too long for a regular protocol usage, no matter use the case. 30 seconds or what it is, is just too long to start a remote. Discovery is for development or unknown devices.
Thanks for fixing this.
When running
device list
ordevice dump-static-port
the application seems to send all the port information requests but still uses the old static info.See the situation below where the motor had 6 modes in the static port info, but 5 in reality. Eventhough the motor reported 5 modes earlier, the 6th (index 5) is also requested and results in an error.
It goes wrong here:
The reply translates as: Error - Port Mode Information Request - Port 0 - Invalid use (e.g. parameter error(s)
Which makes sense, because it is requesting mode 5 (so the 6th mode) where earlier the device announced 5 modes (( checked, the bold number is 'Total Mode Count'_:
I didn't doublecheck this, but this probably is because the TechnicLargeLinearMotor.GetStaticPortInfoMessages announces 6 modes: 0B-00-43-00-01-0F-06-1E-00-1F-00
For my motor it outputs this version info. could this be two versions?
If I remove the static port info messages it works and I get:
Here are the differences with what is checked in: