/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2021/12/21
 */
package org.ts.ddcs.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.process.DataProcessHolder;
import org.ts.ddcs.tcp.TcpWorker;

/***
 * Date:2021/12/21
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @mender：（文件的修改者，文件创建者之外的人）
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@RestController
@RequestMapping("/test")
public class RtuTestController {
    @PostMapping(value = "datagram/send")
    public JSONObject sendDatagram(@RequestBody JSONObject data) {
        JSONObject result = new JSONObject();
        try {
            String ip = data.getString("ip");
            String datagram = data.getString("datagram");
            String datagramAgreement = data.getString("datagramAgreement");
            TcpWorker tcpWorker = DataProcessHolder.newInstance().dataProcess.getTcpWorker(ip);
            if (null != tcpWorker) {
                tcpWorker.put(datagram,datagramAgreement);
            }
            result.put("code","0");
        } catch (Exception e) {
            LogHelper.error(e);
            result.put("code","1");
        }
        return result;
    }
}
