P1 and A1 series printers serve JPEG frames on port 6000 over TLS, behind the same access code. This adds the connection, a frame reader, and POST /api/printers/:id/camera/test, which waits for one picture and says what arrived — enough to find out whether the camera answers before any viewer is built. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
24 lines
1.1 KiB
JavaScript
24 lines
1.1 KiB
JavaScript
const test = require('node:test');
|
||
const assert = require('node:assert/strict');
|
||
const { hello, jpegSize } = require('../lib/printerCamera');
|
||
|
||
test('the camera hello carries the username and code in the right places', () => {
|
||
const buf = hello('12345678');
|
||
assert.equal(buf.length, 80);
|
||
assert.equal(buf.readUInt32LE(0), 0x40);
|
||
assert.equal(buf.readUInt32LE(4), 0x3000);
|
||
assert.equal(buf.subarray(16, 20).toString('ascii'), 'bblp');
|
||
assert.equal(buf.subarray(16, 48).toString('ascii').replace(/\0+$/, ''), 'bblp');
|
||
assert.equal(buf.subarray(48, 80).toString('ascii').replace(/\0+$/, ''), '12345678');
|
||
});
|
||
|
||
test('a frame’s size is read from the JPEG itself', () => {
|
||
// A JPEG header: start marker, a comment segment, then the frame header.
|
||
const jpeg = Buffer.concat([
|
||
Buffer.from([0xff, 0xd8]),
|
||
Buffer.from([0xff, 0xfe, 0x00, 0x04, 0x61, 0x62]), // comment, skipped
|
||
Buffer.from([0xff, 0xc0, 0x00, 0x11, 0x08, 0x04, 0x38, 0x07, 0x80]), // 1080 × 1920
|
||
]);
|
||
assert.deepEqual(jpegSize(jpeg), { height: 1080, width: 1920 });
|
||
assert.equal(jpegSize(Buffer.from([0xff, 0xd8, 0x00])), null);
|
||
});
|