|
|
|
@ -59,6 +59,24 @@ namespace DCT_test |
|
|
|
// =========================================================================
|
|
|
|
|
|
|
|
// TODO: 사용자 정의 파일 파싱 및 패킷 조립 로직을 이곳에 구현하세요.
|
|
|
|
// 20260907 add txt file
|
|
|
|
string fileExt = System.IO.Path.GetExtension(filePath); |
|
|
|
|
|
|
|
switch (fileExt.ToLower()) |
|
|
|
{ |
|
|
|
case ".txt": |
|
|
|
ParseTxtFile(filePath, result); |
|
|
|
break; |
|
|
|
|
|
|
|
case ".csv": |
|
|
|
break; |
|
|
|
|
|
|
|
case ".mf4": |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
result.Success = result.Packets.Count > 0; |
|
|
|
if (!result.Success && string.IsNullOrEmpty(result.ErrorMessage)) |
|
|
|
@ -74,5 +92,52 @@ namespace DCT_test |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public bool ParseTxtFile(string filePath, LogFileReadResult result) |
|
|
|
{ |
|
|
|
bool bRet = false; |
|
|
|
try |
|
|
|
{ |
|
|
|
if (File.Exists(filePath)) |
|
|
|
{ |
|
|
|
//파일을 사용한 후 닫아주기위해 using으로 묶어준다.
|
|
|
|
StreamReader reader = new StreamReader(filePath); |
|
|
|
string line; |
|
|
|
|
|
|
|
while ((line = reader.ReadLine()) != null) |
|
|
|
{ |
|
|
|
if (line.StartsWith("[Recv]") == true) |
|
|
|
{ |
|
|
|
if (line.Substring(31, 2) == "A3" |
|
|
|
|| line.Substring(31, 2) == "A4" |
|
|
|
|| line.Substring(31, 2) == "D0") |
|
|
|
{ |
|
|
|
|
|
|
|
string data = line.Substring(22); |
|
|
|
byte cmdId = Convert.ToByte(line.Substring(31, 2), 16); |
|
|
|
int arrayLen = Convert.ToByte(line.Substring(25, 2), 16) << 8 | Convert.ToByte(line.Substring(28, 2), 16) - 1; |
|
|
|
byte[] dataArray = new byte[arrayLen]; |
|
|
|
|
|
|
|
for (int i = 34, idx = 0; i < line.Length - 6; i += 3) |
|
|
|
dataArray[idx++] = Convert.ToByte(line.Substring(i, 2), 16); |
|
|
|
|
|
|
|
DctPacket packet = DctPacket.Create(cmdId, dataArray); |
|
|
|
|
|
|
|
result.Packets.Add(packet); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
bRet = true; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
bRet = false; |
|
|
|
result.ErrorMessage = $"ParseTxtFile error: {ex.Message}"; |
|
|
|
} |
|
|
|
return bRet; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|