# An Efficient Adaptive Data-Link-Layer Architecture for LoRa Networks
## 4 Data Link Layer Design
### LoRa Parameter Calculator  
The developed calculator is a tool that aids its users (i.e., network administrators) in the selection of the values for LoRa parameters to be used in the initial configuration and deployment of the LoRa devices.  
The calculator takes a set of LoRa parameters as input, namely the maximum ToA, the payload length and the coding rate (CR), as well as the estimated processing time for execution of the ASFS algorithm by the packet forwarder microcontroller and the transceiver power consumption (which are device dependent). Since the CR provides recovery from packet errors, it is eminently application-dependant. For example, in an application scenario that is loss tolerant, then CR can have the highest value (4/5), which corresponds to the minimum level of redundancy. On the other hand, in applications where it is critical to minimize the data loss, then the CR should have the minimum value (4/8).  
Based on these input values, many important metrics are calculated and displayed by this tool: the energy consumption per packet, the effective ToA, the maximum link budget (difference between the transmitter output power and the sensitivity of the receiver), the maximum receiver (Rx) sensitivity (which determines the minimum strength of a signal that the packet forwarder can detect), the maximum time necessary for the ASFS algorithm to execute an iteration (used by the packet forwarder to detect incoming packets), the minimum time (Tmin) between messages (a restriction imposed by fair use of the ISM bands) and the maximum number of packets that can be sent in a day. It also calculates the Bw and the preamble length to be used in the transceiver configuration. The inputs and outputs of the calculator can be observed in Figure 4.  
For the development of the LoRa parameter calculator, as a starting point, a LoRa air-time calculator was used [21], as it already contains many of the necessary parameters.  
Figure 4: Inputs and outputs of the LoRa parameters calculator.  
Then, it was adapted to receive the necessary inputs and calculate the output parameters iteratively, taking the ASFS algorithm requirements into consideration. The maximum time it takes for the ASFS algorithm to run an iteration can be defined as the cumulative CAD detection periods (\(T_{max}\)), as described in the previous section.  
The calculator algorithm is depicted in Figure 5. It iterates over all possible bandwidths and returns the lowest Bw that fulfills the Max ToA requirement. To verify this, the calculator considers a maximum SF (12), the maximum TxP, and the application-specific payload and CR. Along with the Bw, the calculator outputs the calculated preamble lengths for each spreading factor and the important metrics related to the set of parameters in Figure 4.  
The user configures the node with the Bw output with the calculator, an SF, and a TxP of choice. It should be noted that the output Bw offers the highest possible range. The initial SF and TxP are not very important since they will be dynamically minimized according to the link quality by the proposed ADL mechanism. However, starting with the highest SF and TxP values ensures the node will work from the first moment.