forked from deepch/vdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.go
185 lines (167 loc) · 5.35 KB
/
struct.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package dvrip
import (
"crypto/md5"
"encoding/binary"
"time"
)
var magicEnd = [2]byte{0x0A, 0x00}
const alnum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
type Payload struct {
Head byte
Version byte
_ byte
_ byte
Session int32
SequenceNumber int32
_ byte
_ byte
MsgID int16
BodyLength int32
}
type LoginResp struct {
AliveInterval int `json:"AliveInterval"`
ChannelNum int `json:"ChannelNum"`
DeviceType string `json:"DeviceType "`
ExtraChannel int `json:"ExtraChannel"`
Ret int `json:"Ret"`
SessionID string `json:"SessionID"`
}
type requestCode uint16
const (
codeLogin requestCode = 1000
codeKeepAlive requestCode = 1006
codeSystemInfo requestCode = 1020
codeNetWorkNetCommon requestCode = 1042
codeGeneral requestCode = 1042
codeChannelTitle requestCode = 1046
codeSystemFunction requestCode = 1360
codeEncodeCapability requestCode = 1360
codeOPPTZControl requestCode = 1400
codeOPMonitor requestCode = 1413
codeOPTalk requestCode = 1434
codeOPTimeSetting requestCode = 1450
codeOPMachine requestCode = 1450
codeOPTimeQuery requestCode = 1452
codeAuthorityList requestCode = 1470
codeUsers requestCode = 1472
codeGroups requestCode = 1474
codeAddGroup requestCode = 1476
codeModifyGroup requestCode = 1478
codeDelGroup requestCode = 1480
codeAddUser requestCode = 1482
codeModifyUser requestCode = 1484
codeDelUser requestCode = 1486
codeModifyPassword requestCode = 1488
codeAlarmSet requestCode = 1500
codeOPNetAlarm requestCode = 1506
codeAlarmInfo requestCode = 1504
codeOPSendFile requestCode = 1522
codeOPSystemUpgrade requestCode = 1525
codeOPNetKeyboard requestCode = 1550
codeOPSNAP requestCode = 1560
codeOPMailTest requestCode = 1636
)
type statusCode int
const (
statusOK statusCode = 100
statusUnknownError statusCode = 101
statusUnsupportedVersion statusCode = 102
statusRequestNotPermitted statusCode = 103
statusUserAlreadyLoggedIn statusCode = 104
statusUserIsNotLoggedIn statusCode = 105
statusUsernameOrPasswordIsIncorrect statusCode = 106
statusUserDoesNotHaveNecessaryPermissions statusCode = 107
statusPasswordIsIncorrect statusCode = 203
statusStartOfUpgrade statusCode = 511
statusUpgradeWasNotStarted statusCode = 512
statusUpgradeDataErrors statusCode = 513
statusUpgradeError statusCode = 514
statusUpgradeSuccessful statusCode = 515
)
var statusCodes = map[statusCode]string{
statusOK: "OK",
statusUnknownError: "Unknown error",
statusUnsupportedVersion: "Unsupported version",
statusRequestNotPermitted: "Request not permitted",
statusUserAlreadyLoggedIn: "User already logged in",
statusUserIsNotLoggedIn: "User is not logged in",
statusUsernameOrPasswordIsIncorrect: "Username or password is incorrect",
statusUserDoesNotHaveNecessaryPermissions: "User does not have necessary permissions",
statusPasswordIsIncorrect: "Password is incorrect",
statusStartOfUpgrade: "Start of upgrade",
statusUpgradeWasNotStarted: "Upgrade was not started",
statusUpgradeDataErrors: "Upgrade data errors",
statusUpgradeError: "Upgrade error",
statusUpgradeSuccessful: "Upgrade successful",
}
var requestCodes = map[requestCode]string{
codeOPMonitor: "OPMonitor",
codeOPTimeSetting: "OPTimeSetting",
}
type MetaInfo struct {
Width int
Height int
Datetime time.Time
FPS int
Frame string
Type string
}
type Frame struct {
Data []byte
Meta MetaInfo
}
//sofiaHash func
func sofiaHash(password string) string {
digest := md5.Sum([]byte(password))
hash := make([]byte, 0, 8)
for i := 1; i < len(digest); i += 2 {
sum := int(digest[i-1]) + int(digest[i])
hash = append(hash, alnum[sum%len(alnum)])
}
return string(hash)
}
//parseMediaType func
func parseMediaType(dataType uint32, mediaCode byte) string {
switch dataType {
case 0x1FC, 0x1FD:
switch mediaCode {
case 1:
return "MPEG4"
case 2:
return "H264"
case 3:
return "H265"
}
case 0x1F9:
if mediaCode == 1 || mediaCode == 6 {
return "info"
}
case 0x1FA:
if mediaCode == 0xE {
return "PCM_ALAW"
}
case 0x1FE:
if mediaCode == 0 {
return "JPEG"
}
default:
return "unknown"
}
return "unexpected"
}
//parseDatetime func
func parseDatetime(value uint32) time.Time {
second := int(value & 0x3F)
minute := int((value & 0xFC0) >> 6)
hour := int((value & 0x1F000) >> 12)
day := int((value & 0x3E0000) >> 17)
month := int((value & 0x3C00000) >> 22)
year := int(((value & 0xFC000000) >> 26) + 2000)
return time.Date(year, time.Month(month), day, hour, minute, second, 0, time.UTC)
}
//binSize func
func binSize(val int) []byte {
buf := make([]byte, 4)
binary.BigEndian.PutUint32(buf, uint32(val))
return buf
}