Compare commits
	
		
			12 Commits
		
	
	
		
			v2.0.4-alp
			...
			v2.1.8-alp
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						ec06ee84de
	
				 | 
					
					
						|||
| 
						
						
							
						
						92e59cf650
	
				 | 
					
					
						|||
| 
						
						
							
						
						5c5496fa7f
	
				 | 
					
					
						|||
| 
						
						
							
						
						2737e23369
	
				 | 
					
					
						|||
| 
						
						
							
						
						b4ec470e2f
	
				 | 
					
					
						|||
| 
						
						
							
						
						6012bccf64
	
				 | 
					
					
						|||
| 
						
						
							
						
						4c631db418
	
				 | 
					
					
						|||
| 
						
						
							
						
						26f354d82d
	
				 | 
					
					
						|||
| 
						
						
							
						
						edc86fb706
	
				 | 
					
					
						|||
| 
						
						
							
						
						eaaa634558
	
				 | 
					
					
						|||
| 
						
						
							
						
						51308a2395
	
				 | 
					
					
						|||
| 
						
						
							
						
						9d2db3672c
	
				 | 
					
					
						
							
								
								
									
										256
									
								
								cmd/dev-client/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										256
									
								
								cmd/dev-client/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,256 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/models"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/protocol"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/smart"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/utils"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"syscall"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var videoPack *smart.SmartChannelPackage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						conn, err := net.Dial("tcp", "10.100.100.99:9006")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var pack = protocol.Package{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.Payload.Module = "CERTIFICATE"
 | 
				
			||||||
 | 
						pack.Payload.Operation = "CONNECT"
 | 
				
			||||||
 | 
						pack.SetParameters(models.CertificateConnectClientRequest{})
 | 
				
			||||||
 | 
						conn.Write(pack.PackPackage())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						handle(conn)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleSpecialPackages(_ *smart.SmartPackage, pack protocol.Package) error {
 | 
				
			||||||
 | 
						switch pack.SSRC {
 | 
				
			||||||
 | 
						case protocol.SpecialPayloadTypeGPS:
 | 
				
			||||||
 | 
							fmt.Printf("%+v\n", pack.GPS)
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return fmt.Errorf("unhandled special operation: %d", pack.SSRC)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleLivePackages(_ *smart.SmartPackage, pack protocol.Package) error {
 | 
				
			||||||
 | 
						fmt.Printf("%+v\n", pack)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleCertificateConnect(sPack *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
 | 
						var params models.CertificateConnectClientResponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err = pack.GetResponseAs(¶ms); err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed to get response: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var response = models.CertificateVerificationRequest{
 | 
				
			||||||
 | 
							S0: utils.GenerateVerifyKey(params.S0),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.Payload.Operation = "VERIFY"
 | 
				
			||||||
 | 
						pack.SetParameters(response)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sPack.Write(pack.PackPackage())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleVerify(sPack *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
 | 
						var params models.CertificateVerificationResponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err = pack.GetResponseAs(¶ms); err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed to get response: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if params.ErrorCode == 0 {
 | 
				
			||||||
 | 
							fmt.Println("ШАЛОСТЬ УДАЛАСЬ!")
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							fmt.Println("шалость НЕ удалась(((")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var request = models.CertificateLoginRequest{
 | 
				
			||||||
 | 
							ClientID: 0,
 | 
				
			||||||
 | 
							MAC:      "",
 | 
				
			||||||
 | 
							User:     "admin",
 | 
				
			||||||
 | 
							Password: "",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.Payload.Operation = "LOGIN"
 | 
				
			||||||
 | 
						pack.SetParameters(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sPack.Write(pack.PackPackage())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleLogin(sPack *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
 | 
						var params models.CertificateLoginResponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err = pack.GetResponseAs(¶ms); err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed to get response: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						conn, err := net.Dial("tcp", "10.100.100.99:9006")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						videoPack, err = smart.NewSmartChannelPackage(conn, sPack)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						go videoPack.Run()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						videoPack.AddLiveSource(2, func(data []byte) error {
 | 
				
			||||||
 | 
							fmt.Println("Есть контакт!")
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var request = models.MediaStreamModelRequestLiveVideoRequest{
 | 
				
			||||||
 | 
							StreamName: videoPack.GetChannelName(),
 | 
				
			||||||
 | 
							StreamType: models.StreamTypeMain,
 | 
				
			||||||
 | 
							Channel:    4,
 | 
				
			||||||
 | 
							AudioValid: 4,
 | 
				
			||||||
 | 
							FrameMode:  0,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.Payload.Module = "MEDIASTREAMMODEL"
 | 
				
			||||||
 | 
						pack.Payload.Operation = "REQUESTALIVEVIDEO"
 | 
				
			||||||
 | 
						pack.SetParameters(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sPack.Write(pack.PackPackage())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleRequestLiveVideo(sPack *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
 | 
						var params models.MediaStreamModelRequestLiveVideoResponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err = pack.GetResponseAs(¶ms); err != nil {
 | 
				
			||||||
 | 
							return fmt.Errorf("failed to get response: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if params.ErrorCode != 0 {
 | 
				
			||||||
 | 
							fmt.Println("Request live stream error:", params.ErrorCode, params.ErrorCause)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("%+v\n", params)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleKeepAlive(sPack *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
 | 
						serial := sPack.Storage["serial"]
 | 
				
			||||||
 | 
						fmt.Println(serial, "still alive!")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.SetResponse(nil)
 | 
				
			||||||
 | 
						sPack.Write(pack.PackPackage())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleGetConfig(sPack *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
 | 
						serial := sPack.Storage["serial"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						os.WriteFile(fmt.Sprintf("./%s.json", serial), pack.RawPayload, 0644)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var request models.ConfigModelSetRequest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err = pack.GetParametersAs(&request); err != nil {
 | 
				
			||||||
 | 
							fmt.Println(err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleUselessAlarms(sPack *smart.SmartPackage, pack protocol.Package, response models.SendAlarmInfoResponse) (err error) {
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleVideoLossAlarm(sPack *smart.SmartPackage, pack protocol.Package, response models.SendAlarmInfoResponse) (err error) {
 | 
				
			||||||
 | 
						fmt.Println("Video loss alarm!")
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleCameraCoveredAlarm(sPack *smart.SmartPackage, pack protocol.Package, response models.SendAlarmInfoResponse) (err error) {
 | 
				
			||||||
 | 
						fmt.Println("Camera covered alarm!")
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handleSPI(_ *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
 | 
						var params models.SpiParameters
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err = pack.GetParametersAs(¶ms); err != nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("%+v\n", params)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func createSmartPackage(conn net.Conn) (pack *smart.SmartPackage) {
 | 
				
			||||||
 | 
						pack = smart.NewSmartPackage(conn)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.AddPayloadHandler(protocol.PayloadTypeLive, handleLivePackages)
 | 
				
			||||||
 | 
						pack.AddPayloadHandler(protocol.PayloadTypeSpecial, handleSpecialPackages)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.AddJSONHandler("CERTIFICATE", "CONNECT", handleCertificateConnect)
 | 
				
			||||||
 | 
						pack.AddJSONHandler("CERTIFICATE", "VERIFY", handleVerify)
 | 
				
			||||||
 | 
						pack.AddJSONHandler("CERTIFICATE", "LOGIN", handleLogin)
 | 
				
			||||||
 | 
						pack.AddJSONHandler("CERTIFICATE", "KEEPALIVE", handleKeepAlive)
 | 
				
			||||||
 | 
						pack.AddJSONHandler("MEDIASTREAMMODEL", "REQUESTALIVEVIDEO", handleRequestLiveVideo)
 | 
				
			||||||
 | 
						pack.AddJSONHandler("CONFIGMODEL", "GET", handleGetConfig)
 | 
				
			||||||
 | 
						pack.AddJSONHandler("DEVEMM", "SPI", handleSPI)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.AddAlarmHandler(protocol.AlarmTypeMotionDetection, handleUselessAlarms)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.AddAlarmHandler(protocol.AlarmTypeVideoLoss, handleVideoLossAlarm)
 | 
				
			||||||
 | 
						pack.AddAlarmHandler(protocol.AlarmTypeCameraCovered, handleCameraCoveredAlarm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func isNetConnClosedErr(err error) bool {
 | 
				
			||||||
 | 
						switch {
 | 
				
			||||||
 | 
						case
 | 
				
			||||||
 | 
							errors.Is(err, net.ErrClosed),
 | 
				
			||||||
 | 
							errors.Is(err, io.EOF),
 | 
				
			||||||
 | 
							errors.Is(err, syscall.EPIPE):
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func handle(conn net.Conn) {
 | 
				
			||||||
 | 
						pack := createSmartPackage(conn)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						for {
 | 
				
			||||||
 | 
							if err = pack.Handle(); err != nil {
 | 
				
			||||||
 | 
								fmt.Println("Error:", err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if isNetConnClosedErr(err) {
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -3,7 +3,9 @@ package main
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"gitea.unprism.ru/KRBL/n9m/v2"
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/models"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/protocol"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/smart"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
@@ -30,9 +32,9 @@ func main() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleSpecialPackages(_ *n9m.SmartPackage, pack n9m.Package) error {
 | 
					func handleSpecialPackages(_ *smart.SmartPackage, pack protocol.Package) error {
 | 
				
			||||||
	switch pack.SSRC {
 | 
						switch pack.SSRC {
 | 
				
			||||||
	case n9m.SpecialPayloadTypeGPS:
 | 
						case protocol.SpecialPayloadTypeGPS:
 | 
				
			||||||
		fmt.Printf("%+v\n", pack.GPS)
 | 
							fmt.Printf("%+v\n", pack.GPS)
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
@@ -40,16 +42,16 @@ func handleSpecialPackages(_ *n9m.SmartPackage, pack n9m.Package) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleCertificateConnect(sPack *n9m.SmartPackage, pack n9m.Package) (err error) {
 | 
					func handleCertificateConnect(sPack *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
	var params n9m.CertificateConnectRequest
 | 
						var params models.CertificateConnectRequest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = pack.GetParametersAs(¶ms); err != nil {
 | 
						if err = pack.GetParametersAs(¶ms); err != nil {
 | 
				
			||||||
		return fmt.Errorf("failed to get parameters: %w", err)
 | 
							return fmt.Errorf("failed to get parameters: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var response = n9m.CertificateConnectResponse{
 | 
						var response = models.CertificateConnectResponse{
 | 
				
			||||||
		ErrorCode:   0,
 | 
							ErrorCode:   0,
 | 
				
			||||||
		CommandMask: n9m.CommandMaskAll,
 | 
							CommandMask: models.CommandMaskAll,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pack.SetResponse(response)
 | 
						pack.SetResponse(response)
 | 
				
			||||||
@@ -61,7 +63,7 @@ func handleCertificateConnect(sPack *n9m.SmartPackage, pack n9m.Package) (err er
 | 
				
			|||||||
	fmt.Println("Connected:", params.SerialNumber)
 | 
						fmt.Println("Connected:", params.SerialNumber)
 | 
				
			||||||
	sPack.Storage["serial"] = params.SerialNumber
 | 
						sPack.Storage["serial"] = params.SerialNumber
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var request n9m.ConfigModelGetRequest
 | 
						var request models.ConfigModelGetRequest
 | 
				
			||||||
	request.MDVR = "?"
 | 
						request.MDVR = "?"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pack.Payload.Module = "CONFIGMODEL"
 | 
						pack.Payload.Module = "CONFIGMODEL"
 | 
				
			||||||
@@ -73,7 +75,7 @@ func handleCertificateConnect(sPack *n9m.SmartPackage, pack n9m.Package) (err er
 | 
				
			|||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleKeepAlive(sPack *n9m.SmartPackage, pack n9m.Package) (err error) {
 | 
					func handleKeepAlive(sPack *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
	serial := sPack.Storage["serial"]
 | 
						serial := sPack.Storage["serial"]
 | 
				
			||||||
	fmt.Println(serial, "still alive!")
 | 
						fmt.Println(serial, "still alive!")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -83,12 +85,12 @@ func handleKeepAlive(sPack *n9m.SmartPackage, pack n9m.Package) (err error) {
 | 
				
			|||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleGetConfig(sPack *n9m.SmartPackage, pack n9m.Package) (err error) {
 | 
					func handleGetConfig(sPack *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
	serial := sPack.Storage["serial"]
 | 
						serial := sPack.Storage["serial"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	os.WriteFile(fmt.Sprintf("./%s.json", serial), pack.RawPayload, 0644)
 | 
						os.WriteFile(fmt.Sprintf("./%s.json", serial), pack.RawPayload, 0644)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var request n9m.ConfigModelSetRequest
 | 
						var request models.ConfigModelSetRequest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err = pack.GetParametersAs(&request); err != nil {
 | 
						if err = pack.GetParametersAs(&request); err != nil {
 | 
				
			||||||
		fmt.Println(err)
 | 
							fmt.Println(err)
 | 
				
			||||||
@@ -98,33 +100,46 @@ func handleGetConfig(sPack *n9m.SmartPackage, pack n9m.Package) (err error) {
 | 
				
			|||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleUselessAlarms(sPack *n9m.SmartPackage, pack n9m.Package, response n9m.SendAlarmInfoResponse) (err error) {
 | 
					func handleUselessAlarms(sPack *smart.SmartPackage, pack protocol.Package, response models.SendAlarmInfoResponse) (err error) {
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleVideoLossAlarm(sPack *n9m.SmartPackage, pack n9m.Package, response n9m.SendAlarmInfoResponse) (err error) {
 | 
					func handleVideoLossAlarm(sPack *smart.SmartPackage, pack protocol.Package, response models.SendAlarmInfoResponse) (err error) {
 | 
				
			||||||
	fmt.Println("Video loss alarm!")
 | 
						fmt.Println("Video loss alarm!")
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handleCameraCoveredAlarm(sPack *n9m.SmartPackage, pack n9m.Package, response n9m.SendAlarmInfoResponse) (err error) {
 | 
					func handleCameraCoveredAlarm(sPack *smart.SmartPackage, pack protocol.Package, response models.SendAlarmInfoResponse) (err error) {
 | 
				
			||||||
	fmt.Println("Camera covered alarm!")
 | 
						fmt.Println("Camera covered alarm!")
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func createSmartPackage(conn net.Conn) (pack *n9m.SmartPackage) {
 | 
					func handleSPI(_ *smart.SmartPackage, pack protocol.Package) (err error) {
 | 
				
			||||||
	pack = n9m.NewSmartPackage(conn)
 | 
						var params models.SpiParameters
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pack.AddPayloadHandler(n9m.PayloadTypeSpecial, handleSpecialPackages)
 | 
						if err = pack.GetParametersAs(¶ms); err != nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("%+v\n", params)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func createSmartPackage(conn net.Conn) (pack *smart.SmartPackage) {
 | 
				
			||||||
 | 
						pack = smart.NewSmartPackage(conn)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.AddPayloadHandler(protocol.PayloadTypeSpecial, handleSpecialPackages)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pack.AddJSONHandler("CERTIFICATE", "CONNECT", handleCertificateConnect)
 | 
						pack.AddJSONHandler("CERTIFICATE", "CONNECT", handleCertificateConnect)
 | 
				
			||||||
	pack.AddJSONHandler("CERTIFICATE", "KEEPALIVE", handleKeepAlive)
 | 
						pack.AddJSONHandler("CERTIFICATE", "KEEPALIVE", handleKeepAlive)
 | 
				
			||||||
	pack.AddJSONHandler("CONFIGMODEL", "GET", handleGetConfig)
 | 
						pack.AddJSONHandler("CONFIGMODEL", "GET", handleGetConfig)
 | 
				
			||||||
 | 
						pack.AddJSONHandler("DEVEMM", "SPI", handleSPI)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pack.AddAlarmHandler(n9m.AlarmTypeMotionDetection, handleUselessAlarms)
 | 
						pack.AddAlarmHandler(protocol.AlarmTypeMotionDetection, handleUselessAlarms)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pack.AddAlarmHandler(n9m.AlarmTypeVideoLoss, handleVideoLossAlarm)
 | 
						pack.AddAlarmHandler(protocol.AlarmTypeVideoLoss, handleVideoLossAlarm)
 | 
				
			||||||
	pack.AddAlarmHandler(n9m.AlarmTypeCameraCovered, handleCameraCoveredAlarm)
 | 
						pack.AddAlarmHandler(protocol.AlarmTypeCameraCovered, handleCameraCoveredAlarm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										38
									
								
								devemm.go
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								devemm.go
									
									
									
									
									
								
							@@ -1,38 +0,0 @@
 | 
				
			|||||||
package n9m
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 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
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
							
								
								
									
										190
									
								
								evem.go
									
									
									
									
									
								
							
							
						
						
									
										190
									
								
								evem.go
									
									
									
									
									
								
							@@ -1,190 +0,0 @@
 | 
				
			|||||||
package n9m
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 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         AlarmType   `json:"ALARMTYPE"`
 | 
					 | 
				
			||||||
	CommandType       uint        `json:"CMDTYPE"`
 | 
					 | 
				
			||||||
	AlarmUID          uint        `json:"ALARMUID"`
 | 
					 | 
				
			||||||
	NumberOfRestarts  uint        `json:"RUN"`
 | 
					 | 
				
			||||||
	AlarmLevel        AlarmLevel  `json:"ALARMAS"`
 | 
					 | 
				
			||||||
	AlarmCount        uint        `json:"ALARMCOUNT"`
 | 
					 | 
				
			||||||
	TriggerType       TriggerType `json:"TRIGGERTYPE"`
 | 
					 | 
				
			||||||
	ContinueTime      uint        `json:"CONTINUETIME"`
 | 
					 | 
				
			||||||
	CurrentTime       uint        `json:"CURRENTTIME"`
 | 
					 | 
				
			||||||
	Language          Language    `json:"L"`
 | 
					 | 
				
			||||||
	GPSData           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         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 AlarmType uint
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	AlarmTypeVideoLoss AlarmType = iota
 | 
					 | 
				
			||||||
	AlarmTypeCameraCovered
 | 
					 | 
				
			||||||
	AlarmTypeMotionDetection
 | 
					 | 
				
			||||||
	AlarmTypeStorageAbnormal
 | 
					 | 
				
			||||||
	AlarmTypeUserDefined
 | 
					 | 
				
			||||||
	AlarmTypeSentriesInspection
 | 
					 | 
				
			||||||
	AlarmTypeViolation
 | 
					 | 
				
			||||||
	AlarmTypeEmergency
 | 
					 | 
				
			||||||
	AlarmTypeSpeedAlarm
 | 
					 | 
				
			||||||
	AlarmTypeLowVoltage
 | 
					 | 
				
			||||||
	AlarmTypeOutOfFence = iota + 7
 | 
					 | 
				
			||||||
	AlarmTypeAccAlarm
 | 
					 | 
				
			||||||
	AlarmTypePeripheralsDropped
 | 
					 | 
				
			||||||
	AlarmTypeStopAnnouncement
 | 
					 | 
				
			||||||
	AlarmTypeGpsAntenna
 | 
					 | 
				
			||||||
	AlarmTypeDayNightSwitch
 | 
					 | 
				
			||||||
	AlarmTypeProhibitDriving
 | 
					 | 
				
			||||||
	AlarmTypeSerialAlarm = iota + 15
 | 
					 | 
				
			||||||
	AlarmTypeFatigueAlarm
 | 
					 | 
				
			||||||
	AlarmTypeTakeOutParking
 | 
					 | 
				
			||||||
	AlarmTypeGestureAlarm
 | 
					 | 
				
			||||||
	AlarmTypeGreenDriving
 | 
					 | 
				
			||||||
	AlarmTypeIllegalIgnition
 | 
					 | 
				
			||||||
	AlarmTypeIllegalShutdown
 | 
					 | 
				
			||||||
	AlarmTypeCustomExternal
 | 
					 | 
				
			||||||
	AlarmTypeThinkingLKJ
 | 
					 | 
				
			||||||
	AlarmTypeTAX3
 | 
					 | 
				
			||||||
	AlarmTypeOilAlarm
 | 
					 | 
				
			||||||
	AlarmTypeBusLineOccupation
 | 
					 | 
				
			||||||
	AlarmTypeForgottenAlarm
 | 
					 | 
				
			||||||
	AlarmTypeSpecialCustomerFault
 | 
					 | 
				
			||||||
	AlarmTypeTemperatureAbnormal
 | 
					 | 
				
			||||||
	AlarmTypeTemperatureChangeAbnormal
 | 
					 | 
				
			||||||
	AlarmTypeSmokeAlarm
 | 
					 | 
				
			||||||
	AlarmTypeGBox
 | 
					 | 
				
			||||||
	AlarmTypeLicensePlateRecognition
 | 
					 | 
				
			||||||
	AlarmTypeAnotherSpeedAlarm
 | 
					 | 
				
			||||||
	AlarmTypeWirelessSignalAbnormal
 | 
					 | 
				
			||||||
	AlarmTypeArming
 | 
					 | 
				
			||||||
	AlarmTypePhoneCall
 | 
					 | 
				
			||||||
	AlarmTypeGPSFault
 | 
					 | 
				
			||||||
	AlarmTypeDSMFault
 | 
					 | 
				
			||||||
	AlarmTypeFireBox
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type AlarmLevel uint
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	AlarmLevelImportant AlarmLevel = iota
 | 
					 | 
				
			||||||
	AlarmLevelGeneral
 | 
					 | 
				
			||||||
	AlarmLevelEmergency
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type TriggerType uint
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	TriggerTypeManual TriggerType = iota
 | 
					 | 
				
			||||||
	TriggerTypeAutomatic
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type Language uint
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	LanguageSimplifiedChinese Language = iota
 | 
					 | 
				
			||||||
	LanguageEnglish
 | 
					 | 
				
			||||||
	LanguageKorean
 | 
					 | 
				
			||||||
	LanguageItalian
 | 
					 | 
				
			||||||
	LanguageGerman
 | 
					 | 
				
			||||||
	LanguageThai
 | 
					 | 
				
			||||||
	LanguageTurkey
 | 
					 | 
				
			||||||
	LanguagePortugal
 | 
					 | 
				
			||||||
	LanguageSpain
 | 
					 | 
				
			||||||
	LanguageRomania
 | 
					 | 
				
			||||||
	LanguageGreece
 | 
					 | 
				
			||||||
	LanguageFrench
 | 
					 | 
				
			||||||
	LanguageRussian
 | 
					 | 
				
			||||||
	LanguageDutch
 | 
					 | 
				
			||||||
	LanguageHebrew
 | 
					 | 
				
			||||||
	LanguageChineseTraditional
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
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"`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
// main server util
 | 
					 | 
				
			||||||
func (e *Package) ResponseAlarm(alarmType int64, alarmUID int64, cmdno int64, cmdtype int64, run int64, serial string, Sid string) {
 | 
					 | 
				
			||||||
	e.Payload = map[string]any{
 | 
					 | 
				
			||||||
		"MODULE":    "EVEM",
 | 
					 | 
				
			||||||
		"OPERATION": "SENDALARMINFO",
 | 
					 | 
				
			||||||
		"RESPONSE": map[string]any{
 | 
					 | 
				
			||||||
			"ALARMTYPE": alarmType,
 | 
					 | 
				
			||||||
			"ALARMUID":  alarmUID,
 | 
					 | 
				
			||||||
			"CMDNO":     cmdno,
 | 
					 | 
				
			||||||
			"CMDTYPE":   cmdtype,
 | 
					 | 
				
			||||||
			"ERRORCODE": 0,
 | 
					 | 
				
			||||||
			"RUN":       run,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		"SESSION": Sid,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
@@ -1,108 +0,0 @@
 | 
				
			|||||||
package n9m
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
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,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
package n9m
 | 
					package models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type NetConnectionType uint
 | 
					type NetConnectionType uint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,12 +35,64 @@ type CertificateConnectRequest struct {
 | 
				
			|||||||
	EvidenceSupport   string                  `json:"EV"`
 | 
						EvidenceSupport   string                  `json:"EV"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type CertificateConnectClientRequest struct {
 | 
				
			||||||
 | 
						UK string `json:"UK"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type CertificateConnectResponse struct {
 | 
					type CertificateConnectResponse struct {
 | 
				
			||||||
	ErrorCode   uint   `json:"ERRORCODE"`
 | 
						ErrorCode   uint   `json:"ERRORCODE"`
 | 
				
			||||||
	ErrorCause  string `json:"ERRORCAUSE"`
 | 
						ErrorCause  string `json:"ERRORCAUSE"`
 | 
				
			||||||
	CommandMask uint   `json:"MASKCMD"`
 | 
						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
 | 
					type CommandMaskParameters uint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@@ -54,6 +106,24 @@ const (
 | 
				
			|||||||
	CommandMaskAll = 0b1111111
 | 
						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) {
 | 
					func (e *Package) RequestConnect(session string, serial string, numOfCams int) {
 | 
				
			||||||
	e.Payload = map[string]any{
 | 
						e.Payload = map[string]any{
 | 
				
			||||||
@@ -1,4 +1,8 @@
 | 
				
			|||||||
package n9m
 | 
					package models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/parameters"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -31,7 +35,7 @@ func (e *Package) SetParameters(params map[string]any, serial int, session strin
 | 
				
			|||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ConfigModelSetRequest struct {
 | 
					type ConfigModelSetRequest struct {
 | 
				
			||||||
	MDVR Setting `json:"MDVR"`
 | 
						MDVR parameters.Setting `json:"MDVR"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ConfigModelGetRequest struct {
 | 
					type ConfigModelGetRequest struct {
 | 
				
			||||||
@@ -39,27 +43,27 @@ type ConfigModelGetRequest struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ConfigModelSetResponse struct {
 | 
					type ConfigModelSetResponse struct {
 | 
				
			||||||
	MDVR Setting `json:"MDVR"`
 | 
						MDVR parameters.Setting `json:"MDVR"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (e *Package) InitialConfigModelSetRequest() {
 | 
					func InitialConfig() ConfigModelSetRequest {
 | 
				
			||||||
	e.SetParameters(ConfigModelSetRequest{
 | 
						return ConfigModelSetRequest{
 | 
				
			||||||
		MDVR: Setting{
 | 
							MDVR: parameters.Setting{
 | 
				
			||||||
			KEYS: KEYS{
 | 
								KEYS: parameters.KEYS{
 | 
				
			||||||
				GV: 1, // GPS version
 | 
									GV: 1, // GPS version
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			PGDSM: PGDSM{
 | 
								PGDSM: parameters.PGDSM{
 | 
				
			||||||
				PGPS: PGPS{
 | 
									PGPS: parameters.PGPS{
 | 
				
			||||||
					EN:   1,    // Real-time position monitoring
 | 
										EN:   1,    // Real-time position monitoring
 | 
				
			||||||
					MODE: 0b10, // Enable timer
 | 
										MODE: 0b10, // Enable timer
 | 
				
			||||||
					TM:   10,   // Time interval
 | 
										TM:   10,   // Time interval
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			SUBSTRNET: SUBSTRNET{
 | 
								SUBSTRNET: parameters.SUBSTRNET{
 | 
				
			||||||
				SM: 1,
 | 
									SM: 1,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
							
								
								
									
										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"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										135
									
								
								pkg/models/evem.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								pkg/models/evem.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,135 @@
 | 
				
			|||||||
 | 
					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"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 3.4.1.3
 | 
				
			||||||
 | 
					type EventModelGetAlarmInfoStatusResponse struct {
 | 
				
			||||||
 | 
						ErrorCode            uint                         `json:"ERRORCODE"`
 | 
				
			||||||
 | 
						ErrorCause           string                       `json:"ERRORCAUSE"`
 | 
				
			||||||
 | 
						MotionDetectionAlarm []MotionDetectionAlarmStatus `json:"MD"`
 | 
				
			||||||
 | 
						IOAlarm              []IOAlarmStatus              `json:"IO"`
 | 
				
			||||||
 | 
						StorageAlarm         []StorageAlarmStatus         `json:"ST"`
 | 
				
			||||||
 | 
						CameraCoveredAlarm   []CameraCoveredAlarmStatus   `json:"VS"`
 | 
				
			||||||
 | 
						VideoLossAlarm       []VideoLossAlarmStatus       `json:"VL"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 3.4.1.4.1
 | 
				
			||||||
 | 
					type MotionDetectionAlarmStatus struct {
 | 
				
			||||||
 | 
						Status uint `json:"ISA"`
 | 
				
			||||||
 | 
						Mask   uint `json:"LCH"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 3.4.1.4.2
 | 
				
			||||||
 | 
					type IOAlarmStatus struct {
 | 
				
			||||||
 | 
						Status           uint   `json:"ISA"`
 | 
				
			||||||
 | 
						IONumber         uint   `json:"IONO"`
 | 
				
			||||||
 | 
						Mask             uint   `json:"LCH"`
 | 
				
			||||||
 | 
						Name             string `json:"NAME"`
 | 
				
			||||||
 | 
						NameAbbreviation string `json:"NSER"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 3.4.1.4.4
 | 
				
			||||||
 | 
					type CameraCoveredAlarmStatus struct {
 | 
				
			||||||
 | 
						Status uint `json:"ISA"`
 | 
				
			||||||
 | 
						Mask   uint `json:"LCH"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 3.4.1.4.4
 | 
				
			||||||
 | 
					type VideoLossAlarmStatus struct {
 | 
				
			||||||
 | 
						Status uint `json:"ISA"`
 | 
				
			||||||
 | 
						Mask   uint `json:"LCH"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 3.4.1.4.21
 | 
				
			||||||
 | 
					type StorageAlarmStatus struct {
 | 
				
			||||||
 | 
						SID   any  `json:"SID"`
 | 
				
			||||||
 | 
						Type  uint `json:"ST"`
 | 
				
			||||||
 | 
						Error uint `json:"E"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										53
									
								
								pkg/models/mediastreammodel.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								pkg/models/mediastreammodel.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					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"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
package n9m
 | 
					package models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1,13 +1,16 @@
 | 
				
			|||||||
package n9m
 | 
					package parameters
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 7.2
 | 
					// 7.2
 | 
				
			||||||
type RIP struct {
 | 
					type RIP struct {
 | 
				
			||||||
	DEVID string // ID номер устройства
 | 
						DEVID   string // ID номер устройства
 | 
				
			||||||
	BN    string // бортовой номер
 | 
						BN      string // бортовой номер
 | 
				
			||||||
	BID   string // гос. номер
 | 
						BID     string // гос. номер
 | 
				
			||||||
	LN    string // Название линии
 | 
						LN      string // Название линии
 | 
				
			||||||
	DID   string // номер водительского удостоверения
 | 
						DID     string // номер водительского удостоверения
 | 
				
			||||||
	DNAME string // ФИО водителя
 | 
						DNAME   string // ФИО водителя
 | 
				
			||||||
 | 
						REC     int    // Тип записи видоепотока (0 - беск запись, 1 - запись по событиям, 2 - по расписанию)
 | 
				
			||||||
 | 
						PREREC  int    // Длительность предтревожной записи
 | 
				
			||||||
 | 
						POSTREC int    // Длительность послетревожной записи
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type VS struct {
 | 
					type VS struct {
 | 
				
			||||||
@@ -71,9 +74,11 @@ type NEC struct {
 | 
				
			|||||||
	AEN int // звук (вкл/выкл)
 | 
						AEN int // звук (вкл/выкл)
 | 
				
			||||||
	VEN int // видео (вкл/выкл)
 | 
						VEN int // видео (вкл/выкл)
 | 
				
			||||||
	BR  int // битрейт
 | 
						BR  int // битрейт
 | 
				
			||||||
 | 
						BRM int
 | 
				
			||||||
	ECT int // кодировка
 | 
						ECT int // кодировка
 | 
				
			||||||
	FR  int // фреймрейт
 | 
						FR  int // фреймрейт
 | 
				
			||||||
	FT  int // тип кадров
 | 
						FT  int // тип кадров
 | 
				
			||||||
 | 
						KFI int
 | 
				
			||||||
	QLT int // качество трансляции
 | 
						QLT int // качество трансляции
 | 
				
			||||||
	RST int // разрешение
 | 
						RST int // разрешение
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -95,8 +100,10 @@ type VEC struct {
 | 
				
			|||||||
	ECT int // кодировка
 | 
						ECT int // кодировка
 | 
				
			||||||
	FR  int // фреймрейт
 | 
						FR  int // фреймрейт
 | 
				
			||||||
	QLT int // качество записи
 | 
						QLT int // качество записи
 | 
				
			||||||
 | 
						RM  int // режим работы
 | 
				
			||||||
	AEN int // звук (вкл/выкл)
 | 
						AEN int // звук (вкл/выкл)
 | 
				
			||||||
	ALT int // качество видео при тревоге
 | 
						ALT int // качество видео при тревоге
 | 
				
			||||||
 | 
						BRM int // режим битрейта
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type EOSD struct {
 | 
					type EOSD struct {
 | 
				
			||||||
@@ -134,6 +141,18 @@ type COSD struct {
 | 
				
			|||||||
	Y  int
 | 
						Y  int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MAIN struct {
 | 
				
			||||||
 | 
						VEN uint // 1/0
 | 
				
			||||||
 | 
						RST uint // разрешение
 | 
				
			||||||
 | 
						ECT uint // кодировка
 | 
				
			||||||
 | 
						FR  uint // фреймрейт
 | 
				
			||||||
 | 
						QLT uint // качество записи
 | 
				
			||||||
 | 
						RM  uint // режим работы (0 - всегда, 1 - по расписанию, 2 - по тревоге)
 | 
				
			||||||
 | 
						AEN uint // звук
 | 
				
			||||||
 | 
						ALT uint // качество видео при тревоге
 | 
				
			||||||
 | 
						BRM uint // режим битрейта
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type IOP struct {
 | 
					type IOP struct {
 | 
				
			||||||
	EN  int
 | 
						EN  int
 | 
				
			||||||
	AS  int
 | 
						AS  int
 | 
				
			||||||
@@ -152,6 +171,8 @@ type SAP struct {
 | 
				
			|||||||
	UN  int
 | 
						UN  int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 7.24.3
 | 
				
			||||||
 | 
					// Alarm processing parameters
 | 
				
			||||||
type APR struct {
 | 
					type APR struct {
 | 
				
			||||||
	AR ARR
 | 
						AR ARR
 | 
				
			||||||
	SS SS
 | 
						SS SS
 | 
				
			||||||
@@ -167,13 +188,6 @@ type SS struct {
 | 
				
			|||||||
	EN int
 | 
						EN int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type UAP struct {
 | 
					 | 
				
			||||||
	EN  int
 | 
					 | 
				
			||||||
	AS  int
 | 
					 | 
				
			||||||
	VT  int
 | 
					 | 
				
			||||||
	SDT int
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type PVLAS struct {
 | 
					type PVLAS struct {
 | 
				
			||||||
	EN  int
 | 
						EN  int
 | 
				
			||||||
	AS  int
 | 
						AS  int
 | 
				
			||||||
@@ -257,8 +271,10 @@ type MCMS struct {
 | 
				
			|||||||
	SP []SP // Параметры сервера
 | 
						SP []SP // Параметры сервера
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 7.12.1
 | 
				
			||||||
 | 
					// Central server configuration
 | 
				
			||||||
type SP struct {
 | 
					type SP struct {
 | 
				
			||||||
	EN     int    // Статус сервера
 | 
						EN     int    // Флаг включения
 | 
				
			||||||
	CP     int    // Протокол подключения
 | 
						CP     int    // Протокол подключения
 | 
				
			||||||
	NWT    int    // Способ подключения
 | 
						NWT    int    // Способ подключения
 | 
				
			||||||
	CS     string // Адрес сервера
 | 
						CS     string // Адрес сервера
 | 
				
			||||||
@@ -269,7 +285,45 @@ type SP struct {
 | 
				
			|||||||
	MUPORT int    // UDP-порт медиасервера
 | 
						MUPORT int    // UDP-порт медиасервера
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 7.28
 | 
				
			||||||
 | 
					// NVR remote device parameters
 | 
				
			||||||
 | 
					type REDEV struct {
 | 
				
			||||||
 | 
						EN      int    // Флаг включения
 | 
				
			||||||
 | 
						LOCK    int    // ???
 | 
				
			||||||
 | 
						CHL     int    // Номер канала на устройстве
 | 
				
			||||||
 | 
						RECHL   int    // ???
 | 
				
			||||||
 | 
						ONLINE  int    // Доступно ли сейчас устройство
 | 
				
			||||||
 | 
						RETYPE  int    // Тип устройства
 | 
				
			||||||
 | 
						PROTYPE int    // Тип протокола
 | 
				
			||||||
 | 
						IPTYPE  int    // Тип IP-адреса (IPv4/IPv6)
 | 
				
			||||||
 | 
						CONTYPE int    // ???
 | 
				
			||||||
 | 
						SW      int    // Источник поступаемого сигнала
 | 
				
			||||||
 | 
						REPORT  int    // Порт камеры
 | 
				
			||||||
 | 
						REIP    string // IP камеры
 | 
				
			||||||
 | 
						ID      string // Идентификатор камеры
 | 
				
			||||||
 | 
						RENAME  string // Название устройства
 | 
				
			||||||
 | 
						USER    string // Имя пользователя
 | 
				
			||||||
 | 
						PWD     string // Пароль
 | 
				
			||||||
 | 
						URL     string // ???
 | 
				
			||||||
 | 
						CMDPORT uint   // ???
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 7.29
 | 
				
			||||||
 | 
					// Panel emergency alarm
 | 
				
			||||||
 | 
					type UAP struct {
 | 
				
			||||||
 | 
						EN  int    // Флаг включения
 | 
				
			||||||
 | 
						AS  int    // Уровень тревоги
 | 
				
			||||||
 | 
						T   int    // ???
 | 
				
			||||||
 | 
						VT  int    // ???
 | 
				
			||||||
 | 
						UN  string // Имя тревоги
 | 
				
			||||||
 | 
						UO  string // Имя тривоги на экране водителя
 | 
				
			||||||
 | 
						APR APR    // Параметры обработки тревоги
 | 
				
			||||||
 | 
						// AP  AP     // Параметры тревоги
 | 
				
			||||||
 | 
						SDT int // ???
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 7.30
 | 
					// 7.30
 | 
				
			||||||
 | 
					// Network monitoring status parameters
 | 
				
			||||||
type PGDSM struct {
 | 
					type PGDSM struct {
 | 
				
			||||||
	PGPS PGPS `json:"PGPS,omitempty"`
 | 
						PGPS PGPS `json:"PGPS,omitempty"`
 | 
				
			||||||
	PDSM PDSM `json:"PDSM,omitempty"`
 | 
						PDSM PDSM `json:"PDSM,omitempty"`
 | 
				
			||||||
@@ -286,6 +340,7 @@ type PGPS struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 7.30.2
 | 
					// 7.30.2
 | 
				
			||||||
 | 
					// Device status parameter
 | 
				
			||||||
type PDSM struct {
 | 
					type PDSM struct {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -323,6 +378,7 @@ type Setting struct {
 | 
				
			|||||||
	EOSD      []EOSD    `json:"EOSD,omitempty"`
 | 
						EOSD      []EOSD    `json:"EOSD,omitempty"`
 | 
				
			||||||
	IOP       []IOP     `json:"IOP,omitempty"`
 | 
						IOP       []IOP     `json:"IOP,omitempty"`
 | 
				
			||||||
	SAP       SAP       `json:"SAP,omitempty"`
 | 
						SAP       SAP       `json:"SAP,omitempty"`
 | 
				
			||||||
 | 
						REDEV     []REDEV   `json:"REDEV,omitempty"`
 | 
				
			||||||
	UAP       UAP       `json:"UAP,omitempty"`
 | 
						UAP       UAP       `json:"UAP,omitempty"`
 | 
				
			||||||
	PGDSM     PGDSM     `json:"PGDSM,omitempty"`
 | 
						PGDSM     PGDSM     `json:"PGDSM,omitempty"`
 | 
				
			||||||
	PVLAS     PVLAS     `json:"PVLAS,omitempty"`
 | 
						PVLAS     PVLAS     `json:"PVLAS,omitempty"`
 | 
				
			||||||
							
								
								
									
										57
									
								
								pkg/protocol/alarms.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								pkg/protocol/alarms.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
				
			|||||||
 | 
					package protocol
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type AlarmType uint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						AlarmTypeVideoLoss AlarmType = iota
 | 
				
			||||||
 | 
						AlarmTypeCameraCovered
 | 
				
			||||||
 | 
						AlarmTypeMotionDetection
 | 
				
			||||||
 | 
						AlarmTypeStorageAbnormal
 | 
				
			||||||
 | 
						AlarmTypeUserDefined
 | 
				
			||||||
 | 
						AlarmTypeSentriesInspection
 | 
				
			||||||
 | 
						AlarmTypeViolation
 | 
				
			||||||
 | 
						AlarmTypeEmergency
 | 
				
			||||||
 | 
						AlarmTypeSpeedAlarm
 | 
				
			||||||
 | 
						AlarmTypeLowVoltage
 | 
				
			||||||
 | 
						AlarmTypeOutOfFence = iota + 7
 | 
				
			||||||
 | 
						AlarmTypeAccAlarm
 | 
				
			||||||
 | 
						AlarmTypePeripheralsDropped
 | 
				
			||||||
 | 
						AlarmTypeStopAnnouncement
 | 
				
			||||||
 | 
						AlarmTypeGpsAntenna
 | 
				
			||||||
 | 
						AlarmTypeDayNightSwitch
 | 
				
			||||||
 | 
						AlarmTypeProhibitDriving
 | 
				
			||||||
 | 
						AlarmTypeSerialAlarm = iota + 15
 | 
				
			||||||
 | 
						AlarmTypeFatigueAlarm
 | 
				
			||||||
 | 
						AlarmTypeTakeOutParking
 | 
				
			||||||
 | 
						AlarmTypeGestureAlarm
 | 
				
			||||||
 | 
						AlarmTypeGreenDriving
 | 
				
			||||||
 | 
						AlarmTypeIllegalIgnition
 | 
				
			||||||
 | 
						AlarmTypeIllegalShutdown
 | 
				
			||||||
 | 
						AlarmTypeCustomExternal
 | 
				
			||||||
 | 
						AlarmTypeThinkingLKJ
 | 
				
			||||||
 | 
						AlarmTypeTAX3
 | 
				
			||||||
 | 
						AlarmTypeOilAlarm
 | 
				
			||||||
 | 
						AlarmTypeBusLineOccupation
 | 
				
			||||||
 | 
						AlarmTypeForgottenAlarm
 | 
				
			||||||
 | 
						AlarmTypeSpecialCustomerFault
 | 
				
			||||||
 | 
						AlarmTypeTemperatureAbnormal
 | 
				
			||||||
 | 
						AlarmTypeTemperatureChangeAbnormal
 | 
				
			||||||
 | 
						AlarmTypeSmokeAlarm
 | 
				
			||||||
 | 
						AlarmTypeGBox
 | 
				
			||||||
 | 
						AlarmTypeLicensePlateRecognition
 | 
				
			||||||
 | 
						AlarmTypeAnotherSpeedAlarm
 | 
				
			||||||
 | 
						AlarmTypeWirelessSignalAbnormal
 | 
				
			||||||
 | 
						AlarmTypeArming
 | 
				
			||||||
 | 
						AlarmTypePhoneCall
 | 
				
			||||||
 | 
						AlarmTypeGPSFault
 | 
				
			||||||
 | 
						AlarmTypeDSMFault
 | 
				
			||||||
 | 
						AlarmTypeFireBox
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type AlarmLevel uint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						AlarmLevelImportant AlarmLevel = iota
 | 
				
			||||||
 | 
						AlarmLevelGeneral
 | 
				
			||||||
 | 
						AlarmLevelEmergency
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
package n9m
 | 
					package protocol
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
@@ -88,8 +88,8 @@ func (e *Package) ReadPackage() bool {
 | 
				
			|||||||
		default:
 | 
							default:
 | 
				
			||||||
			fmt.Println("N9M parser warning: unknown special payload type", e.SSRC)
 | 
								fmt.Println("N9M parser warning: unknown special payload type", e.SSRC)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	default:
 | 
							// default:
 | 
				
			||||||
		fmt.Println("N9M parser warning: unknown payload type", e.PayloadType)
 | 
							// 	 fmt.Println("N9M parser warning: unknown payload type", e.PayloadType)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if r.TryError != nil {
 | 
						if r.TryError != nil {
 | 
				
			||||||
@@ -168,7 +168,7 @@ func (e *Package) GetParametersAs(parameters any) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (e *Package) SetParameters(parameters any) {
 | 
					func (e *Package) SetParameters(parameters any) {
 | 
				
			||||||
	e.Payload.Response = struct{}{}
 | 
						e.Payload.Response = nil
 | 
				
			||||||
	e.Payload.Parameter = parameters
 | 
						e.Payload.Parameter = parameters
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -183,6 +183,10 @@ func (e *Package) GetResponseAs(response any) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (e *Package) SetResponse(response any) {
 | 
					func (e *Package) SetResponse(response any) {
 | 
				
			||||||
	e.Payload.Parameter = struct{}{}
 | 
						e.Payload.Parameter = nil
 | 
				
			||||||
	e.Payload.Response = response
 | 
						e.Payload.Response = response
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (e *Package) AddToAccum(data []byte) {
 | 
				
			||||||
 | 
						e.Accum = append(e.Accum, data...)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										22
									
								
								pkg/protocol/languages.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								pkg/protocol/languages.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					package protocol
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Language uint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						LanguageSimplifiedChinese Language = iota
 | 
				
			||||||
 | 
						LanguageEnglish
 | 
				
			||||||
 | 
						LanguageKorean
 | 
				
			||||||
 | 
						LanguageItalian
 | 
				
			||||||
 | 
						LanguageGerman
 | 
				
			||||||
 | 
						LanguageThai
 | 
				
			||||||
 | 
						LanguageTurkey
 | 
				
			||||||
 | 
						LanguagePortugal
 | 
				
			||||||
 | 
						LanguageSpain
 | 
				
			||||||
 | 
						LanguageRomania
 | 
				
			||||||
 | 
						LanguageGreece
 | 
				
			||||||
 | 
						LanguageFrench
 | 
				
			||||||
 | 
						LanguageRussian
 | 
				
			||||||
 | 
						LanguageDutch
 | 
				
			||||||
 | 
						LanguageHebrew
 | 
				
			||||||
 | 
						LanguageChineseTraditional
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
@@ -1,9 +1,8 @@
 | 
				
			|||||||
package n9m
 | 
					package protocol
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"net"
 | 
					 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -138,18 +137,3 @@ type Package struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	Accum []byte
 | 
						Accum []byte
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
type ProcessFunc func(*SmartPackage, Package) error
 | 
					 | 
				
			||||||
type AlarmProcessFunc func(*SmartPackage, Package, SendAlarmInfoResponse) error
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type SmartPackage struct {
 | 
					 | 
				
			||||||
	pack Package
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	conn net.Conn
 | 
					 | 
				
			||||||
	buff []byte
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	payloadProcess map[PayloadType]ProcessFunc
 | 
					 | 
				
			||||||
	jsonProcess    map[string]ProcessFunc
 | 
					 | 
				
			||||||
	alarmProcess   map[AlarmType]AlarmProcessFunc
 | 
					 | 
				
			||||||
	Storage        map[string]interface{}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										8
									
								
								pkg/protocol/trigger.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								pkg/protocol/trigger.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					package protocol
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type TriggerType uint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						TriggerTypeManual TriggerType = iota
 | 
				
			||||||
 | 
						TriggerTypeAutomatic
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
							
								
								
									
										177
									
								
								pkg/smart/channel.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										177
									
								
								pkg/smart/channel.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,177 @@
 | 
				
			|||||||
 | 
					package smart
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/models"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/protocol"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/utils"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
 | 
				
			||||||
 | 
						length  = 6
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewAutoSmartChannelPackage(mainSmartPackage *SmartPackage) (*SmartChannelPackage, error) {
 | 
				
			||||||
 | 
						conn, err := net.Dial(mainSmartPackage.conn.RemoteAddr().Network(), mainSmartPackage.conn.RemoteAddr().String())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return NewSmartChannelPackage(conn, mainSmartPackage)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewSmartChannelPackage(conn net.Conn, mainSmartPackage *SmartPackage) (*SmartChannelPackage, error) {
 | 
				
			||||||
 | 
						pack := NewSmartPackage(conn)
 | 
				
			||||||
 | 
						pack.pack.Payload.Session = mainSmartPackage.pack.Payload.Session
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						channelName, err := registerChannelHandles(pack)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						smartChannelPackage := &SmartChannelPackage{
 | 
				
			||||||
 | 
							pack:     pack,
 | 
				
			||||||
 | 
							mainPack: mainSmartPackage,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							channelName: channelName,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							mutex: sync.RWMutex{},
 | 
				
			||||||
 | 
							ssrc:  make(map[uint16][]func([]byte) error),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.AddPayloadHandler(protocol.PayloadTypeLive, smartChannelPackage.handleLiveVideo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return smartChannelPackage, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (channelPack *SmartChannelPackage) Run() error {
 | 
				
			||||||
 | 
						for {
 | 
				
			||||||
 | 
							if err := channelPack.pack.Handle(); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (channelPack *SmartChannelPackage) GetChannelName() string {
 | 
				
			||||||
 | 
						return channelPack.channelName
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (channelPack *SmartChannelPackage) AddLiveSource(ssrc uint16, source func([]byte) error) {
 | 
				
			||||||
 | 
						channelPack.mutex.Lock()
 | 
				
			||||||
 | 
						defer channelPack.mutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						channelPack.ssrc[ssrc] = append(channelPack.ssrc[ssrc], source)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (channelPack *SmartChannelPackage) handleLiveVideo(sPack *SmartPackage, pack protocol.Package) error {
 | 
				
			||||||
 | 
						channelPack.mutex.RLock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sources, ok := channelPack.ssrc[uint16(pack.SSRC)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !ok || len(sources) == 0 {
 | 
				
			||||||
 | 
							channelPack.mutex.RUnlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var request = models.MediaStreamModelControlStreamRequest{
 | 
				
			||||||
 | 
								PayloadType: protocol.PayloadTypeLive,
 | 
				
			||||||
 | 
								SSRC:        uint16(pack.SSRC),
 | 
				
			||||||
 | 
								StreamName:  channelPack.channelName,
 | 
				
			||||||
 | 
								Command:     models.MediaStreamCommandStop,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							pack.PayloadType = protocol.PayloadTypeData
 | 
				
			||||||
 | 
							pack.Payload.Module = "MEDIASTREAMMODEL"
 | 
				
			||||||
 | 
							pack.Payload.Operation = "CONTROLSTREAM"
 | 
				
			||||||
 | 
							pack.SetParameters(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if _, err := channelPack.mainPack.Write(pack.PackPackage()); err != nil {
 | 
				
			||||||
 | 
								panic(err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var errorMask = map[int]bool{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i, source := range sources {
 | 
				
			||||||
 | 
							if err := source(pack.RawPayload); err != nil {
 | 
				
			||||||
 | 
								errorMask[i] = true
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						channelPack.mutex.RUnlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(errorMask) > 0 {
 | 
				
			||||||
 | 
							newSources := make([]func([]byte) error, 0, len(sources))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for i, source := range sources {
 | 
				
			||||||
 | 
								if !errorMask[i] {
 | 
				
			||||||
 | 
									newSources = append(newSources, source)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							channelPack.mutex.Lock()
 | 
				
			||||||
 | 
							channelPack.ssrc[uint16(pack.SSRC)] = newSources
 | 
				
			||||||
 | 
							channelPack.mutex.Unlock()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func registerChannelHandles(pack *SmartPackage) (string, error) {
 | 
				
			||||||
 | 
						res := make(chan error, 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.AddJSONHandler("CERTIFICATE", "CREATESTREAM", func(smartPackage *SmartPackage, p protocol.Package) error {
 | 
				
			||||||
 | 
							var params models.CertificateCreateStreamResponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if err := p.GetResponseAs(¶ms); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if params.ErrorCode != 0 {
 | 
				
			||||||
 | 
								res <- errors.New(params.ErrorCause)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								res <- nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						channelName := utils.RandomString(length, charset)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var request = models.CertificateCreateStreamRequest{
 | 
				
			||||||
 | 
							StreamName: channelName,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.pack.Payload.Module = "CERTIFICATE"
 | 
				
			||||||
 | 
						pack.pack.Payload.Operation = "CREATESTREAM"
 | 
				
			||||||
 | 
						pack.pack.SetParameters(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack.Write(pack.pack.PackPackage())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for {
 | 
				
			||||||
 | 
							if err := pack.Handle(); err != nil {
 | 
				
			||||||
 | 
								return "", err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							select {
 | 
				
			||||||
 | 
							case err := <-res:
 | 
				
			||||||
 | 
								close(res)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return "", err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								pack.AddJSONHandler("CERTIFICATE", "CREATESTREAM", func(smartPackage *SmartPackage, p protocol.Package) error {
 | 
				
			||||||
 | 
									return errors.New("stream already exists")
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return channelName, nil
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										33
									
								
								pkg/smart/scheme.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								pkg/smart/scheme.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					package smart
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/models"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/protocol"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ProcessFunc func(*SmartPackage, protocol.Package) error
 | 
				
			||||||
 | 
					type AlarmProcessFunc func(*SmartPackage, protocol.Package, models.SendAlarmInfoResponse) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SmartPackage struct {
 | 
				
			||||||
 | 
						pack protocol.Package
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						conn net.Conn
 | 
				
			||||||
 | 
						buff []byte
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						payloadProcess map[protocol.PayloadType]ProcessFunc
 | 
				
			||||||
 | 
						jsonProcess    map[string]ProcessFunc
 | 
				
			||||||
 | 
						alarmProcess   map[protocol.AlarmType]AlarmProcessFunc
 | 
				
			||||||
 | 
						Storage        map[string]interface{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SmartChannelPackage struct {
 | 
				
			||||||
 | 
						pack     *SmartPackage
 | 
				
			||||||
 | 
						mainPack *SmartPackage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						channelName string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mutex sync.RWMutex
 | 
				
			||||||
 | 
						ssrc  map[uint16][]func([]byte) error
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,8 +1,10 @@
 | 
				
			|||||||
package n9m
 | 
					package smart
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/models"
 | 
				
			||||||
 | 
						"gitea.unprism.ru/KRBL/n9m/v2/pkg/protocol"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -16,17 +18,17 @@ func (e *notFoundError) Error() string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func NewSmartPackage(conn net.Conn) *SmartPackage {
 | 
					func NewSmartPackage(conn net.Conn) *SmartPackage {
 | 
				
			||||||
	return &SmartPackage{
 | 
						return &SmartPackage{
 | 
				
			||||||
		pack:           Package{},
 | 
							pack:           protocol.Package{},
 | 
				
			||||||
		conn:           conn,
 | 
							conn:           conn,
 | 
				
			||||||
		buff:           make([]byte, 1024),
 | 
							buff:           make([]byte, 1024),
 | 
				
			||||||
		payloadProcess: make(map[PayloadType]ProcessFunc),
 | 
							payloadProcess: make(map[protocol.PayloadType]ProcessFunc),
 | 
				
			||||||
		jsonProcess:    make(map[string]ProcessFunc),
 | 
							jsonProcess:    make(map[string]ProcessFunc),
 | 
				
			||||||
		alarmProcess:   make(map[AlarmType]AlarmProcessFunc),
 | 
							alarmProcess:   make(map[protocol.AlarmType]AlarmProcessFunc),
 | 
				
			||||||
		Storage:        make(map[string]interface{}),
 | 
							Storage:        make(map[string]interface{}),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (pack *SmartPackage) AddPayloadHandler(payloadType PayloadType, processFunc ProcessFunc) {
 | 
					func (pack *SmartPackage) AddPayloadHandler(payloadType protocol.PayloadType, processFunc ProcessFunc) {
 | 
				
			||||||
	pack.payloadProcess[payloadType] = processFunc
 | 
						pack.payloadProcess[payloadType] = processFunc
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -34,16 +36,16 @@ func (pack *SmartPackage) AddJSONHandler(module, operation string, processFunc P
 | 
				
			|||||||
	pack.jsonProcess[fmt.Sprintf("%s:%s", module, operation)] = processFunc
 | 
						pack.jsonProcess[fmt.Sprintf("%s:%s", module, operation)] = processFunc
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (pack *SmartPackage) AddAlarmHandler(alarmType AlarmType, processFunc AlarmProcessFunc) {
 | 
					func (pack *SmartPackage) AddAlarmHandler(alarmType protocol.AlarmType, processFunc AlarmProcessFunc) {
 | 
				
			||||||
	pack.alarmProcess[alarmType] = processFunc
 | 
						pack.alarmProcess[alarmType] = processFunc
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (pack *SmartPackage) handleAlarm() (err error) {
 | 
					func (pack *SmartPackage) handleAlarm() (err error) {
 | 
				
			||||||
	if !(pack.pack.PayloadType == PayloadTypeData && pack.pack.Payload.Module == "EVEM" && pack.pack.Payload.Operation == "SENDALARMINFO") {
 | 
						if !(pack.pack.PayloadType == protocol.PayloadTypeData && pack.pack.Payload.Module == "EVEM" && pack.pack.Payload.Operation == "SENDALARMINFO") {
 | 
				
			||||||
		return fmt.Errorf("invalid payload type or operation for alarm handling")
 | 
							return fmt.Errorf("invalid payload type or operation for alarm handling")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var params SendAlarmInfoParameters
 | 
						var params models.SendAlarmInfoParameters
 | 
				
			||||||
	if err = pack.pack.GetParametersAs(¶ms); err != nil {
 | 
						if err = pack.pack.GetParametersAs(¶ms); err != nil {
 | 
				
			||||||
		return fmt.Errorf("invalid payload")
 | 
							return fmt.Errorf("invalid payload")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -56,7 +58,7 @@ func (pack *SmartPackage) handleAlarm() (err error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var response SendAlarmInfoResponse
 | 
						var response models.SendAlarmInfoResponse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	response.ErrorCode = 0
 | 
						response.ErrorCode = 0
 | 
				
			||||||
	response.AlarmType = params.AlarmType
 | 
						response.AlarmType = params.AlarmType
 | 
				
			||||||
@@ -69,7 +71,7 @@ func (pack *SmartPackage) handleAlarm() (err error) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (pack *SmartPackage) handleJson() (err error) {
 | 
					func (pack *SmartPackage) handleJson() (err error) {
 | 
				
			||||||
	if pack.pack.PayloadType != PayloadTypeData {
 | 
						if pack.pack.PayloadType != protocol.PayloadTypeData {
 | 
				
			||||||
		return fmt.Errorf("invalid json payload type")
 | 
							return fmt.Errorf("invalid json payload type")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -133,7 +135,7 @@ func (pack *SmartPackage) Handle() (err error) {
 | 
				
			|||||||
	return pack.handleLoop()
 | 
						return pack.handleLoop()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (pack *SmartPackage) GetPackage() Package {
 | 
					func (pack *SmartPackage) GetPackage() protocol.Package {
 | 
				
			||||||
	return pack.pack
 | 
						return pack.pack
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										23
									
								
								pkg/utils/crypto.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								pkg/utils/crypto.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					package utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"crypto/hmac"
 | 
				
			||||||
 | 
						"crypto/md5"
 | 
				
			||||||
 | 
						"encoding/hex"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func generateHMAC(key string, data string) string {
 | 
				
			||||||
 | 
						mac := hmac.New(md5.New, []byte(key))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mac.Write([]byte(data))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return hex.EncodeToString(mac.Sum(nil))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GenerateVerifyKey(key string) string {
 | 
				
			||||||
 | 
						return generateHMAC(key, key)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GeneratePasswordHash(password string) string {
 | 
				
			||||||
 | 
						return generateHMAC("streaming", password)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										18
									
								
								pkg/utils/random.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								pkg/utils/random.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					package utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"math/rand"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// seededRand is a source of random numbers seeded with the current time.
 | 
				
			||||||
 | 
					var seededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// randomString generates a random string of the specified length using the given charset.
 | 
				
			||||||
 | 
					func RandomString(length int, charset string) string {
 | 
				
			||||||
 | 
						b := make([]byte, length)
 | 
				
			||||||
 | 
						for i := range b {
 | 
				
			||||||
 | 
							b[i] = charset[seededRand.Intn(len(charset))]
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return string(b)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,28 +0,0 @@
 | 
				
			|||||||
package test
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"gitea.unprism.ru/KRBL/n9m/v2"
 | 
					 | 
				
			||||||
	"testing"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func TestCertificateConnection(t *testing.T) {
 | 
					 | 
				
			||||||
	dump := []byte{0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0xe9, 0x52, 0x0, 0x0, 0x0, 0x7b, 0x22, 0x4d, 0x4f, 0x44, 0x55, 0x4c, 0x45, 0x22, 0x3a, 0x22, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x22, 0x2c, 0x22, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x22, 0x3a, 0x22, 0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x22, 0x2c, 0x22, 0x50, 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x22, 0x3a, 0x7b, 0x22, 0x41, 0x55, 0x54, 0x4f, 0x43, 0x41, 0x52, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x41, 0x55, 0x54, 0x4f, 0x4e, 0x4f, 0x22, 0x3a, 0x22, 0x30, 0x22, 0x2c, 0x22, 0x43, 0x41, 0x52, 0x4e, 0x55, 0x4d, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x43, 0x48, 0x41, 0x4e, 0x4e, 0x45, 0x4c, 0x22, 0x3a, 0x31, 0x32, 0x2c, 0x22, 0x43, 0x49, 0x44, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x43, 0x4e, 0x41, 0x4d, 0x45, 0x22, 0x3a, 0x22, 0x43, 0x55, 0x53, 0x54, 0x4f, 0x4d, 0x45, 0x52, 0x5f, 0x4e, 0x55, 0x4c, 0x4c, 0x22, 0x2c, 0x22, 0x44, 0x45, 0x56, 0x43, 0x4c, 0x41, 0x53, 0x53, 0x22, 0x3a, 0x34, 0x2c, 0x22, 0x44, 0x45, 0x56, 0x4e, 0x41, 0x4d, 0x45, 0x22, 0x3a, 0x22, 0x4d, 0x44, 0x56, 0x52, 0x22, 0x2c, 0x22, 0x44, 0x45, 0x56, 0x54, 0x59, 0x50, 0x45, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x44, 0x4c, 0x49, 0x50, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x4c, 0x49, 0x50, 0x22, 0x3a, 0x22, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x22, 0x2c, 0x22, 0x4d, 0x54, 0x22, 0x3a, 0x22, 0x65, 0x74, 0x68, 0x30, 0x22, 0x7d, 0x5d, 0x2c, 0x22, 0x44, 0x4c, 0x50, 0x22, 0x3a, 0x5b, 0x38, 0x30, 0x2c, 0x39, 0x30, 0x30, 0x36, 0x5d, 0x2c, 0x22, 0x44, 0x53, 0x4e, 0x4f, 0x22, 0x3a, 0x22, 0x30, 0x30, 0x38, 0x38, 0x30, 0x33, 0x36, 0x31, 0x42, 0x38, 0x22, 0x2c, 0x22, 0x45, 0x49, 0x44, 0x22, 0x3a, 0x22, 0x6e, 0x6f, 0x74, 0x65, 0x62, 0x6f, 0x6f, 0x6b, 0x22, 0x2c, 0x22, 0x45, 0x56, 0x22, 0x3a, 0x22, 0x56, 0x31, 0x2e, 0x31, 0x22, 0x2c, 0x22, 0x46, 0x53, 0x56, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x4c, 0x49, 0x4e, 0x45, 0x4e, 0x4f, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x4d, 0x41, 0x43, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x49, 0x4d, 0x41, 0x43, 0x22, 0x3a, 0x22, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x22, 0x2c, 0x22, 0x4d, 0x54, 0x22, 0x3a, 0x22, 0x65, 0x74, 0x68, 0x30, 0x22, 0x7d, 0x5d, 0x2c, 0x22, 0x4d, 0x4f, 0x44, 0x45, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x4d, 0x54, 0x59, 0x50, 0x45, 0x22, 0x3a, 0x33, 0x31, 0x2c, 0x22, 0x4e, 0x45, 0x54, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x50, 0x52, 0x4f, 0x22, 0x3a, 0x22, 0x31, 0x2e, 0x30, 0x2e, 0x35, 0x22, 0x2c, 0x22, 0x53, 0x54, 0x59, 0x50, 0x45, 0x22, 0x3a, 0x35, 0x34, 0x2c, 0x22, 0x54, 0x53, 0x45, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x55, 0x4e, 0x41, 0x4d, 0x45, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x55, 0x4e, 0x4f, 0x22, 0x3a, 0x22, 0x22, 0x7d, 0x2c, 0x22, 0x53, 0x45, 0x53, 0x53, 0x49, 0x4f, 0x4e, 0x22, 0x3a, 0x22, 0x36, 0x63, 0x65, 0x64, 0x35, 0x63, 0x66, 0x37, 0x2d, 0x61, 0x34, 0x35, 0x63, 0x2d, 0x34, 0x61, 0x63, 0x61, 0x2d, 0x62, 0x39, 0x64, 0x35, 0x2d, 0x66, 0x65, 0x39, 0x34, 0x61, 0x62, 0x36, 0x32, 0x66, 0x39, 0x65, 0x61, 0x22, 0x7d, 0xa}
 | 
					 | 
				
			||||||
	pack := n9m.Package{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pack.AddToAccum(dump)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if !pack.ReadPackage() {
 | 
					 | 
				
			||||||
		t.Error("Package wasn't read!")
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var connectionParams n9m.CertificateConnectRequest
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err := pack.GetParametersAs(&connectionParams); err != nil {
 | 
					 | 
				
			||||||
		t.Error(err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	fmt.Println(connectionParams)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										25
									
								
								utils.go
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								utils.go
									
									
									
									
									
								
							@@ -1,25 +0,0 @@
 | 
				
			|||||||
package n9m
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"encoding/hex"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// add bytes to accum
 | 
					 | 
				
			||||||
func (e *Package) AddToAccum(data []byte) {
 | 
					 | 
				
			||||||
	e.Accum = append(e.Accum, data...)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// why store a string and constantly change it to the same thing
 | 
					 | 
				
			||||||
// the stored string is not used
 | 
					 | 
				
			||||||
func (e *Package) GetToken() {
 | 
					 | 
				
			||||||
	hexStream := "3876431502000010380000007b224b4559223a22434c49454e544c4f47494e222c22524553504f4e5345223a7b22434c49454e544944223a2237643531323030227d7d00"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	e.RawPayload, _ = hex.DecodeString(hexStream)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// the same
 | 
					 | 
				
			||||||
func (e *Package) RequestGetTokenDop() {
 | 
					 | 
				
			||||||
	hexStream := "3876431501000010360000007b224b4559223a224c4f47494e222c22504152414d223a7b224355534552223a2231222c22505744223a22313233343536227d7d0a00"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	e.RawPayload, _ = hex.DecodeString(hexStream)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user