void MakeReport() { string report = @"D:\Battery report.txt"; ParameterManager.LoadFromFile(@"D:\BQ20Z45_V2.xml"); System.IO.File.Delete(report); IoLog.Instance.FilePath = report; foreach (ParameterItem item in ParameterManager.Instance.Parameters) { string line = item.Name + ": "; try { switch (item.Format) { case "D3": /*000 256*/ { line += SbsRead(item.Commmand, item.Size)[0].ToString(item.Format); break; } case "D5": /*00000 .. 65535*/ { line += BitConverter.ToUInt16(SbsRead(item.Commmand, item.Size), 0).ToString(item.Format); break; } case "X4": /*0000 .. FFFF*/ { line += "0x" + BitConverter.ToUInt16(SbsRead(item.Commmand, item.Size), 0).ToString(item.Format); break; } case "X8": /*00000000 .. FFFFFFFF*/ { line += "0x" + BitConverter.ToUInt32(SbsRead(item.Commmand, item.Size), 0).ToString(item.Format); break; } case "string": { line += System.Text.Encoding.UTF8.GetString(SbsBlockRead(item.Commmand, item.Size)); break; } case "yyyyMMdd": { ushort temp = BitConverter.ToUInt16(SbsRead(item.Commmand, item.Size), 0); var years = ((temp & 0xFE00) >> 9) + 1980; var months = (temp & 0x01E0) >> 5; var days = (temp & 0x001F); line += new DateTime(years, months, days).ToString(item.Format, System.Globalization.CultureInfo.InvariantCulture); break; } default: { throw new Exception("Format " + item.Format + " not support."); } } } catch (Exception ex) { line += "Error:" + ex.Message; } line += " " + item.Unit; IoLog.Instance.WriteLine(line); } }
public void LoadFile() { ParameterManager.LoadFromFile(ParamFilePath); Assert.AreEqual(2, ParameterManager.Instance.Parameters.Count); }