package com.xhpc.pp.logic;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.xhpc.common.enums.StationDeviceEnum;
import com.xhpc.pp.domain.XhpcDeviceMessage;
import com.xhpc.pp.mapper.XhpcDeviceMessageMapper;
import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.tx.logic.ServiceLogic;
import com.xhpc.pp.utils.HexUtils;
import com.xhpc.pp.utils.security.CRCCalculator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
import static com.xhpc.common.data.redis.StaticBeanUtil.seqHex;

@Lazy
@Component("PileConfigDataLogic")
public class PileConfigDataLogic implements ServiceLogic {


    private static final Logger log = LoggerFactory.getLogger(PileConfigDataLogic.class);

    @Resource
    XhpcDeviceMessageMapper deviceMessageMapper;


    @Override
    public ServiceResult service(ServiceParameter sp) throws Exception {


        return null;
    }


    public static String translate(String pileNo, String powerNumber) {

        String skey = "pile:".concat(pileNo).concat(".seqhex");
        String resultStr = "680D".concat(seqHex(skey)).concat("0052")
                .concat(pileNo).concat("00").concat(String.format("%02X", Long.parseLong(powerNumber)));
        resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
        return resultStr;
    }

}
