From d934e93d93416d8a677600946e58140736e135de Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Fri, 27 Oct 2023 16:26:38 +0400 Subject: [PATCH] progress --- app/index.js | 2 +- config/modbus-client.config.js | 3 - controllers/modbus.controller.js | 34 ++++++++++- data.db | Bin 20480 -> 20480 bytes index.d.ts | 7 --- public/css/dist.css | 20 ++++++- public/index.html | 89 +++++++++++++++++------------ public/js/app.js | 45 +++++++++------ routes/api.router.js | 31 ---------- routes/api/index.js | 14 +++++ routes/api/modbus.router.js | 17 ++++++ routes/index.js | 2 +- validators/index.js | 2 +- validators/modbus-device.schema.js | 12 ++++ 14 files changed, 174 insertions(+), 104 deletions(-) delete mode 100644 routes/api.router.js create mode 100644 routes/api/index.js create mode 100644 routes/api/modbus.router.js create mode 100644 validators/modbus-device.schema.js 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 7ab0cfc11f91cbc778b7487c8651f9dbfda1b6e8..87d5438059f248f8afd871641ae29ff8801598c3 100644 GIT binary patch delta 215 zcmZozz}T>Wae}nqe+C8yRv?Cfu8BIvjQ=+#EaPVhXJ8NC*yzj7F;R_?ok4T~vmsQ8ApnxuFH8Uc delta 220 zcmZozz}T>Wae}nqBL)TrRv?Cfx`{f*jE^=ZEaPV>V_+}a*qFo4F_E2-ok4WI^X7Q* zRJP5JWtEv&t}yUl*(|7VieFiaftx{Cok^5Ql#!Du#5usw(n!zH%tFsV&(Oe_@mq09 zamwcJ`n&=>Ed0|M_@D8g=HI|S9jLXP-$I;)ok5;~L7KxQwJb9^RYBRrCow5CN5Mpr o87RTXh>$Sm5P(P-OER%DOg`@~E+qkUlRPJ*G$%~6AykPW0J%3a+yDRo 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 @@ - -
-