4、测试代码
package com.haoyu.module.jcstruct;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.alibaba.fastjson.JSONObject;
import com.haoyu.module.jcstruct.common.BaseDataType;
import com.haoyu.module.jcstruct.dispatch.DispatchCenterService;
import com.haoyu.module.jcstruct.exception.DtuMessageException;
import com.haoyu.module.jcstruct.model.ResolveResult;
import com.haoyu.module.jcstruct.model.ResponseResult;
import com.haoyu.module.jcstruct.opt.JFieldOpt;
import com.haoyu.module.jcstruct.opt.OptManager;
import com.haoyu.module.jcstruct.resolve.DefaultResolve;
import com.haoyu.module.jcstruct.template.TemplateContainer;
import com.haoyu.module.jcstruct.test.handle.GatewayServerCodeType;
import com.haoyu.module.jcstruct.utils.HexUtils;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-cjava.xml")
public class AppTest
{
@Autowired
private TemplateContainer templateContainer;
@Autowired
private OptManager optManager;
@Autowired
private DispatchCenterService dispatchCenterService;
@Autowired
private DefaultResolve defaultResolve;
// 测试解析特征值,协议号0x02
private void testCharacterResolve() throws DtuMessageException, IOException
{
byte[] data = new byte[] { -86, -86, -3, 79, -6, -119, 2, 18, -85, -51, -17, 1, 0, 31, 101, -61, 3, 83, 0, 10, -26, 2, 0, 10, 1, 87, 6, 69, 3, -80, 0, -18, 3, 98, 1, -59, 1, -114, 7, 66, 4, 104, 31, -86, 85 };
ResolveResult json = defaultResolve.resolve(data, null);
// 处理特征值
ResponseResult responseResult = dispatchCenterService.handle(json.getId(), json.getResult());
byte[] rtnData = defaultResolve.unresolve(responseResult.getId(), responseResult.getData());
System.out.println("处理特征值以后返回给C结构数据为:" + HexUtils.bytesToHexString(rtnData));
}
// 测试解析波形,协议号0x04
private void testWaveResolve() throws DtuMessageException, IOException
{
// 申请上传波形
byte[] data = new byte[] { -86, -86, -3, 79, -6, -119, 4, 18, -85, -51, -17, 1, 0, 14, 102, 72, 4, 2, 1, 10, -26, 0, 0, 0, 100, -16, -86, 85 };
Resolve