Communication between a Java Agent and a C application with Legato


#1

Hello

What is the best way of communication beween a Java Agent and a C application with Legato? We need the Java agent to call propietary AT commands inside a C application. Java Agent need sto call to the AT command inside the C application. What is the best way of doing this? We should use IPC and defining an IDL interface or there´s a better way?

Is there already a sample providing a similar functionality?

Thanks

Isabel


How to install the embedded JVM on target?
#2

The recommended way of doing this with Legato is to write a small stub using JNI. The C-side of the stub is compiled as a stand-alone Legato component, allowing it to call Legato APIs. This stub then can be called from your Java application to get access (indirectly) to the Legato functionality.

Here’s a sample app which showing the technique (accessing the positioning & sms APIs from Java): java-sample.zip (7.6 KB). The main Java application is in java-sample/JavaTest, and smsBridge and positioningBridge are the stubs.

Hope that helps.


#3

Thank you kdunwoody

Case is a little more complex. We will use Java agent JNI to call Legato API libraries in “C”

We have
• One process A (Agent A) implementing a propietary AT commands and business logic.
• Sencond process B (Agent B) in charge of monitoring process and update of Agent A .

Attach the diagram

• Can we do calls to AT ad-hoc commands from process B so it´s process A the one sending the commands and receiving the answers as if it was a serial port behaviour?
• If it´s not possible, Can we use IPC to communicate both process? Is there any sample in Java?

Thank you

IsabelJava Agent.docx (49.8 KB)


#4

I’m not sure about AT commands (not my area). Maybe you could open /dev/ttyAT from inside process B and send/receive commands that way?

Legato .api are the interface definitions for an IPC mechanism, so you can:

  1. create your own .api file defining the interface you need,
  2. implement the API in your C program (as described in http://legato.io/legato-docs/latest/basicAppsIPC.html#basicAppsIPC_helloIPCCreateServer), and then
  3. call it in your Java program (as shown in my sample).