diff --git a/web/src/main/java/com/zhehekeji/web/entity/RFID.java b/web/src/main/java/com/zhehekeji/web/entity/RFID.java new file mode 100644 index 0000000..e56642c --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/entity/RFID.java @@ -0,0 +1,22 @@ +package com.zhehekeji.web.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("RFID") +public class RFID { + + @TableId(type = IdType.AUTO) + private Integer id; + + private Integer streetId; + + private Integer direction; + + private String ip; + + private Integer port; +} diff --git a/web/src/main/java/com/zhehekeji/web/mapper/RFIDMapper.java b/web/src/main/java/com/zhehekeji/web/mapper/RFIDMapper.java new file mode 100644 index 0000000..91e8340 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/mapper/RFIDMapper.java @@ -0,0 +1,7 @@ +package com.zhehekeji.web.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zhehekeji.web.entity.RFID; + +public interface RFIDMapper extends BaseMapper { +} diff --git a/web/src/main/java/com/zhehekeji/web/pojo/street/StreetVO.java b/web/src/main/java/com/zhehekeji/web/pojo/street/StreetVO.java index f6d276e..06146e6 100644 --- a/web/src/main/java/com/zhehekeji/web/pojo/street/StreetVO.java +++ b/web/src/main/java/com/zhehekeji/web/pojo/street/StreetVO.java @@ -1,6 +1,9 @@ package com.zhehekeji.web.pojo.street; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; import com.zhehekeji.web.entity.Street; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @@ -21,4 +24,11 @@ public class StreetVO extends Street { private String rightSensorGunIp; private Integer rightSensorGunPort; + + + @JsonProperty(value="RFIDIp") + private String RFIDIp; + + @JsonProperty(value="RFIDPort") + private Integer RFIDPort; } diff --git a/web/src/main/java/com/zhehekeji/web/service/RFID/CMD.java b/web/src/main/java/com/zhehekeji/web/service/RFID/CMD.java new file mode 100644 index 0000000..b766f44 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/service/RFID/CMD.java @@ -0,0 +1,203 @@ +package com.zhehekeji.web.service.RFID; + +/** + * Regarding UHF return code and description, please refer to Serial_Protocol_User's_Guide_V2.38_en + * + */ +public class CMD { + public final static byte RESET = 0x70; + public final static byte SET_UART_BAUDRATE = 0x71; + public final static byte GET_FIRMWARE_VERSION = 0x72; + public final static byte SET_READER_ADDRESS = 0x73; + public final static byte SET_WORK_ANTENNA = 0x74; + public final static byte GET_WORK_ANTENNA = 0x75; + public final static byte SET_OUTPUT_POWER = 0x76; + public final static byte GET_OUTPUT_POWER = 0x77; + public final static byte SET_FREQUENCY_REGION = 0x78; + public final static byte GET_FREQUENCY_REGION = 0x79; + public final static byte SET_BEEPER_MODE = 0x7A; + public final static byte GET_READER_TEMPERATURE = 0x7B; + public final static byte READ_GPIO_VALUE = 0x60; + public final static byte WRITE_GPIO_VALUE = 0x61; + public final static byte SET_ANT_CONNECTION_DETECTOR = 0x62; + public final static byte GET_ANT_CONNECTION_DETECTOR = 0x63; + public final static byte SET_TEMPORARY_OUTPUT_POWER = 0x66; + public final static byte SET_READER_IDENTIFIER = 0x67; + public final static byte GET_READER_IDENTIFIER = 0x68; + public final static byte SET_RF_LINK_PROFILE = 0x69; + public final static byte GET_RF_LINK_PROFILE = 0x6A; + public final static byte GET_RF_PORT_RETURN_LOSS = 0x7E; + public final static byte INVENTORY = (byte) 0x80; + public final static byte READ_TAG = (byte) 0x81; + public final static byte WRITE_TAG = (byte) 0x82; + public final static byte LOCK_TAG = (byte) 0x83; + public final static byte KILL_TAG = (byte) 0x84; + public final static byte SET_ACCESS_EPC_MATCH = (byte) 0x85; + public final static byte GET_ACCESS_EPC_MATCH = (byte) 0x86; + public final static byte REAL_TIME_INVENTORY = (byte) 0x89; + public final static byte FAST_SWITCH_ANT_INVENTORY = (byte) 0x8A; + public final static byte CUSTOMIZED_SESSION_TARGET_INVENTORY = (byte) 0x8B; + public final static byte SET_IMPINJ_FAST_TID = (byte) 0x8C; + public final static byte SET_AND_SAVE_IMPINJ_FAST_TID = (byte) 0x8D; + public final static byte GET_IMPINJ_FAST_TID = (byte) 0x8E; + public final static byte ISO18000_6B_INVENTORY = (byte) 0xB0; + public final static byte ISO18000_6B_READ_TAG = (byte) 0xB1; + public final static byte ISO18000_6B_WRITE_TAG = (byte) 0xB2; + public final static byte ISO18000_6B_LOCK_TAG = (byte) 0xB3; + public final static byte ISO18000_6B_QUERY_LOCK_TAG = (byte) 0xB4; + public final static byte GET_INVENTORY_BUFFER = (byte) 0x90; + public final static byte GET_AND_RESET_INVENTORY_BUFFER = (byte) 0x91; + public final static byte GET_INVENTORY_BUFFER_TAG_COUNT = (byte) 0x92; + public final static byte RESET_INVENTORY_BUFFER = (byte) 0x93; + public final static byte OPERATE_TAG_MASK = (byte) 0x98; + public final static byte GET_OUTPUT_POWER_EIGHT = (byte) 0x97; + + /** + * The description of command. + * @param btCmd the command code. + * @return String the description of command. + */ + public static String format(byte btCmd) + { + String strCmd = ""; + switch (btCmd) + { + case RESET: + strCmd = "Reset reader."; + break; + case SET_UART_BAUDRATE: + strCmd = "Set baud rate of serial port."; + break; + case GET_FIRMWARE_VERSION: + strCmd = "Get firmware version."; + break; + case SET_READER_ADDRESS: + strCmd = "Set reader’s address."; + break; + case SET_WORK_ANTENNA: + strCmd = "Set working antenna."; + break; + case GET_WORK_ANTENNA: + strCmd = "Query current working antenna."; + break; + case SET_OUTPUT_POWER: + strCmd = "Set RF output power."; + break; + case GET_OUTPUT_POWER: + strCmd = "Query current RF output power."; + break; + case SET_FREQUENCY_REGION: + strCmd = "Set RF frequency spectrum."; + break; + case GET_FREQUENCY_REGION: + strCmd = "Query RF frequency spectrum."; + break; + case SET_BEEPER_MODE: + strCmd = "Set reader’s buzzer hehavior."; + break; + case GET_READER_TEMPERATURE: + strCmd = "Check reader’s internal temperature."; + break; + case READ_GPIO_VALUE: + strCmd = "Get GPIO1, GPIO2 status."; + break; + case WRITE_GPIO_VALUE: + strCmd = "Set GPIO3, GPIO4 status."; + break; + case SET_ANT_CONNECTION_DETECTOR: + strCmd = "Set antenna detector status."; + break; + case GET_ANT_CONNECTION_DETECTOR: + strCmd = "Get antenna detector status."; + break; + case SET_TEMPORARY_OUTPUT_POWER: + strCmd = "Set RF power without saving to flash."; + break; + case SET_READER_IDENTIFIER: + strCmd = "Set reader’s identification bytes."; + break; + case GET_READER_IDENTIFIER: + strCmd = "Get reader’s identification bytes."; + break; + case SET_RF_LINK_PROFILE: + strCmd = "Set RF link profile."; + break; + case GET_RF_LINK_PROFILE: + strCmd = "Get RF link profile."; + break; + case GET_RF_PORT_RETURN_LOSS: + strCmd = "Get current antenna port’s return loss."; + break; + case INVENTORY: + strCmd = "Inventory EPC C1G2 tags to buffer."; + break; + case READ_TAG: + strCmd = "Read EPC C1G2 tag(s)."; + break; + case WRITE_TAG: + strCmd = "Write EPC C1G2 tag(s)."; + break; + case LOCK_TAG: + strCmd = "Lock EPC C1G2 tag(s)."; + break; + case KILL_TAG: + strCmd = "Kill EPC C1G2 tag(s)."; + break; + case SET_ACCESS_EPC_MATCH: + strCmd = "Set tag access filter by EPC."; + break; + case GET_ACCESS_EPC_MATCH: + strCmd = "Query access filter by EPC."; + break; + case REAL_TIME_INVENTORY: + strCmd = "Inventory tags in real time mode."; + break; + case FAST_SWITCH_ANT_INVENTORY: + strCmd = "Real time inventory with fast ant switch."; + break; + case CUSTOMIZED_SESSION_TARGET_INVENTORY: + strCmd = "Inventory with desired session and inventoried flag."; + break; + case SET_IMPINJ_FAST_TID: + strCmd = "Set impinj FastTID function(Without saving to FLASH)."; + break; + case SET_AND_SAVE_IMPINJ_FAST_TID: + strCmd = "Set impinj FastTID function(Save to FLASH)."; + break; + case GET_IMPINJ_FAST_TID: + strCmd = "Get current FastTID setting."; + break; + case ISO18000_6B_INVENTORY: + strCmd = "Inventory 18000-6B tag(s)."; + break; + case ISO18000_6B_READ_TAG: + strCmd = "Read 18000-6B tag."; + break; + case ISO18000_6B_WRITE_TAG: + strCmd = "Write 18000-6B tag."; + break; + case ISO18000_6B_LOCK_TAG: + strCmd = "Lock 18000-6B tag data byte."; + break; + case ISO18000_6B_QUERY_LOCK_TAG: + strCmd = "Query lock 18000-6B tag data byte."; + break; + case GET_INVENTORY_BUFFER: + strCmd = "Get buffered data without clearing."; + break; + case GET_AND_RESET_INVENTORY_BUFFER: + strCmd = "Get and clear buffered data."; + break; + case GET_INVENTORY_BUFFER_TAG_COUNT: + strCmd = "Query how many tags are buffered."; + break; + case RESET_INVENTORY_BUFFER: + strCmd = "Clear buffer."; + break; + default: + strCmd = "Unknown error."; + break; + } + return strCmd; + } +} diff --git a/web/src/main/java/com/zhehekeji/web/service/RFID/ERROR.java b/web/src/main/java/com/zhehekeji/web/service/RFID/ERROR.java new file mode 100644 index 0000000..f955291 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/service/RFID/ERROR.java @@ -0,0 +1,187 @@ +package com.zhehekeji.web.service.RFID; + +/** + * Regarding UHF error code and description, please refer to Serial_Protocol_User's_Guide_V2.38_en + * + * + */ +public class ERROR { + public final static byte SUCCESS = 0x10; + public final static byte FAIL = 0x11; + public final static byte MCU_RESET_ERROR = 0x20; + public final static byte CW_ON_ERROR = 0x21; + public final static byte ANTENNA_MISSING_ERROR = 0x22; + public final static byte WRITE_FLASH_ERROR = 0x23; + public final static byte READ_FLASH_ERROR = 0x24; + public final static byte SET_OUTPUT_POWER_ERROR = 0x25; + public final static byte TAG_INVENTORY_ERROR = 0x31; + public final static byte TAG_READ_ERROR = 0x32; + public final static byte TAG_WRITE_ERROR = 0x33; + public final static byte TAG_LOCK_ERROR = 0x34; + public final static byte TAG_KILL_ERROR = 0x35; + public final static byte NO_TAG_ERROR = 0x36; + public final static byte INVENTORY_OK_BUT_ACCESS_FAIL = 0x37; + public final static byte BUFFER_IS_EMPTY_ERROR = 0x38; + public final static byte ACCESS_OR_PASSWORD_ERROR = 0x40; + public final static byte PARAMETER_INVALID = 0x41; + public final static byte PARAMETER_INVALID_WORDCNT_TOO_LONG = 0x42; + public final static byte PARAMETER_INVALID_MEMBANK_OUT_OF_RANGE = 0x43; + public final static byte PARAMETER_INVALID_LOCK_REGION_OUT_OF_RANGE = 0x44; + public final static byte PARAMETER_INVALID_LOCK_ACTION_OUT_OF_RANGE = 0x45; + public final static byte PARAMETER_READER_ADDRESS_INVALID = 0x46; + public final static byte PARAMETER_INVALID_ANTENNA_ID_OUT_OF_RANGE = 0x47; + public final static byte PARAMETER_INVALID_OUTPUT_POWER_OUT_OF_RANGE = 0x48; + public final static byte PARAMETER_INVALID_FREQUENCY_REGION_OUT_OF_RANGE = 0x49; + public final static byte PARAMETER_INVALID_BAUDRATE_OUT_OF_RANGE = 0x4A; + public final static byte PARAMETER_BEEPER_MODE_OUT_OF_RANGE = 0x4B; + public final static byte PARAMETER_EPC_MATCH_LEN_TOO_LONG = 0x4C; + public final static byte PARAMETER_EPC_MATCH_LEN_ERROR = 0x4D; + public final static byte PARAMETER_INVALID_EPC_MATCH_MODE = 0x4E; + public final static byte PARAMETER_INVALID_FREQUENCY_RANGE = 0x4F; + public final static byte FAIL_TO_GET_RN16_FROM_TAG = 0x50; + public final static byte PARAMETER_INVALID_DRM_MODE = 0x51; + public final static byte PLL_LOCK_FAIL = 0x52; + public final static byte RF_CHIP_FAIL_TO_RESPONSE = 0x53; + public final static byte FAIL_TO_ACHIEVE_DESIRED_OUTPUT_POWER = 0x54; + public final static byte COPYRIGHT_AUTHENTICATION_FAIL = 0x55; + public final static byte SPECTRUM_REGULATION_ERROR = 0x56; + public final static byte OUTPUT_POWER_TOO_LOW = 0x57; + public final static byte UNKONW_ERROR = 0x58; + + /** + * The description of error code. + * @param btErrorCode the error code. + * @return String the description of error code. + */ + public static String format(byte btErrorCode) + { + String strErrorCode = ""; + switch (btErrorCode) + { + case SUCCESS: + strErrorCode = "Command succeeded."; + break; + case FAIL: + strErrorCode = "Command failed."; + break; + case MCU_RESET_ERROR: + strErrorCode = "CPU reset error."; + break; + case CW_ON_ERROR: + strErrorCode = "Turn on CW error."; + break; + case ANTENNA_MISSING_ERROR: + strErrorCode = "Antenna is missing."; + break; + case WRITE_FLASH_ERROR: + strErrorCode = "Write flash error."; + break; + case READ_FLASH_ERROR: + strErrorCode = "Read flash error."; + break; + case SET_OUTPUT_POWER_ERROR: + strErrorCode = "Set output power error."; + break; + case TAG_INVENTORY_ERROR: + strErrorCode = "Error occurred when inventory."; + break; + case TAG_READ_ERROR: + strErrorCode = "Error occurred when read."; + break; + case TAG_WRITE_ERROR: + strErrorCode = "Error occurred when write."; + break; + case TAG_LOCK_ERROR: + strErrorCode = "Error occurred when lock."; + break; + case TAG_KILL_ERROR: + strErrorCode = "Error occurred when kill."; + break; + case NO_TAG_ERROR: + strErrorCode = "There is no tag to be operated."; + break; + case INVENTORY_OK_BUT_ACCESS_FAIL: + strErrorCode = "Tag Inventoried but access failed."; + break; + case BUFFER_IS_EMPTY_ERROR: + strErrorCode = "Buffer is empty."; + break; + case ACCESS_OR_PASSWORD_ERROR: + strErrorCode = "Access failed or wrong password."; + break; + case PARAMETER_INVALID: + strErrorCode = "Invalid parameter."; + break; + case PARAMETER_INVALID_WORDCNT_TOO_LONG: + strErrorCode = "WordCnt is too long."; + break; + case PARAMETER_INVALID_MEMBANK_OUT_OF_RANGE: + strErrorCode = "MemBank out of range."; + break; + case PARAMETER_INVALID_LOCK_REGION_OUT_OF_RANGE: + strErrorCode = "Lock region out of range."; + break; + case PARAMETER_INVALID_LOCK_ACTION_OUT_OF_RANGE: + strErrorCode = "LockType out of range."; + break; + case PARAMETER_READER_ADDRESS_INVALID: + strErrorCode = "Invalid reader address."; + break; + case PARAMETER_INVALID_ANTENNA_ID_OUT_OF_RANGE: + strErrorCode = "AntennaID out of range."; + break; + case PARAMETER_INVALID_OUTPUT_POWER_OUT_OF_RANGE: + strErrorCode = "Output power out of range."; + break; + case PARAMETER_INVALID_FREQUENCY_REGION_OUT_OF_RANGE: + strErrorCode = "Frequency region out of range."; + break; + case PARAMETER_INVALID_BAUDRATE_OUT_OF_RANGE: + strErrorCode = "Baud rate out of range."; + break; + case PARAMETER_BEEPER_MODE_OUT_OF_RANGE: + strErrorCode = "Buzzer behavior out of range."; + break; + case PARAMETER_EPC_MATCH_LEN_TOO_LONG: + strErrorCode = "EPC match is too long."; + break; + case PARAMETER_EPC_MATCH_LEN_ERROR: + strErrorCode = "EPC match length wrong."; + break; + case PARAMETER_INVALID_EPC_MATCH_MODE: + strErrorCode = "Invalid EPC match mode."; + break; + case PARAMETER_INVALID_FREQUENCY_RANGE: + strErrorCode = "Invalid frequency range."; + break; + case FAIL_TO_GET_RN16_FROM_TAG: + strErrorCode = "Failed to receive RN16 from tag."; + break; + case PARAMETER_INVALID_DRM_MODE: + strErrorCode = "Invalid DRM mode."; + break; + case PLL_LOCK_FAIL: + strErrorCode = "PLL can not lock."; + break; + case RF_CHIP_FAIL_TO_RESPONSE: + strErrorCode = "No response from RF chip."; + break; + case FAIL_TO_ACHIEVE_DESIRED_OUTPUT_POWER: + strErrorCode = "Can’t achieve desired output power level."; + break; + case COPYRIGHT_AUTHENTICATION_FAIL: + strErrorCode = "Can’t authenticate firmware copyright."; + break; + case SPECTRUM_REGULATION_ERROR: + strErrorCode = "Spectrum regulation wrong."; + break; + case OUTPUT_POWER_TOO_LOW: + strErrorCode = "Output power too low."; + break; + default: + strErrorCode = "Unknown Error"; + break; + } + return strErrorCode; + } +} diff --git a/web/src/main/java/com/zhehekeji/web/service/RFID/HEAD.java b/web/src/main/java/com/zhehekeji/web/service/RFID/HEAD.java new file mode 100644 index 0000000..c98f33c --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/service/RFID/HEAD.java @@ -0,0 +1,6 @@ +package com.zhehekeji.web.service.RFID; + +public class HEAD { + /**UHF mark to indicate the head of data package */ + public final static byte HEAD = (byte) 0xA0; +} diff --git a/web/src/main/java/com/zhehekeji/web/service/RFID/MessageTran.java b/web/src/main/java/com/zhehekeji/web/service/RFID/MessageTran.java new file mode 100644 index 0000000..90631f6 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/service/RFID/MessageTran.java @@ -0,0 +1,172 @@ +package com.zhehekeji.web.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 + + /** + * 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.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.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.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); + } +} diff --git a/web/src/main/java/com/zhehekeji/web/service/RFID/RFIDSocket.java b/web/src/main/java/com/zhehekeji/web/service/RFID/RFIDSocket.java new file mode 100644 index 0000000..39019ec --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/service/RFID/RFIDSocket.java @@ -0,0 +1,207 @@ +package com.zhehekeji.web.service.RFID; + +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +import java.io.*; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.util.*; + +/** + * sick扫码枪 + */ +@Slf4j +public class RFIDSocket { + + private Socket socket; + + private OutputStream os; + + private InputStream is; + + private Queue buffer; + + private boolean running; + + private int step; + + private int length; + + private int index; + + /** + * 读到的所有code标签 + */ + private Set tags = new HashSet<>(); + + private List byteList = new ArrayList<>(30); + + public Set getTags(){ + return tags; + } + + public RFIDSocket(String ip,int port){ + socket = new Socket(); + os = null; + is = null; + try { + socket.connect(new InetSocketAddress(ip,port),3000); + os = socket.getOutputStream(); + is = socket.getInputStream(); + } catch (IOException e) { + log.error("RFIDSocket time out,ip:{},info:{}",ip,e); + + } + } + + public void readData() throws IOException { + running = true; + buffer = new LinkedList(); + + Thread thread = new Thread(new Runnable() { + + @SneakyThrows + @Override + public void run() { + while (true){ + if(!running){ + System.out.println("stop"); + break; + } + int i = 0; + try { + //读不到会阻塞 返回-1表示连接已断开 + i = is.read(); + } catch (IOException e) { + log.error("disconnect"); + } + if(i == -1){ + + break; + } + int count = 0; + try { + count = is.available(); + if(count > 0){ + //把之前read的字节嫁过来 + byte[]readBytes = new byte[count+1]; + readBytes[0] = (byte)i; + is.read(readBytes,1,count); + for(byte b:readBytes){ + buffer.offer(b); + } + } + } catch (IOException e) { + log.error(""); + } + while (buffer.size()> 0){ + String code = readTag(); + if(code != null){ + tags.add(code); + } + } + } + + } + }); + thread.start(); + } + + private String readTag(){ + String tag = null; + Byte b = buffer.poll(); + if(b == null){ + return tag; + } + if(step == 0){ + //判断是否表示头 + if(b == HEAD.HEAD){ + step++; + byteList.add(b); + } + }else if(step == 1){ + //读长度 + length = b & 0xff; + step++; + byteList.add(b); + }else if(step == 2){ + byteList.add(b); + index++; + if(index == length-1){ + step++; + } + }else if(step == 3){ + byteList.add(b); + byte[]bytes = new byte[byteList.size()]; + for(int i = 0;i map = new HashMap<>(); map.put("street_id",id); lightSourceMapper.deleteByMap(map); + rfidMapper.deleteByMap(map); StreetConn.del(id); } @@ -227,6 +239,7 @@ public class StreetService { lightSourceMapper.update(lightSource,new UpdateWrapper().eq("street_id",street.getId())); } sensorGunConfig(streetVO,street.getId()); + RFIDConfig(streetVO,street.getId()); Thread thread2 = new Thread(new Runnable() { @Override public void run() { @@ -286,6 +299,20 @@ public class StreetService { } } + public void RFIDConfig(StreetVO streetVO,Integer streetId){ + Map map = new HashMap<>(); + map.put("street_id",streetId); + rfidMapper.deleteByMap(map); + if(!StringUtils.isEmpty(streetVO.getRFIDIp()) && streetVO.getRFIDPort() != null){ + RFID rfid = new RFID(); + rfid.setStreetId(streetId); + rfid.setPort(streetVO.getRFIDPort()); + rfid.setIp(streetVO.getRFIDIp()); + rfidMapper.insert(rfid); + } + + } + /** * 获取货架号 diff --git a/web/src/main/resources/application-dev.yml b/web/src/main/resources/application-dev.yml index ba761f7..9954434 100644 --- a/web/src/main/resources/application-dev.yml +++ b/web/src/main/resources/application-dev.yml @@ -60,8 +60,8 @@ lightSource: type: 2 num: 4 index: 1 -# -----------扫码枪 -# ------------type 1: sick +# -----------扫码方式 +# ------------type 1: sick扫码枪 2:南北达RFID sensor: type: 1 # -----tray 托盘 diff --git a/web/src/main/resources/mapper/StreetMapper.xml b/web/src/main/resources/mapper/StreetMapper.xml index b3d1b68..8c73b87 100644 --- a/web/src/main/resources/mapper/StreetMapper.xml +++ b/web/src/main/resources/mapper/StreetMapper.xml @@ -5,13 +5,15 @@