[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug for exact cause of ppm glithes #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions crossbow.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ RxDeviceState_t rxDeviceState = {};
TxDeviceState_t txDeviceState = {};
volatile RadioState_t radioState = {};

volatile uint8_t debugPhase;

uint8_t tmpBuffer[MAX_PACKET_SIZE];

uint8_t getRadioRssi(void)
Expand Down Expand Up @@ -262,7 +264,8 @@ int8_t getFrameToTransmit(QspConfiguration_t *qsp) {
*/
void loop(void)
{

debugPhase = DEBUG_LOOP_START;

uint32_t currentMillis = millis();

/*
Expand All @@ -280,6 +283,7 @@ void loop(void)
}

if (radioState.bytesToRead != NO_DATA_TO_READ) {
debugPhase = DEBUG_READ_START;
LoRa.read(tmpBuffer, radioState.bytesToRead);

for (int i = 0; i < radioState.bytesToRead; i++) {
Expand All @@ -295,6 +299,7 @@ void loop(void)
radioState.deviceState = RADIO_STATE_RX;

radioState.bytesToRead = NO_DATA_TO_READ;
debugPhase = DEBUG_READ_END;
}

bool transmitPayload = false;
Expand All @@ -311,6 +316,14 @@ void loop(void)

#ifdef DEVICE_MODE_TX

static int prev = 0;

if (abs(ppmReader.get(0) - prev) > 10) {
Serial.println(debugPhase);
}

prev = ppmReader.get(0);

if (
radioState.deviceState == RADIO_STATE_RX &&
qsp.protocolState == QSP_STATE_IDLE &&
Expand Down Expand Up @@ -414,6 +427,7 @@ void loop(void)

if (qsp.canTransmit && transmitPayload)
{
debugPhase = DEBUG_TX_START;
uint8_t size;
LoRa.beginPacket();
//Prepare packet
Expand All @@ -426,11 +440,14 @@ void loop(void)
radioState.deviceState = RADIO_STATE_TX;

transmitPayload = false;
debugPhase = DEBUG_TX_END;
}

#ifdef DEVICE_MODE_TX

debugPhase = DEBUG_BUZZER_START;
buzzerProcess(TX_BUZZER_PIN, currentMillis, &buzzer);
debugPhase = DEBUG_BUZZER_END;

// This routing enables when TX starts to receive signal from RX for a first time or after
// failsafe
Expand Down Expand Up @@ -507,14 +524,15 @@ void loop(void)
display.display();
}
#endif

#endif

#endif
debugPhase = DEBUG_LOOP_END;

}

void onReceive(int packetSize)
{
debugPhase = DEBUG_RECEIVE_START;
/*
* We can start reading only when radio is not reading.
* If not reading, then we might start
Expand All @@ -533,4 +551,5 @@ void onReceive(int packetSize)
radioState.deviceState = RADIO_STATE_RX;
}
}
debugPhase = DEBUG_RECEIVE_END;
}
13 changes: 13 additions & 0 deletions variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ enum debugConfigFlags {
DEBUG_FLAG_LED = 0b00000010
};

enum ppmDebugPhases {
DEBUG_RECEIVE_START = 0,
DEBUG_RECEIVE_END = 1,
DEBUG_TX_START = 2,
DEBUG_TX_END = 3,
DEBUG_READ_START = 4,
DEBUG_READ_END = 5,
DEBUG_BUZZER_START = 6,
DEBUG_BUZZER_END = 7,
DEBUG_LOOP_END = 8,
DEBUG_LOOP_START = 9
};

#define PPM_INPUT_PIN 0 // Has to be one of Interrupt pins
#define PPM_INPUT_INTERRUPT 2 // For Pro Micro 1, For Pro Mini 0

Expand Down