nope/modules/mod-Generic-PLC-Interface/helpers/gen-setup-belegung.ts

70 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-08-30 07:45:44 +00:00
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2018-12-19 15:26:04
* @modify date 2020-03-12 21:41:12
* @desc [Tool to convert the the provided Inputs to a config file]
*/
import { writeFileSync } from "fs";
2020-09-08 14:59:06 +00:00
import { padString } from "../../mod-TypeScript-Library/src/String-Methods";
2020-08-30 07:45:44 +00:00
export const DEFAULT_GUI_CONFIG = "./config/gui-configuration.json";
function _genOutputBool(
start: number,
numberOfByts: number,
modName: string,
preLabel = "out_"
) {
let counter = 0;
let ret = "";
do {
const str =
preLabel +
padString(start + Math.floor(counter / 8), 3) +
"_" +
(counter % 8).toString() +
"\t" +
modName +
"\tBool\t%Q" +
(start + Math.floor(counter / 8)).toString() +
"." +
(counter % 8).toString();
if (counter === 0) {
ret = str;
} else {
ret += "\n" + str;
}
counter++;
} while (counter < numberOfByts * 8);
return ret;
}
if (require.main == module) {
const mods = [
[0, 4, "SPS"],
[12, 4, "ET200"]
];
let ret = "";
for (const [counter, m] of mods.entries()) {
const str = _genOutputBool(...m);
if (counter === 0) {
ret = str;
} else {
ret += "\n" + str;
}
}
writeFileSync(
2020-09-08 14:59:06 +00:00
"./modules/mod-Generic-PLC-Interface/helpers/SPS-Belegung-Raw.txt",
2020-08-30 07:45:44 +00:00
ret,
{ encoding: "utf-8" }
);
}