|
|
|
@ -31,6 +31,14 @@ const ( |
|
|
|
|
Type_ISO = byte(0x1) |
|
|
|
|
AntennaOn = byte(0x1) |
|
|
|
|
AntennaOff = byte(0x0) |
|
|
|
|
ColorOff = byte(0x0) |
|
|
|
|
ColorRed = byte(0x1) |
|
|
|
|
ColorGreen = byte(0x2) |
|
|
|
|
ColorYellow = byte(0x3) |
|
|
|
|
RequestStd = byte(0x26) |
|
|
|
|
RequestAll = byte(0x52) |
|
|
|
|
AuthModeKeyA = byte(0x60) |
|
|
|
|
AuthModeKeyB = byte(0x61) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type baudList struct { |
|
|
|
@ -95,11 +103,21 @@ func (s *Sl500) RfInitCom(baud byte) ([]byte, error) { |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfInitDeviceNumber(deviceId []byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0201, deviceId) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfGetDeviceNumber() ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0301, []byte{}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfGetModel() ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0401, []byte{}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfAntennaSta(antennaState byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0C01, []byte{antennaState}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
@ -115,6 +133,76 @@ func (s *Sl500) RfBeep(durationMs byte) ([]byte, error) { |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfLight(color byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0701, []byte{color}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfRequest(requestType byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0102, []byte{requestType}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfAnticoll() ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0202, []byte{}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfSelect(serialNumber []byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0302, serialNumber) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfHalt() ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0402, []byte{}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfM1Authentication2(authMode byte, blockNumber byte, key []byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0702, []byte{authMode, blockNumber}, key) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfM1Read(blockNumber byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0802, []byte{blockNumber}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfM1Write(blockNumber byte, data []byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0902, []byte{blockNumber}, data) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfM1Initval(blockNumber byte, initialValue []byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0A02, []byte{blockNumber}, initialValue) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfM1Readval(blockNumber byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0B02, []byte{blockNumber}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfM1Decrement(blockNumber byte, decrementValue []byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0C02, []byte{blockNumber}, decrementValue) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfM1Increment(blockNumber byte, incrementValue []byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0D02, []byte{blockNumber}, incrementValue) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfM1Restore(blockNumber byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0E02, []byte{blockNumber}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Sl500) RfM1Transfer(blockNumber byte) ([]byte, error) { |
|
|
|
|
sendRequest(s.port, 0x0F02, []byte{blockNumber}) |
|
|
|
|
return readResponse(s.port) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func readResponse(port *serial.Port) ([]byte, error) { |
|
|
|
|
var buf []byte |
|
|
|
|
innerBuf := make([]byte, 128) |
|
|
|
@ -148,10 +236,15 @@ func readResponse(port *serial.Port) ([]byte, error) { |
|
|
|
|
|
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if buf[0] != 0xAA || buf[1] != 0xBB { |
|
|
|
|
return nil, fmt.Errorf("Response format invalid") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if buf[8] != 0x0 { |
|
|
|
|
return nil, fmt.Errorf("Response status is fail") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
buf = buf[3:] |
|
|
|
|
ver := byte(0x00) |
|
|
|
|
|
|
|
|
@ -163,14 +256,20 @@ func readResponse(port *serial.Port) ([]byte, error) { |
|
|
|
|
return nil, fmt.Errorf("Response verification failed") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return buf[3 : len(buf)-1], nil |
|
|
|
|
buf = buf[4 : len(buf)-1] |
|
|
|
|
|
|
|
|
|
return buf, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func sendRequest(port *serial.Port, commandCode int16, bytesData []byte) { |
|
|
|
|
func sendRequest(port *serial.Port, commandCode int16, bytesData ...[]byte) { |
|
|
|
|
buf := new(bytes.Buffer) |
|
|
|
|
|
|
|
|
|
ver := byte(0x00) |
|
|
|
|
length := len(bytesData) + 5 |
|
|
|
|
length := 5 |
|
|
|
|
|
|
|
|
|
for _, b := range bytesData { |
|
|
|
|
length += len(b) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
binary.Write(buf, binary.BigEndian, byte(0xAA)) |
|
|
|
|
binary.Write(buf, binary.BigEndian, byte(0xBB)) |
|
|
|
@ -178,7 +277,10 @@ func sendRequest(port *serial.Port, commandCode int16, bytesData []byte) { |
|
|
|
|
binary.Write(buf, binary.BigEndian, byte(0x00)) |
|
|
|
|
binary.Write(buf, binary.BigEndian, int16(0)) // device id
|
|
|
|
|
binary.Write(buf, binary.BigEndian, commandCode) |
|
|
|
|
binary.Write(buf, binary.BigEndian, bytesData) |
|
|
|
|
|
|
|
|
|
for _, data := range bytesData { |
|
|
|
|
binary.Write(buf, binary.BigEndian, data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, k := range buf.Bytes()[3:] { |
|
|
|
|
ver = ver ^ k |
|
|
|
|