parent
cbbbfc123b
commit
681ad300e3
@ -0,0 +1,93 @@
|
|||||||
|
package cn.iocoder.yudao.module.camera.controller.admin.radar;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||||
|
import cn.iocoder.yudao.module.camera.controller.admin.radar.vo.RadarPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.camera.controller.admin.radar.vo.RadarRespVO;
|
||||||
|
import cn.iocoder.yudao.module.camera.controller.admin.radar.vo.RadarSaveReqVO;
|
||||||
|
import cn.iocoder.yudao.module.camera.service.radar.RadarDO;
|
||||||
|
import cn.iocoder.yudao.module.camera.service.radar.RadarService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - Radar")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/logistics/Radar")
|
||||||
|
@Validated
|
||||||
|
public class RadarController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RadarService radarService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建Radar")
|
||||||
|
@PreAuthorize("@ss.hasPermission('logistics:Radar:create')")
|
||||||
|
public CommonResult<Integer> createRadar(@Valid @RequestBody RadarSaveReqVO createReqVO) {
|
||||||
|
return success(radarService.createRadar(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新Radar")
|
||||||
|
@PreAuthorize("@ss.hasPermission('logistics:Radar:update')")
|
||||||
|
public CommonResult<Boolean> updateRadar(@Valid @RequestBody RadarSaveReqVO updateReqVO) {
|
||||||
|
radarService.updateRadar(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除Radar")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('logistics:Radar:delete')")
|
||||||
|
public CommonResult<Boolean> deleteRadar(@RequestParam("id") Integer id) {
|
||||||
|
radarService.deleteRadar(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得Radar")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('logistics:Radar:query')")
|
||||||
|
public CommonResult<RadarRespVO> getRadar(@RequestParam("id") Integer id) {
|
||||||
|
RadarDO Radar = radarService.getRadar(id);
|
||||||
|
return success(BeanUtils.toBean(Radar, RadarRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得Radar分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('logistics:Radar:query')")
|
||||||
|
public CommonResult<PageResult<RadarRespVO>> getRadarPage(@Valid RadarPageReqVO pageReqVO) {
|
||||||
|
PageResult<RadarDO> pageResult = radarService.getRadarPage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, RadarRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出Radar Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('logistics:Radar:export')")
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
public void exportRadarExcel(@Valid RadarPageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<RadarDO> list = radarService.getRadarPage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "Radar.xls", "数据", RadarRespVO.class,
|
||||||
|
BeanUtils.toBean(list, RadarRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package cn.iocoder.yudao.module.camera.controller.admin.radar.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - Radar分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class RadarPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "巷道id", example = "8923")
|
||||||
|
private Integer streetId;
|
||||||
|
|
||||||
|
@Schema(description = "方向")
|
||||||
|
private Integer direction;
|
||||||
|
|
||||||
|
@Schema(description = "ip")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Schema(description = "端口")
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
package cn.iocoder.yudao.module.camera.controller.admin.radar.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||||
|
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - Radar Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class RadarRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "3186")
|
||||||
|
@ExcelProperty("id")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Schema(description = "巷道id", example = "8923")
|
||||||
|
@ExcelProperty("巷道id")
|
||||||
|
private Integer streetId;
|
||||||
|
|
||||||
|
@Schema(description = "方向")
|
||||||
|
@ExcelProperty(value = "方向", converter = DictConvert.class)
|
||||||
|
@DictFormat("direction") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||||
|
private Integer direction;
|
||||||
|
|
||||||
|
@Schema(description = "ip")
|
||||||
|
@ExcelProperty("ip")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Schema(description = "端口")
|
||||||
|
@ExcelProperty("端口")
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package cn.iocoder.yudao.module.camera.controller.admin.radar.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - Radar新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class RadarSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "3186")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Schema(description = "巷道id", example = "8923")
|
||||||
|
private Integer streetId;
|
||||||
|
|
||||||
|
@Schema(description = "方向")
|
||||||
|
private Integer direction;
|
||||||
|
|
||||||
|
@Schema(description = "ip")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Schema(description = "端口")
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package cn.iocoder.yudao.module.camera.dal.mysql.rfid;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import cn.iocoder.yudao.module.camera.controller.admin.radar.vo.RadarPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.camera.service.radar.RadarDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RFID Mapper
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface RadarMapper extends BaseMapperX<RadarDO> {
|
||||||
|
|
||||||
|
default PageResult<RadarDO> selectPage(RadarPageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<RadarDO>()
|
||||||
|
.eqIfPresent(RadarDO::getStreetId, reqVO.getStreetId())
|
||||||
|
.eqIfPresent(RadarDO::getDirection, reqVO.getDirection())
|
||||||
|
.eqIfPresent(RadarDO::getIp, reqVO.getIp())
|
||||||
|
.eqIfPresent(RadarDO::getPort, reqVO.getPort())
|
||||||
|
.orderByDesc(RadarDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
default List<RadarDO> selectListByStreetId(Integer streetId) {
|
||||||
|
return selectList(RadarDO::getStreetId, streetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
default int deleteByStreetId(Integer streetId) {
|
||||||
|
return delete(RadarDO::getStreetId, streetId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
package cn.iocoder.yudao.module.camera.service.radar;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.*;
|
||||||
|
import org.glassfish.jaxb.core.v2.TODO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RFID DO
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@TableName("logistics_radar")
|
||||||
|
@KeySequence("logistics_radar_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class RadarDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Integer id;
|
||||||
|
/**
|
||||||
|
* 巷道id
|
||||||
|
*/
|
||||||
|
private Integer streetId;
|
||||||
|
/**
|
||||||
|
* 方向
|
||||||
|
*
|
||||||
|
* 枚举 {@link TODO direction 对应的类}
|
||||||
|
*/
|
||||||
|
private Integer direction;
|
||||||
|
/**
|
||||||
|
* ip
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
/**
|
||||||
|
* 端口
|
||||||
|
*/
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package cn.iocoder.yudao.module.camera.service.radar;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.module.camera.controller.admin.radar.vo.RadarPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.camera.controller.admin.radar.vo.RadarSaveReqVO;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RFID Service 接口
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public interface RadarService extends IService< RadarDO> {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建RFID
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Integer createRadar(@Valid RadarSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新RFID
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateRadar(@Valid RadarSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除RFID
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteRadar(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得RFID
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return RFID
|
||||||
|
*/
|
||||||
|
RadarDO getRadar(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得RFID分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return RFID分页
|
||||||
|
*/
|
||||||
|
PageResult<RadarDO> getRadarPage(RadarPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
package cn.iocoder.yudao.module.camera.service.radar;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import cn.iocoder.yudao.module.camera.controller.admin.radar.vo.RadarPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.camera.controller.admin.radar.vo.RadarSaveReqVO;
|
||||||
|
import cn.iocoder.yudao.module.camera.dal.mysql.rfid.RadarMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.RFID_NOT_EXISTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RFID Service 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class RadarServiceImpl extends ServiceImpl<RadarMapper, RadarDO> implements RadarService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RadarMapper radarMapper;
|
||||||
|
@Override
|
||||||
|
public Integer createRadar(RadarSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
RadarDO rfid = BeanUtils.toBean(createReqVO, RadarDO.class);
|
||||||
|
radarMapper.insert(rfid);
|
||||||
|
// 返回
|
||||||
|
return rfid.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateRadar(RadarSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateRadarExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
RadarDO updateObj = BeanUtils.toBean(updateReqVO, RadarDO.class);
|
||||||
|
radarMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteRadar(Integer id) {
|
||||||
|
// 校验存在
|
||||||
|
validateRadarExists(id);
|
||||||
|
// 删除
|
||||||
|
radarMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateRadarExists(Integer id) {
|
||||||
|
if (radarMapper.selectById(id) == null) {
|
||||||
|
throw exception(RFID_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RadarDO getRadar(Integer id) {
|
||||||
|
return radarMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<RadarDO> getRadarPage(RadarPageReqVO pageReqVO) {
|
||||||
|
return radarMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,172 @@
|
|||||||
|
package cn.iocoder.yudao.module.camera.service.rfid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object of describing data package;
|
||||||
|
* @author Administrator
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MessageTran {
|
||||||
|
private byte btPacketType; //head of data, defauld value is 0xA0
|
||||||
|
private byte btDataLen; //Length of data package, which means the byte quantity after the "length", not including the "length"
|
||||||
|
private byte btReadId; //Address of reader
|
||||||
|
private byte btCmd; //The commend code of data package
|
||||||
|
private byte[] btAryData; //The commend specification of data package, some commends without specification
|
||||||
|
private byte btCheck; //Checksum
|
||||||
|
private byte[] btAryTranData; //Complete data package
|
||||||
|
|
||||||
|
public final static byte HEAD = (byte) 0xA0;
|
||||||
|
/**
|
||||||
|
* MessageTran default constructor
|
||||||
|
*/
|
||||||
|
public MessageTran() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessageTran Constructor
|
||||||
|
* @param btReadId address of reader
|
||||||
|
* @param btCmd command code of data package
|
||||||
|
* @param btAryData command parameters of data package, some commands without parameters
|
||||||
|
*/
|
||||||
|
public MessageTran(byte btReadId, byte btCmd, byte[] btAryData) {
|
||||||
|
int nLen = btAryData.length;
|
||||||
|
|
||||||
|
this.btPacketType = HEAD;
|
||||||
|
|
||||||
|
this.btDataLen = (byte)(nLen + 3);
|
||||||
|
this.btReadId = btReadId;
|
||||||
|
this.btCmd = btCmd;
|
||||||
|
|
||||||
|
this.btAryData = new byte[nLen];
|
||||||
|
System.arraycopy(btAryData, 0, this.btAryData, 0, btAryData.length);
|
||||||
|
//btAryData.CopyTo(this.btAryData, 0);
|
||||||
|
|
||||||
|
this.btAryTranData = new byte[nLen + 5];
|
||||||
|
this.btAryTranData[0] = this.btPacketType;
|
||||||
|
this.btAryTranData[1] = this.btDataLen;
|
||||||
|
this.btAryTranData[2] = this.btReadId;
|
||||||
|
this.btAryTranData[3] = this.btCmd;
|
||||||
|
System.arraycopy(this.btAryData, 0, this.btAryTranData, 4, this.btAryData.length);
|
||||||
|
//this.btAryData.CopyTo(this.btAryTranData, 4);
|
||||||
|
|
||||||
|
this.btCheck = checkSum(this.btAryTranData, 0, nLen + 4);
|
||||||
|
int b = this.btCheck & 0xff;
|
||||||
|
System.out.println("check:"+b);
|
||||||
|
this.btAryTranData[nLen + 4] = this.btCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessageTran Constructor
|
||||||
|
* @param btReadId address of reader
|
||||||
|
* @param btCmd read command
|
||||||
|
*/
|
||||||
|
public MessageTran(byte btReadId, byte btCmd) {
|
||||||
|
this.btPacketType = HEAD;
|
||||||
|
this.btDataLen = 0x03;
|
||||||
|
this.btReadId = btReadId;
|
||||||
|
this.btCmd = btCmd;
|
||||||
|
|
||||||
|
this.btAryTranData = new byte[5];
|
||||||
|
this.btAryTranData[0] = this.btPacketType;
|
||||||
|
this.btAryTranData[1] = this.btDataLen;
|
||||||
|
this.btAryTranData[2] = this.btReadId;
|
||||||
|
this.btAryTranData[3] = this.btCmd;
|
||||||
|
|
||||||
|
this.btCheck = checkSum(this.btAryTranData, 0, 4);
|
||||||
|
this.btAryTranData[4] = this.btCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessageTran constructor
|
||||||
|
* @param btAryTranData complete data package
|
||||||
|
*/
|
||||||
|
public MessageTran(byte[] btAryTranData) {
|
||||||
|
int nLen = btAryTranData.length;
|
||||||
|
|
||||||
|
this.btAryTranData = new byte[nLen];
|
||||||
|
System.arraycopy(btAryTranData, 0, this.btAryTranData, 0, btAryTranData.length);
|
||||||
|
//btAryTranData.CopyTo(this.btAryTranData, 0);
|
||||||
|
|
||||||
|
|
||||||
|
byte btCK = checkSum(this.btAryTranData, 0, this.btAryTranData.length - 1);
|
||||||
|
if (btCK != btAryTranData[nLen - 1]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.btPacketType = btAryTranData[0];
|
||||||
|
this.btDataLen = btAryTranData[1];
|
||||||
|
this.btReadId = btAryTranData[2];
|
||||||
|
this.btCmd = btAryTranData[3];
|
||||||
|
this.btCheck = btAryTranData[nLen - 1];
|
||||||
|
|
||||||
|
if (nLen > 5) {
|
||||||
|
this.btAryData = new byte[nLen - 5];
|
||||||
|
for (int nloop = 0; nloop < nLen - 5; nloop++ ) {
|
||||||
|
this.btAryData[nloop] = btAryTranData[4 + nloop];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain complete data package
|
||||||
|
* @return Data package
|
||||||
|
*/
|
||||||
|
public byte[] getAryTranData() {
|
||||||
|
return this.btAryTranData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain command parameters of data package, some command without parameters
|
||||||
|
* @return commends parameters
|
||||||
|
*/
|
||||||
|
public byte[] getAryData() {
|
||||||
|
return this.btAryData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain address of reader
|
||||||
|
* @return Address of reader
|
||||||
|
*/
|
||||||
|
public byte getReadId() {
|
||||||
|
return this.btReadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain command of data package
|
||||||
|
* @return command
|
||||||
|
*/
|
||||||
|
public byte getCmd() {
|
||||||
|
return this.btCmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obain head of data, default 0xA0
|
||||||
|
* @return head of data
|
||||||
|
*/
|
||||||
|
public byte getPacketType() {
|
||||||
|
return this.btPacketType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check head of data
|
||||||
|
* @return Result of checking
|
||||||
|
*/
|
||||||
|
public boolean checkPacketType() {
|
||||||
|
return this.btPacketType == HEAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate checksum
|
||||||
|
* @param btAryBuffer data
|
||||||
|
* @param nStartPos start position
|
||||||
|
* @param nLen Checking length
|
||||||
|
* @return Checksum
|
||||||
|
*/
|
||||||
|
public byte checkSum(byte[] btAryBuffer, int nStartPos, int nLen) {
|
||||||
|
byte btSum = 0x00;
|
||||||
|
|
||||||
|
for (int nloop = nStartPos; nloop < nStartPos + nLen; nloop++ ) {
|
||||||
|
btSum += btAryBuffer[nloop];
|
||||||
|
}
|
||||||
|
return (byte)(((~btSum) + 1) & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue