Skip to content

Commit 6f75583

Browse files
authored
Merge pull request #21 from stprograms/16_update_telegram
Updated telegrams
2 parents 7ae8283 + 8cb592a commit 6f75583

22 files changed

+1227
-339
lines changed

.vscode/launch.json

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,33 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
// Use IntelliSense to find out which attributes exist for C# debugging
6-
// Use hover for the description of the existing attributes
7-
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
8-
"name": ".NET Core Launch (console)",
5+
"name": "Grap from serial 1",
96
"type": "coreclr",
107
"request": "launch",
118
"preLaunchTask": "build",
129
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/bin/Debug/net6.0/RS485 Monitor.dll",
10+
"program": "${workspaceFolder}/RS485 Monitor/bin/Debug/net8.0/RS485 Monitor.dll",
1411
"args": [""],
1512
"cwd": "${workspaceFolder}",
1613
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
1714
"console": "internalConsole",
1815
"stopAtEntry": false
1916
},
2017
{
21-
// Use IntelliSense to find out which attributes exist for C# debugging
22-
// Use hover for the description of the existing attributes
23-
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
24-
"name": ".NET Core Launch with args",
18+
"name": "Read from file",
2519
"type": "coreclr",
2620
"request": "launch",
2721
"preLaunchTask": "build",
2822
// If you have changed target frameworks, make sure to update the program path.
29-
"program": "${workspaceFolder}/bin/Debug/net6.0/RS485 Monitor.dll",
30-
"args": ["${workspaceFolder}\\..\\Traces\\raw_20230501_103841.bin", "-g"],
23+
"program": "${workspaceFolder}/RS485 Monitor/bin/Debug/net8.0/RS485 Monitor.dll",
24+
"args": [
25+
"${workspaceFolder}\\..\\Traces\\raw_20230501_103841.bin",
26+
"-g"
27+
],
3128
"cwd": "${workspaceFolder}",
3229
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
3330
"console": "internalConsole",
3431
"stopAtEntry": false
3532
},
36-
{
37-
// Use IntelliSense to find out which attributes exist for C# debugging
38-
// Use hover for the description of the existing attributes
39-
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
40-
"name": ".NET Core Launch Helptext",
41-
"type": "coreclr",
42-
"request": "launch",
43-
"preLaunchTask": "build",
44-
// If you have changed target frameworks, make sure to update the program path.
45-
"program": "${workspaceFolder}/bin/Debug/net6.0/RS485 Monitor.dll",
46-
"args": ["--version"],
47-
"cwd": "${workspaceFolder}",
48-
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
49-
"console": "internalConsole",
50-
"stopAtEntry": false
51-
},
52-
{
53-
"name": ".NET Core Attach",
54-
"type": "coreclr",
55-
"request": "attach"
56-
}
5733
]
58-
}
34+
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ Current fed into or taken from the battery. Values < 0 describe discharge of the
307307
| 6 | 3 | 96 | Ctrl | Ctrl (6,0) | |
308308
| 6 | 4 | 95 | Ctrl | Ctrl (6,6) | |
309309
| 6 | 5 | 94 | Battery | Disconnect | |
310-
| 6 | 6 | 93 | Battery | Battery (8,1) | |
311-
| 6 | 7 | 92 | Battery | Battery (8,0) | |
310+
| 6 | 6 | 93 | Battery | Battery (8,1) | charge current to high |
311+
| 6 | 7 | 92 | Battery | Battery (8,0) | charging stopped |
312312
| 7 | 0 | 91 | Battery | Battery[Temp] >= 3B(60°C) | |
313-
| 7 | 1 | 90 | Battery | Battery (8,2) | |
313+
| 7 | 1 | 90 | Battery | Battery (8,2) | discharge current too high |
314314
| 7 | 2 | 89 | Battery | Battery (8,5) | |
315315
| 7 | 3 | 88 | Battery | Battery (8,7) | |
316316
| 7 | 4 | 87 | X | | |

RS485 Monitor/src/TelegramParser.cs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void ParseChunk(byte[] rawData)
132132
/// <summary>
133133
/// Parse the given file
134134
/// </summary>
135-
/// <param name="filePath"></param>
135+
/// <param name="filePath"></param>
136136
public void ParseFile(string filePath)
137137
{
138138
FileInfo info = new(filePath);
@@ -199,28 +199,23 @@ private void FinishBlock()
199199
return null;
200200
}
201201

202-
// Check if we can convert
203-
if ( tg.Type == BaseTelegram.TelegramType.READ_RESPONSE)
202+
// Define known telegrams
203+
Dictionary<UInt16, Type> knownTelegrams = new()
204204
{
205-
if (tg.Source == 0xAA && tg.Destination == 0x5A && tg.PDU.Length == 10)
206-
{
207-
tg = new BatteryStatus(tg);
208-
}
209-
else if (tg.Source == 0xAA && tg.Destination == 0xDA && tg.PDU.Length == 10)
210-
{
211-
tg = new ECUStatus(tg);
212-
}
213-
}
214-
215-
else if (tg.Type == BaseTelegram.TelegramType.READ_REQUEST)
205+
{ControllerRequest.TELEGRAM_ID, typeof(ControllerRequest) },
206+
{ControllerResponse.TELEGRAM_ID, typeof(ControllerResponse) },
207+
{BatteryRequest.TELEGRAM_ID, typeof(BatteryRequest) },
208+
{BatteryResponse.TELEGRAM_ID, typeof(BatteryResponse) },
209+
{SpeedometerRequest.TELEGRAM_ID, typeof(SpeedometerRequest) },
210+
{SpeedometerResponse.TELEGRAM_ID, typeof(SpeedometerResponse) },
211+
};
212+
213+
// try to fetch the special telegram type
214+
if (knownTelegrams.TryGetValue(tg.Id, out Type? specialType))
216215
{
217-
if (tg.Source == 0xBA && tg.Destination == 0xAA && tg.PDU.Length == GSMStatus.RAW_DATA_LEN)
218-
{
219-
tg = new GSMStatus(tg);
220-
}
216+
tg = (BaseTelegram?)Activator.CreateInstance(specialType, [tg]);
221217
}
222218

223219
return tg;
224220
}
225-
226-
}
221+
}

0 commit comments

Comments
 (0)