Initial push

This commit is contained in:
Ano-sys
2026-02-22 23:30:15 +01:00
commit 7a2d858dfb
58 changed files with 9896 additions and 0 deletions
@@ -0,0 +1,42 @@
// server/routes/serialUtils.js
const router = require('express').Router();
const { listSerialPorts, connectSerial, getLatestPacket } = require('../serial');
router.get('/serialports', async (req, res) => {
try {
const ports = await listSerialPorts();
res.json(ports);
} catch (err) {
console.error('Error listing ports:', err);
res.status(500).json({ error: 'Could not list serial ports' });
}
});
router.get('/latest', (req, res) => {
const payload = getLatestPacket();
if (!payload) {
return res.status(204).end(); // No Content
}
res.json(payload);
});
router.post('/connect', (req, res) => {
const { path } = req.body;
if (!path) {
return res.status(400).json({ error: 'Path is required' });
}
try {
connectSerial(path);
res.json({
ok: true,
connectedTo: path,
baudRate: 115200
});
} catch (err) {
console.error('Failed to connect:', err);
res.status(500).json({ error: 'Could not open serial port' });
}
});
module.exports = router;