Tuesday, December 7, 2021

JPL Toolkit on Termux in a cheap chinese smartphone

My laziness is unforgivable. Even if I rarely have some interesting news to offer to readers (as you can see from the following lines, I'm still deeply interested in exploring basic planetary position calculus from an astrological point of view, and I have already talked a lot about JPL toolkit), once in a while I feel the urge to communicate what I have learnt to anyone who can be find some interest in it. Something has changed, however. First of all, I'm going to write next posts in plain English because most of my readers are from abroad, google translator does a good job, but anyway ...

Another important novelty is the fact that I have totally abandoned Python 2, because it is deprecated and Python ver 3 is much richer and interesting. Most of my post in the past utilized the versions 2, I'll try to upgrade them every time it's necessary. But let's talk again about the JPL toolkit, which is the de facto standard for astronomical calculations. Many astrological softwares are based upon the Swiss Ephemeris, which are C libraries that make use of the jpl ephemeris, so I think it's better go with the original, as the development of software with the Swisseph is free only for non commercial products. As you could appreciate from my past posts, building a shared library from the C NASA routines is relatively straightforward, so why not use it? Let's recapitulate the fundamentals, and then let's implement the necessary routines on a specific debian-like platform, named TERMUX, which is usable on most cheap smartphones (mine is Meizu M5 Note, 64bit Arm Android 7 based, rather old phone, but it's fine for my purposes). No need to root your device, you can use it as it is, so you won't have any problem with your bank application or other institutional ones.

Main installation

To install Termux, forget about Google store, the app is unmantained. Install F-Droid app on your Android phone, than download the Termux apk from the F-Droid repository, it's easily recognizable from its icon:

Now launch the application from your screen. You will be welcomed to Termux and you'll see something like this photo:

The keyboard you see in the photo is the Hacker's Keyboard, you can install it from Play Store, but feel free to use the one you feel most comfortable with

Now let's do a few maintaining tasks. At prompt type:

pkg install root-repo
apt update
apt upgrade -y
apt install build-essential binutils wget openssh

N.B.: all four arguments in one line

build-essential and binutils are the minimum tools required to perform compilation and linking, wget is aimed at downloading files from the web, openssh is needed to install a ssh server on our phone.

If you see an error message like "The following signatures couldn't be verified because the public key is not available", don't worry. Write the command termux-change-repo, press enter and select the main repository, than the default repository or any one in the list, than repeat the commands.

To have access to the phone memory, use the following command:

termux-setup-storage and press enter

in your home directory, type ls and you'll see a new storage subdirectory, which contains the access to the main directories used by your phone during normal usage, the most important is storage/downloads. We'll use it later

Create a ssh connection from PC

As you may have ascertained, it's rather difficult to use a phone keyboard. To make this stuff easy, let's give access to Termux to your computer.

If you have installed, as in my previous instructions, the package openssh, it's a matter of seconds activating a ssh access to your phone. Type sshd and press enter. Remember: by default the ssh port in Termus is 8022, not 22.

Now you must find your phone coordinates: type whoami and press enter, this give you your identity, mine, in this exact moment, is u0_a119.

Create a password for ssh: type passwd and press enter. You will be prompted to type a password, then to retype it. Don't create a read only password, if you are prompted to do so.

Connect your phone to your home LAN, and get its address by typing ip addr and pressing enter. Under a long list of devices, you'll find and address like 192.168.1.120 or similar, the most important part are the first two numbers 192.168. Write the full address down, it's your ip coordinate in the LAN.

Now in your PC type in a terminal emulator (cmd in Windows, any terminal available in Linux or Mac): ssh u0_a119@192.168.1.120 -p 8022. Of course, change the argument to represent your real coordinates. If all is fine, you'll be within your phone home directory. You'll receive a warm welcome message, identical to the one you have already seen opening Termux. Hooray! Every new command you'll be typing in your PC terminal, will be executed in your phone memory.

Get the right JPL source

From your browser go to the following web page:

NAIF toolkit C sources.

Browse the following link:

PC, CYGWIN, gCC, 64bit

A new page will open, copy the link address of cspice.tar.gz (if you don't know how to do right click the link and copy the address, not the string).

Then in the Termux terminal you just opened type wget <paste here your link address>

After the download has finished (it will take a while), you will find a cspice.tar.gz file in your home directory

Same procedure for the file importCspice.csh, until you see it in your directory next to the .gz file

Now install tcsh, it's the shell you need to perform some fundamental operations. Type in your terminal apt install tcsh and press enter

Almost done. Unzip your cspice.tar.gz with gunzip cspice.tar.gz, your file is now named cspice.tar

Type tcsh importCSpice.csh and let the script do its job, it will take some time, ignore warnings, and wait until you see the message Toolkit Build Complete.

Where do we go from here?

As I told you a few years ago, the just finished compilation produces a lot of useful function to work with ephemeris files and a static library, not exactly the one we need.

In the upcoming posts we will talk about the creation of a dynamic C library and the linking of it in a basic C program, and how to bind it from a python3 script. In the following posts we will find a way to use these new libraries in a graphical setting, something similar to a true Android application. Let me know if the procedures described in this page are good for you or if you need some help. See you soon ...

No comments:

Post a Comment

How to create a virtual linux machine with qemu under Debian or Ubuntu with near native graphics performance

It's been a long time since my latest post. I know, I'm lazy. But every now and then I like to publish something that other people c...