This commit is contained in:
xzb 2023-11-21 14:30:42 +08:00
parent ad24ce236b
commit 939c0dcaf8
3 changed files with 12 additions and 45 deletions

View File

@ -203,31 +203,40 @@ const (
const (
CAN_CRC16_ATPREQ = 0x11021
CAN_CRC32 = 0x04C11DB7
)
var (
crc16AtpReqTable []uint32 = nil
crc32CanTable []uint32 = nil
)
func CanCreateCrcTable() {
if crc16AtpReqTable == nil {
crc16AtpReqTable = CreateCrcTable(CAN_CRC16_ATPREQ, 16, false)
}
if crc32CanTable == nil {
crc32CanTable = CreateCrcTable(CAN_CRC32, 32, false)
}
}
func calculateAtpReqCrc16(data []byte) uint16 {
crc := CrcTableBased(data, 16, 0, false, false, 0, crc16AtpReqTable)
return uint16(crc)
}
func calculateCanCrc32(data []byte) uint32 {
crc := CrcTableBased(data, 32, 0xFF_FF_FF_FF, false, false, 0, crc32CanTable)
return crc
}
// CRC32A的校验范围是报文+时间戳A
func calculateDataRspCrc32A(data []byte) uint32 {
return 0
return calculateCanCrc32(data)
}
// CRC32B的校验范围是报文+时间戳B
func calculateDataRspCrc32B(data []byte) uint32 {
return 0
return calculateCanCrc32(data)
}
func calculateDataRspCrc32C(data []byte) uint32 {
return 0
return calculateCanCrc32(data)
}

View File

@ -1,41 +0,0 @@
package tcp
import "net"
type client struct {
laddr *net.TCPAddr //local address
raddr *net.TCPAddr //remote address
con *net.TCPConn //tcp 连接
}
func (c *client) NewClientWithLocal(remoteAddr string, localAddr string) *client {
ra, raEr := net.ResolveTCPAddr("tcp", remoteAddr)
if raEr != nil {
panic(raEr)
}
c.raddr = ra
//
la, laEr := net.ResolveTCPAddr("tcp", localAddr)
if laEr != nil {
panic(laEr)
}
c.laddr = la
return c
}
func (c *client) NewClient(remoteAddr string) *client {
ra, raEr := net.ResolveTCPAddr("tcp", remoteAddr)
if raEr != nil {
panic(raEr)
}
c.raddr = ra
c.con.LocalAddr()
return c
}
func (c *client) Start() error {
con, e := net.DialTCP(c.raddr.Network(), c.laddr, c.raddr)
if e != nil {
return e
}
c.con = con
return nil
}

View File

@ -1 +0,0 @@
package tcp