Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail early in case of error from mavsdk stream #9

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
430 changes: 180 additions & 250 deletions Sources/action/action.go

Large diffs are not rendered by default.

1,044 changes: 192 additions & 852 deletions Sources/action/action.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Sources/action/action_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

189 changes: 79 additions & 110 deletions Sources/action_server/action_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package action_server

import (
"context"
"fmt"
"io"
"log"

codes "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
status "google.golang.org/grpc/status"
)

type ServiceImpl struct {
Client ActionServerServiceClient
}

/*
Subscribe to ARM/DISARM commands


ArmDisarm Subscribe to ARM/DISARM commands
*/
func (a *ServiceImpl) ArmDisarm(
ctx context.Context,

func (a *ServiceImpl) ArmDisarm(ctx context.Context) (<-chan *ArmDisarm, error) {
) (<-chan *ArmDisarm, error) {
ch := make(chan *ArmDisarm)
request := &SubscribeArmDisarmRequest{}
stream, err := a.Client.SubscribeArmDisarm(ctx, request)
Expand All @@ -38,8 +38,7 @@ func (a *ServiceImpl) ArmDisarm(ctx context.Context) (<-chan *ArmDisarm, error)
if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled {
return
}
fmt.Printf("Unable to receive ArmDisarm messages, err: %v\n", err)
break
log.Fatalf("Unable to receive ArmDisarm messages, err: %v", err)
}
ch <- m.GetArm()
}
Expand All @@ -48,12 +47,12 @@ func (a *ServiceImpl) ArmDisarm(ctx context.Context) (<-chan *ArmDisarm, error)
}

/*
Subscribe to DO_SET_MODE


FlightModeChange Subscribe to DO_SET_MODE
*/
func (a *ServiceImpl) FlightModeChange(
ctx context.Context,

func (a *ServiceImpl) FlightModeChange(ctx context.Context) (<-chan FlightMode, error) {
) (<-chan FlightMode, error) {
ch := make(chan FlightMode)
request := &SubscribeFlightModeChangeRequest{}
stream, err := a.Client.SubscribeFlightModeChange(ctx, request)
Expand All @@ -72,8 +71,7 @@ func (a *ServiceImpl) FlightModeChange(ctx context.Context) (<-chan FlightMode,
if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled {
return
}
fmt.Printf("Unable to receive FlightModeChange messages, err: %v\n", err)
break
log.Fatalf("Unable to receive FlightModeChange messages, err: %v", err)
}
ch <- m.GetFlightMode()
}
Expand All @@ -82,12 +80,12 @@ func (a *ServiceImpl) FlightModeChange(ctx context.Context) (<-chan FlightMode,
}

/*
Subscribe to takeoff command


Takeoff Subscribe to takeoff command
*/
func (a *ServiceImpl) Takeoff(
ctx context.Context,

func (a *ServiceImpl) Takeoff(ctx context.Context) (<-chan bool, error) {
) (<-chan bool, error) {
ch := make(chan bool)
request := &SubscribeTakeoffRequest{}
stream, err := a.Client.SubscribeTakeoff(ctx, request)
Expand All @@ -106,8 +104,7 @@ func (a *ServiceImpl) Takeoff(ctx context.Context) (<-chan bool, error) {
if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled {
return
}
fmt.Printf("Unable to receive Takeoff messages, err: %v\n", err)
break
log.Fatalf("Unable to receive Takeoff messages, err: %v", err)
}
ch <- m.GetTakeoff()
}
Expand All @@ -116,12 +113,12 @@ func (a *ServiceImpl) Takeoff(ctx context.Context) (<-chan bool, error) {
}

/*
Subscribe to land command


Land Subscribe to land command
*/
func (a *ServiceImpl) Land(
ctx context.Context,

func (a *ServiceImpl) Land(ctx context.Context) (<-chan bool, error) {
) (<-chan bool, error) {
ch := make(chan bool)
request := &SubscribeLandRequest{}
stream, err := a.Client.SubscribeLand(ctx, request)
Expand All @@ -140,8 +137,7 @@ func (a *ServiceImpl) Land(ctx context.Context) (<-chan bool, error) {
if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled {
return
}
fmt.Printf("Unable to receive Land messages, err: %v\n", err)
break
log.Fatalf("Unable to receive Land messages, err: %v", err)
}
ch <- m.GetLand()
}
Expand All @@ -150,12 +146,12 @@ func (a *ServiceImpl) Land(ctx context.Context) (<-chan bool, error) {
}

/*
Subscribe to reboot command


Reboot Subscribe to reboot command
*/
func (a *ServiceImpl) Reboot(
ctx context.Context,

func (a *ServiceImpl) Reboot(ctx context.Context) (<-chan bool, error) {
) (<-chan bool, error) {
ch := make(chan bool)
request := &SubscribeRebootRequest{}
stream, err := a.Client.SubscribeReboot(ctx, request)
Expand All @@ -174,8 +170,7 @@ func (a *ServiceImpl) Reboot(ctx context.Context) (<-chan bool, error) {
if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled {
return
}
fmt.Printf("Unable to receive Reboot messages, err: %v\n", err)
break
log.Fatalf("Unable to receive Reboot messages, err: %v", err)
}
ch <- m.GetReboot()
}
Expand All @@ -184,12 +179,12 @@ func (a *ServiceImpl) Reboot(ctx context.Context) (<-chan bool, error) {
}

/*
Subscribe to shutdown command


Shutdown Subscribe to shutdown command
*/
func (a *ServiceImpl) Shutdown(
ctx context.Context,

func (a *ServiceImpl) Shutdown(ctx context.Context) (<-chan bool, error) {
) (<-chan bool, error) {
ch := make(chan bool)
request := &SubscribeShutdownRequest{}
stream, err := a.Client.SubscribeShutdown(ctx, request)
Expand All @@ -208,8 +203,7 @@ func (a *ServiceImpl) Shutdown(ctx context.Context) (<-chan bool, error) {
if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled {
return
}
fmt.Printf("Unable to receive Shutdown messages, err: %v\n", err)
break
log.Fatalf("Unable to receive Shutdown messages, err: %v", err)
}
ch <- m.GetShutdown()
}
Expand All @@ -218,12 +212,12 @@ func (a *ServiceImpl) Shutdown(ctx context.Context) (<-chan bool, error) {
}

/*
Subscribe to terminate command


Terminate Subscribe to terminate command
*/
func (a *ServiceImpl) Terminate(
ctx context.Context,

func (a *ServiceImpl) Terminate(ctx context.Context) (<-chan bool, error) {
) (<-chan bool, error) {
ch := make(chan bool)
request := &SubscribeTerminateRequest{}
stream, err := a.Client.SubscribeTerminate(ctx, request)
Expand All @@ -242,8 +236,7 @@ func (a *ServiceImpl) Terminate(ctx context.Context) (<-chan bool, error) {
if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled {
return
}
fmt.Printf("Unable to receive Terminate messages, err: %v\n", err)
break
log.Fatalf("Unable to receive Terminate messages, err: %v", err)
}
ch <- m.GetTerminate()
}
Expand All @@ -252,19 +245,16 @@ func (a *ServiceImpl) Terminate(ctx context.Context) (<-chan bool, error) {
}

/*
Can the vehicle takeoff

Parameters
----------
allowTakeoff bool


SetAllowTakeoff Can the vehicle takeoff
*/
func (s *ServiceImpl) SetAllowTakeoff(
ctx context.Context,
allowTakeoff bool,

func (s *ServiceImpl) SetAllowTakeoff(ctx context.Context, allowTakeoff bool) (*SetAllowTakeoffResponse, error) {

request := &SetAllowTakeoffRequest{}
request.AllowTakeoff = allowTakeoff
) (*SetAllowTakeoffResponse, error) {
request := &SetAllowTakeoffRequest{
AllowTakeoff: allowTakeoff,
}
response, err := s.Client.SetAllowTakeoff(ctx, request)
if err != nil {
return nil, err
Expand All @@ -273,22 +263,18 @@ func (s *ServiceImpl) SetAllowTakeoff(ctx context.Context, allowTakeoff bool) (*
}

/*
Can the vehicle arm when requested

Parameters
----------
armable bool

forceArmable bool


SetArmable Can the vehicle arm when requested
*/

func (s *ServiceImpl) SetArmable(ctx context.Context, armable bool, forceArmable bool) (*SetArmableResponse, error) {

request := &SetArmableRequest{}
request.Armable = armable
request.ForceArmable = forceArmable
func (s *ServiceImpl) SetArmable(
ctx context.Context,
armable bool,
forceArmable bool,

) (*SetArmableResponse, error) {
request := &SetArmableRequest{
Armable: armable,
ForceArmable: forceArmable,
}
response, err := s.Client.SetArmable(ctx, request)
if err != nil {
return nil, err
Expand All @@ -297,22 +283,18 @@ func (s *ServiceImpl) SetArmable(ctx context.Context, armable bool, forceArmable
}

/*
Can the vehicle disarm when requested

Parameters
----------
disarmable bool

forceDisarmable bool


SetDisarmable Can the vehicle disarm when requested
*/

func (s *ServiceImpl) SetDisarmable(ctx context.Context, disarmable bool, forceDisarmable bool) (*SetDisarmableResponse, error) {

request := &SetDisarmableRequest{}
request.Disarmable = disarmable
request.ForceDisarmable = forceDisarmable
func (s *ServiceImpl) SetDisarmable(
ctx context.Context,
disarmable bool,
forceDisarmable bool,

) (*SetDisarmableResponse, error) {
request := &SetDisarmableRequest{
Disarmable: disarmable,
ForceDisarmable: forceDisarmable,
}
response, err := s.Client.SetDisarmable(ctx, request)
if err != nil {
return nil, err
Expand All @@ -321,21 +303,16 @@ func (s *ServiceImpl) SetDisarmable(ctx context.Context, disarmable bool, forceD
}

/*
Set which modes the vehicle can transition to (Manual always allowed)

Parameters
----------
flightModes *AllowableFlightModes



SetAllowableFlightModes Set which modes the vehicle can transition to (Manual always allowed)
*/
func (s *ServiceImpl) SetAllowableFlightModes(
ctx context.Context,
flightModes *AllowableFlightModes,

func (s *ServiceImpl) SetAllowableFlightModes(ctx context.Context, flightModes *AllowableFlightModes) (*SetAllowableFlightModesResponse, error) {

request := &SetAllowableFlightModesRequest{}
request.FlightModes = flightModes

) (*SetAllowableFlightModesResponse, error) {
request := &SetAllowableFlightModesRequest{
FlightModes: flightModes,
}
response, err := s.Client.SetAllowableFlightModes(ctx, request)
if err != nil {
return nil, err
Expand All @@ -344,24 +321,16 @@ func (s *ServiceImpl) SetAllowableFlightModes(ctx context.Context, flightModes *
}

/*
Get which modes the vehicle can transition to (Manual always allowed)



Returns
-------
False
FlightModes : AllowableFlightModes


GetAllowableFlightModes Get which modes the vehicle can transition to (Manual always allowed)
*/
func (s *ServiceImpl) GetAllowableFlightModes(
ctx context.Context,

func (s *ServiceImpl) GetAllowableFlightModes(ctx context.Context) (*GetAllowableFlightModesResponse, error) {
) (*GetAllowableFlightModesResponse, error) {
request := &GetAllowableFlightModesRequest{}
response, err := s.Client.GetAllowableFlightModes(ctx, request)
if err != nil {
return nil, err
}
return response, nil

}
Loading