@springfield/ham-radio-utils 2.1.0 → 2.2.0

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.
@@ -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 (commandType === 'readSegment') {
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 ? Array.from(dataSent) : undefined;
87
- const dataReceivedArray = dataReceived ? Array.from(dataReceived) : undefined;
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
- description,
93
- dataSent: dataSentArray,
94
+ dataChunks,
94
95
  dataExpected,
95
96
  dataReceived: dataReceivedArray,
96
- dataChunks,
97
- success: true,
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 ? Array.from(dataSent) : undefined;
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
- success: false,
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) return 'sendReceive';
144
- if ('send' in step) return 'send';
145
- if ('receive' in step) return 'receive';
146
- if ('readSegment' in step) return 'readSegment';
147
- if ('writeSegment' in step) return 'writeSegment';
148
- if ('setVariable' in step) return 'setVariable';
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) return step.sendReceive.description;
154
- if ('send' in step && step.send.description) return step.send.description;
155
- if ('receive' in step && step.receive.description) return step.receive.description;
156
- if ('readSegment' in step && step.readSegment.description) return step.readSegment.description;
157
- if ('writeSegment' in step && step.writeSegment.description) return step.writeSegment.description;
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) return step.sendReceive.receive;
163
- if ('receive' in step) return step.receive;
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
  }