1
- use core:: { future:: Future , pin:: Pin , task:: { Context , Poll } , cell :: RefCell } ;
1
+ use core:: { future:: Future , pin:: Pin , task:: { Context , Poll } } ;
2
2
use futures_util:: task:: AtomicWaker ;
3
- use mcu_if:: { alloc:: { vec:: Vec , rc:: Rc } } ; // !!!!
4
3
use super :: { BlockwiseData , BLOCKWISE_HDR_MAX } ;
5
4
6
5
pub const REQ_ADDR_MAX : usize = 64 ;
7
6
pub const REQ_URI_MAX : usize = 64 ;
8
- const REQ_PAYLOAD_MAX : usize = 48 ;
9
- const REQ_OUT_MAX : usize = 128 ; // !!!!
7
+
8
+ const PAYLOAD_REQ_MAX : usize = 48 ;
9
+ const PAYLOAD_OUT_MAX : usize = 128 ;
10
+
11
+ type PayloadReq = heapless:: Vec < u8 , PAYLOAD_REQ_MAX > ;
12
+ pub type PayloadOut = heapless:: Vec < u8 , PAYLOAD_OUT_MAX > ;
10
13
11
14
//
12
15
// gcoap client
@@ -27,14 +30,14 @@ const GCOAP_MEMO_RESP_TRUNC: u8 = 0x06;
27
30
28
31
#[ derive( Debug , PartialEq ) ]
29
32
pub enum GcoapMemoState {
30
- Resp ( Option < Vec < u8 > > ) ,
33
+ Resp ( Option < PayloadOut > ) ,
31
34
Timeout ,
32
35
Err ,
33
- RespTrunc ( Option < Vec < u8 > > ) ,
36
+ RespTrunc ( Option < PayloadOut > ) ,
34
37
}
35
38
36
39
impl GcoapMemoState {
37
- pub fn new ( memo_state : u8 , payload : Option < Vec < u8 > > ) -> Self {
40
+ pub fn new ( memo_state : u8 , payload : Option < PayloadOut > ) -> Self {
38
41
match memo_state {
39
42
// ...
40
43
GCOAP_MEMO_RESP => Self :: Resp ( payload) ,
@@ -80,7 +83,7 @@ pub enum Req {
80
83
81
84
impl Req {
82
85
pub fn new ( method : CoapMethod , addr : & str , uri : & str ,
83
- payload : Option < heapless :: Vec < u8 , REQ_PAYLOAD_MAX > > ) -> Self {
86
+ payload : Option < PayloadReq > ) -> Self {
84
87
let inner = ReqInner :: new ( method, addr, uri, payload, false , None , None ) ;
85
88
86
89
match method {
@@ -107,25 +110,24 @@ impl Future for Req {
107
110
108
111
//
109
112
110
- pub type Finale = ( AtomicWaker , heapless :: Vec < u8 , REQ_OUT_MAX > ) ;
113
+ pub type Finale = ( AtomicWaker , Option < GcoapMemoState > ) ;
111
114
112
115
#[ derive( Debug ) ]
113
116
pub struct ReqInner {
114
117
method : CoapMethod ,
115
118
addr : heapless:: String < { REQ_ADDR_MAX } > ,
116
119
uri : heapless:: String < { REQ_URI_MAX } > ,
117
- payload : Option < heapless :: Vec < u8 , REQ_PAYLOAD_MAX > > ,
120
+ payload : Option < PayloadReq > ,
118
121
blockwise : bool ,
119
122
blockwise_state_index : Option < usize > ,
120
123
blockwise_hdr : Option < heapless:: Vec < u8 , BLOCKWISE_HDR_MAX > > ,
121
- // out: Rc<RefCell<Option<GcoapMemoState>>>,
122
124
_waker : Option < AtomicWaker > ,
123
- finale : Option < Finale > , // !!!! !!!!
125
+ finale : Option < Finale > ,
124
126
}
125
127
126
128
impl ReqInner {
127
129
pub fn new ( method : CoapMethod , addr : & str , uri : & str ,
128
- payload : Option < heapless :: Vec < u8 , REQ_PAYLOAD_MAX > > ,
130
+ payload : Option < PayloadReq > ,
129
131
blockwise : bool ,
130
132
blockwise_state_index : Option < usize > ,
131
133
blockwise_hdr : Option < heapless:: Vec < u8 , BLOCKWISE_HDR_MAX > > ) -> Self {
@@ -137,9 +139,8 @@ impl ReqInner {
137
139
blockwise,
138
140
blockwise_state_index,
139
141
blockwise_hdr,
140
- // out: Rc::new(RefCell::new(None)),
141
142
_waker : Some ( AtomicWaker :: new ( ) ) ,
142
- finale : None , // !!!! !!!!
143
+ finale : None ,
143
144
}
144
145
}
145
146
}
@@ -156,7 +157,7 @@ impl Future for ReqInner {
156
157
//outc.borrow_mut().replace(_out);
157
158
//_waker.wake();
158
159
//==== !!!!
159
- panic ! ( "debug " ) ;
160
+ panic ! ( "BUILD SHIM " ) ;
160
161
} ;
161
162
match self . method {
162
163
COAP_METHOD_GET => {
@@ -178,28 +179,25 @@ impl Future for ReqInner {
178
179
}
179
180
} else {
180
181
//super::Xbd::gcoap_get(&self.addr, &self.uri, cb);
181
- //==== !!!! WIP
182
- self . finale . replace ( ( _waker, heapless :: Vec :: new ( ) ) ) ;
182
+ //==== !!!! v2
183
+ self . finale . replace ( ( _waker, None ) ) ;
183
184
super :: Xbd :: gcoap_get_v2 ( & self . addr , & self . uri ,
184
185
self . finale . as_ref ( ) . unwrap ( ) as * const Finale as * mut _ ) ;
185
186
}
186
187
} ,
187
- COAP_METHOD_POST => super :: Xbd :: gcoap_post (
188
+ COAP_METHOD_POST => super :: Xbd :: gcoap_post ( // TODO -> v2
188
189
& self . addr , & self . uri , self . payload . as_ref ( ) . unwrap ( ) . as_slice ( ) , cb) ,
189
- COAP_METHOD_PUT => super :: Xbd :: gcoap_put (
190
+ COAP_METHOD_PUT => super :: Xbd :: gcoap_put ( // TODO -> v2
190
191
& self . addr , & self . uri , self . payload . as_ref ( ) . unwrap ( ) . as_slice ( ) , cb) ,
191
192
_ => todo ! ( ) ,
192
193
}
193
194
194
195
Poll :: Pending
195
196
} else {
196
197
//Poll::Ready(self.out.take().unwrap())
197
- //==== !!!!
198
- crate :: println!( "!!!! before Poll::Ready !!!! finale: {:?}" , self . finale) ;
199
- let out = GcoapMemoState :: new ( // TODO heapless represent `out` from `gcoap_req_resp_handler`
200
- GCOAP_MEMO_RESP ,
201
- Some ( self . finale . as_ref ( ) . unwrap ( ) . 1 . as_slice ( ) . to_vec ( ) ) ) ; // dummy
202
- Poll :: Ready ( out)
198
+ //==== v2
199
+ let ( _, out) = self . finale . take ( ) . unwrap ( ) ;
200
+ Poll :: Ready ( out. unwrap ( ) )
203
201
}
204
202
}
205
203
}
0 commit comments