-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathposition.go
64 lines (53 loc) · 1.61 KB
/
position.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"github.com/ghettovoice/gosip/sip"
)
const MobilePositionMessageFormat = "<?xml version=\"1.0\"?>\r\n" +
"<Query>\r\n" +
"<CmdType>MobilePosition</CmdType>\r\n" +
"<SN>%s</SN>\r\n" +
"<DeviceID>%s</DeviceID>\r\n" +
"<Interval>%d</Interval>\r\n" +
"</Query>\r\n"
type MobilePositionNotify struct {
DeviceID string `xml:"DeviceID"`
CmdType string `xml:"CmdType"`
SN int `xml:"SN"`
Time string `xml:"Time"`
Longitude string `xml:"Longitude"`
Latitude string `xml:"Latitude"`
Speed string `xml:"Speed"`
Direction string `xml:"Direction"`
Altitude string `xml:"Altitude"`
}
func (d *Device) DoSubscribePosition(channelId string) error {
if channelId == "" {
channelId = d.ID
}
//暂时不考虑级联
builder := d.NewRequestBuilder(sip.SUBSCRIBE, Config.SipId, Config.SipContactAddr, channelId)
body := fmt.Sprintf(MobilePositionMessageFormat, "1", channelId, Config.MobilePositionInterval)
expiresHeader := sip.Expires(Config.MobilePositionExpires)
builder.SetExpires(&expiresHeader)
builder.SetContentType(&XmlMessageType)
builder.SetContact(GlobalContactAddress)
builder.SetBody(body)
request, err := builder.Build()
if err != nil {
return err
}
event := Event("Catalog;id=2")
request.AppendHeader(&event)
response, err := SipUA.SendRequestWithTimeout(5, request)
if err != nil {
return err
}
if response.StatusCode() != 200 {
return fmt.Errorf("err code %d", response.StatusCode())
}
return nil
}
func (d *Device) OnMobilePositionNotify(notify *MobilePositionNotify) {
Sugar.Infof("收到位置信息 device:%s data:%v", d.ID, notify)
}