| 1 | package UAV::Pilot::WumpusRover::Server::Backend::Mock; | ||
| 2 | use v5.14; | ||
| 3 | use Moose; | ||
| 4 | use namespace::autoclean; | ||
| 5 | use UAV::Pilot::WumpusRover::Server::Backend; | ||
| 6 | |||
| 7 | |||
| 8 | has 'started' => ( | ||
| 9 | is => 'ro', | ||
| 10 | isa => 'Bool', | ||
| 11 | writer => '_set_started', | ||
| 12 | ); | ||
| 13 | |||
| 14 | foreach (1..8) { | ||
| 15 | my $ch_trim_name = 'ch' . $_ . '_trim'; | ||
| 16 | my $ch_min_name = 'ch' . $_ . '_min'; | ||
| 17 | my $ch_max_name = 'ch' . $_ . '_max'; | ||
| 18 | my $ch_out_name = 'ch' . $_ . '_out'; | ||
| 19 | |||
| 20 | has $ch_trim_name => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => 'Maybe[Int]', | ||
| 23 | writer => '_set_' . $ch_trim_name, | ||
| 24 | ); | ||
| 25 | has $ch_min_name => ( | ||
| 26 | is => 'ro', | ||
| 27 | isa => 'Maybe[Int]', | ||
| 28 | writer => '_set_' . $ch_min_name, | ||
| 29 | ); | ||
| 30 | has $ch_max_name => ( | ||
| 31 | is => 'ro', | ||
| 32 | isa => 'Maybe[Int]', | ||
| 33 | writer => '_set_' . $ch_max_name, | ||
| 34 | ); | ||
| 35 | has $ch_out_name => ( | ||
| 36 | is => 'ro', | ||
| 37 | isa => 'Maybe[Int]', | ||
| 38 | writer => '_set_' . $ch_out_name, | ||
| 39 | ); | ||
| 40 | } | ||
| 41 | |||
| 42 | has 'ch1_max_out' => ( | ||
| 43 | is => 'ro', | ||
| 44 | isa => 'Int', | ||
| 45 | default => 100, | ||
| 46 | ); | ||
| 47 | has 'ch1_min_out' => ( | ||
| 48 | is => 'ro', | ||
| 49 | isa => 'Int', | ||
| 50 | default => 0, | ||
| 51 | ); | ||
| 52 | has 'ch2_max_out' => ( | ||
| 53 | is => 'ro', | ||
| 54 | isa => 'Int', | ||
| 55 | default => 100, | ||
| 56 | ); | ||
| 57 | has 'ch2_min_out' => ( | ||
| 58 | is => 'ro', | ||
| 59 | isa => 'Int', | ||
| 60 | default => 0, | ||
| 61 | ); | ||
| 62 | has 'ch3_max_out' => ( | ||
| 63 | is => 'ro', | ||
| 64 | isa => 'Int', | ||
| 65 | default => 100, | ||
| 66 | ); | ||
| 67 | has 'ch3_min_out' => ( | ||
| 68 | is => 'ro', | ||
| 69 | isa => 'Int', | ||
| 70 | default => 0, | ||
| 71 | ); | ||
| 72 | has 'ch4_max_out' => ( | ||
| 73 | is => 'ro', | ||
| 74 | isa => 'Int', | ||
| 75 | default => 100, | ||
| 76 | ); | ||
| 77 | has 'ch4_min_out' => ( | ||
| 78 | is => 'ro', | ||
| 79 | isa => 'Int', | ||
| 80 | default => 0, | ||
| 81 | ); | ||
| 82 | has 'ch5_max_out' => ( | ||
| 83 | is => 'ro', | ||
| 84 | isa => 'Int', | ||
| 85 | default => 100, | ||
| 86 | ); | ||
| 87 | has 'ch5_min_out' => ( | ||
| 88 | is => 'ro', | ||
| 89 | isa => 'Int', | ||
| 90 | default => 0, | ||
| 91 | ); | ||
| 92 | has 'ch6_max_out' => ( | ||
| 93 | is => 'ro', | ||
| 94 | isa => 'Int', | ||
| 95 | default => 100, | ||
| 96 | ); | ||
| 97 | has 'ch6_min_out' => ( | ||
| 98 | is => 'ro', | ||
| 99 | isa => 'Int', | ||
| 100 | default => 0, | ||
| 101 | ); | ||
| 102 | has 'ch7_max_out' => ( | ||
| 103 | is => 'ro', | ||
| 104 | isa => 'Int', | ||
| 105 | default => 100, | ||
| 106 | ); | ||
| 107 | has 'ch7_min_out' => ( | ||
| 108 | is => 'ro', | ||
| 109 | isa => 'Int', | ||
| 110 | default => 0, | ||
| 111 | ); | ||
| 112 | has 'ch8_max_out' => ( | ||
| 113 | is => 'ro', | ||
| 114 | isa => 'Int', | ||
| 115 | default => 100, | ||
| 116 | ); | ||
| 117 | has 'ch8_min_out' => ( | ||
| 118 | is => 'ro', | ||
| 119 | isa => 'Int', | ||
| 120 | default => 0, | ||
| 121 | ); | ||
| 122 | |||
| 123 | with 'UAV::Pilot::WumpusRover::Server::Backend'; | ||
| 124 | |||
| 125 | |||
| 126 | sub _packet_request_startup | ||
| 127 | { | ||
| 128 | my ($self, $packet) = @_; | ||
| 129 | $self->_set_started( 1 ); | ||
| 130 | return 1; | ||
| 131 | } | ||
| 132 | |||
| 133 | sub _packet_radio_trims | ||
| 134 | { | ||
| 135 | my ($self, $packet) = @_; | ||
| 136 | foreach (1..8) { | ||
| 137 | my $fetch_method = 'ch' . $_ . '_trim'; | ||
| 138 | my $set_method = '_set_ch' . $_ . '_trim'; | ||
| 139 | $self->$set_method( $packet->$fetch_method ); | ||
| 140 | } | ||
| 141 | return 1; | ||
| 142 | } | ||
| 143 | |||
| 144 | sub _packet_radio_out | ||
| 145 | { | ||
| 146 | my ($self, $packet, $server) = @_; | ||
| 147 | foreach (1..8) { | ||
| 148 | my $fetch_method = 'ch' . $_ . '_out'; | ||
| 149 | my $set_method = '_set_ch' . $_ . '_out'; | ||
| 150 | my $ch_map_method = '_map_ch' . $_ . '_value'; | ||
| 151 | |||
| 152 | my $in_value = $packet->$fetch_method // 0; | ||
| 153 | my $out_value = $self->$ch_map_method( $server, $in_value ); | ||
| 154 | $self->$set_method( $out_value ); | ||
| 155 | } | ||
| 156 | return 1; | ||
| 157 | } | ||
| 158 | |||
| 159 | |||
| 160 | no Moose; | ||
| 161 | __PACKAGE__->meta->make_immutable; | ||
| 162 | 1; | ||
| 163 | __END__ | ||
| 164 |