-
Notifications
You must be signed in to change notification settings - Fork 512
Abstraction and PhysicalLayer
RadioLib is designed with one core idea in mind - radio modules like SX126x or LR1110 behave in similar ways and have similar functionalities. Therefore, the same API should be used to access them. This is implemented via RadioLib's most powerful mechanism - the PhysicalLayer class. This class contains the complete interface to control any radio module within RadioLib, in the form of virtual methods. All RadioLib radio modules are derived from PhysicalLayer class and implement those methods, which allows user code to call any PhysicalLayer- compatible radio method by simply casting the radio instance pointer to PhysicalLayer:
// this can be any radio module
SX1262 radio = new Module(10, 2, 9, 3);
// get pointer to the common layer
PhysicalLayer* phy = (PhysicalLayer*)&radio;
// begin etc.
(...)
// now we can use the PHY interface without knowing which radio is it based on!
phy->setFrequency(915.0);Using this mechanism, it is possible to implement custom protocols that work with many different radio types, which is very useful if your project needs to support a varied set of hardware.
An example of using the PhysicalLayer abstraction is also available.