Subversion Repositories Projects

Rev

Rev 229 | Rev 252 | 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  extends ParamsClass


{
// -- 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"},{"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"}},{{"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","Coupling2","Coupling YawCorrect"},{"ACC/Gyro Factor","P-Rate","I-Rate","D-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-P Limit","GPS-I Limit","GPS-D Limit","GPS-ACC","Satelite Minimum","Stick Threhsold","Wind Correction","Speed Compensation","Operating Radius","Angle Limit","PH LoginTime"},{"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}},{{9,10,11,12,13,14,604},{34,35,36,37,38,608},{0,1,2,3,4,5,6,7},{64,65,66,67,68,69,70,71},{42,43,44},{20,22,23,24,47,48,49},{39,40,41,45,46,600,601,602,603},{58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73},{18,19,21,25,26,27},{54,55,56,57},{15,16,17,74},{30,31,32,33,50,51,52,53}}};
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}},{{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_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,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}}};
public final static int[] all_name_positions={75,81};
public final static int[] all_lengths={87,93};
// -- 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={"","","","",""};

    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 void set_name(String nme)
    {
        if (nme.length()>10)
            nme=nme.substring(0,10);
        //      names[act_paramset]=nme;
        int nme_pos=0;
        while(nme_pos<nme.length())
            {
                field[act_paramset][name_start+nme_pos]=(byte)nme.charAt(nme_pos);
                nme_pos++;
            }
        field[act_paramset][name_start+nme_pos]=0;
    }

    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 length=0;
    public  int name_start=0;
    /*
    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(int to)
    {  
        for ( int i=0 ; i<field[act_paramset].length;i++)
       
            {
                field_bak[to][i+2]=field[act_paramset][i];
                field[to][i]=field[act_paramset][i];
            }

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

    }

    public void reset()
    {
        last_parsed_paramset=-1;

        for (int ii=0;ii<MAX_PARAMSETS;ii++)
            field[ii]=null;
    }
       
    public String getParamName(int paramset)
    {
        String res="";
        for ( int i=name_start;i<length;i++)
            {
                if(field[paramset][i]==0)break;
                res+=(char)field[paramset][i];
            }
        return res;
    }

    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]="";
        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=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];
       
    }



}