fix: api/list add channelcout,KeepAliveTime

This commit is contained in:
pg
2025-02-27 17:26:11 +08:00
committed by pggiroro
parent 61607d54fc
commit ae3e76b20b
6 changed files with 1018 additions and 1017 deletions

View File

@@ -95,18 +95,18 @@ func (gb *GB28181ProPlugin) List(ctx context.Context, req *pb.GetDevicesRequest)
} }
pbDevices = append(pbDevices, &pb.Device{ pbDevices = append(pbDevices, &pb.Device{
Id: d.DeviceID, DeviceID: d.DeviceID,
Name: d.Name, Name: d.Name,
Manufacturer: d.Manufacturer, Manufacturer: d.Manufacturer,
Model: d.Model, Model: d.Model,
Owner: d.Owner,
Status: string(d.Status), Status: string(d.Status),
Online: d.Online, Online: d.Online,
Longitude: d.Longitude, Longitude: d.Longitude,
Latitude: d.Latitude, Latitude: d.Latitude,
GpsTime: timestamppb.New(d.GpsTime),
RegisterTime: timestamppb.New(d.RegisterTime), RegisterTime: timestamppb.New(d.RegisterTime),
UpdateTime: timestamppb.New(d.UpdateTime), UpdateTime: timestamppb.New(d.UpdateTime),
KeepAliveTime: timestamppb.New(d.KeepaliveTime),
ChannelCount: int32(d.ChannelCount),
Channels: pbChannels, Channels: pbChannels,
}) })
} }
@@ -176,16 +176,14 @@ func (gb *GB28181ProPlugin) GetDevice(ctx context.Context, req *pb.GetDeviceRequ
}) })
} }
resp.Data = &pb.Device{ resp.Data = &pb.Device{
Id: d.DeviceID, DeviceID: d.DeviceID,
Name: d.Name, Name: d.Name,
Manufacturer: d.Manufacturer, Manufacturer: d.Manufacturer,
Model: d.Model, Model: d.Model,
Owner: d.Owner,
Status: string(d.Status), Status: string(d.Status),
Online: d.Online, Online: d.Online,
Longitude: d.Longitude, Longitude: d.Longitude,
Latitude: d.Latitude, Latitude: d.Latitude,
GpsTime: timestamppb.New(d.GpsTime),
RegisterTime: timestamppb.New(d.RegisterTime), RegisterTime: timestamppb.New(d.RegisterTime),
UpdateTime: timestamppb.New(d.UpdateTime), UpdateTime: timestamppb.New(d.UpdateTime),
Channels: channels, Channels: channels,
@@ -273,18 +271,17 @@ func (gb *GB28181ProPlugin) GetDevices(ctx context.Context, req *pb.GetDevicesRe
} }
pbDevice := &pb.Device{ pbDevice := &pb.Device{
Id: d.DeviceID, DeviceID: d.DeviceID,
Name: d.Name, Name: d.Name,
Manufacturer: d.Manufacturer, Manufacturer: d.Manufacturer,
Model: d.Model, Model: d.Model,
Owner: d.Owner,
Status: string(d.Status), Status: string(d.Status),
Online: d.Online, Online: d.Online,
Longitude: d.Longitude, Longitude: d.Longitude,
Latitude: d.Latitude, Latitude: d.Latitude,
GpsTime: timestamppb.New(d.GpsTime),
RegisterTime: timestamppb.New(d.RegisterTime), RegisterTime: timestamppb.New(d.RegisterTime),
UpdateTime: timestamppb.New(d.UpdateTime), UpdateTime: timestamppb.New(d.UpdateTime),
KeepAliveTime: timestamppb.New(d.KeepaliveTime),
Channels: pbChannels, Channels: pbChannels,
} }
pbDevices = append(pbDevices, pbDevice) pbDevices = append(pbDevices, pbDevice)

View File

@@ -32,7 +32,6 @@ type Device struct {
Name string // 设备名 Name string // 设备名
Manufacturer string // 生产厂商 Manufacturer string // 生产厂商
Model string // 型号 Model string // 型号
Owner string // 所有者
Firmware string // 固件版本 Firmware string // 固件版本
Transport string // 传输协议UDP/TCP Transport string // 传输协议UDP/TCP
StreamMode string // 数据流传输模式UDP:udp传输/TCP-ACTIVEtcp主动模式/TCP-PASSIVEtcp被动模式 StreamMode string // 数据流传输模式UDP:udp传输/TCP-ACTIVEtcp主动模式/TCP-PASSIVEtcp被动模式
@@ -68,7 +67,6 @@ type Device struct {
Recipient sip.Uri `gorm:"-:all"` Recipient sip.Uri `gorm:"-:all"`
channels util.Collection[string, *Channel] `gorm:"-:all"` channels util.Collection[string, *Channel] `gorm:"-:all"`
mediaIp string mediaIp string
GpsTime time.Time // gps时间
Longitude, Latitude string // 经度,纬度 Longitude, Latitude string // 经度,纬度
eventChan chan any eventChan chan any
client *sipgo.Client client *sipgo.Client
@@ -126,7 +124,7 @@ func (d *Device) onMessage(req *sip.Request, tx sip.ServerTransaction, msg *gb28
} }
} }
// 更新当前设备的通道数 // 更新当前设备的通道数
d.ChannelCount = len(msg.DeviceChannelList) d.ChannelCount = msg.SumNum
d.UpdateTime = time.Now() d.UpdateTime = time.Now()
if err := d.plugin.DB.Save(d).Error; err != nil { if err := d.plugin.DB.Save(d).Error; err != nil {
d.Error("save device failed", "error", err) d.Error("save device failed", "error", err)
@@ -146,6 +144,7 @@ func (d *Device) onMessage(req *sip.Request, tx sip.ServerTransaction, msg *gb28
d.Name = msg.DeviceName d.Name = msg.DeviceName
d.Manufacturer = msg.Manufacturer d.Manufacturer = msg.Manufacturer
d.Model = msg.Model d.Model = msg.Model
d.Firmware = msg.Firmware
// 更新设备信息到数据库 // 更新设备信息到数据库
if d.plugin.DB != nil { if d.plugin.DB != nil {
d.UpdateTime = time.Now() d.UpdateTime = time.Now()

View File

@@ -514,6 +514,7 @@ func (gb *GB28181ProPlugin) StoreDevice(deviceid string, req *sip.Request) (d *D
CreateTime: now, CreateTime: now,
UpdateTime: now, UpdateTime: now,
RegisterTime: now, RegisterTime: now,
KeepaliveTime: now,
Status: DeviceRegisterStatus, Status: DeviceRegisterStatus,
Online: true, Online: true,
StreamMode: "UDP", // 默认UDP传输 StreamMode: "UDP", // 默认UDP传输

File diff suppressed because it is too large Load Diff

View File

@@ -488,25 +488,25 @@ message Channel {
int32 RegisterWay = 12; int32 RegisterWay = 12;
int32 Secrecy =13; int32 Secrecy =13;
string Status =14; string Status =14;
google.protobuf.Timestamp gpsTime=15; google.protobuf.Timestamp GpsTime=15;
string Longitude = 16; string Longitude = 16;
string Latitude = 17; string Latitude = 17;
} }
message Device { message Device {
string id = 1; string DeviceID = 1;
string name = 2; string Name = 2;
string manufacturer = 3; string Manufacturer = 3;
string model = 4; string Model = 4;
string owner = 5; string Longitude = 5;
google.protobuf.Timestamp gpsTime=6; string Latitude = 6;
string longitude = 7; string Status = 9;
string latitude = 8; google.protobuf.Timestamp RegisterTime=10;
string status = 9; google.protobuf.Timestamp UpdateTime=11;
google.protobuf.Timestamp registerTime=10; google.protobuf.Timestamp KeepAliveTime=12;
google.protobuf.Timestamp updateTime=11; int32 ChannelCount = 13;
repeated Channel channels = 12; bool Online = 14;
bool online = 13; repeated Channel Channels = 15;
} }
message ResponseList { message ResponseList {

View File

@@ -119,6 +119,7 @@ type (
Manufacturer string Manufacturer string
Model string Model string
Channel string Channel string
Firmware string
DeviceChannelList []DeviceChannel `xml:"DeviceList>Item"` DeviceChannelList []DeviceChannel `xml:"DeviceList>Item"`
RecordList struct { RecordList struct {
Num int `xml:"Num,attr"` Num int `xml:"Num,attr"`