if (process.argv.length > 2) {
	var omcwbyte2 = 0;
	if (arg = process.argv.slice(2).toString()) {
		omcwbyte2 = parseInt(arg);
		omcwbyte2 = ((omcwbyte2 % 16) & 0x0F);
	}
	var cwRegSep = Boolean(omcwbyte2 & 0b0100);
	var cwTopSol = Boolean(omcwbyte2 & 0b0010);
	var cwBotSol = Boolean(omcwbyte2 & 0b0001);

	var omcwtp = 0;
	if (arg = process.argv.slice(3).toString()) {
		omcwtp = parseInt(arg);
		omcwtp = ((omcwtp % 64) & 0x3F);
	}

	var omcwbp = 0;
	if (arg = process.argv.slice(4).toString()) {
		omcwbp = parseInt(arg);
		omcwbp = ((omcwbp % 4) & 0x03);
	}

	var omcwbyte = 0;
	if (arg = process.argv.slice(5).toString()) {
		omcwbyte = parseInt(arg);
		omcwbyte = ((omcwbyte % 16) & 0x0F);
	}


const fs = require('fs');
const net = require('net');

const HOST = '127.0.0.1';
const PORT = 6867;

let jsonData;

try {
jsonData = `
{ 
    				"OMCW":{ 
					"regionSeparator": `+cwRegSep+`,
					"topSolid": `+cwTopSol+`,
					"bottomSolid": `+cwBotSol+`,
					"topPage": ` + omcwtp + `,
					"ldlPage": `+omcwbp+`
				} 
			}
`;
    //jsonData = fs.readFileSync(JSON_FILE, 'utf8');
    //JSON.parse(jsonData); // Validate JSON before sending
} catch (err) {
    console.error(`Failed to load JSON file: ${err.message}`);
    process.exit(1);
}

const socket = net.createConnection(PORT, HOST, () => {
    console.log(`Connected to ${HOST}:${PORT}`);

    socket.write(jsonData, 'utf8', () => {
        console.log(`Sent ${Buffer.byteLength(jsonData)} bytes`);
        socket.end();
    });
});

socket.on('data', (data) => {
    console.log('Received:', data.toString());
});

socket.on('end', () => {
    console.log('Connection closed by remote host');
});

socket.on('error', (err) => {
    console.error(`Socket error: ${err.message}`);
    process.exit(1);
});

}