Skip to content

Commit 1751807

Browse files
committed
feat(TDMA): starting TDMA protcol
1 parent 876b7ec commit 1751807

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

acoustic_modem/include/am_driver.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
// //uint8_t last : 1;
2727
// };
2828

29+
enum class TxState{
30+
SENDING,
31+
WAIT_ACK,
32+
IDLE,
33+
};
34+
35+
2936
enum class MsgType : uint8_t{
3037
Type_def=0,
3138
Type_1 = 1,

acoustic_modem/include/tdma_manager.hpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,25 @@
55
*
66
*/
77

8-
enum class TDMAState{
9-
MY_TURN;
10-
WAIT_TURN;
11-
LISTEN;
12-
}
13-
8+
struct TDMAConfig{
9+
uint8_t num_slots;
10+
uint8_t my_slot;
11+
std::chrono::seconds slot=std::chrono::seconds(25);
12+
std::chrono::milliseconds guard=std::chrono::milliseconds(1000);
13+
std::chrono::steady_clock::time_point t0 = std::chrono::steady_clock::now();
14+
};
1415

1516
class TDMAManager{
1617
public:
17-
TDMAManager(double max_slot_time, double guard_time, double silence_timeout, bool is_master);
18-
19-
// modem is allowed to send
20-
bool can_send();
21-
22-
//change the offset
23-
void offset();
18+
TDMAManager(TDMAConfig config);
19+
20+
// who is transmitting?
21+
uint8_t current_slot(std::chrono::steady_clock::time_point now);
2422

25-
// change who is allowed to send
26-
void update();
23+
// am i allowed to transmit?
24+
bool tx_allowed(std::chrono::steady_clock::time_point now);
2725

2826
private:
29-
double max_slot_time_;
30-
double guard_time_;
31-
double silence_timeout_;
32-
bool is_master_;
33-
TDMAState state;
34-
27+
TDMAConfig cfg;
3528

3629
}

0 commit comments

Comments
 (0)