Home » Modeling » M2T (model-to-text transformation) » [XPAND] Import C files in XPT project
| | | | | | |
Re: [XPAND] Import C files in XPT project [message #835594 is a reply to message #835407] |
Tue, 03 April 2012 12:46 |
|
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 #840722 is a reply to message #835407] |
Tue, 10 April 2012 12:47 |
Ricardo Ben Amor 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 #855958 is a reply to message #855893] |
Wed, 25 April 2012 08:37 |
Ricardo Ben Amor 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 #855997 is a reply to message #855973] |
Wed, 25 April 2012 09:23 |
|
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 |
Ricardo Ben Amor 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.
|
|
| | | | |
Goto Forum:
Current Time: Wed Sep 25 17:30:50 GMT 2024
Powered by FUDForum. Page generated in 0.08554 seconds
|