Android OBD响应转换为十进制

在我的应用程序中,我向OBD端口发送四个基本命令并取回十六进制数据...我不知道为什么我发送命令:

ME:010c

汽车:10c410c0000

为什么信息不以4开头? 并且只能得到410c和obd从汽车接收到的数据?

我使用这种方法来管理十六进制响应并将其转换为人类可读数据,而RawData是一个字符串,它接收消息并清除所有空间,如下所示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;
    }

我使用rawData.substring(7),因为3是我在帖子开头讲述的角色

10C

另外4个是

410C

所以我只得到我需要小数的价值......但有时我得到了束缚。

有人有一些想法,没有问题得到这个?

谢谢

链接地址: http://www.djcxy.com/p/95127.html

上一篇: Android OBD response conversion to decimal

下一篇: Getting VIN number from Car's OBD