package com.imdroid.beidou_fwd.task;

import com.imdroid.beidou_fwd.service.TCPClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Configuration
@EnableScheduling
public class GXLJForwarder extends GXXfzForwarder{
    private final String FORWARDER_NAME = "广西路建";
    @Value("${gxlj.server.host}")
    private String host;

    @Value("${gxlj.server.port}")
    private int port;
    private boolean enabled=true;

    @PostConstruct
    void registerMe(){
        init(FORWARDER_NAME, "TCP "+host+":"+port,6,FWD_DEVICE_ID,30);
        xfzTcpClient = new TCPClient();
        xfzTcpClient.init(host, port,listener);
        if(!enabled) return;
        xfzTcpClient.start();
    }

    /**
     * 每半小时转发GNSS解算结果
     */
    @Scheduled(cron = "0 0/30 * * * ?") // 每30分钟执行一次
    private void forwardGnss() {
        if(!enabled) return;
        logger.debug("gxlj forwardGnss");
        forwardCurrentGnss();
    }
}
