add files
This commit is contained in:
@@ -146,6 +146,9 @@ namespace AGVControl.Models
|
||||
MovementHistory.Clear();
|
||||
MovementHistory.AddRange(lastTwo);
|
||||
}
|
||||
|
||||
// 위치 업데이트 시 자동으로 히스토리 파일에 저장
|
||||
SaveHistoryOnUpdate();
|
||||
}
|
||||
|
||||
// 연결 정보 기반 실제 이동 방향 계산
|
||||
@@ -233,6 +236,98 @@ namespace AGVControl.Models
|
||||
}
|
||||
}
|
||||
|
||||
// 위치 히스토리 파일 저장 (최근 3개만 저장)
|
||||
public void SavePositionHistory(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 최근 3개의 히스토리만 저장
|
||||
var recentHistory = MovementHistory.Skip(Math.Max(0, MovementHistory.Count - 3)).ToList();
|
||||
|
||||
var lines = new List<string>();
|
||||
lines.Add($"# AGV Position History - {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
|
||||
lines.Add("# Format: RFID,Direction,X,Y,Timestamp");
|
||||
|
||||
foreach (var history in recentHistory)
|
||||
{
|
||||
lines.Add($"{history.Value},{history.Direction},{history.Location.X},{history.Location.Y},{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
|
||||
}
|
||||
|
||||
System.IO.File.WriteAllLines(filePath, lines);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 로그 기록 (실제 환경에서는 로깅 시스템 사용)
|
||||
System.Diagnostics.Debug.WriteLine($"SavePositionHistory Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 위치 히스토리 파일 로드
|
||||
public bool LoadPositionHistory(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
return false;
|
||||
|
||||
var lines = System.IO.File.ReadAllLines(filePath);
|
||||
MovementHistory.Clear();
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
// 주석 라인 건너뛰기
|
||||
if (line.StartsWith("#") || string.IsNullOrWhiteSpace(line))
|
||||
continue;
|
||||
|
||||
var parts = line.Split(',');
|
||||
if (parts.Length >= 4)
|
||||
{
|
||||
if (UInt16.TryParse(parts[0], out UInt16 rfidValue) &&
|
||||
Enum.TryParse<AgvDir>(parts[1], out AgvDir direction) &&
|
||||
int.TryParse(parts[2], out int x) &&
|
||||
int.TryParse(parts[3], out int y))
|
||||
{
|
||||
MovementHistory.Add(new movehistorydata
|
||||
{
|
||||
Value = rfidValue,
|
||||
Direction = direction,
|
||||
Location = new Point(x, y)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MovementHistory.Count > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"LoadPositionHistory Error: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 시작 시 위치 히스토리 자동 로드
|
||||
public void LoadHistoryOnStartup()
|
||||
{
|
||||
string historyFilePath = System.IO.Path.Combine(
|
||||
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
|
||||
"agv_position_history.dat"
|
||||
);
|
||||
|
||||
LoadPositionHistory(historyFilePath);
|
||||
}
|
||||
|
||||
// 위치 업데이트 시 자동 저장
|
||||
public void SaveHistoryOnUpdate()
|
||||
{
|
||||
string historyFilePath = System.IO.Path.Combine(
|
||||
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
|
||||
"agv_position_history.dat"
|
||||
);
|
||||
|
||||
SavePositionHistory(historyFilePath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user