Android OBD response conversion to decimal
In my app i send four basic commands to OBD ports and get back hex data... I don't know why if i send the command:
ME: 010c
Car: 10c410c0000
Why the message don't start with 4? And get only 410c and the data that the obd receive from car?
I use this method for manage hex response and convert it to human readable data, and RawData is a String that take the message and clear all space, like this 41 0c 00 00 = 410c0000
   public String getCalculatedResult() {
        //TODO devo convertire i dati da esadecimale a decimale ed effettuare i calcoli
        int calculatedData = 0;
        String dataToShow = null;
        //Log.d("ObdCommand", "rawData: " + rawData.substring(3));
        calculatedData = Integer.parseInt(rawData.substring(7), 16);
        if (Pattern.compile(Pattern.quote(rawData.substring(3,4)),
                    Pattern.CASE_INSENSITIVE).matcher("410D").find()){
            Log.d("ObdCommand", "dentro 410D: ");
            //Velocità veicolo km/h
            dataToShow = String.valueOf(calculatedData) + " Km/h";
            Log.d("ObdCommand", "rawData: " + dataToShow);
        }else if (Pattern.compile(Pattern.quote(rawData.substring(3,4)),
                Pattern.CASE_INSENSITIVE).matcher("410C").find()){
            Log.d("ObdCommand", "dentro 410C: ");
            //Giri minuto veicolo rpm
            calculatedData = calculatedData/4;
            dataToShow = String.valueOf(calculatedData) + " rpm";
        }else if (rawData.substring(3).startsWith("4105")){
            //Temperatura refrigetante C°
            calculatedData = calculatedData - 40;
            dataToShow = String.valueOf(calculatedData) + " C°";
        }else if (rawData.substring(3).startsWith("4151")){
            //Tipo di carburante
            if (rawData.substring(7).startsWith("09")){
                //Benzina
                dataToShow = "Benzina";
            }else if (rawData.substring(7).startsWith("0d")){
                //Metano
                dataToShow = "Metano";
            }
        }
        return dataToShow;
    }
I use the rawData.substring(7) because 3 is the characters that i tell at the start of post
10c
And the other 4 are
410c
So i get only the value that i need to decimal... but sometimes i get outof bound....
Someone have some idea to get this with no problems?
Thanks
链接地址: http://www.djcxy.com/p/95128.html上一篇: 表单提交与playframework
下一篇: Android OBD响应转换为十进制
