You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/rawmaster.rs
+20-8Lines changed: 20 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,6 @@ pub struct RawMaster {
67
67
// synchronization signal for multitask reception
68
68
received:Notify,
69
69
sendable:Condvar,
70
-
send:Condvar,
71
70
sent:Notify,
72
71
73
72
// communication state
@@ -80,7 +79,7 @@ pub struct RawMaster {
80
79
structPduState{
81
80
last_start:usize,
82
81
last_end:usize,
83
-
last_time:Instant,
82
+
ready:bool,
84
83
/// send buffer, it contains one ethercat frame
85
84
send:[u8;MAX_ETHERCAT_FRAME],
86
85
/// reception destination, each containing a reception buffer and additional infos
@@ -102,13 +101,12 @@ impl RawMaster {
102
101
socket:Box::new(socket),
103
102
received:Notify::new(),
104
103
sendable:Condvar::new(),
105
-
send:Condvar::new(),
106
104
sent:Notify::new(),
107
105
108
106
pdu_state:Mutex::new(PduState{
109
107
last_start:EthercatHeader::packed_size(),
110
108
last_end:0,
111
-
last_time:Instant::now(),
109
+
ready:false,
112
110
send:[0;MAX_ETHERCAT_FRAME],
113
111
receive:[0;2*MAX_ETHERCAT_PDU].map(|_| None),
114
112
free:(0 .. 2*MAX_ETHERCAT_PDU).collect(),
@@ -273,8 +271,8 @@ impl RawMaster {
273
271
+ data.len()
274
272
+ PduHeader::packed_size()
275
273
+ PduFooter::packed_size(),"data too big for an ethercat frame");
274
+
state.ready = true;
276
275
self.sendable.notify_one();
277
-
self.send.notify_one();
278
276
let notification = self.sent.notified();
279
277
drop(state);
280
278
notification.await;
@@ -303,7 +301,6 @@ impl RawMaster {
303
301
header.pack(place).unwrap();
304
302
}
305
303
else{
306
-
state.last_time = Instant::now();
307
304
state.last_end = state.last_start;
308
305
}
309
306
@@ -352,6 +349,13 @@ impl RawMaster {
352
349
state.receive[token].as_ref().unwrap().answers
353
350
}
354
351
352
+
/// trigger sending the buffered PDUs, they will be sent as soon as possible by [Self::send] instead of waiting for the frame to be full or for the timeout
353
+
fnflush(&self){
354
+
letmut state = self.pdu_state.lock().unwrap();
355
+
state.ready = true;
356
+
self.sendable.notify_one();
357
+
}
358
+
355
359
/// extract a received frame of PDUs and buffer each for reception by an eventual `self.pdu()` future waiting for it.
0 commit comments