"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AgvNode = void 0;
const agv_constant_1 = require("../../entity/agv.constant");
class AgvNode {
  generateScript(scriptWriter) {
    scriptWriter.appendLine(`local json = require("json")`);
    scriptWriter.appendLine(`local socket = require("socket")`);
    scriptWriter.appendLine(`local agvc =sched.jsonrpc.proxy('http://${agv_constant_1.AGV_DEFAULT_HOST}:${agv_constant_1.AGV_PRC_CONTROL_PORT}/jsonrpc')`);
    const threadName = `handler_thread_safety_status`;
    scriptWriter.appendLine(`${threadName}=thread(function()`);
    scriptWriter.increaseIndent();
    scriptWriter.appendLine(`local safetyEdgeStatus = nil`);
    scriptWriter.appendLine(`while true do`);
    scriptWriter.increaseIndent();
    scriptWriter.appendLine(`sched.sync_program_point()`);
    scriptWriter.appendLine(`local runningInfo = agvc.AgvcInterface.getRunningInfo()`);
    scriptWriter.appendLine(`if runningInfo and runningInfo.safety_edge_status ~= 0 and runningInfo.safety_edge_status ~= safetyEdgeStatus then`);
    scriptWriter.increaseIndent();
    scriptWriter.appendLine(`safetyEdgeStatus = runningInfo.safety_edge_status`);
    scriptWriter.appendLine(`popup(TraceLevel.INFO, "Info", runningInfo.safety_edge_status, 1101)`);
    scriptWriter.appendLine(`pause()`);
    scriptWriter.decreaseIndent();
    scriptWriter.appendLine(`elseif runningInfo ~= nil then`);
    scriptWriter.increaseIndent();
    scriptWriter.appendLine(`safetyEdgeStatus = runningInfo.safety_edge_status`);
    scriptWriter.end();
    scriptWriter.appendLine(`sleep(0.2)`);
    scriptWriter.appendLine(`sched.cancel_point()`);
    scriptWriter.end();
    scriptWriter.decreaseIndent();
    scriptWriter.appendLine(`end, "thread_safety_status")`);
    scriptWriter.appendLine(`run(${threadName})`);
  }
  setModel(dataModel) {}
}
exports.AgvNode = AgvNode;
//# sourceMappingURL=agv-node.js.map