-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFapi_alarms.cs
executable file
·322 lines (307 loc) · 9.1 KB
/
Fapi_alarms.cs
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// Copyright (C) 2009-2023 Lemoine Automation Technologies
//
// SPDX-License-Identifier: GPL-2.0-or-later
using System;
using System.Collections.Generic;
namespace Lemoine.Cnc
{
/// <summary>
/// Fidia input module - alarm part
/// </summary>
public partial class Fapi
{
#region Members
// Warning: accessed by different threads (use 'lock')
readonly IList<CncAlarm> m_alarms = new List<CncAlarm>();
#endregion // Members
#region Get methods / Properties
/// <summary>
/// Get the current alarms
/// </summary>
/// <returns></returns>
public IList<CncAlarm> Alarms {
get {
// Move the alarms in another list, clear the first list
IList<CncAlarm> alarms = new List<CncAlarm>();
lock (m_alarms) {
foreach (var alarm in m_alarms)
alarms.Add(alarm);
m_alarms.Clear();
}
return alarms;
}
}
#endregion // Get methods / Properties
#region Private methods
/// <summary>
/// Function called when a message arrives
/// Executed in another thread
/// </summary>
/// <param name="code"></param>
/// <param name="userData"></param>
void MsgCallback(string code, FapiCorbaLib.UserData userData)
{
// Example of an alarm:
// 00000 00:00:00 ICS000 Message connection OK.
// How the code Works:
// Codes normally are composed of"<ONE DIGIT TYPE><TWO DIGITs KEY OF THE SOURCE>XXXX"
// where XXXX is often but not always "_<number>" and it is used internally.
// The <ONE DIGIT TYPE> is a letter with the following meaning: I, D, R, E, W, F, H, P, L
// -> Information, Debug Message, Request Message, Emergency, Warning, Fatal Error, Hold Message, Custom Message, Log Message (similar to Information)
// The <TWO DIGITs KEY OF THE SOURCE> is the components or process that has generated the message, see the excel attached for a complete list.
log.InfoFormat("Fapi.MsgCallback - received alarm '{0}'", code);
// Prepare the alarm
CncAlarm alarm = null;
// Parse the code
var codeSplit = code.Split(' ');
if (codeSplit.Length >= 4) {
// Code
var alarmNumber = String.Join("", codeSplit[2].Split('_')); // remove all "_"
if (alarmNumber == "IEX330") {
log.WarnFormat("Fapi.MsgCallback - ignored IEX330 alarm '{0}'", code);
return; // This is the last comment => not an alarm
}
if (alarmNumber.StartsWith("D", StringComparison.InvariantCultureIgnoreCase)) {
log.WarnFormat("Fapi.MsgCallback - ignored debug message '{0}'", code);
return; // No debug message
}
// Message
var alarmMessage = codeSplit[3];
for (int i = 4; i < codeSplit.Length; i++)
alarmMessage += " " + codeSplit[i];
// Severity and source
var alarmSeverity = "unknown";
var alarmSource = "unknown";
if (alarmNumber.Length > 3) {
alarmSeverity = GetSeverity(alarmNumber[0]);
alarmSource = GetSource(alarmNumber.Substring(1, 2));
} else {
log.WarnFormat("Fapi.MsgCallback - cannot parse the alarm number '{0}'", alarmNumber);
}
alarm = new CncAlarm("Fidia (fapi)", alarmSource, alarmNumber);
alarm.Properties["severity"] = alarmSeverity;
alarm.Message = alarmMessage;
} else {
// Impossible to parse the alarm
log.Warn("Fapi.MsgCallback - cannot parse the alarm code");
alarm = new CncAlarm("Fidia (fapi)", "unknown", code);
}
alarm.Properties["local time"] = DateTime.Now.ToString();
lock (m_alarms) {
m_alarms.Add(alarm);
// Protection if the list is too big
while (m_alarms.Count > 100) {
log.WarnFormat("Fapi.MsgCallback - too many alarms, removed '{0}' occuring at {1}",
m_alarms[0].Number, m_alarms[0].Properties["local time"]);
m_alarms.RemoveAt(0);
}
}
}
string GetSeverity(char oneDigit)
{
string result = "unknown";
switch (oneDigit) {
case 'I':
result = "information";
break;
case 'D':
result = "debug message";
break;
case 'R':
result = "request message";
break;
case 'E':
result = "emergency";
break;
case 'W':
result = "warning";
break;
case 'F':
result = "fatal error";
break;
case 'H':
result = "hold message";
break;
case 'P':
result = "custom message";
break;
case 'L':
result = "log message";
break;
default:
log.WarnFormat("Fapi.MsgCallback - unknown severity '{0}'", oneDigit);
result = oneDigit + " (unknown)";
break;
}
return result;
}
string GetSource(string twoDigits)
{
string result = "unknown";
switch (twoDigits.ToUpper()) {
case "CN":
result = "CNC";
break;
case "EX":
result = "Programming";
break;
case "PL":
result = "Copying";
break;
case "DG":
result = "Digitizing";
break;
case "SY":
result = "Synchronous axis";
break;
case "AU":
result = "Aucol";
break;
case "MQ":
result = "Tracer, MQR option";
break;
case "UI":
result = "Graphical interface";
break;
case "UT":
result = "Utility module";
break;
case "TM":
result = "Tool measurement";
break;
case "PS":
result = "Operator's actions";
break;
case "DS":
result = "DNCSER";
break;
case "IA":
result = "ILVA";
break;
case "LN":
result = "Transmission line - file transfer service of NCOS";
break;
case "LU":
result = "ILVU";
break;
case "LX":
result = "IoLux, IoLine";
break;
case "SM":
result = "External PLC Siemens 3964R";
break;
case "TC":
result = "Transmission via TCP/IP";
break;
case "SE":
result = "Severe error, bug";
break;
case "IE":
result = "IEC1131";
break;
case "FM":
result = "Transmission line - file transfer service of NCOS";
break;
case "SD":
result = "Siemens drives";
break;
case "ID":
result = "Indramat drives";
break;
case "FD":
result = "Fidia drives";
break;
case "PB":
result = "Profibus";
break;
case "UP":
result = "File uploader";
break;
case "AT":
result = "Actual file task manager";
break;
case "CY":
result = "Cycles (c--)";
break;
case "NE":
result = "Transmission line - file transfer service of NCOS";
break;
case "BG":
result = "Debug";
break;
case "HM":
result = "HiMill";
break;
case "WP":
result = "Pushbutton HPW";
break;
case "ST":
result = "Management dynamic files";
break;
case "ME":
result = "Screw correction";
break;
case "AC":
result = "Adative control (OMATIVE software)";
break;
case "WS":
result = "WS32";
break;
case "FC":
result = "Fapi control";
break;
case "FP":
result = "Fapi";
break;
case "W5":
result = "WS5";
break;
case "QM":
result = "Question manager";
break;
case "P1":
result = "1st Aucol module";
break;
case "P2":
result = "2nd Aucol module";
break;
case "P3":
result = "3rd Aucol module";
break;
case "P4":
result = "4th Aucol module";
break;
case "P5":
result = "5th Aucol module";
break;
case "P6":
result = "6th Aucol module";
break;
case "P7":
result = "7th Aucol module";
break;
case "P8":
result = "8th Aucol module";
break;
case "P9":
result = "9th Aucol module";
break;
case "PA":
result = "10th Aucol module";
break;
case "PZ":
result = "IEC module";
break;
case "CS":
result = "Client software"; // Not documented but I suppose this is related to us (davy)
break;
default:
log.WarnFormat("Fapi.MsgCallback - unknown source '{0}'", twoDigits);
result = twoDigits + " (unknown)";
break;
}
return result;
}
#endregion // Private methods
}
}