private void enqueue_sect_trip_gas(Trip_gas_Content content) { _sect_trip_gas_latest = content; _sect_trip_gas_queue.Enqueue(content); if (_sect_trip_gas_queue.Count > _sect_store_max) { _sect_trip_gas_queue.Dequeue(); } }
public void load_trip_gas() { //XmlSerializerオブジェクトの作成 System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Trip_gas_Content)); try { //ファイルを開く System.IO.FileStream fs = new System.IO.FileStream(_filepath, System.IO.FileMode.Open); try { //XMLファイルから読み込み、逆シリアル化する _total_trip_gas = (Trip_gas_Content)serializer.Deserialize(fs); } catch (XmlException ex) { Console.WriteLine(ex.Message); this.reset_total_trip_gas(); } fs.Close(); } catch (FileNotFoundException ex) { Console.WriteLine(ex.Message); this.reset_total_trip_gas(); } catch (DirectoryNotFoundException ex) { Console.WriteLine(ex.Message); System.IO.Directory.CreateDirectory(@_folderpath); this.reset_sect_trip_gas(); } catch (System.Security.SecurityException ex) { Console.WriteLine(ex.Message); this.reset_total_trip_gas(); } }
//コンストラクタ public Nenpi_Trip_Calculator() { _total_trip_gas = new Trip_gas_Content(); _sect_elapsed = 0; _sect_store_max = 60; _sect_span = 60 * 1000; _sect_trip_gas_temporary = new Trip_gas_Content(); _sect_trip_gas_queue = new Queue <Trip_gas_Content>(); _sect_trip_gas_latest = new Trip_gas_Content(); _save_elapsed = 0; //データ格納しているファイルパスの指定 _folderpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); _filepath = Path.Combine(_folderpath, "." + "FUELTRIP_Logger"); load_trip_gas(); _stopwatch = new Stopwatch(); _stopwatch.Reset(); }
public void reset_sect_trip_gas() { _sect_trip_gas_latest = new Trip_gas_Content(); _sect_trip_gas_queue = new Queue <Trip_gas_Content> (); }
public void reset_total_trip_gas() { _total_trip_gas = new Trip_gas_Content(); }
public void update(double tacho, double speed, double injpulse_width) { if (!_stopwatch.IsRunning) { _stopwatch.Start(); return; } _stopwatch.Stop(); //get elasped time long stopwatch_elasped = _stopwatch.ElapsedMilliseconds; // Set current value _current_speed = speed; _current_tacho = tacho; _current_injpulse_width = injpulse_width; // elaspedが長すぎる場合,タイムアウトを発生 if (stopwatch_elasped > stopwatch_timeout) { _stopwatch.Reset(); _stopwatch.Start(); throw new TimeoutException("tacho/speed/injpulse update span is too large (Timeout)."); } _stopwatch.Reset(); _stopwatch.Start(); _momentary_trip = get_momentary_trip(stopwatch_elasped); _momentary_gas_consumption = get_momentary_gas_comsumption(stopwatch_elasped); _total_trip_gas.trip += _momentary_trip; _total_trip_gas.gas_consumption += _momentary_gas_consumption; _sect_elapsed += stopwatch_elasped; //区間データアップデート if (_sect_elapsed < _sect_span) { _sect_trip_gas_temporary.trip += _momentary_trip; _sect_trip_gas_temporary.gas_consumption += _momentary_gas_consumption; } else { //Section履歴に追加 enqueue_sect_trip_gas(_sect_trip_gas_temporary); _sect_trip_gas_temporary = new Trip_gas_Content(); _sect_elapsed = 0; //区間データ更新イベント発生 SectFUELTRIPUpdated(this, EventArgs.Empty); } //総燃費、総距離を5sごとに保存 if (_save_elapsed < save_span) { _save_elapsed += stopwatch_elasped; } else { save_trip_gas(); _save_elapsed = 0; } }