Skip to content

Commit d227385

Browse files
committed
Improve logging
1 parent 70cbc6d commit d227385

File tree

7 files changed

+140
-34
lines changed

7 files changed

+140
-34
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@brewskey/spark-server",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"license": "AGPL-3.0",
55
"repository": {
66
"type": "git",

packages/spark-protocol/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@brewskey/spark-protocol",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"main": "./dist/index.js",
55
"repository": {
66
"type": "git",

packages/spark-protocol/src/__tests__/FirmwareManager.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ describe('FirmwareManager', () => {
8787
'system-part2-1.0.1-p1.bin',
8888
'bootloader-1.0.1-p1.bin',
8989
],
90+
currentModulesFiles: [
91+
'bootloader-0.6.2-p1.bin',
92+
'system-part1-0.6.3-p1.bin',
93+
'system-part2-0.6.3-p1.bin',
94+
],
9095
});
9196
});
9297

@@ -220,6 +225,74 @@ describe('FirmwareManager', () => {
220225
'system-part1-1.0.1-p1.bin',
221226
'system-part2-1.0.1-p1.bin',
222227
],
228+
currentModulesFiles: [
229+
'p1-bootloader@3.3.1+lto.bin',
230+
'system-part1-0.7.0-p1.bin',
231+
'system-part2-0.7.0-p1.bin',
232+
],
233+
});
234+
});
235+
236+
it('should work for 2.3.1', async () => {
237+
const BAD_DEVICE_THAT_WONT_UPDATE: SystemInformation = {
238+
f: [],
239+
v: {},
240+
p: 8,
241+
m: [
242+
{ s: 16384, l: 'm', vc: 30, vv: 30, f: 'b', n: '0', v: 501, d: [] },
243+
{
244+
s: 262144,
245+
l: 'm',
246+
vc: 30,
247+
vv: 30,
248+
f: 's',
249+
n: '1',
250+
v: 1406,
251+
d: [{ f: 's', n: '2', v: 207, _: '' }],
252+
},
253+
{
254+
s: 262144,
255+
l: 'm',
256+
vc: 30,
257+
vv: 30,
258+
f: 's',
259+
n: '2',
260+
v: 1406,
261+
d: [
262+
{ f: 's', n: '1', v: 1406, _: '' },
263+
{ f: 'b', n: '0', v: 400, _: '' },
264+
],
265+
},
266+
{
267+
s: 131072,
268+
l: 'm',
269+
vc: 30,
270+
vv: 26,
271+
u: '99703CDF1C6D6C6ABCAB382D9EC6EBE0167FB2B9507B5DF521A822E1956EA8FA',
272+
f: 'u',
273+
n: '1',
274+
v: 6,
275+
d: [{ f: 's', n: '2', v: 2302, _: '' }],
276+
},
277+
],
278+
};
279+
const result = await FirmwareManager.getOtaSystemUpdateConfig(
280+
BAD_DEVICE_THAT_WONT_UPDATE,
281+
);
282+
283+
expect(result).toMatchObject({
284+
allModuleFunctions: ['s', 's', 'b'],
285+
allModuleIndices: [1, 2, 0],
286+
allUpdateFiles: [
287+
'p1-system-part1@2.3.1.bin',
288+
'p1-system-part2@2.3.1.bin',
289+
'p1-bootloader@2.0.0-rc.3+lto.bin',
290+
],
291+
currentModulesFiles: [
292+
'p1-bootloader@1.5.1+lto.bin',
293+
'p1-system-part1@1.4.4.bin',
294+
'p1-system-part2@1.4.4.bin',
295+
],
223296
});
224297
});
225298
});

packages/spark-protocol/src/clients/Device.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,9 @@ class Device extends EventEmitter {
397397
this._logger.info(
398398
{
399399
cache_key: this._connectionKey,
400-
deviceID: this.getDeviceID(),
401-
firmwareVersion: this._attributesFromDevice.productFirmwareVersion,
400+
...this._attributesFromDevice,
402401
ip: this.getRemoteIPAddress(),
403-
particleProductId: this._attributesFromDevice.particleProductId,
404-
platformId: this._attributesFromDevice.platformId,
402+
systemInformation,
405403
},
406404
'On device protocol initialization complete',
407405
);
@@ -451,8 +449,6 @@ class Device extends EventEmitter {
451449
reservedFlags: payload.readUInt16BE(4),
452450
};
453451

454-
this._logger.info(this._attributesFromDevice, 'Connection attributes');
455-
456452
if (this._attributesFromDevice.platformId !== 0) {
457453
// This is the maximum for Photon/P1.
458454
// It should be updated for Boron and other types.

packages/spark-protocol/src/lib/FirmwareManager.ts

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,26 @@ const FUNC_BY_NUMBER = {
2929
export type OTAUpdate = {
3030
allModuleFunctions: ModuleDependency['f'][];
3131
allModuleIndices: Array<number>;
32-
systemFile: Buffer;
32+
systemFiles: Buffer[];
3333
allUpdateFiles: Array<string>;
34+
currentModulesFiles: string[];
3435
};
3536

3637
let FirmwareSettings: FirmwareSetting[] = [];
38+
39+
const findSettingForFirmwareModule = (
40+
platformID: number,
41+
dependency: FirmwareModule,
42+
): FirmwareSetting | undefined => {
43+
return FirmwareSettings.find(
44+
({ prefixInfo }: { prefixInfo: FirmwarePrefixInfo }): boolean =>
45+
prefixInfo.platformID === platformID &&
46+
prefixInfo.moduleVersion === dependency.version &&
47+
dependency.func != null &&
48+
prefixInfo.moduleFunction === NUMBER_BY_FUNCTION[dependency.func] &&
49+
prefixInfo.moduleIndex === parseInt(dependency.name, 10),
50+
);
51+
};
3752
class FirmwareManager {
3853
private static binariesDirectory: string;
3954

@@ -45,6 +60,28 @@ class FirmwareManager {
4560
) as FirmwareSetting[];
4661
}
4762

63+
static getCurrentModules(
64+
systemInformation: SystemInformation,
65+
): FirmwareSetting[] {
66+
// Fix 204 version deps. 204 doesn't exist so map it to 207
67+
systemInformation.m.forEach((moduleDependency: ModuleDependency) => {
68+
moduleDependency.d.forEach((subDependency: ModuleSubDependency) => {
69+
if (subDependency.v === 204) {
70+
subDependency.v = 207;
71+
}
72+
});
73+
});
74+
75+
return systemInformation.m
76+
.map((moduleDependency: ModuleDependency) =>
77+
findSettingForFirmwareModule(
78+
systemInformation.p,
79+
new FirmwareModule(moduleDependency),
80+
),
81+
)
82+
.filter(filterFalsyValues);
83+
}
84+
4885
static async getMissingModules(
4986
systemInformation: SystemInformation,
5087
): Promise<FirmwareSetting[] | null | undefined> {
@@ -98,7 +135,10 @@ class FirmwareManager {
98135

99136
return {
100137
...result,
101-
systemFile: systemFiles[0],
138+
systemFiles,
139+
currentModulesFiles: FirmwareManager.getCurrentModules(
140+
systemInformation,
141+
).map((setting: FirmwareSetting) => setting.filename),
102142
};
103143
}
104144

@@ -136,23 +176,11 @@ class FirmwareManager {
136176
}
137177

138178
const iter = 0;
139-
const findSettingForFirmwareModule = (
140-
dependency: FirmwareModule,
141-
): FirmwareSetting | undefined => {
142-
return FirmwareSettings.find(
143-
({ prefixInfo }: { prefixInfo: FirmwarePrefixInfo }): boolean =>
144-
prefixInfo.platformID === platformID &&
145-
prefixInfo.moduleVersion === dependency.version &&
146-
dependency.func != null &&
147-
prefixInfo.moduleFunction === NUMBER_BY_FUNCTION[dependency.func] &&
148-
prefixInfo.moduleIndex === parseInt(dependency.name, 10),
149-
);
150-
};
151179

152180
const addRealDependencies = (
153181
dependency: FirmwareModule,
154182
): FirmwareModule | null => {
155-
const setting = findSettingForFirmwareModule(dependency);
183+
const setting = findSettingForFirmwareModule(platformID, dependency);
156184
if (!setting) {
157185
logger.error({
158186
msg: 'Cannot find firmware for module',
@@ -225,7 +253,7 @@ class FirmwareManager {
225253
return a.name.localeCompare(b.name);
226254
})
227255
.map((dep: FirmwareModule): FirmwareSetting | undefined => {
228-
const setting = findSettingForFirmwareModule(dep);
256+
const setting = findSettingForFirmwareModule(platformID, dep);
229257

230258
if (!setting) {
231259
logger.error({ dep, platformID }, 'Missing firmware setting');

packages/spark-protocol/src/server/DeviceServer.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,16 @@ class DeviceServer {
236236
false,
237237
);
238238

239-
logger.info('Flashing OTA System Firmware', {
240-
filename: config.allUpdateFiles[0],
241-
deviceId: device.getDeviceID(),
242-
systemInformation: JSON.stringify(systemInformation),
243-
});
239+
logger.info(
240+
{
241+
filename: config.allUpdateFiles[0],
242+
deviceId: device.getDeviceID(),
243+
systemInformation,
244+
},
245+
'Flashing OTA System Firmware',
246+
);
244247

245-
await device.flash(config.systemFile);
248+
await device.flash(config.systemFiles[0]);
246249
}, 100);
247250
}
248251

@@ -536,7 +539,13 @@ class DeviceServer {
536539

537540
let shouldSwallowEvent = false;
538541

539-
logger.error(eventData);
542+
logger.info(
543+
{
544+
...device.getAttributes(),
545+
...eventData,
546+
},
547+
eventName,
548+
);
540549

541550
// All spark events except special events should be hidden from the
542551
// event stream.
@@ -720,12 +729,12 @@ class DeviceServer {
720729

721730
logger.info(
722731
{
723-
deviceID,
732+
...device.getAttributes(),
724733
isFromMyDevices,
725734
messageName,
726735
query,
727736
},
728-
'Subscribe Request',
737+
'Subscribe Request ' + messageName,
729738
);
730739

731740
device.sendReply('SubscribeAck', packet.messageId);

src/managers/WebhookManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class WebhookManager {
323323
responseEventData,
324324
webhook,
325325
},
326-
'Webhook',
326+
'Webhook ' + webhook.event,
327327
);
328328
} catch (error) {
329329
logger.error(

0 commit comments

Comments
 (0)