2024-04-20 01:48:14 +00:00
|
|
|
const net = require('net');
|
2024-05-05 15:28:20 +00:00
|
|
|
const { resolve } = require('path');
|
2024-04-20 01:48:14 +00:00
|
|
|
|
2024-05-14 23:06:43 +00:00
|
|
|
/**
|
|
|
|
|
|
|
|
Actions
|
|
|
|
|
|
|
|
0 = NONE,
|
|
|
|
1 = LOAD,
|
|
|
|
2 = DISPLAY,
|
|
|
|
3 = STOP
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
2024-04-20 01:48:14 +00:00
|
|
|
const serverAddress = 'localhost';
|
|
|
|
const serverPort = 8081;
|
|
|
|
|
|
|
|
const client = new net.Socket();
|
2024-05-14 23:06:43 +00:00
|
|
|
let sent = 0;
|
2024-04-20 01:48:14 +00:00
|
|
|
|
|
|
|
console.log(`Connecting to ${serverAddress}:${serverPort}...`);
|
|
|
|
|
|
|
|
async function delay (ms) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return setTimeout(resolve, ms);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-05-14 23:06:43 +00:00
|
|
|
function send (data) {
|
|
|
|
const str = JSON.stringify(data);
|
|
|
|
sent = +new Date();
|
|
|
|
console.log(`[${sent}] SENDING ` + str);
|
|
|
|
client.write(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
function actionLoad (img, x, y, w, h) {
|
|
|
|
const obj = {
|
|
|
|
action : 1, //LOAD
|
|
|
|
image : resolve(img),
|
2024-05-05 15:28:20 +00:00
|
|
|
position : {
|
2024-05-14 23:06:43 +00:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
w,
|
|
|
|
h
|
2024-05-05 15:28:20 +00:00
|
|
|
}
|
2024-04-20 01:48:14 +00:00
|
|
|
};
|
2024-05-14 23:06:43 +00:00
|
|
|
send(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
function actionExpose (img, exposure) {
|
|
|
|
const obj = {
|
|
|
|
action : 2, //DISPLAY
|
|
|
|
image : resolve(img),
|
|
|
|
exposure : [ exposure ]
|
|
|
|
};
|
|
|
|
send(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
function actionStart (img) {
|
|
|
|
const obj = {
|
|
|
|
action : 2, //DISPLAY
|
|
|
|
image : resolve(img)
|
|
|
|
};
|
|
|
|
send(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
function actionStop (img) {
|
|
|
|
const obj = {
|
|
|
|
action : 3, //STOP
|
|
|
|
image : resolve(img)
|
|
|
|
}
|
2024-05-15 00:23:22 +00:00
|
|
|
send(obj);
|
2024-05-14 23:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client.connect(serverPort, serverAddress, async () => {
|
|
|
|
const img = './img/4kSnake.png';
|
|
|
|
actionLoad(img, 0, 0, 320, 320);
|
|
|
|
//
|
2024-04-20 01:48:14 +00:00
|
|
|
await delay(2000);
|
2024-05-14 23:06:43 +00:00
|
|
|
actionExpose(img, 4000);
|
|
|
|
//actionStart(img);
|
|
|
|
//
|
|
|
|
await delay(8000);
|
|
|
|
actionLoad(img, 100, 100, 640, 640);
|
|
|
|
//
|
2024-05-05 15:28:20 +00:00
|
|
|
await delay(1000);
|
2024-05-15 00:23:22 +00:00
|
|
|
actionStart(img);
|
2024-05-14 23:06:43 +00:00
|
|
|
//
|
2024-05-08 20:07:36 +00:00
|
|
|
await delay(2000);
|
2024-05-15 00:23:22 +00:00
|
|
|
actionStop(img);
|
2024-04-20 01:48:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
client.on('data', (data) => {
|
2024-05-14 23:06:43 +00:00
|
|
|
const received = +new Date();
|
|
|
|
console.log(`[${received}] RECEIVED ` + data.toString());
|
|
|
|
console.log(`DIFF ${received - sent}`);
|
2024-04-20 01:48:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
client.on('close', () => {
|
|
|
|
console.log('Closing connection');
|
|
|
|
});
|
|
|
|
|
|
|
|
client.on('error', (err) => {
|
|
|
|
console.error('Error:', err);
|
|
|
|
});
|