private MTO_376 PutInCommandItem(
      Map datacellParams,
      CircleDataItems circleDataItems,
      String commandItemCode,
      String LogicAddress,
      int MpSn) {
    MTO_376 MTO = new MTO_376();
    CollectObject object = new CollectObject();
    CommandItem citem = new CommandItem();
    if (datacellParams != null) citem.setDatacellParam(datacellParams);
    if (circleDataItems != null) {
      citem.setCircleDataItems(circleDataItems);
      citem.setCircleLevel(1);
    }

    citem.setIdentifier(commandItemCode); // 终端上行通信口通信参数设置
    object.AddCommandItem(citem);
    object.setLogicalAddr(LogicAddress);
    object.setEquipProtocol("01");
    object.setMpSn(new int[] {MpSn});

    MTO.getCollectObjects().add(object);

    return MTO;
  }
  //  @Test
  public void testReadRealtimeData() throws Exception {
    System.out.println("ReadRealtimeData");

    CommandItem commandItem = new CommandItem();
    commandItem.setIdentifier("100C0025");

    CollectObject obj = new CollectObject();
    obj.setLogicalAddr("96123456");
    obj.setMpSn(new int[] {1});
    obj.AddCommandItem(commandItem);

    MTO_376 MTO3 = new MTO_376();
    MTO3.addCollectObject(obj);

    RealTimeProxy376 instance = proxy;
    long SequenceCode = instance.readData(MTO3);
    RealTimeTaskDAO task = taskService.getTask(SequenceCode);
    PmPacket376 packet = new PmPacket376();
    packet.setValue(BcdUtils.stringToByteArray(task.getSendmsg()), 0);
    assertTrue(packet.getAddress().getRtua().equals("96123456"));
    assertTrue(packet.getAfn() == 0x0C);
    PmPacket376DA da = new PmPacket376DA();
    PmPacket376DT dt = new PmPacket376DT();
    packet.getDataBuffer().rewind();
    packet.getDataBuffer().getDA(da);
    packet.getDataBuffer().getDT(dt);
    assertTrue(da.getPn() == 1);
    assertTrue(dt.getFn() == 25);
  }
  //  @Test
  public void testReadEquipmentParametersF9() throws Exception {
    CommandItem commandItem = new CommandItem();
    commandItem.setIdentifier("10040009");

    CollectObject obj = new CollectObject();
    obj.setLogicalAddr("96123456");
    obj.setMpSn(new int[] {0});
    obj.AddCommandItem(commandItem);

    MTO_376 MTO3 = new MTO_376();
    MTO3.addCollectObject(obj);

    RealTimeProxy376 instance = proxy;
    long SequenceCode = instance.readParameters(MTO3);

    this.taskService.insertRecvMsg(
        SequenceCode,
        "96123456",
        "55 68 72 00 72 00 68 98 12 96 56 34 00 0A 60 00 00 01 01 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 26 16 55 ");

    Map<String, Map<String, String>> expResult = new HashMap();
    Map<String, String> MapDataItem = new HashMap();

    MapDataItem.put(
        "1004000901",
        "1111111111111111111111111111111111111111111111111111111111111111"); // 主用IP地址和端口
    MapDataItem.put(
        "1004000902",
        "1111111111111111111111111111111111111111111111111111111111111111"); // 事件重要性等级标志位

    expResult.put("96123456#0#10040009", MapDataItem);
    Map result = instance.getReturnByReadParameter(SequenceCode);
    assertEquals(expResult, result);
  }
  //  @Test
  public void testReadEquipmentParametersF3() throws Exception {
    CommandItem commandItem = new CommandItem();
    commandItem.setIdentifier("10040003");

    CollectObject obj = new CollectObject();
    obj.setLogicalAddr("96123456");
    obj.setMpSn(new int[] {0});
    obj.AddCommandItem(commandItem);

    MTO_376 MTO3 = new MTO_376();
    MTO3.addCollectObject(obj);

    RealTimeProxy376 instance = proxy;
    long SequenceCode = instance.readParameters(MTO3);

    this.taskService.insertRecvMsg(
        SequenceCode,
        "96123456",
        "55 68 A2 00 A2 00 68 98 12 96 56 34 00 0A 60 00 00 04 00 C0 A8 00 01 90 1F C0 A8 00 02 90 1F 5A 4A 44 4C 2E 5A 4A 00 00 00 00 00 00 00 00 00 6F 16 55 ");

    Map<String, Map<String, String>> expResult = new HashMap();
    Map<String, String> MapDataItem = new HashMap();

    MapDataItem.put("1004000301", "192.168.0.1:8080"); // 主用IP地址和端口
    MapDataItem.put("1004000302", "192.168.0.2:8080"); // 备用IP地址和端口
    MapDataItem.put("1004000303", "ZJDL.ZJ"); // APN

    expResult.put("96123456#0#10040003", MapDataItem);
    Map result = instance.getReturnByReadParameter(SequenceCode);
    assertEquals(expResult, result);
  }
  //  @Test
  public void testReadEquipmentParametersF1() throws Exception {
    CommandItem commandItem = new CommandItem();
    commandItem.setIdentifier("10040001");

    CollectObject obj = new CollectObject();
    obj.setLogicalAddr("96123456");
    obj.setMpSn(new int[] {0});
    obj.AddCommandItem(commandItem);

    MTO_376 MTO3 = new MTO_376();
    MTO3.addCollectObject(obj);

    RealTimeProxy376 instance = proxy;
    long SequenceCode = instance.readParameters(MTO3);

    this.taskService.insertRecvMsg(
        SequenceCode,
        "96123456",
        "55 68 4A 00 4A 00 68 98 12 96 56 34 00 0A 60 00 00 01 00 0A 14 1E 03 07 0F 8A 16 55  ");

    Map<String, Map<String, String>> expResult = new HashMap();
    Map<String, String> MapDataItem = new HashMap();

    MapDataItem.put("1004000101", "10"); // 终端数传机延时时间RTS
    MapDataItem.put("1004000102", "20"); // 终端作为启动站允许发送传输延时时间
    MapDataItem.put("1004000103", "30"); // 终端等待从动站响应的超时时间
    MapDataItem.put("1004000104", "3"); // 终端等待从动站响应的重发次数
    MapDataItem.put("1004000106", "11100000"); // 需要主站确认的通信服务(CON=1)的标志
    MapDataItem.put("1004000107", "15"); // 心跳周期

    expResult.put("96123456#0#10040001", MapDataItem);
    Map result = instance.getReturnByReadParameter(SequenceCode);
    assertEquals(expResult, result);
  }
  //  @Test
  public void testTransmitMsg() throws Exception {
    Map datacellParams1 = new TreeMap();
    datacellParams1.put("8001C04F01", "2"); // 保护器型号ID
    datacellParams1.put("8001C04F02", "00000001");
    datacellParams1.put("8001C04F03", "0");
    datacellParams1.put("8001C04F04", "0");
    datacellParams1.put("8001C04F05", "0");
    datacellParams1.put("8001C04F06", "01111111");

    CommandItem commandItem = new CommandItem();
    commandItem.setIdentifier("8001C04F");
    commandItem.setDatacellParam(datacellParams1);

    CollectObject_TransMit cob = new CollectObject_TransMit();
    cob.setFuncode((byte) 4);
    cob.setMeterAddr("1");
    cob.setMeterType(MeterType.Meter645);
    cob.setPort((byte) 1);
    SerialPortPara spp = new SerialPortPara();
    spp.setBaudrate(BaudRate.bps_9600);
    spp.setCheckbit(0);
    spp.setStopbit(1);
    spp.setOdd_even_bit(1);
    spp.setDatabit(8);
    cob.setSerialPortPara(spp);
    cob.setTerminalAddr("96123456");
    cob.setWaitforByte((byte) 5);
    cob.setWaitforPacket((byte) 10);
    cob.addCommandItem(commandItem);

    MTO_376 MTO = new MTO_376();
    MTO.addCollectObject_Transmit(cob);

    RealTimeProxy376 instance = proxy;
    long expResult = 0L;
    long SequenceCode = instance.transmitMsg(MTO);

    RealTimeTaskDAO task = taskService.getTask(SequenceCode);
    PmPacket376 packet = new PmPacket376();
    packet.setValue(BcdUtils.stringToByteArray(task.getSendmsg()), 0);
    assertTrue(packet.getAddress().getRtua().equals("96123456"));

    byte[] databuff = packet.getDataBuffer().getValue();
    int head = Gb645MeterPacket.getMsgHeadOffset(databuff, 0);
    Gb645MeterPacket pack = Gb645MeterPacket.getPacket(databuff, head);
    assertTrue(pack.getAddress().getAddress().equals("000000000001"));
    assertTrue(pack.getControlCode().getValue() == 4);
    PmPacketData databuf = pack.getDataAsPmPacketData();
    databuf.rewind();
    assertTrue(databuf.getA8().getValue() == 36);
  }
  //  @Test
  public void testReadEquipmentParametersF26() throws Exception {
    CommandItem commandItem = new CommandItem();
    commandItem.setIdentifier("10040026");

    CollectObject obj = new CollectObject();
    obj.setLogicalAddr("96123455");
    obj.setMpSn(new int[] {0});
    obj.AddCommandItem(commandItem);

    MTO_376 MTO3 = new MTO_376();
    MTO3.addCollectObject(obj);

    RealTimeProxy376 instance = proxy;
    //    long SequenceCode = instance.readParameters(MTO3);

    Map result = instance.getReturnByReadParameter(3616);
    // assertEquals(expResult, result);
  }
Ejemplo n.º 8
0
  /**
   * 一键设置终端参数F10
   *
   * @param mapCO *<"logicalAddr", String> : 逻辑地址 C_TERMINAL.LOGICAL_ADDR *<"equipProtocol", String>
   *     : 设备规约号 C_TERMINAL.PROTOCOL_NO
   *     --------------------------------------------------------------------- <"channelType",
   *     String> : 通道类型 【默认为1(TCP)】 <"pwAlgorith", String> : 密码算法 【默认为0】 <"pwContent", String> :
   *     密码内容 【默认为8888】 <"mpExpressMode", String> : 测量点表示方式 【默认为3(列表方式)】 <"mpSn", String> : 测量点序号组
   *     【默认为[0]】 ---------------------------------------------------------------------
   * @param mapParams *<"1004001001", String> : 本次电能表/交流采样装置配置数量 *<"10040010020001", String> :
   *     本次配置第0001块电能表/交流采样装置序号 【默认与所属测量点号相同】 *<"10040010030001", String> :
   *     本次配置第0001块电能表/交流采样装置所属测量点号 *<"10040010040001", String> : 本次配置第0001块电能表/交流采样装置通信波特率
   *     C_METER.BAUDRATE *<"10040010050001", String> : 本次配置第0001块电能表/交流采样装置通信端口号 C_GP.PORT
   *     *<"10040010060001", String> : 本次配置第0001块电能表/交流采样装置通信协议类型 C_GP.PROTOCOL_NO
   *     *<"10040010070001", String> : 本次配置第0001块电能表/交流采样装置通信地址 C_GP.GP_ADDR
   *     --------------------------------------------------------------------- <"10040010080001",
   *     String> : 本次配置第0001块电能表/交流采样装置通信密码 【默认为000000000000】 <"10040010100001", String> :
   *     本次配置第0001块电能表/交流采样装置电能费率个数 【默认为000100(4个费率)】 <"10040010120001", String> :
   *     本次配置第0001块电能表/交流采样装置有功电能示值的整数位个数 【默认为10(6位)】 <"10040010130001", String> :
   *     本次配置第0001块电能表/交流采样装置有功电能示值的小数位个数 【默认为11(4位)】 <"10040010140001", String> :
   *     本次配置第0001块电能表/交流采样装置所属采集器通信地址 【默认为000000000000】 <"10040010150001", String> :
   *     本次配置第0001块电能表/交流采样装置所属的用户大类号 【默认为0000】 <"10040010160001", String> :
   *     本次配置第0001块电能表/交流采样装置所属的用户小类号 【默认为0000】
   *     ---------------------------------------------------------------------
   * @return map <"collectId", Integer> : 采集ID
   */
  public Map<String, Object> akeySetupTermParamF10(
      Map<String, Object> mapCO, Map<String, String> mapParams) {
    Map<String, Object> map = new HashMap<String, Object>();

    MTO_376 mto376 = new MTO_376();
    CollectObject co = new CollectObject();
    co.setLogicalAddr((String) mapCO.get("logicalAddr"));
    co.setEquipProtocol((String) mapCO.get("equipProtocol"));
    co.setChannelType("1");
    co.setPwAlgorith("0");
    co.setPwContent("8888");
    co.setMpExpressMode(3);
    int[] mpSn = {0};
    co.setMpSn(mpSn);
    CommandItem ci = new CommandItem();
    ci.setIdentifier("10040010");
    ci.setDatacellParam(mapParams);
    co.AddCommandItem(ci);
    mto376.addCollectObject(co);

    return map;
  }
  //  @Test
  public void testReadEquipmentParametersF10() throws Exception {
    Map datacellParams10 = new TreeMap();
    datacellParams10.put("1004001001", "1"); // 主用IP地址和端口

    CircleDataItems circleDataItems = new CircleDataItems();
    for (int i = 1; i <= 3; i++) {
      DataItemGroup group = new DataItemGroup();
      group.AddDataItem(
          new DataItem("1004001002000" + i, String.valueOf(i))); // 本次配置第0001块电能表/交流采样装置序号
      circleDataItems.AddDataItemGroup(group);
    }

    CommandItem commandItem = new CommandItem();
    commandItem.setIdentifier("10040010");
    commandItem.setDatacellParam(datacellParams10);
    commandItem.setCircleDataItems(circleDataItems);

    CollectObject obj = new CollectObject();
    obj.setLogicalAddr("96123456");
    obj.setMpSn(new int[] {0});
    obj.AddCommandItem(commandItem);

    MTO_376 MTO3 = new MTO_376();
    MTO3.addCollectObject(obj);

    RealTimeProxy376 instance = proxy;
    long SequenceCode = instance.readParameters(MTO3);

    //        this.taskService.insertRecvMsg(SequenceCode, "96123456", "55 68 A2 00 A2 00 68 98 12
    // 96 56 34 00 0A 60 00 00 04 00 C0 A8 00 01 90 1F C0 A8 00 02 90 1F 5A 4A 44 4C 2E 5A 4A 00 00
    // 00 00 00 00 00 00 00 6F 16 55 ");
    //        this.taskService.insertRecvMsg(SequenceCode, "96123456", "55 68 A2 00 A2 00 68 98 12
    // 96 56 34 00 0A 60 00 00 04 00 C0 A8 00 01 90 1F C0 A8 00 02 90 1F 5A 4A 44 4C 2E 5A 4A 00 00
    // 00 00 00 00 00 00 00 6F 16 55 ");

    //        Map datacellParams10 = new TreeMap();
    //        datacellParams10.put("1004001001","1");//本次电能表/交流采样装置配置数量
    //        CircleDataItems circleDataItems = new CircleDataItems();
    //        DataItemGroup diGroup1 = new DataItemGroup();
    //        diGroup1.AddDataItem(new DataItem("10040010020001","1"));//本次配置第0001块电能表/交流采样装置序号
    //        diGroup1.AddDataItem(new DataItem("10040010030001","1"));//本次配置第0001块电能表/交流采样装置所属测量点号
    //        diGroup1.AddDataItem(new DataItem("10040010040001","6"));//本次配置第0001块电能表/交流采样装置通信波特率
    //        diGroup1.AddDataItem(new DataItem("10040010050001","1"));//本次配置第0001块电能表/交流采样装置通信端口号
    //        diGroup1.AddDataItem(new
    // DataItem("10040010060001","100"));//本次配置第0001块电能表/交流采样装置通信协议类型
    //        diGroup1.AddDataItem(new DataItem("10040010070001","0"));//本次配置第0001块电能表/交流采样装置通信地址
    //        diGroup1.AddDataItem(new DataItem("10040010080001","0"));//本次配置第0001块电能表/交流采样装置通信密码
    //        diGroup1.AddDataItem(new
    // DataItem("10040010100001","000001"));//本次配置第0001块电能表/交流采样装置电能费率个数
    //        diGroup1.AddDataItem(new
    // DataItem("10040010120001","00"));//本次配置第0001块电能表/交流采样装置有功电能示值的整数位个数
    //        diGroup1.AddDataItem(new
    // DataItem("10040010130001","00"));//本次配置第0001块电能表/交流采样装置有功电能示值的小数位个数
    //        diGroup1.AddDataItem(new
    // DataItem("10040010140001","999999999999"));//本次配置第0001块电能表/交流采样装置所属采集器通信地址
    //        diGroup1.AddDataItem(new
    // DataItem("10040010150001","0000"));//本次配置第0001块电能表/交流采样装置所属的用户大类号
    //        diGroup1.AddDataItem(new
    // DataItem("10040010160001","0000"));//本次配置第0001块电能表/交流采样装置所属的用户小类号

    //        expResult.put("96123456#0#10040010",MapDataItem);
    //        Map result = instance.getReturnByREP(SequenceCode);
    //        assertEquals(expResult, result);
  }