mirror of
https://github.com/markqvist/OpenModem.git
synced 2024-10-01 03:15:46 -04:00
Cleanup
This commit is contained in:
parent
c0b73f0155
commit
409e9d93d0
21
Modem/main.c
21
Modem/main.c
@ -27,11 +27,6 @@ static Serial ser; // Declare a serial interface struct
|
||||
#define ADC_CH 0 // Define which channel (pin) we want
|
||||
// for the ADC (this is A0 on arduino)
|
||||
|
||||
#define TEST_TX false // Whether we should send test packets
|
||||
// periodically, plus what to send:
|
||||
#define TEST_PACKET "Packet received. This is an ACK."
|
||||
#define TEST_TX_INTERVAL 10000L
|
||||
|
||||
|
||||
static uint8_t serialBuffer[MP1_MAX_DATA_SIZE]; // This is a buffer for incoming serial data
|
||||
|
||||
@ -50,13 +45,6 @@ static bool sertx = false; // Flag signifying whether it's time to send da
|
||||
static void mp1Callback(struct MP1Packet *packet) {
|
||||
if (SERIAL_DEBUG) {
|
||||
kfile_printf(&ser.fd, "%.*s\n", packet->dataLength, packet->data);
|
||||
|
||||
if (AUTOREPLY && packet->data[0]-128 == 'R' && packet->data[1]-128 == 'Q') {
|
||||
timer_delay(1000);
|
||||
|
||||
uint8_t output[sizeof(TEST_PACKET)] = TEST_PACKET;
|
||||
mp1Send(&mp1, output, sizeof(TEST_PACKET));
|
||||
}
|
||||
} else {
|
||||
for (unsigned long i = 0; i < packet->dataLength; i++) {
|
||||
kfile_putc(packet->data[i], &ser.fd);
|
||||
@ -174,15 +162,6 @@ int main(void)
|
||||
serialLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Periodically send test data if we should do so
|
||||
if (SERIAL_DEBUG && TEST_TX && timer_clock() - start > ms_to_ticks(TEST_TX_INTERVAL)) {
|
||||
// Reset the timer counter;
|
||||
start = timer_clock();
|
||||
// And send a test packet!
|
||||
uint8_t output[sizeof(TEST_PACKET)] = TEST_PACKET;
|
||||
mp1Send(&mp1, output, sizeof(TEST_PACKET));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,2 +1,2 @@
|
||||
#define VERS_BUILD 1570
|
||||
#define VERS_BUILD 1576
|
||||
#define VERS_HOST "shard"
|
||||
|
Loading…
Reference in New Issue
Block a user