diff --git a/app/index.js b/app/index.js index 531396e..3c297b6 100644 --- a/app/index.js +++ b/app/index.js @@ -4,7 +4,7 @@ import pino from "pino-http"; /** * Routers */ -import { apiRouter } from "#root/routes/api.router.js"; +import { apiRouter } from "#root/routes/index.js"; /** * Middlewares diff --git a/config/modbus-client.config.js b/config/modbus-client.config.js index 7a213cb..087819f 100644 --- a/config/modbus-client.config.js +++ b/config/modbus-client.config.js @@ -1,7 +1,4 @@ import Modbus from "modbus-serial"; const modbusClient = new Modbus(); - -modbusClient.on("close", () => console.log("Modbus connection closed.")); - export default modbusClient; diff --git a/controllers/modbus.controller.js b/controllers/modbus.controller.js index 6bb9f09..9ab78df 100644 --- a/controllers/modbus.controller.js +++ b/controllers/modbus.controller.js @@ -51,6 +51,7 @@ export const modbusController = { if (!modbusClient.isOpen) return res.status(400).json({ message: "Already closed." }); modbusClient.close(undefined); modbusClient.destroy(undefined); + return res.status(200).json({ message: 'Closed.' }); } catch (error) { next(error); } @@ -77,7 +78,22 @@ export const modbusController = { * @param {import('express').Response} res * @param {import('express').NextFunction} next */ - async createSlaveDevice(req, res, next) {}, + async createDevice(req, res, next) { + try { + await db.run(`INSERT INTO "modbus_slaves" ( + "id", + "name", + "g_display_reg_addr", + "g_display_reg_format", + "g_y_label", + "is_logging") + VALUES (?, ?, ?, ?, ?, ?)`, + [...req.body]); + return res.send(200).json({ message: 'Device created.', data: req.body }); + } catch (error) { + next(error) + } + }, /** * Remove modbus slave device @@ -85,7 +101,21 @@ export const modbusController = { * @param {import('express').Response} res * @param {import('express').NextFunction} next */ - async removeSlaveDevice(req, res, next) { + async updateDevice(req, res, next) { + try { + + } catch (error) { + next(error); + } + }, + + /** + * Remove modbus slave device + * @param {import('express').Request} req + * @param {import('express').Response} res + * @param {import('express').NextFunction} next + */ + async removeDevice(req, res, next) { try { const device = await db.get(`SELECT id FROM "modbus_slaves" WHERE id = ?`, [req.body.id]); if (!device) return res.status(404).json({ message: 'Device not found.' }); diff --git a/data.db b/data.db index 7ab0cfc..87d5438 100644 Binary files a/data.db and b/data.db differ diff --git a/index.d.ts b/index.d.ts index 257292a..541d82e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,10 +10,3 @@ export type AppConfig = { log_interval_ms: number; }; -export type SlaveModbusDevice = { - id: number; - name: string; - display_reg_addr: number | null; - display_reg_format: number | null; - is_logging: boolean; -} \ No newline at end of file diff --git a/public/css/dist.css b/public/css/dist.css index 9bb17d3..feda3cf 100644 --- a/public/css/dist.css +++ b/public/css/dist.css @@ -682,6 +682,18 @@ video { margin-top: 1.5rem; } +.mb-1 { + margin-bottom: 0.25rem; +} + +.mb-2 { + margin-bottom: 0.5rem; +} + +.mb-10 { + margin-bottom: 2.5rem; +} + .block { display: block; } @@ -714,8 +726,12 @@ video { height: 100vh; } -.max-h-\[520px\] { - max-height: 520px; +.max-h-\[400px\] { + max-height: 400px; +} + +.min-h-\[50px\] { + min-height: 50px; } .w-1 { diff --git a/public/index.html b/public/index.html index 3fc467e..a7fcdce 100644 --- a/public/index.html +++ b/public/index.html @@ -27,31 +27,34 @@
+ Devices: - No devices added. -
+ + No devices added. + +
-

+
Connection:
- Status: + + Status: Opened Closed @@ -63,20 +66,27 @@

+
Edit - Delete + href="#"> + Delete +
+

+

Display values

@@ -90,7 +100,7 @@ - -
-