Subversion Repositories Projects

Rev

Rev 220 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/**************************************************
 *                                            
 * class representing the Params Structure    
 *                                            
 * Author:        Marcus -LiGi- Bueschleb      
 *
 * see README for further Infos
 *
 *************************************************/


package org.ligi.ufo;



public class MKParamsParser
    implements MKParamDefinitions

{

// -- start generated code --
public final static int PARAMTYPE_BYTE=0;
public final static int PARAMTYPE_BITSWITCH=1;
public final static int PARAMTYPE_STICK=2;
public final static String[][] all_tab_names={{"Altitude","Camera","Channels","Configuration","Coupling","Gyro","Looping","Navi","Other","Output","Stick","User"}};
public final static String[][][] all_field_names={{{"Min. Accelerate","Barometric D","Setpoint","Altitude P","Gain","Z-ACC","3-Way switch"},{"Servo control","Nick compensation","Servo min","Servo max","Refresh rate","Invert Direction"},{"Nick","Roll","Accelerate","Gier","POTI1","POTI2","POTI3","POTI4"},{"ALTITUDE_CONTROL","Switch for Setpoint","Heading Hold","Compas Active","Compas Fix","GPS","Coupling","Yaw Rate Limiter"},{"Yaw pos. feedback","Yaw neg. feedback"},{"ACC/Gyro Factor","P-Rate","I-Rate","ACC/Gyro Comp","Drift-Compensation","Dynamic stability"},{"Gas Limit","Threshold","Hysterese","TurnOver Nick","TurnOver Roll","UP","DOWN","LEFT","RIGHT"},{"Mode Control","GPS-Gain","GPS-P","GPS-I","GPS-D","GPS-ACC","Satelite Minimum","Stick Threhsold","Wind Correction","Speed Compensation","Operating Radius","Angle Limit"},{"Min Gas","Max Gas","Compass Effect","Voltage Warning","Distress Gas","Distress Gas Time"},{"J16 Bitmask","J16 Timing","J17 Bitmask","J17 Timing"},{"Nick/Roll P","Nick/Roll D","Gier P","External Control"},{"Param 1","Param 2","Param 3","Param 4","Param 5","Param 6","Param 7","Param 8"}}};
public final static int[][][] all_field_positions={{{9,10,11,12,13,14,556},{33,34,35,36,37,560},{0,1,2,3,4,5,6,7},{64,65,66,67,68,69,70,71},{41,42},{20,22,23,45,46,47},{38,39,40,43,44,552,553,554,555},{56,57,58,59,60,61,62,63,64,65,66,67},{18,19,21,24,25,26},{52,53,54,55},{15,16,17,68},{29,30,31,32,48,49,50,51}}};
public final static int[][][] all_field_types={{{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH},{PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK,PARAMTYPE_STICK},{PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH},{PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE},{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}}};
public final static int[] all_name_positions={75};
public final static int[] all_lengths={87};
// -- end generated code --

    public final static int MAX_PARAMSETS=5;
    //    public final static int MAX_PARAMLENGTH=100;

    public int[][] field;
    public int[][] field_bak;
    public String[] names={"Paramset 1","Paramset 2","Paramset 3","Paramset 4","Paramset 5"};

    public int act_paramset=0;


    public int params_version=-1;
    public int last_parsed_paramset=-1;
    public int active_paramset=-1;
   
    public boolean found_incompatible=false;

    public String[] stick_names;

    public int get_field_from_act(int pos)
    {       return field[act_paramset][pos];    }

    public void set_field_from_act(int pos,int val)
    {
        if (val>255) val=255;
        if (val<0) val=255;
        field[act_paramset][pos]=val;
    }


    public void field_from_act_add(int pos,int val)
    {
        set_field_from_act(pos , get_field_from_act(pos)+val);
    }

    // for boolean Flags
    public void field_from_act_xor(int pos,int val)
    {
        field[act_paramset][pos]^=val;
    }

    public MKParamsParser()
    {
        field=new int[MAX_PARAMSETS][];
        field_bak=new int[MAX_PARAMSETS][];
       
        for (int ii=0;ii<MAX_PARAMSETS;ii++)
                {
                   field[ii]=null;
                   field_bak[ii]=null;
                 
                }

        stick_names=new String[10];
        for (int i=0;i<10;i++)
            stick_names[i]="not read yet";
    }


    public int[] param_type;
    public int[] param_pos;
    public int[] param_innerpos;

    public  String[] tab_names;
    public  String[][] field_names;
    public  int[][] field_positions;
    public  int[][] field_types;

    public  int length;
    public  int name_start;



    public void use_backup()
    {
        set_by_mk_data(field_bak[act_paramset]);
    }

    public void update_backup()
    {  
        for ( int i=0 ; i<field[act_paramset].length;i++)
            field_bak[act_paramset][i+2]=field[act_paramset][i];

        field_bak[act_paramset][0]=act_paramset+1;
        field_bak[act_paramset][1]=params_version;

    }

    public void set_by_mk_data(int[] in_arr)
    {
        params_version=in_arr[1];
        int definition_pos=params_version-73;


        if ((definition_pos<0)||( (definition_pos>all_tab_names.length)))
            {
                found_incompatible=true;
                return;
            }



        last_parsed_paramset=in_arr[0]-1;

        if (active_paramset==-1)active_paramset=last_parsed_paramset;

        tab_names=all_tab_names[definition_pos];
        field_names=all_field_names[definition_pos];
        field_positions=all_field_positions[definition_pos];
        field_types=all_field_types[definition_pos];

        name_start=all_name_positions[definition_pos];
        length=all_lengths[definition_pos];

        field[last_parsed_paramset]=new int[length];
        field_bak[last_parsed_paramset]=new int[length+2];

        names[last_parsed_paramset]="" + (last_parsed_paramset+1) +": ";
        for ( int i=0;i<length+2;i++)
            {
            if (i<length)
                field[last_parsed_paramset][i]=in_arr[i+2];
            field_bak[last_parsed_paramset][i]=in_arr[i];
            }

        for ( int i=name_start;i<length;i++)
            {
                if(in_arr[i+2]==0)break;
                names[last_parsed_paramset]+=(char)in_arr[i+2];
            }

        for (int i=0;i<10;i++)
            stick_names[i]="not associated";

        for (int tab=0;tab<tab_names.length;tab++)
            for (int item=0;item<field_types[tab].length;item++)
                if (field_types[tab][item]==PARAMTYPE_STICK)
                    stick_names[ field[last_parsed_paramset][field_positions[tab][item]] ] = field_names[tab][item];
       
    }



}