in sim/state/uart.ts [82:147]
constructor() {
let data = new Uint8Array(UartOff.Size);
MMapMethods.register("/dev/lms_uart", {
data,
beforeMemRead: () => {
//console.log("uart before read");
const inputNodes = ev3board().getInputNodes();
for (let port = 0; port < DAL.NUM_INPUTS; port++) {
const node = inputNodes[port];
if (node && node.isUart()) {
// Actual
const index = 0; //UartOff.Actual + port * 2;
util.map16Bit(data, UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index, Math.floor(node.getValue()))
// Status
data[UartOff.Status + port] = node.valueChange() ? UartStatus.UART_PORT_CHANGED : UartStatus.UART_DATA_READY;
}
}
},
read: buf => {
let v = "vSIM"
// for (let i = 0; i < buf.data.length; ++i)
// buf.data[i] = v.charCodeAt(i) || 0
return buf.data.length
},
write: buf => {
return 2
},
ioctl: (id, buf) => {
switch (id) {
case IO.UART_SET_CONN: {
// Set mode
//console.log("IO.UART_SET_CONN");
for (let port = 0; port < DAL.NUM_INPUTS; port++) {
const connection = buf.data[DevConOff.Connection + port]; // CONN_NONE, CONN_INPUT_UART
const type = buf.data[DevConOff.Type + port];
const mode = buf.data[DevConOff.Mode + port];
//console.log(`${port}, mode: ${mode}`)
const node = ev3board().getInputNodes()[port];
if (node) node.setMode(mode);
}
return 2;
}
case IO.UART_CLEAR_CHANGED: {
//console.log("IO.UART_CLEAR_CHANGED")
for (let port = 0; port < DAL.NUM_INPUTS; port++) {
const connection = buf.data[DevConOff.Connection + port]; // CONN_NONE, CONN_INPUT_UART
const type = buf.data[DevConOff.Type + port];
const mode = buf.data[DevConOff.Mode + port];
const node = ev3board().getInputNodes()[port];
if (node) node.setMode(mode);
}
return 2;
}
case IO.UART_READ_MODE_INFO: {
//console.log("IO.UART_READ_MODE_INFO")
const port = buf.data[UartCtlOff.Port];
const mode = buf.data[UartCtlOff.Mode];
const node = ev3board().getInputNodes()[port];
if (node) buf.data[UartCtlOff.TypeData + TypesOff.Type] = node.getDeviceType(); // DEVICE_TYPE_NONE, DEVICE_TYPE_TOUCH,
return 2;
}
}
return 2;
}
})
}