-
-
Notifications
You must be signed in to change notification settings - Fork 620
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
Add Channel Activity Detection ability. #334
Conversation
Hi, In the example, I see we do onCad and if there is signal we do onReceive. What is the advantage if we dont use onCad and use onReceive right away? Thanks a lot. |
That's right. The example is intended to provide a minimum description of CAD.
|
Yes, now I understand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@w-ockham thanks for taking the time to submit this pull request!
src/LoRa.h
Outdated
void onTxDone(void(*callback)()); | ||
|
||
void receive(int size = 0); | ||
void CAD(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on making this lower case or expanded to something like collisionActivityDetect()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it stand for Channel Activity Detection? Additionally, I thought the other day this should be named to make it clear this is CAD DONE, as there is also CadDetect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this? these methods are well self-descriptive enough IMHO. channelActivityDetection switch the receiver to CAD mode, onCadDone register a callback function for CADDone interrupts.
void channelActivityDetection(void);
void onCadDone(void(*callback)(boolean));
@@ -57,9 +57,11 @@ class LoRaClass : public Stream { | |||
|
|||
#ifndef ARDUINO_SAMD_MKRWAN1300 | |||
void onReceive(void(*callback)(int)); | |||
void onCadDone(void(*callback)(boolean)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative name suggestions: onCollisionActivityDetectComplete
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe CAD in Semtech LoRa is Channel Activity Detection.
There is someone sending the data. and it may be not a collision, right?
In page 44, it says "Once the calculation is finished the modem generates the CadDone interrupt. If the correlation was successful, CadDetected is generated simultaneously."
So the name should be onCadDone or onCadDetected.
My 2 cents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But those interrupts are generated on different pins, if you check Table 18, CadDone is raised on DIO0 & DIO3 and CadDetected is raised on DIO1. They also have different functions. CAD is just the process to see if there is any activity on the channel, CadDone raised when it's done. CadDetect is only fired if activity is detected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then onCadDone is fine or onChannelActivityDetectionDone (quite long).
As channel activity doesnt imply channel collission.
When there is channel avtivity and we are sending other packets, then there is collission.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer onCadDone since it's quite simpler than on24Done. :-)
One thing, as far as I was able to understand there are two interrupts possible with CAD one is triggered on any preamble and the other on your specific one. The later one i believe should be mapped to a different dio pin, would it be possible to add that one as well. Thanks! |
As I pointed out in the inline comment.. #334 (comment) One, CADDone, is triggered when the CAD is complete, on DIO0 & DIO2 |
ideally, would it be possible to add another interrupt on DIO1? or its sufficient to short them and use single pin on MCU as long as onReceive is not enabled at the same time. but we would still need to check the relevant register on the radio.
|
I don't think you'd want to just short them, but yes, we should add that, I believe there's an open issue outlining it. But as you suggested, the same functionality can be achieved with just DIO0. When CadDone is raised on this pin, in software you can check the IRQ flag for CadDetected. |
I create this Branch a long time, and use cad to detect receiving data with sf7, sf8, sf9, sf10, sf11 or sf12. |
@w-ockham : I'm going to use your CAD code for my deep-sleep node. Is this possible?
|
@ricaun Will your CAD code wake up a deep sleep MCU and receive the current incoming message? |
@w-ockham : Would you mind explain to me what is B111 in isTransmitting()? |
I believe so, but I design the code to find the spreading factor when the node receiving a message, It's not perfect but It's possible to receive a message from sf7 to sf12 (with some loss).
Interesting, the SX126x has this SetRxDutyCycle function to make the LoRa module switch to receive and sleep. |
The current CAD code syncs CadDone to dio0. Then check flag for cadDetected. I think I will add new code to sync CadDetected to Dio1. Then use dio1 to wakeup MCU. Thanks a lot for your CAD code. :D |
On my code, I used the I guess the |
@ricaun Most of the LoRa boards don't have DIO1 connected. e.g: TTGO, Heltec or Ready-made LoRa PCB. We need DIO1 for CadDetected. |
B111 is binary 111 or 0x07.
|
This example from @w-ockham has something "not right" too me.
When a CadDetected is detected, LoRa.receive() seems to clear the incoming data? By right, after CADDetected and set to Single RX or RX Continous Mode, we should receive the current incoming message. |
I have been trying to get this code to work for the last few hours, and I was running into the same problem as IOTThinks where only every other packet was being received. After trying several other things which didn't work, I added a call to
This seems to have fixed the problem and CAD is working as expected and I'm now receiving all packets! 😄 |
@Cangjie103 there are still fixes that need to be addressed on this, please look at the inline comments and fix those before merging. |
This PR has been modified, tested and merged and currently is available in the 'master' branch. Please test and check for side effects. Additionally while reading some of the details on During a CAD the following operations take place:
This last line in particular seems to indicate the purpose is to detect if you are able to receive, not if you're able to transmit. Maybe further testing will indicate if both are the case. |
This modification adds the following functions.
LoRa.onCadDone(callback) : Register the callback function for channel activity detection.
LoRa.CAD(void) : Activate channel activity detection mode.