Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] Import C files in XPT project
[XPAND] Import C files in XPT project [message #835407] Tue, 03 April 2012 07:03 Go to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi everybody,

I would like to know if it possible to use a file .C in a xpand project. My purpose is to use file .C for generate some value, and i would like to recover this value and use it in my XPT files.

Thanks in advance for your reply.

Best regards,
Re: [XPAND] Import C files in XPT project [message #835564 is a reply to message #835407] Tue, 03 April 2012 11:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

please define "use a file .C" do you mean parse it and generate something out of it? this is surely possible but you have to do it yourself e.g. leveraging Eclipse CDT to gain access to the ast
.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #835572 is a reply to message #835564] Tue, 03 April 2012 12:11 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi and thanks for your reply,

I mean : I have a function in a .C files, that function generates a value (CRC) with 4 arguments in entrance.

My goal, is to use my arguments define in my XPT project and call the function from the C files to generate the value (CRC). And in last, recover the value from the C file and integrate their in my XPT project.

I hope i'm more specific in my request.

Best Regards,
Re: [XPAND] Import C files in XPT project [message #835575 is a reply to message #835572] Tue, 03 April 2012 12:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

have never done something but

Xpand -> Java Extension -> Java Class using Java Native Interface (JNI) -> C should/could work

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #835578 is a reply to message #835575] Tue, 03 April 2012 12:20 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi,

I'm a beginner in OAW and I never do something like that with Java but i'm going to try like you said.

Thanks,
Re: [XPAND] Import C files in XPT project [message #835581 is a reply to message #835578] Tue, 03 April 2012 12:25 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi,

Could you please be more explicative for doing this :
Xpand -> Java Extension -> Java Class using Java Native Interface (JNI) -> C ?

I'm sorry but that only 2 weeks i'm working with OAW...

Regards,
Re: [XPAND] Import C files in XPT project [message #835590 is a reply to message #835581] Tue, 03 April 2012 12:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

in XPand you can use Java Extensions (calling java code)
see the docs http://help.eclipse.org/indigo/topic/org.eclipse.xpand.doc/help/Xtend_language.html
JNI is a Java Thing and thus has nothing special with Xpand so Google is your friend.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #835594 is a reply to message #835407] Tue, 03 April 2012 12:46 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Somehow you would have to get the information from the C file into something that Xpand can interpret. Xpand ships with typesystems for Java, EMF, XSD and EMF UML2. Most likely you would use the JavaBeans Metamodel, which acts on Java Beans. And somehow you would have to transform the C information into Java Beans.

It is not a typical use case for us, but if we would be faced this problem in a project, we would find a way to get it done. Christian's idea is to use the CDT tooling to create Java classes from C code. This might be a way to go. And what he proposes has nothing to do with Xpand first. Think simply that you somehow need a Java object, which holds all the information.

Don't get it wrong, but this is a somehow advanced topic. It will be solvable for sure, but will require some more knowledge. We can only give you an idea of a solution, not the solution itself.

Regards,
~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: [XPAND] Import C files in XPT project [message #835616 is a reply to message #835594] Tue, 03 April 2012 13:11 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi,

Of course i understand. I'm going to work with your suggestion and try to do something which could work.

Thank you very much to both of you.

Regards,
Re: [XPAND] Import C files in XPT project [message #837274 is a reply to message #835616] Thu, 05 April 2012 13:16 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi,

I have did some research about my problem. There is an IDE : Eclipse IDE for C/C++ Developers which can be add to eclipse. It-is possible by this way to communicate between the C code and the XPT code, or it is forced to use a Java gateway to resolve my problem.

I try to find another option to my problem because i have no knowledge in JAVA. But if there is no other way to resolve my problem, i'm going to be forced to learn this language.

Thanks,
Re: [XPAND] Import C files in XPT project [message #837280 is a reply to message #837274] Thu, 05 April 2012 13:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i do not know of such a support. xpand has a possibility to use CDT Beautifier. but thats something different.
but i do not think you need to learn Java with all its possibilities and libaries to do a single JNI call.
other way rould: using JNI is a thing a java programmer ususally does not do Wink


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #840722 is a reply to message #835407] Tue, 10 April 2012 12:47 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi,

Finally i decide to developped a new JAVA application which did the same work as my .C file.

Now I have to find the way to use my java function into my XPAND File.

My java file:
package javaapplication1;

import java.util.*;

public class JavaApplication1 {
    
    public static final int CRC_HEADER_POLY = 0x385;
    public static final int CRC_HEADER_INIT = 0x1a;
    public static final int CRC_HEADER_DEGRE_POLY = 11;
    public static final int CRC_HEADER_DATA_LENGTH = 20;
    
    /*public static void main(String[] args) 
            {
            //calculation(9, 16, 0, 0);
            System.out.println(calculation(9, 16, 0, 0));
            }*/
    
    public static int create_header(int frame_id,int payload_length,int sync_bit,int startup_bit)
            {
             return ((sync_bit<<19)|(startup_bit<<18)|(frame_id<<7)|payload_length);
            }

    public static int result(int frame_id,int payload_length,int sync_bit,int startup_bit)
            {
                int shiftreg = CRC_HEADER_INIT;
		int i;
		int bit;
		int data;
		//data=0x00490;
		data=create_header(frame_id,payload_length,sync_bit,startup_bit);
		for(i = CRC_HEADER_DATA_LENGTH-1; i>=0; i--) {

			bit = ((shiftreg >> (CRC_HEADER_DEGRE_POLY-1)) &0x1) ^ ((data >> i) & 0x1);

			shiftreg <<= 1;

			if(bit==1) shiftreg ^= CRC_HEADER_POLY;

			shiftreg &= (1 << CRC_HEADER_DEGRE_POLY)-1;

		}
		return shiftreg;

            }
    
    public static int calculation(int frame_id,int payload_length,int sync_bit,int startup_bit)
        {
        return result(frame_id,payload_length,sync_bit,startup_bit);
        }
    

}    


I want to call the function "calculation", and catch the result which is return.

So I'm going to seek information into the different documentation. If you have an idea about this, i'll be glad to be help.

Regards,

[Updated on: Tue, 10 April 2012 12:48]

Report message to a moderator

Re: [XPAND] Import C files in XPT project [message #840760 is a reply to message #840722] Tue, 10 April 2012 13:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi search the docs for JAVA Extension

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #855083 is a reply to message #840760] Tue, 24 April 2012 13:59 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi,

I had make a break in my application. Now i'm starting again. I'm still confuse about XPAND/XTEND/JAVA. In the documentation of XTEND process, thay said that : "In some rare cases one does want to call a Java method from inside an expression".

Maybe it be better to create directly my function into the XTEND file maybe? Because my java function isn't so bigger and difficult to implement.

Regards,
Re: [XPAND] Import C files in XPT project [message #855343 is a reply to message #855083] Tue, 24 April 2012 18:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

theoretically yes. practically no: Xpand/Xtend do not support Bitshifting stuff.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #855866 is a reply to message #855343] Wed, 25 April 2012 07:03 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Okay thank you for your answer.

So i have to stay with my java applet. In the documentation I found, i learn that to call an java applet i have to create an XTEND file which can do the work.
About my java applet, i have to include the java file and my java class into my project that right?

Regards
Re: [XPAND] Import C files in XPT project [message #855878 is a reply to message #855866] Wed, 25 April 2012 07:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Yes. You could alternatively bundle it as a jar file and add this one
to the classpath


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #855879 is a reply to message #855866] Wed, 25 April 2012 07:17 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
My question seems a little stupid but i did my java applet into the software NetBeans IDE. And into my applet, i have different file like 3 folders : Build / nbproject /src (in this folder, i have my java file and his class) and two files : build / manifest.mf .

That why i'm asking, which file I have to include into my XPAND project. I thinking, that I have to include just my java files and java class but i'm not sure.

Regards,
Re: [XPAND] Import C files in XPT project [message #855892 is a reply to message #855879] Wed, 25 April 2012 07:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Du you have jdt (java dev tools) in your eclipse. If yes simply drop
the .java file into the source folder of your expand project


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #855893 is a reply to message #855879] Wed, 25 April 2012 07:31 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Okay, So I include just my java file and my java class. It works without problem. But into my java file it stay a warning : "the import java.util is never used". I think it's not a problem for me...
Re: [XPAND] Import C files in XPT project [message #855958 is a reply to message #855893] Wed, 25 April 2012 08:37 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Okay, now i'm going to use the XTEND file for calling my java applet. In the documentation the say that i have to call the function i want like this : "String timestamp() :
JAVA datamodel.generator.util.TemplateUtils.timestamp();"

So, referring to my code I had post in my last message, i think i have to do this :

Integer calculation(Integer frame_id,Integer payload_length,Integer sync_bit,Integer startup_bit) :
JAVA calculation(Integer frame_id,Integer payload_length,Integer sync_bit,Integer startup_bit;

Do you think it's correcT?
Re: [XPAND] Import C files in XPT project [message #855963 is a reply to message #855958] Wed, 25 April 2012 08:40 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Sorry mistake :

Integer calculation(Integer frame_id,Integer payload_length,Integer sync_bit,Integer startup_bit) :
JAVA utilCRC.JavaApplication1.calculation(Integer frame_id,Integer payload_length,Integer sync_bit,Integer startup_bit;

The name of my Xtend file is utilCRC.
Re: [XPAND] Import C files in XPT project [message #855972 is a reply to message #855963] Wed, 25 April 2012 08:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Guess you have to write java.lang.Integer

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #855973 is a reply to message #855972] Wed, 25 April 2012 08:52 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
I have to include these library into my XTEND file?
Re: [XPAND] Import C files in XPT project [message #855997 is a reply to message #855973] Wed, 25 April 2012 09:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

JAVA extensions dont like primitives.
and: your syntax is totally wrong

I actually mean as an example:

src/de/itemis/test/TestExtension.ext
Integer calculation(Integer frame_id,Integer payload_length,Integer sync_bit,Integer startup_bit) :
JAVA de.itemis.test.TestExtension.calculation(java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer);

src/de/itemis/test/TestExtension.java
package de.itemis.test;
public class TestExtension {
    public static Integer calculation(Integer frame_id,Integer payload_length,Integer sync_bit,Integer startup_bit) {
        return 42;    
    }
}}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #856033 is a reply to message #855997] Wed, 25 April 2012 09:57 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Okay, i really don't know that JAVA extensions don't likes primitives.

So i did this :

src/javaapplication1/JavaApplication1.ext
Integer calculation(Integer frame_id,Integer payload_length,Integer sync_bit,Integer startup_bit) :
JAVA javaapplication1.JavaApplication1.calculation(java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer);


src/javaapplication1/JavaApplication1.java
public class JavaApplication1 {

public static int calculation(int frame_id,int payload_length,int sync_bit,int startup_bit)
        {
        return result(frame_id,payload_length,sync_bit,startup_bit);
        }
}



My EXT file follow me an erro into :
calculation(java.lang.Integer,java.lang.Integer,java.lang.Integer,java.lang.Integer);


It says that the function calcultion isn't found.

Re: [XPAND] Import C files in XPT project [message #856060 is a reply to message #856033] Wed, 25 April 2012 10:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
As I said: you need objects instead of primitives in the java class

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #856117 is a reply to message #856060] Wed, 25 April 2012 11:34 Go to previous messageGo to next message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Hi,

Sorry, i have forgot this part. Indeed, now it's working. Now, i have to use my function into my XPT file. In the documentation they used "EXTENSION" properties to call the different files? It is the same in my case?
Re: [XPAND] Import C files in XPT project [message #856155 is a reply to message #856117] Wed, 25 April 2012 12:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Yes

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [XPAND] Import C files in XPT project [message #856402 is a reply to message #856155] Wed, 25 April 2012 16:20 Go to previous message
Ricardo Ben Amor is currently offline Ricardo Ben AmorFriend
Messages: 51
Registered: March 2012
Member
Thanks for your help again Christian. My applet works perfectly
Previous Topic:[XPand, mwe] Call "javac" and "jar" within workflow?
Next Topic:model xmi
Goto Forum:
  


Current Time: Fri Mar 29 00:31:07 GMT 2024

Powered by FUDForum. Page generated in 0.06462 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top