OpenSCADAWiki: Home Page En/Works/ Adapt Android
 
 (2 Kb) This page is frozen, actual one here.


OpenSCADA adaption to the software platform "Android"

Name: AdaptAndroid
Founded: February 2017
Status: Android specific expandings of the project OpenSCADA.
Achievement: Packs to APK packages by CrystaxNDKr10 (>= ABI 19, Android 4.4) and NDKr13 (>= ABI 21, Android 5), starts and works through JNI through the WWW and Qt5, tested on DB.Model.AGLKS.
Current difficulty, spent time: 18 (Android) + 4 (OpenSCADA and core libs) + 6(Qt5) days
Members: Roman Savochenko
Description: The sub-project's purpose is to adapt the project OpenSCADA to run on the software platform Android which wide used on more mobile, TV, SmartWatch and other devices.
Task: http://oscada.org/en/development/tasks/posts/tasks_forming_formirovanie_zadach/openscada_adapting_to_the_android_os_tablet_asus_nexus_7_ii_workout.
Android logotype (32 Kb)


Contents

Introduction

Android is an operation system initially developed by Android Inc., which Google bought in 2005, Android was unveiled in 2007, along with the founding of the Open Handset Alliance — a consortium of hardware, software, and telecommunication companies devoted to advancing open standards for mobile devices.

Android's kernel is based on one of the Linux kernel's long-term support (LTS) branches. Since April 2014, Android devices mainly use versions 3.4, 3.10 or 3.18 of the Linux kernel.

Android is far away from a Linux distribution by it does not include the GNU C Library (it uses Bionic as an alternative C library) and some of other components typically found in Linux distributions. Moreover it has a graphical and application stack built on Java VM which excludes initially writing any other program than on the Java language. But in the performance reason JNI uses here to link external native libraries written on C/C++ by a native development kit (NDK). But the LibC Bionic and the core libraries are mostly POSIX compatible. Due more lacks and more limitations into the original Android NDK there was used an user expanded one CrystaX NDK, but last stable version of CrystaX NDK based on NDK r10 and on the task time there allowed original version r13, where more lacks resolved but the native functions of locales still lack.

For developers Google provides Android software development kit (SDK). All projects written to build by Android Development Tools (ADT) and the IDE Eclipse allowed to the packages assemble from the command line and then can be automated, but new projects (see to the current samples) written on/for Android Studio can be built only from the environment and without the command line using. The sub-project implements and tests on Asus Nexus 7 II with the original Android 4.4.4 (Krait) then there uses Andoid-19 SDK version.

Before an action for same OpenSCADA adaption there were read some books, learned some links, created several examples and executed some tests, those are:

Due the method of linking of native programs is the primarily and exclusively only through JNI by connecting a share library then all dependent code of the program must be placed and pre-loaded into shared libraries against the common one or builtin as the static parts to the common one. Placing and loading the dependent code as the shared libraries will cause to extra memory consumption but it's will exclusively the program's libraries. Then compiling the dependent libraries of the program as the static ones is a preferred way for Android!

OpenSCADA

To simplify and early preparing OpenSCADA to JNI in all its parts there is decided to build the program as a native executable and start it from the command-line. Then:






Current compiling and adapting status of the OpenSCADA core, it parts and the dependent libraries condensed and placed to the next table:
Part Compiling
standalone executable
Qt5 and JNI CrystaxNDKr10
Original NDK r13 ABI21
(Builtin for modules)
Tests Commentaries and problems
The dependent libraries
PCRE, for the core OK OK OK Configuring command:
OpenSSL, for: Transport.SSL, DAQ.OPC_UA, Special.FLibSYS (opt) OK OK OK Configuring command:
LibGD, for: the core (opt), UI.WebCfgD (opt), UI.WebVision OK OK OK
Dependent from: libpng, jpeg, freetype, fontconfig
Also has links to macro __GNUC_PREREQ which missed on Android => a workaround placed to "features.h":

Configuring command:
-> libpng OK OK OK A version of "libpng" used from CrystaX and built for Original NDK r13 by a configuring command:
-> jpeg OK OK OK A version of "libjpg" used from CrystaX. and built for Original NDK r13 by a configuring command:
--> expat OK OK OK Configuring command:
--> freetype OK OK OK Configuring command:
-> fontconfig OK OK OK Configure for proper folders of the fonts. Configuring command:

libfftw3, for UI.{Vision,WebVision} (opt), Special.FLibSYS (opt) OK OK OK Configuring command:
libiconv, for the core (opt) OK OK OK Successful built and used an external library. Configuring command:

Builtin one into CrystaX wrong and unfinished.
libintl (gettext), for the core (opt) OK OK OK configure.ac fixed to check symbol libintl_bindtextdomain into the library "libintl" and the symbol "libiconv_open" into the library "libiconv" checking before.
Successful built and used the external "libiconv".
Needed for "iconv" implementation but into CrystaX it is broken:
CRYSTAX_PANI: issetugid() not implemented!!!
Configuring command:
libcrypt (GlibC), for the core (opt) ?
libQt5, for UI.{QTStarter,QTCfg,Vision} OK OK OK Too specific for configuration and have some building's bugs, then it has fixed and adapted to architecture "armeabi-v7a-hard", for details see here. Due the problems with armeabi-v7a-hard the building was fully switched to armeabi-v7a but with parameters "-march=armv7-a -mfloat-abi=softfp -mfpu=vfp"!
Configuring command (hard-float):

Most the patched problems of building Qt5 has for Crystax NDK r10 and has not for Original NDK r13. Also Qt5 has significant problems of look (font's size and images show) at it building for hard-float! See details into the proper section.
Configuring command (soft-float):

OpenSCADA
Generic and the core library OK OK OK
  • Test for some different for C(EN) locale => successful for uk_UA.UTF-8.
  • Move the project AGLKS files to the device and try it from UI.WebVision.
  • Build mostly modules of OpenSCADA as separated "SO" and move them to a different folder.
  • Move all files of OpenSCADA to a separated folder. Prepare an environment to open external modules of OpenSCADA on an example of the module Special.SystemTests.
  • Performance tests executing for different options of the compiler.
  • Make the performance tests without "-mthumb".
  • Mostly modules included/builtin to the OpenSCADA core library.
  • The "pthread" library checking added by a macro AX_PTHREAD.
  • Core libraries moved from direct pointing to checking, for: -lm, -ldl, -lcrypt, -lz, -lpcre.
  • Some conditional definitions added for the program code:
    • ResAlloc: Check and define "__GLIBC_PREREQ" but into Android the LibC implementation Bionic; pthread_condattr_setclock() disabled for Android;
    • SYS: Needed parts moved from ieee754.h to the same file.
    • SYS: Multi CPU management and pthread_attr_setinheritsched() disabled for Android.
    • Mess: Messages encoding disabled for charset "US-ASCII", it's default one on Android.
    • Security: libcrypt checking expanded for crypt.h and to locked using for the function crypt().
    • Schedule: The core library name points straight into dlopen() for included/builtin modules but Bionic is wrong for the typical "NULL" into GLibC, by the definition "CoreLibNmToDlOpen".
DB.SQLite OK OK OK
  • Execute the DB tests.
  • Configure to store configuration here.
A version of "libpng" used from CrystaX and built for Original NDK r13 by a configuring command for version 3.8.7.1:
DB.DBF OK OK OK Execute the DB tests.
DAQ.JavaLikeCalc OK OK OK Performance tests.
DAQ.LogicLev OK OK OK -
DAQ.BlockCalc OK OK OK -
DAQ.DAQGate OK OK OK -
DAQ.System OK OK OK (as a module) Create an automatic controller object and see for what sources are allowed. Allowed types of sensors: "CPU", "Net statistic", "Memory", "HDD statistic", "Up time".
DAQ.ModBus OK OK OK -
DAQ.DCON OK OK OK -
DAQ.OPC_UA OK OK OK (as a module) Create an input transport, an endpoint and connect remotely to it. Adapted to include/builtin into the OpenSCADA core.
Archive.FSArch OK OK OK -
Archive.DBArch OK OK OK -
Transport.Sockets OK OK OK Configure an input transport to remote connect to it. The function getservbyname_r() switched to getservbyname() for Android.
Transport.Serial OK OK OK (as a module) - Checking for linux/serial.h added and for linux/i2c-dev.h fixed.
Transport.SSL OK OK OK Configure an input transport to remote connect to it.
  • "/tmp" folder missed then we must use some other here but tmpnam() uses itself => switched to a local file for Android.
  • The function getservbyname_r() switched to getservbyname() for Android.
Protocol.SelfSystem OK OK OK Remote connect to it. The dependence to "libcrypto" of OpenSSL moved to be optional.
Protocol.UserProtocol OK OK OK -
Protocol.HTTP OK OK OK -
UI.VCAEngine OK OK OK (as a module)
UI.QTStarter OK OK OK (as a module) Adapt to start up from JNI.
UI.QTCfg OK OK OK (as a module)
UI.Vision OK OK OK (as a module)
UI.WebCfg OK OK OK (as a module)
UI.WebCfgD OK OK OK (as a module) Move the images to the OpenSCADA folder and try its and the module. A strong dependence from GD removed.
UI.WebVision OK OK OK (as a module) The library LibGD test on a trend of the primitive "Diagram" and a widget of the primitive "ElFigure" of the project AGLKS. Dependence to LibGD expanded by: -lpng -ljpeg -lfontconfig -lexpat -lfreetype
UI.WebUser OK OK OK (as a module)
Special.FLibSYS OK OK OK - Conditional test and using to SSL, for md5().
Special.SystemTests OK OK OK (as a module)
Special.FLibMath OK OK OK (as a module) Performance tests.
Special.FLibComplex1 OK OK OK (as a module)

In process of adaptation OpenSCADA to work on Android there was performed the significant approaches into the "autotool" based build environment OpenSCADA which can help further for adaption to work on other software platforms:

Qt5

Qt5 is cross-platform GUI toolkit and framework which historically used into OpenSCADA only as a GUI toolkit into Qt-based modules. Qt5 is a complex one and it has different problems on different versions and building options. For build examples of Qt5 next procedure was used.


Followed table represents problems of different version of Qt5 represented on an example "icons":
Version Options Problems
5.7 soft-float Equal to versions 5.8 and 5.9 but have problems at installing where it tries install to "/var".
5.8 GCC 5 Font is normal into bookmarks of the file dialog. May be it is generic problem into 5.7 5.8, (GCC 4.9), 5.9.
5.7, 5.8, 5.9 hard-float All Qt icons miss or too small.
5.9 CrystaX NDK r10, GCC 5 Build error by StdLib C++ some difference:

Appending B. Extended performance tests on Asus Nexus7 II (Qualcomm Snapdragon APQ8064-1AA, Cortex-A15, 1.5 GHz, 4 Cores)

Test Operation sin(Pi), us , into JavaLikeCalc Operation pow(Pi,2), us , into JavaLikeCalc liboscada.so, MiB
armv5te, Soft, VFP2 0.9 1.58 0.15 0.88 13.79
armv5te, Soft, NEON 0.87 1.65 0.14 0.95 13.79
armv5te, Soft, NEON, Thumb 0.88 1.5 0.14 0.9 13
armv7-a, Soft, VFP 0.161 0.803 0.126 0.838 5.9
armv7-a, Hard, VFP2 0.162 0.776 0.138 0.844 13.85
armv7-a, Hard, NEON 0.168 0.793 0.123 0.854 13.85
armv7-a, Hard, NEON, Thumb 0.17 0.85 0.15 0.87 12.82

Appending A. List of the generic progress of the task


+ purchase a modern internet tablet with Android;
+ read a book about Android NDK, using of Android NDK and Crystalx-NDK;
+ compiling for tests, education and execution;
+ initially (minimum) build and execute OpenSCADA for console (without GUI): PCRE, OpenSCADA Core, builtin modules: Transport.Sockets, Protocol.SelfSystem, DAQ.JavaLikeCalc, Special.FLibMath;
+ make the performance tests for Soft and Hard float;
+ compile for all OpenSCADA key modules to include/builtin them into the core;
+ compile for needed external libraries: OpenSSL, SQLite, GD [expat,libpng,jpeg,fontconfig,freetype], intl, iconv;
+ rebuild all already built parts into the original Ndk (outward the standalone one);
+ build Qt5: in the default configuration, with the early built libraries;
+ initial build OpenSCADA with Qt5;
+ build and observe an example of Qt5 as a Java package (APK);
+ adapt OpenSCADA to Qt5 on Android and build as a Java package (APK); get the program's locale from Java environment and set it to environment LANG;
+ the Java package (APK) resolve for different data files placing and fill in by: OpenSCADA icon and main images, configuration files, files of translation of the interface, files of DB and other of the libraries and models;
+ OpenSCADA main functions related to Qt restore and fix: Qt5 builds with soft-float but hard-float causes the mostly problems; two branches were created, based on CrystaX NDK r10 (from ABI 19) and Original Ndk r13 (from ABI 21); default interface style was set to "fusion";
- Some Android specific expandings of the project OpenSCADA: