Skip to content
Snippets Groups Projects
Select Git revision
  • d411973edc83056f40191f24f709e6dee73a325a
  • master default
  • anders.blomdell
  • typeref
  • pragma
  • compiler-refactoring
  • labcomm2013
  • v2014.1
  • v2014.0
  • v2013.0
10 results

RAPID_CodeGen.jrag

Blame
  • Forked from Anders Blomdell / LabComm
    Source project has a limited visibility.
    Encoder.java 1.48 KiB
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    
    import se.lth.control.labcomm.LabCommEncoderChannel;
    
    /**
     * Simple encoder 
     */
    public class Encoder 
    {
    
      LabCommEncoderChannel encoder;
    
      public Encoder(OutputStream out) 
        throws Exception 
      {
        encoder = new LabCommEncoderChannel(out);
        theTwoInts.register(encoder);
        IntString.register(encoder);
        TwoArrays.register(encoder);
      }
    
      public void doEncode() throws java.io.IOException {
        TwoInts x = new TwoInts();
        x.a = 17;
        x.b = 42;
    
        IntString y = new IntString();
        y.x = 37;
        y.s = "Testing, testing";
    
        TwoArrays ta = new TwoArrays();
        ta.fixed = new int[] {14, 25};
    //    ta.variable = new int[][] {{1,2},{0x11,0x12},{0x21,0x22},{0x31,0x32}};
        ta.variable = new int[][] {{1,2, 3, 4},{0x21,0x22,0x23,0x24}};
    
        System.out.println("Encoding theTwoInts, a="+x.a+", b="+x.b);
        theTwoInts.encode(encoder, x);
    
        System.out.println("Encoding IntString, x="+y.x+", s="+y.s);
        IntString.encode(encoder, y);
    
        System.out.println("Encoding TwoArrays");
        for(int i = 0; i < ta.variable.length; i++) {
    	for(int j=0; j < ta.variable[0].length; j++)
    		System.out.println(ta.variable[i][j]);
    	System.out.println("---");
        }
        TwoArrays.encode(encoder, ta);
      }
    
    
      public static void main(String[] arg) throws Exception {
        FileOutputStream fos = new FileOutputStream(arg[0]);
        Encoder example = new Encoder(fos);
        example.doEncode();
        fos.close();
      }
    
    }