@springfield/ham-radio-utils 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/schemas/radio-protocol-schema.json +538 -0
- package/dist/utils/schema-validator.d.ts +10 -0
- package/dist/utils/schema-validator.d.ts.map +1 -0
- package/dist/utils/schema-validator.js +29 -0
- package/dist/utils/schema-validator.js.map +1 -0
- package/dist/utils/ui-logger-factory.d.ts +3 -3
- package/dist/utils/ui-logger-factory.d.ts.map +1 -1
- package/dist/utils/ui-logger-factory.js +13 -13
- package/dist/utils/ui-logger-factory.js.map +1 -1
- package/dist/utils/ui-logger.d.ts.map +1 -1
- package/dist/utils/ui-logger.js +49 -33
- package/dist/utils/ui-logger.js.map +1 -1
- package/package.json +10 -5
- package/src/index.ts +4 -0
- package/src/schemas/radio-protocol-schema.json +538 -0
- package/src/utils/schema-validator.ts +40 -0
- package/src/utils/ui-logger-factory.ts +14 -14
- package/src/utils/ui-logger.ts +62 -33
package/src/utils/ui-logger.ts
CHANGED
|
@@ -40,6 +40,7 @@ export class UILogger {
|
|
|
40
40
|
this.logger = logger;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// eslint-disable-next-line max-params
|
|
43
44
|
startCommand(stepIndex: number, totalSteps: number, operation: string, step: UIProtocolStep): void {
|
|
44
45
|
const commandId = `${operation}-${stepIndex}`;
|
|
45
46
|
const startTime = Date.now();
|
|
@@ -53,14 +54,15 @@ export class UILogger {
|
|
|
53
54
|
commandId,
|
|
54
55
|
commandType,
|
|
55
56
|
description,
|
|
56
|
-
stepIndex,
|
|
57
|
-
totalSteps,
|
|
58
57
|
operation,
|
|
59
58
|
startTime,
|
|
59
|
+
stepIndex,
|
|
60
|
+
totalSteps,
|
|
60
61
|
})
|
|
61
62
|
.info('Command started');
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
// eslint-disable-next-line max-params
|
|
64
66
|
logCommandSuccess(stepIndex: number, totalSteps: number, operation: string, step: UIProtocolStep, context: any): void {
|
|
65
67
|
const commandId = `${operation}-${stepIndex}`;
|
|
66
68
|
const startTime = this.commandStartTimes.get(commandId) || Date.now();
|
|
@@ -77,34 +79,35 @@ export class UILogger {
|
|
|
77
79
|
|
|
78
80
|
// For readSegment, also extract chunk logs if present
|
|
79
81
|
let dataChunks = undefined;
|
|
80
|
-
if (
|
|
82
|
+
if ('readSegment' === commandType) {
|
|
81
83
|
dataChunks = context.variables?.get('lastReadSegmentChunks');
|
|
82
84
|
// For readSegment, we don't need the flattened dataSent/dataReceived since we have dataChunks
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
// Convert dataSent and dataReceived to byte array format if they exist
|
|
86
|
-
const dataSentArray = dataSent ?
|
|
87
|
-
const dataReceivedArray = dataReceived ?
|
|
88
|
+
const dataSentArray = dataSent ? [...dataSent] : undefined;
|
|
89
|
+
const dataReceivedArray = dataReceived ? [...dataReceived] : undefined;
|
|
88
90
|
|
|
89
91
|
this.logger
|
|
90
92
|
.withMetadata({
|
|
91
93
|
commandType,
|
|
92
|
-
|
|
93
|
-
dataSent: dataSentArray,
|
|
94
|
+
dataChunks,
|
|
94
95
|
dataExpected,
|
|
95
96
|
dataReceived: dataReceivedArray,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
startTime,
|
|
99
|
-
endTime,
|
|
97
|
+
dataSent: dataSentArray,
|
|
98
|
+
description,
|
|
100
99
|
duration,
|
|
100
|
+
endTime,
|
|
101
|
+
operation,
|
|
102
|
+
startTime,
|
|
101
103
|
stepIndex,
|
|
104
|
+
success: true,
|
|
102
105
|
totalSteps,
|
|
103
|
-
operation,
|
|
104
106
|
})
|
|
105
107
|
.info('Command completed successfully');
|
|
106
108
|
}
|
|
107
109
|
|
|
110
|
+
// eslint-disable-next-line max-params
|
|
108
111
|
logCommandFailure(stepIndex: number, totalSteps: number, operation: string, step: UIProtocolStep, error: Error, context: any): void {
|
|
109
112
|
const commandId = `${operation}-${stepIndex}`;
|
|
110
113
|
const startTime = this.commandStartTimes.get(commandId) || Date.now();
|
|
@@ -119,53 +122,79 @@ export class UILogger {
|
|
|
119
122
|
const dataExpected = this.getExpectedData(step);
|
|
120
123
|
|
|
121
124
|
// Convert dataSent to byte array format if it exists
|
|
122
|
-
const dataSentArray = dataSent ?
|
|
125
|
+
const dataSentArray = dataSent ? [...dataSent] : undefined;
|
|
123
126
|
|
|
124
127
|
this.logger
|
|
125
128
|
.withMetadata({
|
|
126
129
|
commandType,
|
|
127
|
-
description,
|
|
128
|
-
dataSent: dataSentArray,
|
|
129
130
|
dataExpected,
|
|
131
|
+
dataSent: dataSentArray,
|
|
132
|
+
description,
|
|
133
|
+
duration,
|
|
134
|
+
endTime,
|
|
130
135
|
error: error.message,
|
|
131
|
-
|
|
136
|
+
operation,
|
|
132
137
|
startTime,
|
|
133
|
-
endTime,
|
|
134
|
-
duration,
|
|
135
138
|
stepIndex,
|
|
139
|
+
success: false,
|
|
136
140
|
totalSteps,
|
|
137
|
-
operation,
|
|
138
141
|
})
|
|
139
142
|
.info('Command failed');
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
private getCommandType(step: UIProtocolStep): string {
|
|
143
|
-
if ('sendReceive' in step)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if ('
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
if ('sendReceive' in step) {
|
|
147
|
+
return 'sendReceive';
|
|
148
|
+
}
|
|
149
|
+
if ('send' in step) {
|
|
150
|
+
return 'send';
|
|
151
|
+
}
|
|
152
|
+
if ('receive' in step) {
|
|
153
|
+
return 'receive';
|
|
154
|
+
}
|
|
155
|
+
if ('readSegment' in step) {
|
|
156
|
+
return 'readSegment';
|
|
157
|
+
}
|
|
158
|
+
if ('writeSegment' in step) {
|
|
159
|
+
return 'writeSegment';
|
|
160
|
+
}
|
|
161
|
+
if ('setVariable' in step) {
|
|
162
|
+
return 'setVariable';
|
|
163
|
+
}
|
|
149
164
|
return 'unknown';
|
|
150
165
|
}
|
|
151
166
|
|
|
152
167
|
private getStepDescription(step: UIProtocolStep): string {
|
|
153
|
-
if ('sendReceive' in step && step.sendReceive.description)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if ('
|
|
157
|
-
|
|
168
|
+
if ('sendReceive' in step && step.sendReceive.description) {
|
|
169
|
+
return step.sendReceive.description;
|
|
170
|
+
}
|
|
171
|
+
if ('send' in step && step.send.description) {
|
|
172
|
+
return step.send.description;
|
|
173
|
+
}
|
|
174
|
+
if ('receive' in step && step.receive.description) {
|
|
175
|
+
return step.receive.description;
|
|
176
|
+
}
|
|
177
|
+
if ('readSegment' in step && step.readSegment.description) {
|
|
178
|
+
return step.readSegment.description;
|
|
179
|
+
}
|
|
180
|
+
if ('writeSegment' in step && step.writeSegment.description) {
|
|
181
|
+
return step.writeSegment.description;
|
|
182
|
+
}
|
|
158
183
|
return 'No description';
|
|
159
184
|
}
|
|
160
185
|
|
|
161
186
|
private getExpectedData(step: UIProtocolStep): any {
|
|
162
|
-
if ('sendReceive' in step && step.sendReceive.receive)
|
|
163
|
-
|
|
187
|
+
if ('sendReceive' in step && step.sendReceive.receive) {
|
|
188
|
+
return step.sendReceive.receive;
|
|
189
|
+
}
|
|
190
|
+
if ('receive' in step) {
|
|
191
|
+
return step.receive;
|
|
192
|
+
}
|
|
164
193
|
if ('readSegment' in step) {
|
|
165
194
|
// For readSegment, return both start and end chunk receive patterns
|
|
166
195
|
return {
|
|
167
|
-
startChunk: step.readSegment.startChunk.receive,
|
|
168
196
|
endChunk: step.readSegment.endChunk.receive,
|
|
197
|
+
startChunk: step.readSegment.startChunk.receive,
|
|
169
198
|
type: 'readSegment',
|
|
170
199
|
};
|
|
171
200
|
}
|