예제 #1
0
        public static void Main(string[] args)
        {
            AppSettings appsetting;

            try
            {
                appsetting = LoadSettingXml("fueltriplogger_settings.xml");
                appsetting.ValidateSettings();
            }
            catch (XmlException ex)
            {
                //Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                return;
            }
            catch (FileNotFoundException ex)
            {
                //Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                return;
            }
            catch (DirectoryNotFoundException ex)
            {
                //Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                return;
            }
            catch (System.Security.SecurityException ex)
            {
                //Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                return;
            }
            catch (ArgumentException ex)
            {
                logger.Error(ex.Message);
                return;
            }
            RequiredParameterCode codelist = appsetting.getRequiredParameterCodes();

            FUELTRIPLogger fueltriplogger1 = new FUELTRIPLogger(appsetting);

            fueltriplogger1.WebsocketServerListenPortNo = appsetting.websocket_port;
            fueltriplogger1.KeepAliveInterval           = appsetting.keepalive_interval;

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            fueltriplogger1.start();

            while (Console.ReadKey().KeyChar != 'q')
            {
                Thread.Sleep(500);
                continue;
            }

            fueltriplogger1.stop();
        }
예제 #2
0
        /// <summary>
        /// Construct WebsocketClients.
        /// </summary>
        /// <param name="appSettings">AppSettings</param>
        public WebSocketClients(AppSettings appSettings)
        {
            RequiredParameterCode requiredCodes = appSettings.getRequiredParameterCodes();

            DefiWSClient    = initializeDefiCOMWSClient(appSettings.defiserver_url, requiredCodes.DefiCodes);
            SSMWSClient     = initializeSSMCOMWSClient(appSettings.ssmserver_url, requiredCodes.SSMCodes);
            ArduinoWSClient = initializeArduinoCOMWSClient(appSettings.arduinoserver_url, requiredCodes.ArduinoCodes);
            ELM327WSClient  = initializeELM327COMWSClient(appSettings.elm327server_url, requiredCodes.ELM327OBDCodes);

            runningState = false;
        }
예제 #3
0
        /// <summary>
        /// Create the list of parameter code from data source and calculation method setting.
        /// </summary>
        /// <returns>The list of required parameter code.</returns>
        public RequiredParameterCode getRequiredParameterCodes()
        {
            RequiredParameterCode requiredCodes = new RequiredParameterCode();
            FuelCalculationMethod calcMethod    = this.Calculation.FuelCalculationMethod;
            DataSource            dataSource    = this.Calculation.DataSource;

            // Decide parameter code for trip (vehicle speed)
            switch (dataSource.VehicleSpeedSource)
            {
            case WebSocketType.SSM:
                requiredCodes.SSMCodes.Add(SSMParameterCode.Vehicle_Speed);
                break;

            case WebSocketType.ARDUINO:
                requiredCodes.ArduinoCodes.Add(ArduinoParameterCode.Vehicle_Speed);
                break;

            case WebSocketType.ELM327:
                requiredCodes.ELM327OBDCodes.Add(OBDIIParameterCode.Vehicle_Speed);
                break;

            default:
                throw new ArgumentException("Vehicle speed is supported only on SSM, Arduino, ELM327.");
            }

            // Decide parameter code for fuel consumption.
            switch (calcMethod)
            {
            case FuelCalculationMethod.FUEL_RATE:
            {
                switch (dataSource.FuelRateSource)
                {
                case WebSocketType.ELM327:
                    requiredCodes.ELM327OBDCodes.Add(OBDIIParameterCode.Engine_fuel_rate);
                    break;

                default:
                    throw new ArgumentException("Engine Fuel rate is supported only on ELM327.");
                }
                break;
            }

            case FuelCalculationMethod.RPM_INJECTION_PW:
            {
                switch (dataSource.InjectionPWSource)
                {
                case WebSocketType.SSM:
                    requiredCodes.SSMCodes.Add(SSMParameterCode.Fuel_Injection_1_Pulse_Width);
                    break;

                default:
                    throw new ArgumentException("Fuel injection pulse width is supported only on SSM");
                }
                switch (dataSource.RPMSource)
                {
                case WebSocketType.DEFI:
                    requiredCodes.DefiCodes.Add(DefiParameterCode.Engine_Speed);
                    break;

                case WebSocketType.SSM:
                    requiredCodes.SSMCodes.Add(SSMParameterCode.Engine_Speed);
                    break;

                case WebSocketType.ARDUINO:
                    requiredCodes.ArduinoCodes.Add(ArduinoParameterCode.Engine_Speed);
                    break;

                case WebSocketType.ELM327:
                    requiredCodes.ELM327OBDCodes.Add(OBDIIParameterCode.Engine_Speed);
                    break;
                }
                break;
            }

            case FuelCalculationMethod.MASS_AIR_FLOW_AF:
            {
                switch (dataSource.MassAirFlowSource)
                {
                case WebSocketType.SSM:
                    requiredCodes.SSMCodes.Add(SSMParameterCode.Mass_Air_Flow);
                    break;

                case WebSocketType.ELM327:
                    requiredCodes.ELM327OBDCodes.Add(OBDIIParameterCode.Mass_Air_Flow);
                    break;

                default:
                    throw new ArgumentException("Mass air flow is supported only on SSM or ELM327.");
                }
                switch (dataSource.AFRatioSource)
                {
                case WebSocketType.SSM:
                    requiredCodes.SSMCodes.Add(SSMParameterCode.Air_Fuel_Sensor_1);
                    break;

                case WebSocketType.ELM327:
                    requiredCodes.ELM327OBDCodes.Add(OBDIIParameterCode.Command_equivalence_ratio);
                    break;

                default:
                    throw new ArgumentException("A/F ratio is supported only on SSM or ELM327.");
                }
                break;
            }

            case FuelCalculationMethod.MASS_AIR_FLOW:
            {
                switch (dataSource.MassAirFlowSource)
                {
                case WebSocketType.SSM:
                    requiredCodes.SSMCodes.Add(SSMParameterCode.Mass_Air_Flow);
                    break;

                case WebSocketType.ELM327:
                    requiredCodes.ELM327OBDCodes.Add(OBDIIParameterCode.Mass_Air_Flow);
                    break;

                default:
                    throw new ArgumentException("Mass air flow is supported only on SSM or ELM327.");
                }
                break;
            }
            }
            return(requiredCodes);
        }