function TLccNode.ProcessMessage(SourceLccMessage: TLccMessage): Boolean;
var
TestNodeID: TNodeID;
Temp: TEventID;
AddressSpace, OperationType, TractionCode: Byte;
DoDefault: Boolean;
begin
// By the time a messages drops into this method it is a fully qualified OpenLCB
// message. Any CAN messages that are sent as multi frames have been combined
// into a full OpenLCB message.
Result := False;
TestNodeID[0] := 0;
TestNodeID[1] := 0;
// First look for a duplicate NodeID
if EqualNodeID(NodeID, SourceLccMessage.SourceID, False) then
begin
Logout;
Exit;
end;
// Next look to see if it is an addressed message and if not for use just exit
if SourceLccMessage.HasDestination then
begin
if not IsDestinationEqual(SourceLccMessage) then
Exit;
end;
case SourceLccMessage.MTI of
MTI_OPTIONAL_INTERACTION_REJECTED :
begin
// TODO need a call back handler
end;
// *************************************************************************
// *************************************************************************
MTI_VERIFY_NODE_ID_NUMBER :
begin
if SourceLccMessage.DataCount = 6 then
begin
SourceLccMessage.ExtractDataBytesAsNodeID(0, TestNodeID);
if EqualNodeID(TestNodeID, NodeID, False) then
begin
WorkerMessage.LoadVerifiedNodeID(NodeID, GetAlias);
SendMessageFunc(WorkerMessage);
end
end else
begin
WorkerMessage.LoadVerifiedNodeID(NodeID, GetAlias);
SendMessageFunc(WorkerMessage);
end;
Result := True;
end;
MTI_VERIFY_NODE_ID_NUMBER_DEST :
begin
WorkerMessage.LoadVerifiedNodeID(NodeID, GetAlias);
SendMessageFunc(WorkerMessage);
Result := True;
end;
MTI_VERIFIED_NODE_ID_NUMBER :
begin
// TODO need a call back handler
end;
// *************************************************************************
// *************************************************************************
MTI_SIMPLE_NODE_INFO_REQUEST :
begin
WorkerMessage.LoadSimpleNodeIdentInfoReply(NodeID, GetAlias, SourceLccMessage.SourceID, SourceLccMessage.CAN.SourceAlias, ProtocolSimpleNodeInfo.PackedFormat(StreamManufacturerData, StreamConfig));
SendMessageFunc(WorkerMessage);
Result := True;
end;
MTI_SIMPLE_NODE_INFO_REPLY :
begin // Called if I send a SNIP Request and the other node replies
// TODO need a call back handler
Result := True;
end;
// *************************************************************************
// *************************************************************************
MTI_PROTOCOL_SUPPORT_INQUIRY :
begin
WorkerMessage.LoadProtocolIdentifyReply(NodeID, GetAlias, SourceLccMessage.SourceID, SourceLccMessage.CAN.SourceAlias, ProtocolSupportedProtocols.EncodeFlags);
SendMessageFunc(WorkerMessage);
Result := True;
end;
MTI_PROTOCOL_SUPPORT_REPLY :
begin // Called if I send a Protocol Support and loads the ProtocolSupportedProtocols with the data
// TODO need a call back handler
Result := True;
end;
// *************************************************************************
// Producer/Consumer tell me what events do you care about (for routers, getting mass
// results for the state of the layout
// *************************************************************************
MTI_EVENTS_IDENTIFY :
begin
SendConsumedEvents;
SendProducedEvents;
Result := True;
end;
MTI_EVENTS_IDENTIFY_DEST :
begin
SendConsumedEvents; // already known the destination is us
SendProducedEvents;
Result := True;
end;
// *************************************************************************
// General Producer/Consumer Queries
// *************************************************************************
MTI_PRODUCER_IDENDIFY :
begin
// First see if we have any built in producers we can to reply automatically
// Note that the expectation is the app is maintaining the state of the event
// objects in parallel through the TProtocolEventsProduced object (Clear/Set/Unkown)
// Let the application have a crack
DoDefault := True;
(NodeManager as INodeManagerCallbacks).DoProducerIdentify(Self, SourceLccMessage, DoDefault);
if DoDefault then
begin
Temp := SourceLccMessage.ExtractDataBytesAsEventID(0);
SendProducerIdentify(Temp); // Compatible with Smart Pascal
end;
Result := True;
end;
MTI_CONSUMER_IDENTIFY :
begin
// First see if we have any preregistred consumers that we use that
// we can to reply automatically, we are not the producers so we
// don't need to keep the state upto date
// Let the application have a crack
DoDefault := True;
(NodeManager as INodeManagerCallbacks).DoProducerIdentify(Self, SourceLccMessage, DoDefault);
if DoDefault then
begin
Temp := SourceLccMessage.ExtractDataBytesAsEventID(0);
SendConsumerIdentify(Temp); // Compatible with Smart Pascal
end;
Result := True;
end;
// *************************************************************************
// This block of messages is if we sent at "Producer" or "Consumer" Identify
// and these are the results coming back... I am not sure what "Consumer" Identify
// needs different states as the replying node is not in control of the state only
// the "Producer" is in control
// *************************************************************************
MTI_CONSUMER_IDENTIFIED_CLEAR :
begin
..........