Example #1
0
        /// <summary>
        ///  Initializes a given commands math expression based on supplied unit type
        /// </summary>
        /// <param name="bthcmd"></param>
        /// <param name="Unit_Type"></param>

        public void InitExpression(BluetoothCmd bthcmd, UserSetting.UNIT_TYPE Unit_Type)
        {
            if (bthcmd.Command_Types == null || bthcmd.Command_Types.Length == 0)
            {
                return;
            }

            InitUnitType(bthcmd, Unit_Type);

            if (string.IsNullOrEmpty(sExpression))
            {
                return;
            }

            string varvalue;

            e         = null;
            arguments = null;

            e         = new Expression(sExpression.Trim());
            arguments = new List <Argument>();

            for (int idx = 0; idx < bthcmd.Command_Types.Length; idx++)
            {
                varvalue = ProcessValues.GetVariable(idx);
                arguments.Add(new Argument(varvalue));
                e.addArguments(arguments[idx]);
                //arguments[idx].setArgumentValue(0); // ToDo: initial value?
            }

            min      = bthcmd.Value_Min;
            max      = bthcmd.Value_Max;
            decimals = bthcmd.Decimals;
        }
Example #2
0
 public void InitExpressions(UserSetting.UNIT_TYPE Unit_Type)
 {
     foreach (BluetoothCmd b in this) // Init expressions
     {
         b.InitExpression(b, Unit_Type);
     }
 }
Example #3
0
 public static void InitUnitType(BluetoothCmd bthcmd, UserSetting.UNIT_TYPE Unit_Type)
 {
     if (Unit_Type == UserSetting.UNIT_TYPE.IMPERIAL)
     {
         unitsImperial.InitType(bthcmd);
     }
     else
     {
         unitsMetric.InitType(bthcmd);
     }
 }
Example #4
0
        public void CreateTestCommands(UserSetting.UNIT_TYPE Unit_Type, bool isInitialize)
        {
            // Format 01##01
            // 01 = Service
            // https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_05

            Add(new BluetoothCmd()
            {
                Id   = 0,
                Name = "IGN",
                Expression_Imperial = "",
                Units_Imperial      = "",
                Cmd           = "ATIGN",
                Rate          = 1000,
                isRxBytes     = false,
                isSelected    = true,
                Command_Types = new[] { COMMAND_TYPE.DEFAULT }
            });

            Add(new BluetoothCmd()
            {
                Id   = 1,
                Name = "TEMP",
                Expression_Imperial = "(a * 100 / 255)",
                Units_Imperial      = "F",
                Expression_Metric   = "(a * 100 / 255)",
                Units_Metric        = "C",
                Cmd           = "01051",
                Rate          = 2000,
                Decimals      = 0,
                Value_Min     = -60,
                Value_Max     = 300,
                isRxBytes     = true,
                Bytes         = 1,
                isSelected    = true,
                Command_Types = new[] { COMMAND_TYPE.DEFAULT }
            });

            Add(new BluetoothCmd()
            {
                Id   = 2,
                Name = "VSS",
                Expression_Imperial = "(a * 1)",
                Units_Imperial      = "MPH",
                Expression_Metric   = "(a * 1)",
                Units_Metric        = "KPH",
                Cmd           = "010D1",
                Rate          = 1000,
                Decimals      = 1,
                Value_Min     = 0,
                Value_Max     = 300,
                isRxBytes     = true,
                Bytes         = 1,
                isSelected    = true,
                Command_Types = new[] { COMMAND_TYPE.VSS }
            });

            Add(new BluetoothCmd()
            {
                Id   = 3,
                Name = "TPS",
                Expression_Imperial = "(a * 1)",
                Units_Imperial      = "%",
                Expression_Metric   = "(a * 1)",
                Units_Metric        = "%",
                Cmd           = "010D1",
                Rate          = 1000,
                Decimals      = 0,
                Value_Min     = 0,
                Value_Max     = 100,
                isRxBytes     = true,
                Bytes         = 1,
                isSelected    = false,
                Command_Types = new[] { COMMAND_TYPE.TPS }
            });

            Add(new BluetoothCmd()
            {
                Id   = 4,
                Name = "MAF",
                Expression_Imperial = "(a * 1)",
                Units_Imperial      = "G/S",
                Expression_Metric   = "(a * 1)",
                Units_Metric        = "G/S",
                Cmd           = "010D1",
                Rate          = 1000,
                Decimals      = 1,
                Value_Min     = 0,
                Value_Max     = 10000,
                isRxBytes     = true,
                Bytes         = 1,
                isSelected    = false,
                Command_Types = new[] { COMMAND_TYPE.MAF }
            });

            Add(new BluetoothCmd()
            {
                Id   = 5,
                Name = "RPM",
                Expression_Imperial = "(a * 1)",
                Units_Imperial      = "x1000",
                Expression_Metric   = "(a * 1)",
                Units_Metric        = "x1000",
                Cmd           = "010D1",
                Rate          = 500,
                Decimals      = 0,
                Value_Min     = 0,
                Value_Max     = 10000,
                isRxBytes     = true,
                Bytes         = 1,
                isSelected    = false,
                Command_Types = new[] { COMMAND_TYPE.DEFAULT }
            });

            Add(new BluetoothCmd()
            {
                Id   = 6,
                Name = "Mileage",
                Expression_Imperial = "(14.7*b*1740.572)/(3600*c/100)",
                Units_Imperial      = "MPG",
                Expression_Metric   = "(14.7*b*1740.572)/(3600*c/100)",
                Units_Metric        = "KPG",
                Cmd           = "",
                Rate          = 2000,
                Decimals      = 1,
                Value_Min     = 0,
                Value_Max     = 100,
                isRxBytes     = false,
                Bytes         = 0,
                isSelected    = false,
                Command_Types = new[] { COMMAND_TYPE.MPG, COMMAND_TYPE.VSS, COMMAND_TYPE.MAF }
            });

            if (isInitialize)
            {
                InitCommandBytes();
                InitExpressions(Unit_Type);
            }
        }