From 66a64111fc828e3f2560b8a9ab98e72668a240a8 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Mon, 26 Dec 2016 18:37:55 +0100 Subject: [PATCH] bebop: enable video on firmware 3.3+ Signed-off-by: deadprogram --- platforms/parrot/bebop/bebop_adaptor.go | 2 + platforms/parrot/bebop/bebop_driver.go | 10 +++++ platforms/parrot/bebop/client/client.go | 44 +++++++++++++++++++ platforms/parrot/bebop/client/constants.go | 3 ++ .../parrot/bebop/client/examples/video.go | 12 ++++- platforms/parrot/bebop/test_helper.go | 2 + 6 files changed, 72 insertions(+), 1 deletion(-) diff --git a/platforms/parrot/bebop/bebop_adaptor.go b/platforms/parrot/bebop/bebop_adaptor.go index 2a02e0aa..37eb9524 100644 --- a/platforms/parrot/bebop/bebop_adaptor.go +++ b/platforms/parrot/bebop/bebop_adaptor.go @@ -23,6 +23,8 @@ type drone interface { StopRecording() error HullProtection(protect bool) error Outdoor(outdoor bool) error + VideoEnable(enable bool) error + VideoStreamMode(mode int8) error } // Adaptor is gobot.Adaptor representation for the Bebop diff --git a/platforms/parrot/bebop/bebop_driver.go b/platforms/parrot/bebop/bebop_driver.go index 5393cfc4..4adcf0d5 100644 --- a/platforms/parrot/bebop/bebop_driver.go +++ b/platforms/parrot/bebop/bebop_driver.go @@ -140,3 +140,13 @@ func (a *Driver) HullProtection(protect bool) error { func (a *Driver) Outdoor(outdoor bool) error { return a.adaptor().drone.Outdoor(outdoor) } + +// VideoEnable tells the drone to start/stop streaming video +func (a *Driver) VideoEnable(enable bool) error { + return a.adaptor().drone.VideoEnable(enable) +} + +// VideoStreamMode tells the drone what mode to use for streaming video +func (a *Driver) VideoStreamMode(mode int8) error { + return a.adaptor().drone.VideoStreamMode(mode) +} diff --git a/platforms/parrot/bebop/client/client.go b/platforms/parrot/bebop/client/client.go index cb792b15..281a7d60 100644 --- a/platforms/parrot/bebop/client/client.go +++ b/platforms/parrot/bebop/client/client.go @@ -651,6 +651,50 @@ func (b *Bebop) Outdoor(outdoor bool) error { return err } +func (b *Bebop) VideoEnable(enable bool) error { + cmd := &bytes.Buffer{} + + cmd.WriteByte(ARCOMMANDS_ID_PROJECT_ARDRONE3) + cmd.WriteByte(ARCOMMANDS_ID_ARDRONE3_CLASS_MEDIASTREAMING) + + tmp := &bytes.Buffer{} + binary.Write(tmp, + binary.LittleEndian, + uint16(ARCOMMANDS_ID_ARDRONE3_MEDIASTREAMING_CMD_VIDEOENABLE), + ) + + cmd.Write(tmp.Bytes()) + + tmp = &bytes.Buffer{} + binary.Write(tmp, binary.LittleEndian, bool2int8(enable)) + cmd.Write(tmp.Bytes()) + + _, err := b.write(b.networkFrameGenerator(cmd, ARNETWORKAL_FRAME_TYPE_DATA, BD_NET_CD_NONACK_ID).Bytes()) + return err +} + +func (b *Bebop) VideoStreamMode(mode int8) error { + cmd := &bytes.Buffer{} + + cmd.WriteByte(ARCOMMANDS_ID_PROJECT_ARDRONE3) + cmd.WriteByte(ARCOMMANDS_ID_ARDRONE3_CLASS_MEDIASTREAMING) + + tmp := &bytes.Buffer{} + binary.Write(tmp, + binary.LittleEndian, + uint16(ARCOMMANDS_ID_ARDRONE3_MEDIASTREAMING_CMD_VIDEOSTREAMMODE), + ) + + cmd.Write(tmp.Bytes()) + + tmp = &bytes.Buffer{} + binary.Write(tmp, binary.LittleEndian, mode) + cmd.Write(tmp.Bytes()) + + _, err := b.write(b.networkFrameGenerator(cmd, ARNETWORKAL_FRAME_TYPE_DATA, BD_NET_CD_NONACK_ID).Bytes()) + return err +} + func bool2int8(b bool) int8 { if b { return 1 diff --git a/platforms/parrot/bebop/client/constants.go b/platforms/parrot/bebop/client/constants.go index 1319a59f..f7270a0e 100644 --- a/platforms/parrot/bebop/client/constants.go +++ b/platforms/parrot/bebop/client/constants.go @@ -174,4 +174,7 @@ const ( ARCOMMANDS_ID_ARDRONE3_SPEEDSETTINGS_CMD_MAXROTATIONSPEED byte = 1 ARCOMMANDS_ID_ARDRONE3_SPEEDSETTINGS_CMD_HULLPROTECTION byte = 2 ARCOMMANDS_ID_ARDRONE3_SPEEDSETTINGS_CMD_OUTDOOR byte = 3 + + ARCOMMANDS_ID_ARDRONE3_MEDIASTREAMING_CMD_VIDEOENABLE byte = 0 + ARCOMMANDS_ID_ARDRONE3_MEDIASTREAMING_CMD_VIDEOSTREAMMODE byte = 1 ) diff --git a/platforms/parrot/bebop/client/examples/video.go b/platforms/parrot/bebop/client/examples/video.go index b87fba5e..91db5a0e 100644 --- a/platforms/parrot/bebop/client/examples/video.go +++ b/platforms/parrot/bebop/client/examples/video.go @@ -1,5 +1,5 @@ /* - This example will connect to the Bebop and stream it's video to a webpage + This example will connect to the Bebop and stream its video to a webpage via ffserver. This requires you to have both ffmpeg and ffserver installed on your computer. @@ -32,6 +32,16 @@ func main() { return } + if err := bebop.VideoEnable(true); err != nil { + fmt.Println(err) + return + } + + if err := bebop.VideoStreamMode(0); err != nil { + fmt.Println(err) + return + } + ffmpeg := exec.Command("ffmpeg", "-i", "pipe:0", "http://localhost:8090/bebop.ffm") ffmpegErr, err := ffmpeg.StderrPipe() diff --git a/platforms/parrot/bebop/test_helper.go b/platforms/parrot/bebop/test_helper.go index 65635c96..5b116e27 100644 --- a/platforms/parrot/bebop/test_helper.go +++ b/platforms/parrot/bebop/test_helper.go @@ -19,3 +19,5 @@ func (t testDrone) StartRecording() error { return nil } func (t testDrone) StopRecording() error { return nil } func (t testDrone) HullProtection(protect bool) error { return nil } func (t testDrone) Outdoor(outdoor bool) error { return nil } +func (t testDrone) VideoEnable(enable bool) error { return nil } +func (t testDrone) VideoStreamMode(mode int8) error { return nil }