-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealTime.cs
More file actions
108 lines (98 loc) · 3.01 KB
/
Copy pathRealTime.cs
File metadata and controls
108 lines (98 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.IO;
using System.Text;
using MtkClient.Library.Config;
using MtkClient.Library.Connection;
using MtkClient.Library.Utils;
namespace MtkClient.Library
{
public class RealTime : LogBase
{
private readonly MtkConfig _config;
private readonly Port _port;
public RealTime(MtkConfig config, Port port, LogLevel logLevel = LogLevel.Info)
{
InitLogger(logLevel);
_config = config;
_port = port;
}
public bool EnableBromLog()
{
try
{
_port.UsbWrite(new byte[] { Preloader.CMD_UART1_LOG_EN });
var ack = _port.RWord();
if (ack == Preloader.ACK)
{
Info("BROM logging enabled");
return true;
}
Warning("Failed to enable BROM logging");
return false;
}
catch (Exception ex)
{
Error($"EnableBromLog failed: {ex.Message}");
return false;
}
}
public bool SetBaudRate(uint baudRate)
{
try
{
_port.UsbWrite(new byte[] { Preloader.CMD_UART1_SET_BAUDRATE });
var ack = _port.RWord();
if (ack != Preloader.ACK) return false;
_port.UsbWrite(MtkUtils.Pack32BE(baudRate));
ack = _port.RWord();
if (ack == Preloader.ACK)
{
Info($"Baud rate set to {baudRate}");
return true;
}
return false;
}
catch (Exception ex)
{
Error($"SetBaudRate failed: {ex.Message}");
return false;
}
}
public byte[] ReadBromLog()
{
try
{
_port.UsbWrite(new byte[] { Preloader.CMD_GET_BROM_LOG });
var ack = _port.RWord();
if (ack != Preloader.ACK) return null;
var lenData = _port.RdWord();
if (lenData == null) return null;
var log = _port.UsbRead((int)lenData.Value);
if (log != null)
Info($"BROM log: {log.Length} bytes received");
return log;
}
catch (Exception ex)
{
Error($"ReadBromLog failed: {ex.Message}");
return null;
}
}
public bool SaveBromLog(string filePath)
{
var log = ReadBromLog();
if (log == null || log.Length == 0) return false;
try
{
File.WriteAllBytes(filePath, log);
Info($"BROM log saved to {filePath}");
return true;
}
catch (Exception ex)
{
Error($"Save BROM log failed: {ex.Message}");
return false;
}
}
}
}