Receiving multiple messages from message port

Discuss suspected bugs with other users and Sim Innovations Staff

Moderators: russ, Ralph

Message
Author
alkargr
Posts: 14
Joined: Tue Feb 25, 2020 6:34 pm

Receiving multiple messages from message port

#1 Post by alkargr »

When you have more than one instruments that receive messages from the same hardware_id, the instrument gets the same message times the number of instruments.

E.g. If you have instr A with id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message) and instrB with id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message),
and you send one message from arduino, you get 2 messages to both instruments.

And if the message is for example to execute a function to type letter A on scratchpad of FMS, then you get AA.
If the message is to toggle something ON/OFF then you get OFF->ON->OFF.

I used timer to ignore redundant messages, but that's not the solution.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Receiving multiple messages from message port

#2 Post by Sling »

Hi,

Your example is not 2 instruments as you state but 2 message port links added to the same instrument. Why are you adding the same message port link twice. Just pass the data via one only.

lonespace
Posts: 64
Joined: Wed Mar 25, 2020 1:58 am

Re: Receiving multiple messages from message port

#3 Post by lonespace »

I’m not sure you read it right, @Sling. From the description, he’s got two instruments with the message port connection set up (instr a and instr b)

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Receiving multiple messages from message port

#4 Post by Sling »

Hi,

Thanks lonespace. Upon reading again I think I latched onto the idea that you wouldn’t do what the OP is doing and convinced myself it was therefore within the same instrument. Either way both are flawed.

With that in mind, on to the original question. You shouldn’t be trying to communicate with the same message port board from 2 separate instruments. The best way to do what you want would be to do the message port comms in one of your instruments and then pass whatever the other instrument needs via iic (inter instrument communication). That’s specifically what iic is for.

Hope this helps you arrive at a better solution. Let us know if you have questions about iic but if you have message port working it should be easy to get to grips with iic.

Tony

alkargr
Posts: 14
Joined: Tue Feb 25, 2020 6:34 pm

Re: Receiving multiple messages from message port

#5 Post by alkargr »

That's a good idea! I'll try it with si commands.
Thank you!

JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Receiving multiple messages from message port

#6 Post by JackZ »

You could try to differentiate the receiving instrument’s target by the payload ID, ie reserving messages in the 0-99 I’d range for Inst A, then say in the 1000-1099 for inst B?

In the Arduino code you check the payload ID then react only to the ID range it’s supposed to work with?
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

lonespace
Posts: 64
Joined: Wed Mar 25, 2020 1:58 am

Re: Receiving multiple messages from message port

#7 Post by lonespace »

That still doesn’t solve the problem of the duplicate messages

JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Receiving multiple messages from message port

#8 Post by JackZ »

@lonespace So if you have a ready made solution, I’d love to know it.

The payload ID should do the trick, since the « redundant » messages will have a different ID so each instrument can just ignore the non relevant one.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

lonespace
Posts: 64
Joined: Wed Mar 25, 2020 1:58 am

Re: Receiving multiple messages from message port

#9 Post by lonespace »

@JackZ I don’t think that’ll work; from the sounds of it, if you send:
Message ID=1, payload 0x5F intended for instrument A
Message ID=2, payload 0xB2 intended for instrument B

Both instruments will receive *two copies* of both payloads. If you tell instrument A to ignore payload 2, you still have to code instrument A to also ignore duplicate payload 1’s

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Receiving multiple messages from message port

#10 Post by Sling »

I think my suggestion of iic or the method suggested by @JackZ should work. Without knowing how much data is passing it’s hard to say which approach would be best for the application.

Post Reply