Refactor and simplify package structure and interfaces.
Reorganize code by removing unused files, restructuring package organization, and updating import references to new paths. This simplifies handling of smart and protocol-related operations, improves maintainability, and eliminates redundancy.
This commit is contained in:
168
pkg/models/certificate.go
Normal file
168
pkg/models/certificate.go
Normal file
@ -0,0 +1,168 @@
|
||||
package models
|
||||
|
||||
type NetConnectionType uint
|
||||
|
||||
const (
|
||||
NetConnectionWired NetConnectionType = iota
|
||||
NetConnectionWireless
|
||||
)
|
||||
|
||||
type TimeShiftSupportFlag uint8
|
||||
|
||||
const (
|
||||
TimeShiftNotSupported TimeShiftSupportFlag = iota
|
||||
TimeShiftSupported
|
||||
)
|
||||
|
||||
type FileSystemVersionNumber uint8
|
||||
|
||||
const (
|
||||
FileSystemVersion4 FileSystemVersionNumber = iota
|
||||
FileSystemVersion5
|
||||
)
|
||||
|
||||
type CertificateConnectRequest struct {
|
||||
Net NetConnectionType `json:"NET"`
|
||||
SerialNumber string `json:"DSNO"`
|
||||
DeviceName string `json:"DEVNAME"`
|
||||
ChannelsNumber uint `json:"CHANNEL"`
|
||||
LicensePlate string `json:"CARNUM"`
|
||||
DeviceNumber string `json:"AUTONO"`
|
||||
VehicleNumber string `json:"AUTOCAR"`
|
||||
TimeShiftSupport TimeShiftSupportFlag `json:"TSE"`
|
||||
FileSystemVersion FileSystemVersionNumber `json:"FSV"`
|
||||
ICCID string `json:"ICCID"`
|
||||
EvidenceSupport string `json:"EV"`
|
||||
}
|
||||
|
||||
type CertificateConnectClientRequest struct {
|
||||
UK string `json:"UK"`
|
||||
}
|
||||
|
||||
type CertificateConnectResponse struct {
|
||||
ErrorCode uint `json:"ERRORCODE"`
|
||||
ErrorCause string `json:"ERRORCAUSE"`
|
||||
CommandMask uint `json:"MASKCMD"`
|
||||
}
|
||||
|
||||
type CertificateConnectClientResponse struct {
|
||||
S0 string `json:"S0"`
|
||||
}
|
||||
|
||||
type CertificateVerificationRequest struct {
|
||||
S0 string `json:"S0"`
|
||||
}
|
||||
|
||||
type CertificateVerificationResponse struct {
|
||||
ErrorCode uint `json:"ERRORCODE"`
|
||||
ErrorCause string `json:"ERRORCAUSE"`
|
||||
ReturnFlag bool `json:"RETURN"`
|
||||
}
|
||||
|
||||
type CertificateLoginRequest struct {
|
||||
ClientID uint `json:"CID,omitempty"`
|
||||
MAC string `json:"MAC,omitempty"`
|
||||
User string `json:"USER"`
|
||||
Password string `json:"PASSWD"`
|
||||
PlayDevID uint `json:"PLAYDEVID"`
|
||||
}
|
||||
|
||||
type CertificateLoginResponse struct {
|
||||
SerialNumber string `json:"DSNO"`
|
||||
DeviceName string `json:"DEVNAME"`
|
||||
ChannelsNumber uint `json:"CHANNEL"`
|
||||
UID string `json:"UID"`
|
||||
AlarmInputNumber uint `json:"ALARMIN"`
|
||||
AlarmOutputNumber uint `json:"ALARMOUT"`
|
||||
DeviceType string `json:"TYPE"`
|
||||
DeviceClass DeviceType `json:"DEVCLASS"`
|
||||
CurrentVersion string `json:"PRO"`
|
||||
LicensePlate string `json:"CARNUM"`
|
||||
UserLever UserAccessLevel `json:"LEVEL"`
|
||||
CompanyName string `json:"CPN"`
|
||||
CustomerName string `json:"CNAME"`
|
||||
AudioChannelsNumber uint `json:"ACHN"`
|
||||
}
|
||||
|
||||
type CertificateCreateStreamRequest struct {
|
||||
StreamName string `json:"STREAMNAME"`
|
||||
}
|
||||
|
||||
type CertificateCreateStreamResponse struct {
|
||||
ErrorCode uint `json:"ERRORCODE"`
|
||||
ErrorCause string `json:"ERRORCAUSE"`
|
||||
}
|
||||
|
||||
type CommandMaskParameters uint
|
||||
|
||||
const (
|
||||
CommandMaskAlarm = 1 << iota
|
||||
CommandMaskScanningGun
|
||||
CommandMaskPassengerFlow
|
||||
CommandMaskFaceContrast
|
||||
CommandMaskCard
|
||||
CommandMaskShutdownReport
|
||||
CommandMaskGPSReport
|
||||
CommandMaskAll = 0b1111111
|
||||
)
|
||||
|
||||
type DeviceType uint
|
||||
|
||||
const (
|
||||
DeviceTypeDVR DeviceType = 1 + iota
|
||||
DeviceTypeIPC
|
||||
DeviceTypeNVR
|
||||
DeviceTypeMIPC
|
||||
DeviceTypeMDVR
|
||||
)
|
||||
|
||||
type UserAccessLevel uint
|
||||
|
||||
const (
|
||||
UserAccessLevelSuperAdmin UserAccessLevel = iota
|
||||
UserAccessLevelAdministrator
|
||||
UserAccessLeverUser
|
||||
)
|
||||
|
||||
/*
|
||||
func (e *Package) RequestConnect(session string, serial string, numOfCams int) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "CERTIFICATE",
|
||||
"OPERATION": "CONNECT",
|
||||
"PARAMETER": map[string]any{
|
||||
"DSNO": serial,
|
||||
"CHANNEL": numOfCams,
|
||||
},
|
||||
"SESSION": session,
|
||||
}
|
||||
}
|
||||
|
||||
// video server util
|
||||
func (e *Package) ResponseConnect(Sid string, streamName string) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "CERTIFICATE",
|
||||
"OPERATION": "CREATESTREAM",
|
||||
"RESPONSE": map[string]any{
|
||||
"ERRORCODE": 0,
|
||||
"STREAMNAME": streamName,
|
||||
},
|
||||
"SESSION": Sid,
|
||||
}
|
||||
}
|
||||
|
||||
// main server util
|
||||
func (e *Package) ResponseCertificateConnect(Sid string) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "CERTIFICATE",
|
||||
"OPERATION": "CONNECT",
|
||||
"RESPONSE": map[string]any{
|
||||
"ERRORCAUSE": "",
|
||||
"ERRORCODE": 0,
|
||||
"MASKCMD": 5,
|
||||
"PRO": "1.0.5",
|
||||
},
|
||||
"SESSION": Sid,
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
83
pkg/models/configmodel.go
Normal file
83
pkg/models/configmodel.go
Normal file
@ -0,0 +1,83 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gitea.unprism.ru/KRBL/n9m/v2/pkg/parameters"
|
||||
)
|
||||
|
||||
/*
|
||||
|
||||
// request reqistration parameters (directly to register)
|
||||
func (e *Package) RequestParameters(params map[string]any, serial int, session string) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "CONFIGMODEL",
|
||||
"OPERATION": "GET",
|
||||
"PARAMETER": map[string]any{
|
||||
"MDVR": params["MDVR"],
|
||||
"SERIAL": serial,
|
||||
},
|
||||
"SESSION": session,
|
||||
}
|
||||
} // end of 'RequestParameters' function
|
||||
|
||||
// set reigeter parameters (directly to register)
|
||||
func (e *Package) SetParameters(params map[string]any, serial int, session string) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "CONFIGMODEL",
|
||||
"OPERATION": "SET",
|
||||
"PARAMETER": map[string]any{
|
||||
"MDVR": params["MDVR"],
|
||||
"SERIAL": serial,
|
||||
},
|
||||
"SESSION": session,
|
||||
}
|
||||
// log.Println(e.Payload)
|
||||
} // end of 'SetParameters' function
|
||||
*/
|
||||
|
||||
type ConfigModelSetRequest struct {
|
||||
MDVR parameters.Setting `json:"MDVR"`
|
||||
}
|
||||
|
||||
type ConfigModelGetRequest struct {
|
||||
MDVR interface{} `json:"MDVR"`
|
||||
}
|
||||
|
||||
type ConfigModelSetResponse struct {
|
||||
MDVR parameters.Setting `json:"MDVR"`
|
||||
}
|
||||
|
||||
func InitialConfig() ConfigModelSetRequest {
|
||||
return ConfigModelSetRequest{
|
||||
MDVR: parameters.Setting{
|
||||
KEYS: parameters.KEYS{
|
||||
GV: 1, // GPS version
|
||||
},
|
||||
PGDSM: parameters.PGDSM{
|
||||
PGPS: parameters.PGPS{
|
||||
EN: 1, // Real-time position monitoring
|
||||
MODE: 0b10, // Enable timer
|
||||
TM: 10, // Time interval
|
||||
},
|
||||
},
|
||||
SUBSTRNET: parameters.SUBSTRNET{
|
||||
SM: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func (e *Package) ResponseConfigModelSet(Sid string) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "CONFIGMODUL", // it's not error
|
||||
"OPERATION": "SET",
|
||||
"RESPONSE": map[string]any{
|
||||
"ERRORCODE": 0,
|
||||
"ERRORCAUSE": "None",
|
||||
"ERRORDESCRIPTION": "None",
|
||||
},
|
||||
"SESSION": Sid,
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
215
pkg/models/devemm.go
Normal file
215
pkg/models/devemm.go
Normal file
@ -0,0 +1,215 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.unprism.ru/KRBL/n9m/v2/pkg/protocol"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
|
||||
// main server util
|
||||
func (e *Package) RequestGeolocation(serial int, Sid string) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "DEVEMM",
|
||||
"OPERATION": "GETPOS",
|
||||
"PARAMETER": map[string]any{
|
||||
"SERIAL": serial,
|
||||
},
|
||||
"SESSION": Sid,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Package) ResponseGeolocation(errorCode int, errorCause string, serial int, longitude float32, latitude float32, altitude float32, speed int, course int, time string) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "DEVEMM",
|
||||
"OPERATION": "GETPOS",
|
||||
"RESPONSE": map[string]any{
|
||||
"ERRORCODE": errorCode,
|
||||
"ERRORCAUSE": errorCause,
|
||||
"SERIAL": serial,
|
||||
"P": map[string]any{
|
||||
"V": errorCode == 0,
|
||||
"J": fmt.Sprintf("%4.6v", longitude),
|
||||
"W": fmt.Sprintf("%4.6v", latitude),
|
||||
"H": fmt.Sprintf("%4.6v", altitude),
|
||||
"S": speed, // unit - 0.01 km/h
|
||||
"C": course, // direction (angle from north)
|
||||
"T": time, // yyyymmddhhmmss
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// 3.4.5.28
|
||||
type SpiParameters struct {
|
||||
DriveFlag uint `json:"T"`
|
||||
DataMask uint `json:"M"`
|
||||
Position protocol.GPSData `json:"P"`
|
||||
DeviceStatus SpiDeviceStatus `json:"S"`
|
||||
}
|
||||
|
||||
// 3.4.5.28.1
|
||||
type SpiDeviceStatus struct {
|
||||
Status3G uint `json:"G3"`
|
||||
Status3GStrength uint `json:"G3S"`
|
||||
Status4G uint `json:"G4"`
|
||||
Status4GStrength uint `json:"G4S"`
|
||||
WIFIStatus uint `json:"W"`
|
||||
WIFIStrength uint `json:"WS"`
|
||||
Voltage float64 `json:"V"`
|
||||
DeviceTemperature float64 `json:"DT"`
|
||||
IndoorTemperature float64 `json:"TC"`
|
||||
Speed float64 `json:"S"`
|
||||
KeyIgnitionState uint `json:"SW"`
|
||||
RecordStatus []uint `json:"RE"`
|
||||
Time time.Time `json:"T"`
|
||||
StorageDeviceNumber uint `json:"STC"`
|
||||
StorageDeviceInfo []StorageDeviceInfo `json:"SINFO"`
|
||||
VideoLossStatus []uint `json:"VS"`
|
||||
Humidity float64 `json:"H"`
|
||||
TotalMileage float64 `json:"TM"`
|
||||
HardDriveHeating uint `json:"HTR"`
|
||||
}
|
||||
|
||||
func (g *SpiDeviceStatus) MarshalJSON() ([]byte, error) {
|
||||
var alias struct {
|
||||
Status3G uint `json:"G3"`
|
||||
Status3GStrength uint `json:"G3S"`
|
||||
Status4G uint `json:"G4"`
|
||||
Status4GStrength uint `json:"G4S"`
|
||||
WIFIStatus uint `json:"W"`
|
||||
WIFIStrength uint `json:"WS"`
|
||||
Voltage uint `json:"V"`
|
||||
DeviceTemperature uint `json:"DT"`
|
||||
IndoorTemperature uint `json:"TC"`
|
||||
Speed uint `json:"S"`
|
||||
SpeedUnits uint `json:"SU"`
|
||||
KeyIgnitionState uint `json:"SW"`
|
||||
RecordStatus []uint `json:"RE"`
|
||||
Time string `json:"T"`
|
||||
StorageDeviceNumber uint `json:"STC"`
|
||||
StorageDeviceInfo []StorageDeviceInfo `json:"SINFO"`
|
||||
VideoLossStatus []uint `json:"VS"`
|
||||
Humidity uint `json:"H"`
|
||||
TotalMileage string `json:"TM"`
|
||||
HardDriveHeating uint `json:"HTR"`
|
||||
}
|
||||
|
||||
convert := func(v float64) uint {
|
||||
if v < 0 {
|
||||
return uint(-v * 100)
|
||||
} else {
|
||||
return uint((v + 100) * 100)
|
||||
}
|
||||
}
|
||||
|
||||
alias.Status3G = g.Status3G
|
||||
alias.Status3GStrength = g.Status3GStrength
|
||||
alias.Status4G = g.Status4G
|
||||
alias.Status4GStrength = g.Status4GStrength
|
||||
alias.WIFIStatus = g.WIFIStatus
|
||||
alias.WIFIStrength = g.WIFIStrength
|
||||
alias.Voltage = uint(g.Voltage * 100)
|
||||
alias.DeviceTemperature = convert(g.DeviceTemperature)
|
||||
alias.IndoorTemperature = convert(g.IndoorTemperature)
|
||||
alias.Speed = uint(g.Speed * 100)
|
||||
alias.SpeedUnits = 0
|
||||
alias.KeyIgnitionState = g.KeyIgnitionState
|
||||
alias.RecordStatus = g.RecordStatus
|
||||
alias.Time = g.Time.Format("20060102150405")
|
||||
alias.StorageDeviceNumber = g.StorageDeviceNumber
|
||||
alias.StorageDeviceInfo = g.StorageDeviceInfo
|
||||
alias.VideoLossStatus = g.VideoLossStatus
|
||||
alias.Humidity = uint(g.Humidity * 10000)
|
||||
alias.TotalMileage = fmt.Sprintf("%.6f", g.TotalMileage)
|
||||
alias.HardDriveHeating = g.HardDriveHeating
|
||||
|
||||
return json.Marshal(alias)
|
||||
}
|
||||
|
||||
func (g *SpiDeviceStatus) UnmarshalJSON(data []byte) (err error) {
|
||||
var alias struct {
|
||||
Status3G uint `json:"G3"`
|
||||
Status3GStrength uint `json:"G3S"`
|
||||
Status4G uint `json:"G4"`
|
||||
Status4GStrength uint `json:"G4S"`
|
||||
WIFIStatus uint `json:"W"`
|
||||
WIFIStrength uint `json:"WS"`
|
||||
Voltage uint `json:"V"`
|
||||
DeviceTemperature uint `json:"TD"`
|
||||
IndoorTemperature uint `json:"TC"`
|
||||
Speed uint `json:"S"`
|
||||
SpeedUnits uint `json:"SU"`
|
||||
KeyIgnitionState uint `json:"SW"`
|
||||
RecordStatus []uint `json:"RE"`
|
||||
Time string `json:"T"`
|
||||
StorageDeviceNumber uint `json:"STC"`
|
||||
StorageDeviceInfo []StorageDeviceInfo `json:"SINFO"`
|
||||
VideoLossStatus []uint `json:"VS"`
|
||||
Humidity uint `json:"H"`
|
||||
TotalMileage string `json:"TM"`
|
||||
HardDriveHeating uint `json:"HTR"`
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(data, &alias); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
convert := func(v uint) float64 {
|
||||
if v < 10000 {
|
||||
return -float64(v) / 100
|
||||
} else {
|
||||
return float64(v-10000) / 100
|
||||
}
|
||||
}
|
||||
|
||||
g.Status3G = alias.Status3G
|
||||
g.Status3GStrength = alias.Status3GStrength
|
||||
g.Status4G = alias.Status4G
|
||||
g.Status4GStrength = alias.Status4GStrength
|
||||
g.WIFIStatus = alias.WIFIStatus
|
||||
g.WIFIStrength = alias.WIFIStrength
|
||||
g.Voltage = float64(alias.Voltage) / 100
|
||||
g.DeviceTemperature = convert(alias.DeviceTemperature)
|
||||
g.IndoorTemperature = convert(alias.IndoorTemperature)
|
||||
|
||||
g.Speed = float64(alias.Speed) / 100.0
|
||||
switch alias.SpeedUnits {
|
||||
case 0:
|
||||
break
|
||||
case 1:
|
||||
g.Speed *= 1.609
|
||||
default:
|
||||
return fmt.Errorf("Strange speed units")
|
||||
}
|
||||
|
||||
g.KeyIgnitionState = alias.KeyIgnitionState
|
||||
g.RecordStatus = alias.RecordStatus
|
||||
g.Time, _ = time.Parse("20060102150405", alias.Time)
|
||||
g.StorageDeviceNumber = alias.StorageDeviceNumber
|
||||
g.StorageDeviceInfo = alias.StorageDeviceInfo
|
||||
g.VideoLossStatus = alias.VideoLossStatus
|
||||
g.Humidity = float64(alias.Humidity) / 10000
|
||||
|
||||
if g.TotalMileage, err = strconv.ParseFloat(alias.TotalMileage, 64); err != nil {
|
||||
return fmt.Errorf("invalid longitude: %w", err)
|
||||
}
|
||||
|
||||
g.HardDriveHeating = alias.HardDriveHeating
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 3.4.5.28.3
|
||||
type StorageDeviceInfo struct {
|
||||
Type uint `json:"T"`
|
||||
MediaTime uint `json:"O"`
|
||||
Status uint `json:"S"`
|
||||
Capacity uint `json:"TS"`
|
||||
FreeCapacity uint `json:"LS"`
|
||||
}
|
90
pkg/models/evem.go
Normal file
90
pkg/models/evem.go
Normal file
@ -0,0 +1,90 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gitea.unprism.ru/KRBL/n9m/v2/pkg/protocol"
|
||||
)
|
||||
|
||||
// 3.4.1.3
|
||||
type EventModelGetAlarmStatusInfoResponse struct {
|
||||
ErrorCode uint `json:"ERRORCODE"`
|
||||
ErrorCause string `json:"ERRORCAUSE"`
|
||||
StorageErrors []StorageErrorStatus `json:"ST"`
|
||||
AnotherStorageErrors []AnotherStorageErrorStatus `json:"VS"`
|
||||
VideoLossErrors []VideoLossErrorStatus `json:"VL"`
|
||||
GPSError GPSErrorStatus `json:"GFA"`
|
||||
GPSAntennaError GPSAntennaErrorStatus `json:"GPSS"`
|
||||
}
|
||||
|
||||
// 3.4.1.4.21
|
||||
type StorageErrorStatus struct {
|
||||
CameraCovered uint `json:"ISA"`
|
||||
ChannelBind uint `json:"LHC"`
|
||||
}
|
||||
|
||||
// 3.4.1.4.4
|
||||
type AnotherStorageErrorStatus struct {
|
||||
}
|
||||
|
||||
// 3.4.1.4.5
|
||||
type VideoLossErrorStatus struct {
|
||||
}
|
||||
|
||||
// 3.4.1.4.44
|
||||
type GPSErrorStatus struct {
|
||||
}
|
||||
|
||||
// 3.4.1.4.46
|
||||
type GPSAntennaErrorStatus struct {
|
||||
}
|
||||
|
||||
// 3.4.1.5
|
||||
// Alarm upload
|
||||
type SendAlarmInfoParameters struct {
|
||||
AlarmType protocol.AlarmType `json:"ALARMTYPE"`
|
||||
CommandType uint `json:"CMDTYPE"`
|
||||
AlarmUID uint `json:"ALARMUID"`
|
||||
NumberOfRestarts uint `json:"RUN"`
|
||||
AlarmLevel protocol.AlarmLevel `json:"ALARMAS"`
|
||||
AlarmCount uint `json:"ALARMCOUNT"`
|
||||
TriggerType protocol.TriggerType `json:"TRIGGERTYPE"`
|
||||
ContinueTime uint `json:"CONTINUETIME"`
|
||||
CurrentTime uint `json:"CURRENTTIME"`
|
||||
Language protocol.Language `json:"L"`
|
||||
GPSData protocol.GPSData `json:"P"`
|
||||
RealTimeUpload uint `json:"REAL"`
|
||||
InstructionSerial uint `json:"CMDNO"`
|
||||
}
|
||||
|
||||
// 3.4.1.5
|
||||
// Alarm upload
|
||||
type SendAlarmInfoResponse struct {
|
||||
ErrorCode uint `json:"ERRORCODE"`
|
||||
AlarmType protocol.AlarmType `json:"ALARMTYPE"`
|
||||
ErrorCause string `json:"ERRORCAUSE"`
|
||||
CommandType uint `json:"CMDTYPE"`
|
||||
AlarmUID uint `json:"ALARMUID"`
|
||||
NumberOfRestarts uint `json:"RUN"`
|
||||
InstructionSerial uint `json:"CMDNO"`
|
||||
}
|
||||
|
||||
// 3.4.1.5.1
|
||||
type SendAlarmInfoCameraParameters struct {
|
||||
SendAlarmInfoParameters
|
||||
|
||||
Channel uint `json:"CHANNEL"`
|
||||
ChannelMask uint `json:"CHANNELMASK"`
|
||||
LCH []uint `json:"LCH"`
|
||||
Push uint `json:"PUSH"`
|
||||
AlarmName string `json:"ALARMNAME"`
|
||||
AlarmAbbreviation string `json:"SER"`
|
||||
}
|
||||
|
||||
type EventModelGetAlarmingResponse struct {
|
||||
CameraCoveredChannelMask uint `json:"VS_CH"`
|
||||
CameraCoveredAlarmMask uint `json:"VS_AT"`
|
||||
CameraCoveredStatusMask uint `json:"VS_AS"`
|
||||
|
||||
VideoLossChannelMask uint `json:"VL_CH"`
|
||||
VideoLossAlarmMask uint `json:"VL_AT"`
|
||||
VideoLossStatusMask uint `json:"VL_AS"`
|
||||
}
|
160
pkg/models/mediastreammodel.go
Normal file
160
pkg/models/mediastreammodel.go
Normal file
@ -0,0 +1,160 @@
|
||||
package models
|
||||
|
||||
import "gitea.unprism.ru/KRBL/n9m/v2/pkg/protocol"
|
||||
|
||||
type StreamType uint
|
||||
|
||||
const (
|
||||
StreamTypeSub StreamType = iota
|
||||
StreamTypeMain
|
||||
StreamTypeMobile
|
||||
)
|
||||
|
||||
type MediaStreamModelRequestLiveVideoRequest struct {
|
||||
SSRC uint `json:"SSRC,omitempty"`
|
||||
StreamName string `json:"STREAMNAME"`
|
||||
StreamType StreamType `json:"STREAMTYPE"`
|
||||
Channel uint `json:"CHANNEL"`
|
||||
AudioValid uint `json:"AUDIOVALID"`
|
||||
Destination string `json:"IPANDPORT,omitempty"`
|
||||
FrameCount uint `json:"FRAMECOUNT,omitempty"`
|
||||
FrameMode uint `json:"FRAMEMODE"`
|
||||
}
|
||||
|
||||
type MediaStreamModelRequestLiveVideoResponse struct {
|
||||
SSRC uint `json:"SSRC"`
|
||||
StreamName string `json:"STREAMNAME"`
|
||||
StreamType StreamType `json:"STREAMTYPE"`
|
||||
ErrorCode uint `json:"ERRORCODE"`
|
||||
ErrorCause string `json:"ERRORCAUSE"`
|
||||
}
|
||||
|
||||
type MediaStreamCommand uint
|
||||
|
||||
const (
|
||||
MediaStreamCommandStop MediaStreamCommand = iota
|
||||
MediaStreamCommandResume
|
||||
MediaStreamCommandPause
|
||||
MediaStreamCommandSwitchVideoStream
|
||||
MediaStreamAudioManagement
|
||||
MediaStreamFrameRate
|
||||
MediaStreamSendingMode
|
||||
)
|
||||
|
||||
type MediaStreamModelControlStreamRequest struct {
|
||||
PayloadType protocol.PayloadType `json:"PT"`
|
||||
SSRC uint16 `json:"SSRC"`
|
||||
StreamName string `json:"STREAMNAME"`
|
||||
Command MediaStreamCommand `json:"CMD"`
|
||||
|
||||
StreamType StreamType `json:"STREAMTYPE,omitempty"`
|
||||
AudioValid uint `json:"AUDIOVALID,omitempty"`
|
||||
FrameMode uint `json:"FRAMEMODE,omitempty"`
|
||||
}
|
||||
|
||||
/*
|
||||
var ip string = os.Getenv("SERVER_IP")
|
||||
|
||||
func (e *Package) MediaRequestDownloadVideo(token int, serial string, session string, camNo int, date string, begin_time string, end_time string, recordID string, serverId int) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "MEDIASTREAMMODEL",
|
||||
"OPERATION": "REQUESTDOWNLOADVIDEO",
|
||||
"PARAMETER": map[string]any{
|
||||
"PT": 3,
|
||||
"SSRC": 1,
|
||||
"STREAMNAME": "DOWNLOAD" + "_" + serial + "_" + fmt.Sprint(camNo) + "_" + fmt.Sprint(serverId),
|
||||
"STREAMTYPE": 1, // main stream
|
||||
"RECORDID": recordID,
|
||||
"CHANNEL": 1 << (camNo - 1),
|
||||
"STARTTIME": date + begin_time,
|
||||
"ENDTIME": date + end_time,
|
||||
"OFFSETFLAG": 1,
|
||||
"OFFSET": 0,
|
||||
"IPANDPORT": ip + ":12092",
|
||||
"SERIAL": token,
|
||||
"DT": 1, // high speed download
|
||||
},
|
||||
"SESSION": session,
|
||||
}
|
||||
}
|
||||
|
||||
// main server util
|
||||
func (e *Package) MediaRequestAliveVideo(token int, camNo int64, Sid string, serial string, quality int64) {
|
||||
|
||||
channel := 0
|
||||
|
||||
if camNo == 1 {
|
||||
channel = 1
|
||||
} else {
|
||||
channel = 1 << (camNo - 1)
|
||||
}
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "MEDIASTREAMMODEL",
|
||||
"OPERATION": "REQUESTALIVEVIDEO",
|
||||
"PARAMETER": map[string]any{
|
||||
"AUDIOVALID": 1,
|
||||
"CHANNEL": channel,
|
||||
"FRAMEMODE": 0,
|
||||
"IPANDPORT": ip + ":12092",
|
||||
"STREAMNAME": "LIVE" + "_" + serial + "_" + fmt.Sprint(camNo),
|
||||
"STREAMTYPE": quality,
|
||||
"SERIAL": token,
|
||||
},
|
||||
"SESSION": Sid,
|
||||
}
|
||||
}
|
||||
|
||||
// main server util
|
||||
func (e *Package) MediaRequestRemotePlayback(token int, serial string, session string, camNo int, date string, begin_time string, end_time string, serverId int) {
|
||||
if end_time == "" {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "MEDIASTREAMMODEL",
|
||||
"OPERATION": "REQUESTREMOTEPLAYBACK",
|
||||
"PARAMETER": map[string]any{
|
||||
"STREAMNAME": "PLAYBACK" + "_" + fmt.Sprint(serial) + "_" + fmt.Sprint(camNo) + "_" + fmt.Sprint(serverId),
|
||||
"STREAMTYPE": 1, // main stream
|
||||
"VIDEOTYPE": 2, // common files
|
||||
"CHANNEL": 1 << (camNo - 1),
|
||||
"STARTTIME": date + begin_time,
|
||||
"IPANDPORT": ip + ":12092",
|
||||
"SERIAL": token,
|
||||
"PBST": 0,
|
||||
},
|
||||
"SESSION": session,
|
||||
}
|
||||
} else {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "MEDIASTREAMMODEL",
|
||||
"OPERATION": "REQUESTREMOTEPLAYBACK",
|
||||
"PARAMETER": map[string]any{
|
||||
"STREAMNAME": "PLAYBACK" + "_" + fmt.Sprint(serial) + "_" + fmt.Sprint(camNo) + "_" + fmt.Sprint(serverId),
|
||||
"STREAMTYPE": 1, // main stream
|
||||
"VIDEOTYPE": 2, // common files
|
||||
"CHANNEL": 1 << (camNo - 1),
|
||||
"STARTTIME": date + begin_time,
|
||||
"ENDTIME": date + end_time,
|
||||
"IPANDPORT": ip + ":12092",
|
||||
"SERIAL": token,
|
||||
"PBST": 0,
|
||||
},
|
||||
"SESSION": session,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// main server util
|
||||
func (e *Package) ControlRemotePlayback(token int, serial string, session string, camNo int, date string, begin_time string, end_time string, serverId int) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "MEDIASTREAMMODEL",
|
||||
"OPERATION": "CONTROLREMOTEPLAYBACK",
|
||||
"PARAMETER": map[string]any{
|
||||
"STREAMNAME": fmt.Sprint(serial) + "_" + fmt.Sprint(camNo) + "_" + fmt.Sprint(serverId),
|
||||
"SERIAL": token,
|
||||
"PALYBACKCMD": 5, // main stream
|
||||
"CHANNEL": 268435455, // common files
|
||||
},
|
||||
"SESSION": session,
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
84
pkg/models/storm.go
Normal file
84
pkg/models/storm.go
Normal file
@ -0,0 +1,84 @@
|
||||
package models
|
||||
|
||||
/*
|
||||
|
||||
func (e *Package) ResponseCalendar(errorCode int, errorCause string, serial int, dates []string) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "STORM",
|
||||
"OPERATION": "GETCALENDAR",
|
||||
"RESPONSE": map[string]any{
|
||||
"ERRORCODE": errorCode,
|
||||
"ERRORCAUSE": errorCause,
|
||||
"SERIAL": serial,
|
||||
"COUNT": len(dates),
|
||||
"CALENDER": dates,
|
||||
// no CHCALENDER[COUNT]
|
||||
// no T[COUNT]
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Package) RequestCalendar(queryTime string, serial int, session string, camNo int64) {
|
||||
channel := 1 << (camNo - 1)
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "STORM",
|
||||
"OPERATION": "GETCALENDAR",
|
||||
"PARAMETER": map[string]any{
|
||||
"CALENDARTYPE": 1, // Month data
|
||||
"STREAMTYPE": 1, // Main Stream
|
||||
"FILETYPE": 0b111111, // get file type
|
||||
"PICMTYPE": 0b10, // fixed timing pictures (fixed framerate)
|
||||
"APT0": 0xFFFFFF, // get every alarm
|
||||
"APT1": 0xFFFF, // get every alarm
|
||||
"AUDIOTYPE": 0b111, // normal recording, passenger complaints, alarm recording
|
||||
"CHANNEL": channel, // request all channels
|
||||
"QUERYTIME": queryTime, // year + month = xxxxxx
|
||||
"SERIAL": serial,
|
||||
"NEWSTREAMTYPE": 0b111, // master stream (bit1)
|
||||
"RFSTORAGE": 0, // 0 - hdd, 1 - sd
|
||||
},
|
||||
"SESSION": session,
|
||||
}
|
||||
}
|
||||
|
||||
// filenames without fileextension
|
||||
func (e *Package) ResponseFileList(errorCode int, errorCause string, serial int, filenames []string, fileextensions []int, ids []string) {
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "STORM",
|
||||
"OPERATION": "QUERYFILELIST",
|
||||
"RESPONSE": map[string]any{
|
||||
"ERRORCODE": errorCode,
|
||||
"ERRORCAUSE": errorCause,
|
||||
"SERIAL": serial,
|
||||
"SENDFILECOUNT": len(filenames),
|
||||
"RECORD": filenames,
|
||||
"FILETYPE": fileextensions,
|
||||
"RECORDID": ids,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Package) RequestFileList(queryTime string, serial int, session string, camNo int64) {
|
||||
channel := 1 << (camNo - 1)
|
||||
e.Payload = map[string]any{
|
||||
"MODULE": "STORM",
|
||||
"OPERATION": "QUERYFILELIST",
|
||||
"PARAMETER": map[string]any{
|
||||
"STREAMTYPE": 1, // Main Stream
|
||||
"FILETYPE": 0b111111, // get all filetypes
|
||||
"PICMTYPE": 0b10, // fixed timing pictures (fixed framerate)
|
||||
"APT0": 0xFFFFFF, // get every alarm
|
||||
"APT1": 0xFFFF, // get every alarm
|
||||
"AUDIOTYPE": 0b111, // normal recording, passenger complaints, alarm recording
|
||||
"CHANNEL": channel, // request all channels
|
||||
"STARTTIME": queryTime + "000000",
|
||||
"ENDTIME": queryTime + "235959",
|
||||
"SERIAL": serial,
|
||||
"NEWSTREAMTYPE": 0b10, // master stream (bit1)
|
||||
"RFSTORAGE": 0, // 0 - hdd, 1 - sd
|
||||
},
|
||||
"SESSION": session,
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
Reference in New Issue
Block a user