# Design and Analysis of Adaptive Hierarchical Low-Power Long-Range Networks
## 4 Software Implementation  
In Theoretical Computer Science, researchers usually design their algorithms as abstract as possible to hide technical issues that may arise due to hardware restrictions. Due to this, developers can decide on how the given protocol can be turned into functional code for a real-world system. In theory, this part is simple, as developers need to simply follow the steps provided by the theoretical algorithm, but, in reality, hardware and development software limitations may require hard work to work around the assumptions made in the theoretical description. Implementing protocols for wireless sensor networks is even harder, as devices have extremely limited resources and the same software implementation needs to usually run on different types of devices. This heterogeneous nature (both in terms of hardware and software) and complexity can explain also why many theorists rarely engage in Software Engineering.  
To overcome these issues, we implement our algorithm in _Wiselib_[37]: a code library that allows implementations to be OS-independent. Wiselib is implemented based on C++ and templates, but without virtual inheritance and exceptions which is rarely available in wireless sensor networks. Algorithm implementations of Wiselib can be on-demand compiled for several supported platforms and firmwares. It also supports simulators without the need to change any code in your implementation. In its latest version, _Wiselib_ can support systems implemented using C (Contiki, RiotOS), C++ (iSense), neSC (TinyOS), Android (via the C/C++ NDK) and iOS.  
_Wiselib_ also provides developers with the ability to share their implemented algorithms and re-use the algorithms implemented by other developers. It also offers implementation of various data structures that are implemented and support all the available hardware platforms, overcoming the different ways to store data (due to memory alignment, inability to support dynamic memory, etc.). It is important to use these safe types as much as possible since they have been tested before on most hardware platforms. Currently, _Wiselib_ offers a total of 60 Open Source implementations of standard algorithms like Localization algorithms, Cryptographic schemes, Distributed data structures, etc.  
_Wiselib_ also supports the simulator _Shawn_[38] and _TOSSIM_[39], allowing developers to easily test their software before the transition to actual hardware. This feature allows for validation of the implementation and also offers quality and scalability testing without time-consuming deployment procedures and harsh debugging environments. Furthermore, apart from ordinary sensor device targets or simulation environments, it is also possible to run Wiselib code directly as a native C application on a Linux or Windows PC. The generated application acts as a sensor device, but with the limitations of the host machine. On the one hand, there is basic OS functionality provided, such as a timer for event registration, or a clock providing the current time. On the other hand, it is possible to connect an IEEE 802.15.4 device to the host machine, so that the application can directly communicate even with other hardware sensor devices.