-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bff24d1
commit 3f6dce1
Showing
9 changed files
with
248 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package model | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/cuteLittleDevil/go-jt808/protocol" | ||
"github.com/cuteLittleDevil/go-jt808/protocol/jt808" | ||
"github.com/cuteLittleDevil/go-jt808/protocol/utils" | ||
"github.com/cuteLittleDevil/go-jt808/shared/consts" | ||
"strings" | ||
) | ||
|
||
type P0x9101 struct { | ||
BaseHandle | ||
// ServerIPLen 视频服务器IP地址长度 | ||
ServerIPLen byte `json:"serverIPLen"` | ||
// ServerIPAddr 视频服务器IP地址 | ||
ServerIPAddr string `json:"serverIPAddr"` | ||
// TcpPort 视频服务器TCP端口号,不使用TCP协议传输时保持默认值0即可(TCP和UDP二选一,当TCP和UDP均非默认值时一般以TCP为准) | ||
TcpPort uint16 `json:"tcpPort"` | ||
// UdpPort 视频服务器UDP端口号,不使用UDP协议传输时保持默认值0即可(TCP和UDP二选一,当TCP和UDP均非默认值时一般以TCP为准) | ||
UdpPort uint16 `json:"udpPort"` | ||
// ChannelNo 逻辑通道号 | ||
ChannelNo byte `json:"channelNo"` | ||
// DataType 数据类型 0-音视频 1-视频 2-双向对讲 3-监听 4-中心广播 5-透传 | ||
DataType byte `json:"dataType"` | ||
// StreamType 码流类型 0-主码流 1-子码流 | ||
StreamType byte `json:"streamType"` | ||
} | ||
|
||
func (p *P0x9101) Protocol() consts.JT808CommandType { | ||
return consts.P9101RealTimeAudioVideoRequest | ||
} | ||
|
||
func (p *P0x9101) ReplyProtocol() consts.JT808CommandType { | ||
return consts.T0001GeneralRespond | ||
} | ||
|
||
func (p *P0x9101) Parse(jtMsg *jt808.JTMessage) error { | ||
body := jtMsg.Body | ||
if len(body) < 1 { | ||
return protocol.ErrBodyLengthInconsistency | ||
} | ||
p.ServerIPLen = body[0] | ||
if len(body) != 1+int(p.ServerIPLen)+7 { | ||
return protocol.ErrBodyLengthInconsistency | ||
} | ||
n := int(p.ServerIPLen) | ||
p.ServerIPAddr = string(body[1 : n+1]) | ||
p.TcpPort = binary.BigEndian.Uint16(body[n+1:]) | ||
p.UdpPort = binary.BigEndian.Uint16(body[n+3:]) | ||
p.ChannelNo = body[n+5] | ||
p.DataType = body[n+6] | ||
p.StreamType = body[n+7] | ||
return nil | ||
} | ||
|
||
func (p *P0x9101) Encode() []byte { | ||
data := make([]byte, 0, 25) | ||
data = append(data, p.ServerIPLen) | ||
data = append(data, utils.String2FillingBytes(p.ServerIPAddr, len(p.ServerIPAddr))...) | ||
data = append(data, byte(p.TcpPort>>8), byte(p.TcpPort)) | ||
data = append(data, byte(p.UdpPort>>8), byte(p.UdpPort)) | ||
data = append(data, p.ChannelNo) | ||
data = append(data, p.DataType) | ||
data = append(data, p.StreamType) | ||
return data | ||
} | ||
|
||
func (p *P0x9101) ReplyBody(_ *jt808.JTMessage) ([]byte, error) { | ||
return nil, nil | ||
} | ||
|
||
func (p *P0x9101) String() string { | ||
return strings.Join([]string{ | ||
"数据体对象:{", | ||
fmt.Sprintf("\t%s:[%x]", p.Protocol(), p.Encode()), | ||
fmt.Sprintf("\t[%02x] 服务器IP地址长度:[%d]", p.ServerIPLen, p.ServerIPLen), | ||
fmt.Sprintf("\t[%x] 服务器IP地址:[%s]", p.ServerIPAddr, p.ServerIPAddr), | ||
fmt.Sprintf("\t[%04x] 服务器视频通道监听端口号(TCP):[%d]", p.TcpPort, p.TcpPort), | ||
fmt.Sprintf("\t[%04x] 服务器视频通道监听端口号(UDP):[%d]", p.UdpPort, p.UdpPort), | ||
fmt.Sprintf("\t[%02x] 逻辑通道号:[%d]", p.ChannelNo, p.ChannelNo), | ||
fmt.Sprintf("\t[%02x] 数据类型:[%d]", p.DataType, p.DataType), | ||
fmt.Sprintf("\t[%02x] 码流类型:[%d]", p.StreamType, p.StreamType), | ||
"}", | ||
}, "\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package model | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/cuteLittleDevil/go-jt808/protocol" | ||
"github.com/cuteLittleDevil/go-jt808/protocol/jt808" | ||
"github.com/cuteLittleDevil/go-jt808/protocol/utils" | ||
"github.com/cuteLittleDevil/go-jt808/shared/consts" | ||
"strings" | ||
) | ||
|
||
type T0x1005 struct { | ||
BaseHandle | ||
// StartTime 开始时间 BCD[6] CMT+8时区(上海时区) | ||
StartTime string `json:"startTime"` | ||
// EndTime 结束时间 BCD[6] CMT+8时区(上海时区) | ||
EndTime string `json:"endTime"` | ||
// BoardNumber 上车人数 从起始时间到结束时间的上车人数 | ||
BoardNumber uint16 `json:"boardNumber"` | ||
// AlightNumber 下车人数 从起始时间到结束时间的上车人数 | ||
AlightNumber uint16 `json:"alightNumber"` | ||
} | ||
|
||
func (t *T0x1005) Protocol() consts.JT808CommandType { | ||
return consts.T1005UploadPassengerFlow | ||
} | ||
|
||
func (t *T0x1005) ReplyProtocol() consts.JT808CommandType { | ||
return 0 | ||
} | ||
|
||
func (t *T0x1005) Parse(jtMsg *jt808.JTMessage) error { | ||
body := jtMsg.Body | ||
if len(body) != 16 { | ||
return protocol.ErrBodyLengthInconsistency | ||
} | ||
t.StartTime = utils.BCD2Time(body[:6]) | ||
t.EndTime = utils.BCD2Time(body[6:12]) | ||
t.BoardNumber = binary.BigEndian.Uint16(body[12:14]) | ||
t.AlightNumber = binary.BigEndian.Uint16(body[14:16]) | ||
return nil | ||
} | ||
|
||
func (t *T0x1005) Encode() []byte { | ||
data := make([]byte, 20) | ||
startBcdTime := utils.Time2BCD(t.StartTime) | ||
copy(data[0:6], startBcdTime) | ||
endBcdTime := utils.Time2BCD(t.EndTime) | ||
copy(data[6:12], endBcdTime) | ||
binary.BigEndian.PutUint16(data[12:14], t.BoardNumber) | ||
binary.BigEndian.PutUint16(data[14:16], t.AlightNumber) | ||
return data | ||
} | ||
|
||
func (t *T0x1005) ReplyBody(_ *jt808.JTMessage) ([]byte, error) { | ||
return nil, nil | ||
} | ||
|
||
func (t *T0x1005) String() string { | ||
return strings.Join([]string{ | ||
"数据体对象:{", | ||
fmt.Sprintf("\t%s:[%x]", t.Protocol(), t.Encode()), | ||
fmt.Sprintf("\t[%x] 开始时间:[%s]", utils.Time2BCD(t.StartTime), t.StartTime), | ||
fmt.Sprintf("\t[%x] 结束时间:[%s]", utils.Time2BCD(t.EndTime), t.EndTime), | ||
fmt.Sprintf("\t[%04x] 上车人数:[%d]", t.BoardNumber, t.BoardNumber), | ||
fmt.Sprintf("\t[%04x] 下车人数:[%d]", t.AlightNumber, t.AlightNumber), | ||
"}", | ||
}, "\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters