@SuppressWarnings("unchecked") private int getRessiueBlocks(DlmsRequest req, DlmsRequest dr) { int offset = 0; List<Integer> ressiueBlocks = null; if (req.containsKey(DlmsUpgradeAssisant.REISSUE_LIST)) { ressiueBlocks = (List<Integer>) req.getAppendParam(DlmsUpgradeAssisant.REISSUE_LIST); } else { ressiueBlocks = new ArrayList<Integer>(); } if (DlmsUpgradeAssisant.UPGRADE_03.equals(req.getOperator()) || DlmsUpgradeAssisant.UPGRADE_RESSIUE.equals(req.getOperator())) { return offset; } ASN1BitString bitString = req.getParams()[0].resultData.getBitString(); byte[] bitValue = bitString.getValue(); // 获得有效位数 int blockCount = (bitValue.length - 1) * 8 - bitValue[0]; getRessiueBlocks(bitValue, blockCount, ressiueBlocks, offset + 1); if (req.containsKey(DlmsUpgradeAssisant.CURRENT_INDEX)) { offset = (Integer) req.getAppendParam(DlmsUpgradeAssisant.CURRENT_INDEX); } else { offset = 0; } dr.addAppendParam(DlmsUpgradeAssisant.REISSUE_LIST, ressiueBlocks); return offset; }
/** * DLMS升级第三步 传输升级包文件,客户端按照Step 1中获取的imageBlockSize分帧传送升级包文件,升级包的传输通过action操作image * transfer对象的方法2完成; * * @param req * @param dr */ private boolean upgradeStep_03(DlmsRequest req, DlmsRequest dr) { if (req.getParams()[0].resultCode != 0) return false; dr.setOperator(DlmsUpgradeAssisant.UPGRADE_03); dr.setOpType(DLMS_OP_TYPE.OP_ACTION); int i_maxSize = (Integer) dr.getAppendParam(DlmsUpgradeAssisant.MAX_SIZE); byte[] content = (byte[]) dr.getAppendParam(DlmsUpgradeAssisant.UPGRADE_CONTENT); int currentBlockNum = 0; if (!dr.containsKey(DlmsUpgradeAssisant.CURRENT_BLOCK_NUM)) currentBlockNum = 0; else currentBlockNum = (Integer) dr.getAppendParam(DlmsUpgradeAssisant.CURRENT_BLOCK_NUM) + 1; dr.addAppendParam(DlmsUpgradeAssisant.CURRENT_BLOCK_NUM, currentBlockNum); if (tracer.isEnabled()) { tracer.trace( "MeterId:" + dr.getMeterId() + ",BlockCount:" + (Integer) dr.getAppendParam(DlmsUpgradeAssisant.BLOCK_COUNT) + ",CurrentBlockNum:" + currentBlockNum); } if (currentBlockNum == (Integer) dr.getAppendParam(DlmsUpgradeAssisant.BLOCK_COUNT) || (content.length % i_maxSize == 0 && currentBlockNum + 1 == (Integer) dr.getAppendParam(DlmsUpgradeAssisant.BLOCK_COUNT))) { // 当前发送是最后一帧 dr.addAppendParam(DlmsUpgradeAssisant.IS_TRANSFER_FINISHED, true); } byte[] currentSendBlock = getCurUpgradeBlock(content, currentBlockNum, i_maxSize); String logicAddr = req.getMeterId(); int tn = 0; if (req.getRelayParam() != null) { logicAddr = req.getRelayParam().getDcLogicalAddress(); tn = req.getRelayParam().getMeasurePoint(); } if (tracer.isEnabled()) tracer.trace( "meterId:" + logicAddr + ",tn:" + tn + ",currentBlockNum:" + currentBlockNum + ",blockContent:" + HexDump.toHex(currentSendBlock)); blockTransferRequest(dr, currentBlockNum, currentSendBlock); return true; }
/** * 升级过程传输数据块 判断是否传输完毕,如果传输完毕直接进入第4步,否则继续传输 * * @param req * @param dr * @return */ private boolean blockTransfering(DlmsRequest req, DlmsRequest dr) { if (req.getParams()[0].resultCode != 0) return false; if (dr.containsKey(DlmsUpgradeAssisant.IS_TRANSFER_FINISHED)) { // 发送完毕了,检查升级包是否完毕 boolean isTransferFinished = (Boolean) dr.getAppendParam(DlmsUpgradeAssisant.IS_TRANSFER_FINISHED); if (isTransferFinished) { upgradeStep_04(req, dr); } else { reissueBlock(dr); } } else { upgradeStep_03(req, dr); } return true; }