File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 66 */
77
88struct TDMAConfig {
9+ // should be two with just two nodes
910 uint8_t num_slots;
1011 uint8_t my_slot;
1112 std::chrono::seconds slot=std::chrono::seconds(25 );
@@ -15,7 +16,7 @@ struct TDMAConfig{
1516
1617class TDMAManager {
1718 public:
18- TDMAManager (TDMAConfig config);
19+ TDMAManager (TDMAConfig config) : cfg(config){}
1920
2021 // who is transmitting?
2122 uint8_t current_slot (std::chrono::steady_clock::time_point now);
Original file line number Diff line number Diff line change 1+ #include " tdma_manager.hpp"
2+
3+ // return type can be changed
4+ uint8_t TDMAManager::current_slot (std::chrono::steady_clock::time_point now){
5+ auto cycle=cfg.num_slots *cfg.slot ;
6+ auto elapsed=now-cfg.t0 ;
7+ // how far are we in the cycle
8+ auto time_cycle=elapsed%cycle;
9+ uint8_t slot_i= time_cycle/cfg.slot ;
10+ return slot_i
11+ }
12+
13+ bool TDMAManager::tx_allowed (std::chrono::steady_clock::time_point now){
14+ if (current_slot (now)!=cfg.my_slot ){
15+ return false ;
16+ }
17+ auto cycle=cfg.num_slots *cfg.slot ;
18+ auto elapsed=now-cfg.t0 ;
19+ // how far are we in the cycle
20+ auto time_cycle=elapsed%cycle;
21+ uint8_t slot_i= time_cycle/cfg.slot ;
22+ auto offset_in_slot=time_cycle%cfg.slot ;
23+
24+ if (offset_in_slot<cfg.guard ){
25+ return false ;
26+ }
27+ if (offset_in_slot>(cfg.slot -cfg.guard )){
28+ return false ;
29+ }
30+ return true ;
31+ }
You can’t perform that action at this time.
0 commit comments