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 03:03  |
Eclipse User |
|
|
|
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 #835594 is a reply to message #835407] |
Tue, 03 April 2012 08:46   |
Eclipse User |
|
|
|
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
|
|
| | | |
Re: [XPAND] Import C files in XPT project [message #840722 is a reply to message #835407] |
Tue, 10 April 2012 08:47   |
Eclipse User |
|
|
|
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 08:48] by Moderator
|
|
| | | | | | | | |
Re: [XPAND] Import C files in XPT project [message #855958 is a reply to message #855893] |
Wed, 25 April 2012 04:37   |
Eclipse User |
|
|
|
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 05:23   |
Eclipse User |
|
|
|
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;
}
}}
|
|
|
Re: [XPAND] Import C files in XPT project [message #856033 is a reply to message #855997] |
Wed, 25 April 2012 05:57   |
Eclipse User |
|
|
|
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: Tue Jul 22 14:24:30 EDT 2025
Powered by FUDForum. Page generated in 0.08618 seconds
|