/// <summary> /// Processes the new lines. /// </summary> /// <param name="lines">The lines.</param> public override void ProcessNewLines( string[] lines ) { BatteryInfo = new BatteryInfo ( ); foreach ( var line in lines ) { var match = line.Match ( BATTERY_LEVEL, REOPTIONS ); if ( match.Success ) { try { BatteryInfo.Level = Int32.Parse ( match.Groups[1].Value ); } catch ( FormatException ) { this.LogWarn ( String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } match = line.Match ( SCALE, REOPTIONS ); if ( match.Success ) { try { BatteryInfo.Scale = Int32.Parse ( match.Groups[1].Value ); } catch ( FormatException ) { this.LogWarn ( String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } match = line.Match ( AC_POWER, REOPTIONS ); if ( match.Success ) { BatteryInfo.ACPowered = String.Compare ( match.Groups[1].Value, bool.TrueString, true ) == 0; } match = line.Match ( USB_POWER, REOPTIONS ); if ( match.Success ) { BatteryInfo.UsbPowered = String.Compare ( match.Groups[1].Value, bool.TrueString, true ) == 0; } match = line.Match ( PRESENT, REOPTIONS ); if ( match.Success ) { BatteryInfo.Present = String.Compare ( match.Groups[1].Value, bool.TrueString, true ) == 0; } match = line.Match ( STATUS, REOPTIONS ); if ( match.Success ) { try { var i = Int32.Parse ( match.Groups[1].Value ); BatteryInfo.Status = i.ToEnum<BatteryInfo.StatusTypes> ( ); } catch ( FormatException ) { this.LogWarn ( String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } match = line.Match ( HEALTH, REOPTIONS ); if ( match.Success ) { try { var i = Int32.Parse ( match.Groups[1].Value ); BatteryInfo.Health = i.ToEnum<BatteryInfo.HealthTypes> ( ); } catch ( FormatException ) { this.LogWarn ( String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } match = line.Match ( VOLTAGE, REOPTIONS ); if ( match.Success ) { try { BatteryInfo.Voltage = Int32.Parse ( match.Groups[1].Value ); } catch ( FormatException ) { this.LogWarn ( String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } match = line.Match ( TYPE, REOPTIONS ); if ( match.Success ) { BatteryInfo.Type = match.Groups[1].Value; } match = line.Match ( TEMP, REOPTIONS ); if ( match.Success ) { try { BatteryInfo.Temperature = Int32.Parse ( match.Groups[1].Value ); } catch ( FormatException ) { this.LogWarn ( String.Format ( "Failed to parse {0} as an integer", match.Groups[1].Value ) ); } } } }
public BatteryInfo GetBatteryInfo( String device, long freshness ) { if ( lastBatteryInfo != null && this.lastBatteryCheckTime > ( DateTime.Now.AddMilliseconds ( -freshness ) ) ) { return lastBatteryInfo; } var receiver = new BatteryReceiver ( ); var result = this.CommandRun ( device, AdbCommand.Shell, "dumbsys battery" ); //"dumpsys battery", receiver, BATTERY_TIMEOUT ); lastBatteryInfo = receiver.BatteryInfo; lastBatteryCheckTime = DateTime.Now; return lastBatteryInfo; }
/// <summary> /// Processes the new lines. /// </summary> /// <param name="lines">The lines.</param> public override void ProcessNewLines(string[] lines) { BatteryInfo = new BatteryInfo( ); foreach (var line in lines) { var match = line.Match(BATTERY_LEVEL, REOPTIONS); if (match.Success) { try { BatteryInfo.Level = Int32.Parse(match.Groups[1].Value); } catch (FormatException) { this.LogWarn(String.Format("Failed to parse {0} as an integer", match.Groups[1].Value)); } } match = line.Match(SCALE, REOPTIONS); if (match.Success) { try { BatteryInfo.Scale = Int32.Parse(match.Groups[1].Value); } catch (FormatException) { this.LogWarn(String.Format("Failed to parse {0} as an integer", match.Groups[1].Value)); } } match = line.Match(AC_POWER, REOPTIONS); if (match.Success) { BatteryInfo.ACPowered = String.Compare(match.Groups[1].Value, bool.TrueString, true) == 0; } match = line.Match(USB_POWER, REOPTIONS); if (match.Success) { BatteryInfo.UsbPowered = String.Compare(match.Groups[1].Value, bool.TrueString, true) == 0; } match = line.Match(PRESENT, REOPTIONS); if (match.Success) { BatteryInfo.Present = String.Compare(match.Groups[1].Value, bool.TrueString, true) == 0; } match = line.Match(STATUS, REOPTIONS); if (match.Success) { try { var i = Int32.Parse(match.Groups[1].Value); BatteryInfo.Status = i.ToEnum <BatteryInfo.StatusTypes> ( ); } catch (FormatException) { this.LogWarn(String.Format("Failed to parse {0} as an integer", match.Groups[1].Value)); } } match = line.Match(HEALTH, REOPTIONS); if (match.Success) { try { var i = Int32.Parse(match.Groups[1].Value); BatteryInfo.Health = i.ToEnum <BatteryInfo.HealthTypes> ( ); } catch (FormatException) { this.LogWarn(String.Format("Failed to parse {0} as an integer", match.Groups[1].Value)); } } match = line.Match(VOLTAGE, REOPTIONS); if (match.Success) { try { BatteryInfo.Voltage = Int32.Parse(match.Groups[1].Value); } catch (FormatException) { this.LogWarn(String.Format("Failed to parse {0} as an integer", match.Groups[1].Value)); } } match = line.Match(TYPE, REOPTIONS); if (match.Success) { BatteryInfo.Type = match.Groups[1].Value; } match = line.Match(TEMP, REOPTIONS); if (match.Success) { try { BatteryInfo.Temperature = Int32.Parse(match.Groups[1].Value); } catch (FormatException) { this.LogWarn(String.Format("Failed to parse {0} as an integer", match.Groups[1].Value)); } } } }