本文整理匯總了Golang中github.com/pdf/golifx/protocol/v2/packet.Packet.GetSource方法的典型用法代碼示例。如果您正苦於以下問題:Golang Packet.GetSource方法的具體用法?Golang Packet.GetSource怎麽用?Golang Packet.GetSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pdf/golifx/protocol/v2/packet.Packet
的用法示例。
在下文中一共展示了Packet.GetSource方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: process
func (p *V2) process(pkt *packet.Packet, addr *net.UDPAddr) {
common.Log.Debugf("Processing packet from %v: source %v, type %v, sequence %v, target %v, tagged %v, resRequired %v, ackRequired %v: %+v\n", addr.IP, pkt.GetSource(), pkt.GetType(), pkt.GetSequence(), pkt.GetTarget(), pkt.GetTagged(), pkt.GetResRequired(), pkt.GetAckRequired(), *pkt)
// Update device seen time for any targeted packets
if pkt.Target != 0 {
dev, err := p.getDevice(pkt.Target)
if err == nil {
dev.SetSeen(time.Now())
}
}
// Broadcast packets, or packets generated by other clients
if pkt.GetSource() != packet.ClientID {
switch pkt.GetType() {
case device.StatePower:
dev, err := p.getDevice(pkt.GetTarget())
if err != nil {
common.Log.Debugf("Skipping StatePower packet for unknown device: source %v, type %v, sequence %v, target %v, tagged %v, resRequired %v, ackRequired %v: %+v\n", pkt.GetSource(), pkt.GetType(), pkt.GetSequence(), pkt.GetTarget(), pkt.GetTagged(), pkt.GetResRequired(), pkt.GetAckRequired(), *pkt)
return
}
err = dev.SetStatePower(pkt)
if err != nil {
common.Log.Debugf("Failed setting StatePower on device: source %v, type %v, sequence %v, target %v, tagged %v, resRequired %v, ackRequired %v: %+v\n", pkt.GetSource(), pkt.GetType(), pkt.GetSequence(), pkt.GetTarget(), pkt.GetTagged(), pkt.GetResRequired(), pkt.GetAckRequired(), *pkt)
return
}
case device.StateLabel:
dev, err := p.getDevice(pkt.GetTarget())
if err != nil {
common.Log.Debugf("Skipping StateLabel packet for unknown device: source %v, type %v, sequence %v, target %v, tagged %v, resRequired %v, ackRequired %v: %+v\n", pkt.GetSource(), pkt.GetType(), pkt.GetSequence(), pkt.GetTarget(), pkt.GetTagged(), pkt.GetResRequired(), pkt.GetAckRequired(), *pkt)
return
}
err = dev.SetStateLabel(pkt)
if err != nil {
common.Log.Debugf("Failed setting StatePower on device: source %v, type %v, sequence %v, target %v, tagged %v, resRequired %v, ackRequired %v: %+v\n", pkt.GetSource(), pkt.GetType(), pkt.GetSequence(), pkt.GetTarget(), pkt.GetTagged(), pkt.GetResRequired(), pkt.GetAckRequired(), *pkt)
return
}
case device.State:
dev, err := p.getDevice(pkt.GetTarget())
if err != nil {
common.Log.Debugf("Skipping State packet for unknown device: source %v, type %v, sequence %v, target %v, tagged %v, resRequired %v, ackRequired %v: %+v\n", pkt.GetSource(), pkt.GetType(), pkt.GetSequence(), pkt.GetTarget(), pkt.GetTagged(), pkt.GetResRequired(), pkt.GetAckRequired(), *pkt)
return
}
light, ok := dev.(*device.Light)
if !ok {
common.Log.Debugf("Skipping State packet for non-light device: source %v, type %v, sequence %v, target %v, tagged %v, resRequired %v, ackRequired %v: %+v\n", pkt.GetSource(), pkt.GetType(), pkt.GetSequence(), pkt.GetTarget(), pkt.GetTagged(), pkt.GetResRequired(), pkt.GetAckRequired(), *pkt)
return
}
err = light.SetState(pkt)
if err != nil {
common.Log.Debugf("Error setting State on device: source %v, type %v, sequence %v, target %v, tagged %v, resRequired %v, ackRequired %v: %+v\n", pkt.GetSource(), pkt.GetType(), pkt.GetSequence(), pkt.GetTarget(), pkt.GetTagged(), pkt.GetResRequired(), pkt.GetAckRequired(), *pkt)
return
}
default:
common.Log.Debugf("Skipping packet with non-local source: source %v, type %v, sequence %v, target %v, tagged %v, resRequired %v, ackRequired %v: %+v\n", pkt.GetSource(), pkt.GetType(), pkt.GetSequence(), pkt.GetTarget(), pkt.GetTagged(), pkt.GetResRequired(), pkt.GetAckRequired(), *pkt)
}
return
}
// Packets processed at the protocol level regardless of target
switch pkt.GetType() {
case device.StateLocation:
p.addLocation(pkt)
case device.StateGroup:
p.addGroup(pkt)
}
// Packets processed at the protocol level or returned to target
switch pkt.GetType() {
case device.StateService:
dev, err := p.getDevice(pkt.Target)
if err != nil {
dev, err := device.New(addr, p.socket, p.timeout, p.retryInterval, p.Reliable, pkt)
if err != nil {
common.Log.Errorf("Failed creating device: %v\n", err)
return
}
p.addDevice(dev)
return
}
// Perform state discovery on lights
if l, ok := dev.(*device.Light); ok {
if err := l.Get(); err != nil {
common.Log.Debugf("Failed getting light state: %v\n", err)
}
}
default:
if pkt.GetTarget() == 0 {
common.Log.Debugf("Skipping packet without target: %+v\n", *pkt)
return
}
dev, err := p.getDevice(pkt.GetTarget())
if err != nil {
common.Log.Errorf("No known device with ID %v\n", pkt.GetTarget())
return
}
common.Log.Debugf("Returning packet to device %v: %+v\n", dev.ID(), *pkt)
dev.Handle(pkt)
}
}