1+ pub mod operation;
2+
13use super :: * ;
24
35use embedded_hal:: blocking:: delay:: DelayMs ;
@@ -7,7 +9,7 @@ use heapless::{String, Vec};
79pub const MAX_NINA_PARAM_LENGTH : usize = 255 ;
810
911#[ repr( u8 ) ]
10- #[ derive( Debug ) ]
12+ #[ derive( Copy , Clone , Debug ) ]
1113pub enum NinaCommand {
1214 GetFwVersion = 0x37u8 ,
1315 SetPassphrase = 0x11u8 ,
@@ -20,11 +22,43 @@ pub trait NinaParam {
2022 type LengthAsBytes : IntoIterator < Item = u8 > ;
2123
2224 fn new ( data : & str ) -> Self ;
25+
2326 fn from_bytes ( bytes : & [ u8 ] ) -> Self ;
2427
25- fn data ( & mut self ) -> & [ u8 ] ;
28+ fn data ( & self ) -> & [ u8 ] ;
29+
30+ fn length_as_bytes ( & self ) -> Self :: LengthAsBytes ;
31+
32+ fn length ( & self ) -> u16 ;
33+ }
34+
35+ // Used for Nina protocol commands with no parameters
36+ pub struct NinaNoParams {
37+ _placeholder : u8 ,
38+ }
39+
40+ impl NinaParam for NinaNoParams {
41+ type LengthAsBytes = [ u8 ; 0 ] ;
42+
43+ fn new ( _data : & str ) -> Self {
44+ Self { _placeholder : 0 }
45+ }
46+
47+ fn from_bytes ( _bytes : & [ u8 ] ) -> Self {
48+ Self { _placeholder : 0 }
49+ }
50+
51+ fn data ( & self ) -> & [ u8 ] {
52+ & [ 0u8 ]
53+ }
54+
55+ fn length_as_bytes ( & self ) -> Self :: LengthAsBytes {
56+ [ ]
57+ }
2658
27- fn length_as_bytes ( & mut self ) -> Self :: LengthAsBytes ;
59+ fn length ( & self ) -> u16 {
60+ 0u16
61+ }
2862}
2963
3064// Used for single byte params
@@ -71,11 +105,15 @@ impl NinaParam for NinaByteParam {
71105 }
72106 }
73107
74- fn data ( & mut self ) -> & [ u8 ] {
108+ fn data ( & self ) -> & [ u8 ] {
75109 self . data . as_slice ( )
76110 }
77111
78- fn length_as_bytes ( & mut self ) -> Self :: LengthAsBytes {
112+ fn length ( & self ) -> u16 {
113+ self . length as u16
114+ }
115+
116+ fn length_as_bytes ( & self ) -> Self :: LengthAsBytes {
79117 [ self . length as u8 ]
80118 }
81119}
@@ -100,11 +138,15 @@ impl NinaParam for NinaWordParam {
100138 }
101139 }
102140
103- fn data ( & mut self ) -> & [ u8 ] {
141+ fn data ( & self ) -> & [ u8 ] {
104142 self . data . as_slice ( )
105143 }
106144
107- fn length_as_bytes ( & mut self ) -> Self :: LengthAsBytes {
145+ fn length ( & self ) -> u16 {
146+ self . length as u16
147+ }
148+
149+ fn length_as_bytes ( & self ) -> Self :: LengthAsBytes {
108150 [ self . length as u8 ]
109151 }
110152}
@@ -129,11 +171,15 @@ impl NinaParam for NinaSmallArrayParam {
129171 }
130172 }
131173
132- fn data ( & mut self ) -> & [ u8 ] {
174+ fn data ( & self ) -> & [ u8 ] {
133175 self . data . as_slice ( )
134176 }
135177
136- fn length_as_bytes ( & mut self ) -> Self :: LengthAsBytes {
178+ fn length ( & self ) -> u16 {
179+ self . length as u16
180+ }
181+
182+ fn length_as_bytes ( & self ) -> Self :: LengthAsBytes {
137183 [ self . length as u8 ]
138184 }
139185}
@@ -158,11 +204,15 @@ impl NinaParam for NinaLargeArrayParam {
158204 }
159205 }
160206
161- fn data ( & mut self ) -> & [ u8 ] {
207+ fn data ( & self ) -> & [ u8 ] {
162208 self . data . as_slice ( )
163209 }
164210
165- fn length_as_bytes ( & mut self ) -> Self :: LengthAsBytes {
211+ fn length ( & self ) -> u16 {
212+ self . length
213+ }
214+
215+ fn length_as_bytes ( & self ) -> Self :: LengthAsBytes {
166216 [
167217 ( ( self . length & 0xff00 ) >> 8 ) as u8 ,
168218 ( self . length & 0xff ) as u8 ,
@@ -177,22 +227,6 @@ pub trait ProtocolInterface {
177227 fn set_passphrase ( & mut self , ssid : & str , passphrase : & str ) -> Result < ( ) , Error > ;
178228 fn disconnect ( & mut self ) -> Result < ( ) , self :: Error > ;
179229 fn get_conn_status ( & mut self ) -> Result < u8 , self :: Error > ;
180-
181- fn send_cmd ( & mut self , cmd : NinaCommand , num_params : u8 ) -> Result < ( ) , self :: Error > ;
182- fn wait_response_cmd (
183- & mut self ,
184- cmd : NinaCommand ,
185- num_params : u8 ,
186- ) -> Result < [ u8 ; ARRAY_LENGTH_PLACEHOLDER ] , self :: Error > ;
187- fn send_end_cmd ( & mut self ) -> Result < ( ) , self :: Error > ;
188-
189- fn get_byte ( & mut self ) -> Result < u8 , self :: Error > ;
190- fn wait_for_byte ( & mut self , wait_byte : u8 ) -> Result < bool , self :: Error > ;
191- fn check_start_cmd ( & mut self ) -> Result < bool , self :: Error > ;
192- fn read_and_check_byte ( & mut self , check_byte : u8 ) -> Result < bool , self :: Error > ;
193- fn send_param < P : NinaParam > ( & mut self , param : P ) -> Result < ( ) , self :: Error > ;
194- fn send_param_length < P : NinaParam > ( & mut self , param : & mut P ) -> Result < ( ) , self :: Error > ;
195- fn pad_to_multiple_of_4 ( & mut self , command_size : u16 ) ;
196230}
197231
198232#[ derive( Debug , Default ) ]
0 commit comments