SI message port: WIKI error?

Help creating logic scripts for Air Manager Instruments

Moderators: Ralph, russ

Message
Author
JackZ
Posts: 1852
Joined: Mon Feb 22, 2016 1:02 pm

SI message port: WIKI error?

#1 Post by JackZ » Sun Apr 18, 2021 5:04 pm

Hi Guys.

I'm trying to implement my first instrument that uses message_port().

the Wiki example page https://siminnovations.com/wiki/index.p ... agePort.29 for message port include's a code for the Arduino has only one line for the include:

Code: Select all

#include <si_message_port.hpp>
But when I import the current library and use the IDE menu Sketch/Include library/Si message port,
i end up with a whole bunch of includes.

Code: Select all

#include <sim_extern_client.h>
#include <sim_extern_shared.h>
#include <si_base.h>
#include <si_circular_data.h>
#include <si_input_buffer.h>
#include <si_message_port.h>
#include <si_message_port_driver.h>
#include <si_network.h>
#include <si_output_buffer.h>
Is it a problem in the Wiki page only, such as a previous version, or did I do something wrong when importing the message port library into the Arduino IDE library (using Arduino IDE 1.8.3)?

Thanks

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

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

Re: SI message port: WIKI error?

#2 Post by lonespace » Sun Apr 18, 2021 7:07 pm

I can verify that from experimentation,

Code: Select all

 #include <si_message_port.hpp>
Is the only one you need for message port functions

User avatar
Corjan
Posts: 2371
Joined: Thu Nov 19, 2015 9:04 am

Re: SI message port: WIKI error?

#3 Post by Corjan » Sun Apr 18, 2021 7:12 pm

Hi,


Not sure what the IDE generates, but you only need that one.


Corjan

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

Re: SI message port: WIKI error?

#4 Post by JackZ » Sun Apr 18, 2021 7:15 pm

Thanks Guys. @Corjan
So there is definitely something wrong with the latest Arduino IDE, as using the Sketch/Include library/Si message port menu of the IDE imports all these #includes in the code.
Not that a big deal, since one has to manually remove the wrong includes and insert the correct line to use the library. But confusing to say the least, perhaps something is wrong with the way the SI library is installed in the IDE?

While I am at it, I am trying my luck with the Adafruit library for SSD1306 OLEDS that use SPI. No luck so far
It seems that SPI comm interferes with AM Message Port, as my displays go blank as soon as I add a messagePort constructor in my Arduino Code.

Is it the case (SPI interferes with AM), or am I doing something wrong?
If SPI interferes, that basically renders the Message Port way less desirable, as plenty of displays use either SPI or i2C protocol to communicate with the arduino, and the main purpose of message port is to be able to implement non AM supported hardware, among them displays.

Thanks

Jacques
Last edited by JackZ on Mon Apr 19, 2021 7:21 am, edited 3 times in total.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

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

Re: SI message port: WIKI error?

#5 Post by lonespace » Sun Apr 18, 2021 7:45 pm

I’m able to use i2c with the message port, and I can’t see how the message port would interfere with any SPI implementation. Try to create the simplest possible test script that implements both to see if the conflict lies somewhere else in your code.

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

Re: SI message port: WIKI error?

#6 Post by JackZ » Sun Apr 18, 2021 9:43 pm

@lonespace Good advice, thanks!
That’s what I did here, still with no messages on the console. Weird.
https://siminnovations.com/forums/view ... 350#p35350

I'm currently implementing the test code from the excellent Tony's video on MessagePort (wished @Sling had supplied the whole C++ Arduino & AM lua codes in the comments of the vid, BTW :cry: ), so far still nothing appears in the console.

For other people that might be interested, here are the codes copied from the video.

AM test instrument:

Code: Select all

-- This function will be called when a message is received from the Arduino MEGA_2560_D7 is pulled LOW.
function message_callback(id, payload)
    payload_str=""
    i=0
    for _ in pairs(payload) do
        i = i + 1
        if i == 1 then
                 payload_str = tostring(payload[i])
        else 
                payload_str=payload_str..","..tostring(payload[i]) 
        end
    end  
    print("Message received with id:"..id.." and payload of :"..payload_str)
end 


msg_port_id = hw_message_port_add("My_message_port", message_callback)

function button_press()
    state = not state
    send_int = fif(state == true, 1, 0)
    -- sata type can be INT, INT[n],FOAT,FLOAT[n}, BYTE, BYTE[n] or STRING
    hw_message_port_send(msg_port_id, 7, "INT[2]", {send_int, 3})
    hw_message_port_send(msg_port_id, 8, "STRING", "This is a TEST")

end

button_id = button_add(nil, nil,0, 0, 100, 100, button_press)
And the Arduino code.

Code: Select all

/*
	Sim Innovations Message Port example:
	
	In this example we can communicate with Air Manager or Air Player over a standard USB cable.
	This is done using the Message Port library.
	
	See the code below on how to implement this library.
	
	More information on how to implement the Air Manager or Air Player side can be found here:
	https://siminnovations.com/wiki/index.php?title=Hw_message_port_add
	
	
	NOTE: 
	The Message Port library communicates with the PC using Serial Port 0 of the Arduino.
	Do not use Serial port 0 yourself!
*/

#include <si_message_port.hpp>

SiMessagePort* messagePort;
int led=13;
int button1=7;
int button_live=LOW;
int button_current= HIGH;

unsigned long last_debounce_time=0;
unsigned long debounce_wait=50;

static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
	// Do something with a message from Air Manager or Air Player
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_TRACE,String(payload->type));
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO,String(payload->len));
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_WARN,"WARNING");
messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_ERROR,"ERROR");
 
if (message_id==7) {
  digitalWrite(led,payload->data_int[0]);
  messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_DEBUG,String(payload->data_int[1]));
} else if (message_id==8) {
    messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_DEBUG,String(payload->data_string));
  }
}	
	
	// The arguments are only valid within this function!
	// Make a clone if you want to store it

//	if (payload == NULL) {
//		messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received without payload");
//	}
//	else {
//		switch(payload->type) {
//			case SI_MESSAGE_PORT_DATA_TYPE_BYTE:
//				messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received " + payload->len + " bytes: " + payload->data_byte[0]);
//				break;
//			case SI_MESSAGE_PORT_DATA_TYPE_STRING:
//				messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received string: " + payload->data_string);
//				break;
//			case SI_MESSAGE_PORT_DATA_TYPE_INTEGER:
//				messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received " + payload->len + " integers" + payload->data_int[0]);
//				break;
//			case SI_MESSAGE_PORT_DATA_TYPE_FLOAT:
//				messagePort->DebugMessage(SI_MESSAGE_PORT_LOG_LEVEL_INFO, (String)"Received " + payload->len + " floats" + payload->data_float[0]);
//				break;
//		}

 
void setup() {
	// Init library on channel A and Arduino type MEGA 2560
	messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_MEGA_2560, SI_MESSAGE_PORT_CHANNEL_A, new_message_callback);
        pinMode(led,OUTPUT);
        pinMode(button1,INPUT_PULLUP);
}

void loop() {
	// Make sure this function is called regularly
  messagePort->Tick();
  int button_read=digitalRead(button1);
  if (button_read!=button_live) {
      last_debounce_time= millis();
  }
  if ((millis()-last_debounce_time)>debounce_wait) {
    if (button_read!=button_current) {
      button_current=button_read;
      uint8_t payload[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
      messagePort->SendMessage(2,payload,8);
    }
	// You can send your own messages to Air Manager or Air Player
	//messagePort->SendMessage(123);
	//messagePort->SendMessage(123, "hello");
	//messagePort->SendMessage(123, (int32_t)1000);
	//messagePort->SendMessage(123, 2.5f);
	//messagePort->SendMessage(123, (uint8_t) 0xAA);
  
  }
  button_live=button_read;
}
I can see the TX led blinking when i connect the pin#7 to ground but there is absolutely no message on the console neither coming IN or OUT. Same applies when i press the virtual button on the AM instrument side.
And in Air Manager the Arduino is recognized, and the Message Port is displayed as "Active" in the Device tab.

Out of options here, so any help greatly appreciated.

Jacques
Last edited by JackZ on Mon Apr 19, 2021 7:28 am, edited 3 times in total.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

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

Re: SI message port: WIKI error?

#7 Post by Sling » Mon Apr 19, 2021 3:02 am

@JackZ I’ve also had that comment before and you are absolutely right. We missed a trick there. Unfortunately I don’t have the AM code anymore but I purposely made the text size large so you can at least get it from the video. I may still have the Arduino sketch if that may be useful. I’d have to check though.

I’ll take a look at your code when I next get some AM time to see if I spot anything.

Tony

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

Re: SI message port: WIKI error?

#8 Post by JackZ » Mon Apr 19, 2021 7:10 am

@Sling No worries, I ended up by completely reconstructing your code from the video which was readable enough.
If I didn’t do a copy mistake, you’ll find both the Arduino and the Lua code in my previous post. Both codes are available for you to reuse in the YT video comments, as I feel this should be part of the tutorial to be complete, as the codes are quite long. Your tutorial videos are brilliant btw.

Thanks for taking some time to look at my problem.
Kinda frustrating, I am that close to complete my project, all the pure Arduino part is done, the 4 OLEDS displays work fine, the only thing lacking is the AM communication via message port to render it usable.

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

User avatar
jph
Posts: 666
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: SI message port: WIKI error?

#9 Post by jph » Mon Apr 19, 2021 9:33 am

@JackZ
Hello Jacques,

Just to test basic comms only - one way -

Try this code.

Code: Select all

#include <si_message_port.hpp>
SiMessagePort* messagePort;

// for our delay interval
int interval = 500;
unsigned long millis_now = 0;

static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
  // We received a message from Air Manager or Air Player
}

void setup() {
  messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_MEGA_2560, SI_MESSAGE_PORT_CHANNEL_A, new_message_callback);
}
void loop() {
  messagePort->Tick();
    if(millis() >= millis_now + interval){
        millis_now += interval;
    // Send a message with id 777 
    messagePort->SendMessage(777); 
  }
}
and,

Code: Select all

-- This function will be called when a message is received from the Arduino.
function new_message(id, payload)
  print("received new message with id " ..id)
end

id = hw_message_port_add("My message port", new_message)
This purely sends a message with an ID of 777 from Arduino to AM, nothing more.
But at least tests the link.
Please also make sure the hardware attaches prior to running the AM code, it can take between 10 and 20 seconds ! - or it does here ! :shock:
You can change the Arduino delay by varying the - int interval =

Would also be interested in how long the HW takes to connect. (I am using AM4.X here) - but will test with AM 3.X ) --- oops, doesnt work in AM 3.x ..................................
regards,
Joe
Last edited by jph on Mon Apr 19, 2021 9:47 am, edited 1 time in total.
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

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

Re: SI message port: WIKI error?

#10 Post by Sling » Mon Apr 19, 2021 9:34 am

Jacques,

The code looks good other than you are using named hardware for the hw_message_port_add() function. I'm not sure if this is supported for Message port as its designed for custom hardware and likely won't be used by others so the id can be fixed to hardware.

Tony

If it works by changing it, can you update your post with the video code so others have the correct working code.

Thanks

Tony
Last edited by Sling on Mon Apr 19, 2021 10:39 am, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests