From 09ca10947a17e48ecebee853a5d5d33a11ea9d0b Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 14 May 2024 19:06:43 -0400 Subject: [PATCH] Pulled over working features from regression branch. Found that macOS behavior is the issue. --- include/state.hpp | 1 + src/main.cpp | 8 +++- src/state.cpp | 11 ++++- test/test_messages.js | 105 ++++++++++++++++++++++++++++-------------- 4 files changed, 89 insertions(+), 36 deletions(-) diff --git a/include/state.hpp b/include/state.hpp index 4aea0fb..d4ad1cb 100644 --- a/include/state.hpp +++ b/include/state.hpp @@ -45,6 +45,7 @@ class State { void setImage(json& msgData); void setMode(json& msgData); void setExposure(json& msgData); + void setNoExposure(); void setPosition(json& msgData); void setActive () { active = true; } diff --git a/src/main.cpp b/src/main.cpp index b84949a..ce65a2b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -152,14 +152,20 @@ void display () { actionStop(); } state.setInactive(); - postAction(); } + + if (completed) { + postAction(); + completed = false; + } + if (displaying && timing) { auto currentTime = steady_clock::now(); auto elapsedTime = duration_cast(currentTime - startTime).count(); if (elapsedTime > exposureTime) { cout << "Exposed = " << elapsedTime << " ms" << endl; displaying = false; + timing = false; completed = true; } } diff --git a/src/state.cpp b/src/state.cpp index 5b4413e..4144bee 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -56,7 +56,9 @@ void State::setPosition (json& msgData) { } void State::setExposure (json& msgData) { - if (msgData["exposure"].size() == 1) { + if (msgData["exposure"].size() == 0) { + setNoExposure(); + } else if (msgData["exposure"].size() == 1) { exposure = { msgData["exposure"][0] }; cout << "Exposure = " << msgData["exposure"][0] << " ms" << endl; } /*else if (msgData["exposure"].size() == 3) { @@ -69,6 +71,11 @@ void State::setExposure (json& msgData) { } } +void State::setNoExposure () { + exposure = {}; + cout << "No exposure, display indefinitely" << endl; +} + void State::receiveMessage (string msgString) { ERROR = false; json msgData = json::parse(msgString); @@ -95,6 +102,8 @@ void State::receiveMessage (string msgString) { if (action == DISPLAY && msgData.contains("exposure")) { setExposure(msgData); + } else if (action == DISPLAY && !msgData.contains("exposure")) { + setNoExposure(); } setActive(); diff --git a/test/test_messages.js b/test/test_messages.js index 4339a33..05ad961 100644 --- a/test/test_messages.js +++ b/test/test_messages.js @@ -1,10 +1,22 @@ const net = require('net'); const { resolve } = require('path'); +/** + +Actions + +0 = NONE, +1 = LOAD, +2 = DISPLAY, +3 = STOP + +**/ + const serverAddress = 'localhost'; const serverPort = 8081; const client = new net.Socket(); +let sent = 0; console.log(`Connecting to ${serverAddress}:${serverPort}...`); @@ -14,49 +26,74 @@ async function delay (ms) { }); } -client.connect(serverPort, serverAddress, async () => { - const data = { - action : 1, - image: resolve('./img/4kSnake.png'), +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), position : { - x: 100, - y : 100, - w : 320, - h : 320 + x, + y, + w, + h } }; - console.log('SENDING'); - console.log(data); - client.write(JSON.stringify(data)); + 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) + } +} + +client.connect(serverPort, serverAddress, async () => { + const img = './img/4kSnake.png'; + actionLoad(img, 0, 0, 320, 320); + // await delay(2000); - data.action = 2; - delete data.position - data.exposure = [ 4000 ]; - console.log('SENDING'); - console.log(data); - client.write(JSON.stringify(data)); - await delay(6000); - data.action = 1; - data.position = { x: 50, y : 50, w : 320, h : 320 }; - console.log('SENDING'); - console.log(data); - client.write(JSON.stringify(data)); + actionExpose(img, 4000); + //actionStart(img); + // + await delay(8000); + actionLoad(img, 100, 100, 640, 640); + // await delay(1000); - data.action = 2; - delete data.position; - console.log('SENDING'); - console.log(data); - client.write(JSON.stringify(data)); + actionExpose(img, 4000); + //actionStart(img); + // await delay(2000); - data.action = 3; - console.log('SENDING'); - console.log(data); - client.write(JSON.stringify(data)); + //actionStop(img); }); client.on('data', (data) => { - console.log('RECEIVED'); - console.log(data.toString()); + const received = +new Date(); + console.log(`[${received}] RECEIVED ` + data.toString()); + console.log(`DIFF ${received - sent}`); }); client.on('close', () => {