This commit is contained in:
Mark Qvist 2014-04-27 21:13:37 +02:00
parent c0b73f0155
commit 409e9d93d0
4 changed files with 16 additions and 32 deletions

View file

@ -544,21 +544,25 @@ void mp1Init(MP1 *mp1, KFile *modem, mp1_callback_t callback) {
// number, and if it is less than
// MP1_P_PERSISTENCE, we transmit.
bool mp1CarrierSense(MP1 *mp1) {
if (mp1->randomSeed == 0) {
mp1->randomSeed = timer_clock();
srand(mp1->randomSeed);
}
if (MP1_ENABLE_CSMA) {
if (mp1->randomSeed == 0) {
mp1->randomSeed = timer_clock();
srand(mp1->randomSeed);
}
if (timer_clock() - mp1->settleTimer > ms_to_ticks(MP1_SETTLE_TIME)) {
uint8_t r = rand() % 255;
if (r < MP1_P_PERSISTENCE) {
return false;
if (timer_clock() - mp1->settleTimer > ms_to_ticks(MP1_SETTLE_TIME)) {
uint8_t r = rand() % 255;
if (r < MP1_P_PERSISTENCE) {
return false;
} else {
mp1->settleTimer = timer_clock();
return true;
}
} else {
mp1->settleTimer = timer_clock();
return true;
}
} else {
return true;
return false;
}
}

View file

@ -16,6 +16,7 @@
// These two parameters are used for
// P-persistent CSMA
#define MP1_ENABLE_CSMA false
#define MP1_SETTLE_TIME 100UL // The minimum wait time before considering sending
#define MP1_P_PERSISTENCE 85UL // The probability (between 0 and 255) for sending
#define MP1_TXDELAY 150UL // Delay between turning on the transmitter and sending