eata2ew

Custom Earthworm module to collect data from Earthdata PR6-24 digitizer through serial line.

 

ver. 1.1a

Changes:
- enabled Earthworm routines (disable #define standalone in code)
- added reading and parsing channel/location names
- added debug level
- added control number of channels in received data block vs. channels in configurazione file
- enabled transmission of data to Earthworm shared memory
- enabled other bitrates than 115200
- tested on Earthworm 7.10 (Raspberry Raspbian 10) with PL2302 usb-to-serial adapter

edata2ew_v_1_1a.tar.gz

 

 

pi@raspberrypi:~/ew/earthworm_7.10/src/data_sources $ wget crsengineering.altervista.org/ew/earthdata/edata2ew/edata2ew_v_1_1a.tar.gz
--2021-05-26 08:21:04-- http://crsengineering.altervista.org/ew/earthdata/edata2ew/edata2ew_v_1_1a.tar.gz
Resolving crsengineering.altervista.org (crsengineering.altervista.org)... 136.243.138.245
Connecting to crsengineering.altervista.org (crsengineering.altervista.org)|136.243.138.245|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 52307 (51K) [application/x-tar]
Saving to: ‘edata2ew_v_1_1a.tar.gz.1’

edata2ew_v_1_1a.tar.gz.1 100%[======================================================================================================================================================================================================================================================================================================================>] 51.08K 239KB/s in 0.2s

2021-05-26 08:21:05 (239 KB/s) - ‘edata2ew_v_1_1a.tar.gz.1’ saved [52307/52307]

pi@raspberrypi:~/ew/earthworm_7.10/src/data_sources $ tar -xzvf edata2ew_v_1_1a.tar.gz
edata2ew_v_1_1a/
edata2ew_v_1_1a/edata2ew_1_0a.c
edata2ew_v_1_1a/edata2ew.desc
edata2ew_v_1_1a/edata2ew_1_0b.c
edata2ew_v_1_1a/globalvars.h
edata2ew_v_1_1a/makefile.unix
edata2ew_v_1_1a/chron3.c
edata2ew_v_1_1a/edata2ew_tty.d
edata2ew_v_1_1a/edata.h
edata2ew_v_1_1a/edata2ew.c
edata2ew_v_1_1a/chron3.h
pi@raspberrypi:~/ew/earthworm_7.10/src/data_sources $ mv edata2ew_v_1_1a edata2ew
pi@raspberrypi:~/ew/earthworm_7.10/src/data_sources $ cd edata2ew/
pi@raspberrypi:~/ew/earthworm_7.10/src/data_sources/edata2ew $

Then compile:

pi@raspberrypi:~/ew/earthworm_7.10/src/data_sources/edata2ew $ make -f makefile.unix
gcc -g -pthread -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unknown-pragmas -Wno-pragmas -Wformat -Wdeclaration-after-statement -D_LINUX -Dlinux -D_INTEL -D_USE_SCHED -D_USE_PTHREADS -D_USE_TERMIOS -D_FILE_OFFSET_BITS=64 -I/home/pi/ew/earthworm_7.10/include -Wno-implicit-int -Wno-unused-variable -Wno-format-contains-nul -g -D_LINUX -Dlinux -D_INTEL -D_USE_SCHED -D_USE_PTHREADS -D_USE_TERMIOS -D_FILE_OFFSET_BITS=64 -I/home/pi/ew/earthworm_7.10/include -c -o edata2ew.o edata2ew.c
edata2ew.c: In function ‘main’:
edata2ew.c:385:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
unsigned char t;
^~~~~~~~
edata2ew.c:550:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
unsigned short checksum, chkcmp;
^~~~~~~~
edata2ew.c: In function ‘edata2ew_PrintConfig’:
edata2ew.c:1949:113: warning: array subscript has type ‘char’ [-Wchar-subscripts]
logit("","\tch#%d = %s.%s.%s.%s\r\n", (i+1), SystemConfig.NetworkName, SystemConfig.StationCode, Traces.trace[i].cmp, Traces.trace[i].loc);
^
edata2ew.c:1949:134: warning: array subscript has type ‘char’ [-Wchar-subscripts]
logit("","\tch#%d = %s.%s.%s.%s\r\n", (i+1), SystemConfig.NetworkName, SystemConfig.StationCode, Traces.trace[i].cmp, Traces.trace[i].loc);
^
gcc -o /home/pi/ew/earthworm_7.10/bin/edata2ew -g -pthread -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unknown-pragmas -Wno-pragmas -Wformat -Wdeclaration-after-statement -D_LINUX -Dlinux -D_INTEL -D_USE_SCHED -D_USE_PTHREADS -D_USE_TERMIOS -D_FILE_OFFSET_BITS=64 -I/home/pi/ew/earthworm_7.10/include -Wno-implicit-int -Wno-unused-variable -Wno-format-contains-nul -g edata2ew.o -L/home/pi/ew/earthworm_7.10/lib -lew_mt -lm -lpthread
pi@raspberrypi:~/ew/earthworm_7.10/src/data_sources/edata2ew $

On edata2ew_tty.d you can set main parameters such tty port, bitrate, and station configuration (network, station code, channels, locations).

ModuleId MOD_EDATA2EW 		# module id for this import
RingName WAVE_RING 		# transport ring to use for input/output

LogFile 1 			# If 0, don't output to logfile; if 1, do
				# if 2, log to module log but not stderr/stdout

HeartbeatInterval 30 		# Heartbeat interval in seconds


TtyName /dev/ttyUSB0 		# TTY port for edata
Speed 115200 			# baud rate (default 115200, fixed value, it can only work )


StationCode SEAB 		# Assign a station code to the TRACEBUF packets
			 

ChannelNames HHE,HHN,HHZ 	# Assign channel names
				# to the TRACEBUF packets. The list can be
				# delimited by commas or spaces.

Network NC 			# Network name for EW msg headers


# LocationNames 01,01,01 	# Assign location codes to
				# the TRACEBUF packets emitted by edata2ew.
				# Otherwise, default location code
				# will be assigned; currently "--"




#Debug 4 			# debug level: 0 or commented out for no debug
				# logging; 1 - 4 for increasing verbosity
				# default: no debug output

 

 

 

After sterted Earthworm you can run a test (here with debuglevel 4):

pi@raspberrypi:~/ew/earthworm_7.10/src/data_sources/edata2ew $ edata2ew edata2ew_tty.d
[edata2ew] Read configuration file...
Edata2EW configuration:
sw. ver.: 1.1a
serial port: /dev/ttyUSB0
bitrate: 115200 [bit/s]
station code: SEAB
station network: NC
found MOD packet (192 bytes) ...
found DATA packet...
found SUM packet...
let's check checksum...
checksum pass!
components: 3
100 SPS, 4 bytes/sample
block timestamp (from MOD.ltime): 1003331242 seconds
updated time: 1622646442 seconds
2021Jun 2 1507 22.00 UTC
1200 samples on current block (@300 SPS)...
sending trace SEAB.HHE.NC.-- (100) [1622646442.000 --> 1622646442.990]
...success!
sending trace SEAB.HHN.NC.-- (100) [1622646442.000 --> 1622646442.990]
...success!
sending trace SEAB.HHZ.NC.-- (100) [1622646442.000 --> 1622646442.990]
...success!
found MOD packet (192 bytes) ...
found DATA packet...
found SUM packet...
let's check checksum...
checksum pass!
block timestamp (from MOD.ltime): 1003331243 seconds
updated time: 1622646443 seconds
2021Jun 2 1507 23.00 UTC
1200 samples on current block (@300 SPS)...
sending trace SEAB.HHE.NC.-- (100) [1622646443.000 --> 1622646443.990]
...success!
sending trace SEAB.HHN.NC.-- (100) [1622646443.000 --> 1622646443.990]
...success!
sending trace SEAB.HHZ.NC.-- (100) [1622646443.000 --> 1622646443.990]
...success!
found MOD packet (192 bytes) ...
found DATA packet...
found SUM packet...
let's check checksum...
checksum pass!
block timestamp (from MOD.ltime): 1003331244 seconds
updated time: 1622646444 seconds
2021Jun 2 1507 24.00 UTC
1200 samples on current block (@300 SPS)...
sending trace SEAB.HHE.NC.-- (100) [1622646444.000 --> 1622646444.990]
...success!
sending trace SEAB.HHN.NC.-- (100) [1622646444.000 --> 1622646444.990]
...success!
sending trace SEAB.HHZ.NC.-- (100) [1622646444.000 --> 1622646444.990]
...success!

And here check if it's running (don't be scared about latency, it's due to my OS wrong time):

pi@raspberrypi:~/ew/run/params $ sniffwave WAVE_RING
Sniffing WAVE_RING for wild.wild.wild.wild
sniffwave: inRing flushed 99 packets of 45936 bytes total.
sniffwave: Gap in sequence numbers
SEAB.HHE.NC.-- (0x0 0x0) 0 i4 100 100.0 2021/06/02 15:07:22.00 (1622646442.0000) 2021/06/02 15:07:22.99 (1622646442.9900) i255 m156 t19 len 464 [D:-632547.54s F: 0.0s]
SEAB.HHN.NC.-- (0x0 0x0) 0 i4 100 100.0 2021/06/02 15:07:22.00 (1622646442.0000) 2021/06/02 15:07:22.99 (1622646442.9900) i255 m156 t19 len 464 [D:-632547.54s F: 0.0s]
SEAB.HHZ.NC.-- (0x0 0x0) 0 i4 100 100.0 2021/06/02 15:07:22.00 (1622646442.0000) 2021/06/02 15:07:22.99 (1622646442.9900) i255 m156 t19 len 464 [D:-632547.54s F: 0.0s]
SEAB.HHE.NC.-- (0x0 0x0) 0 i4 100 100.0 2021/06/02 15:07:23.00 (1622646443.0000) 2021/06/02 15:07:23.99 (1622646443.9900) i255 m156 t19 len 464 [D:-632547.54s F: 1.0s]
SEAB.HHN.NC.-- (0x0 0x0) 0 i4 100 100.0 2021/06/02 15:07:23.00 (1622646443.0000) 2021/06/02 15:07:23.99 (1622646443.9900) i255 m156 t19 len 464 [D:-632547.54s F: 1.0s]
SEAB.HHZ.NC.-- (0x0 0x0) 0 i4 100 100.0 2021/06/02 15:07:23.00 (1622646443.0000) 2021/06/02 15:07:23.99 (1622646443.9900) i255 m156 t19 len 464 [D:-632547.54s F: 1.0s]
SEAB.HHE.NC.-- (0x0 0x0) 0 i4 100 100.0 2021/06/02 15:07:24.00 (1622646444.0000) 2021/06/02 15:07:24.99 (1622646444.9900) i255 m156 t19 len 464 [D:-632547.54s F: 1.0s]
SEAB.HHN.NC.-- (0x0 0x0) 0 i4 100 100.0 2021/06/02 15:07:24.00 (1622646444.0000) 2021/06/02 15:07:24.99 (1622646444.9900) i255 m156 t19 len 464 [D:-632547.54s F: 1.0s]
SEAB.HHZ.NC.-- (0x0 0x0) 0 i4 100 100.0 2021/06/02 15:07:24.00 (1622646444.0000) 2021/06/02 15:07:24.99 (1622646444.9900) i255 m156 t19 len 464 [D:-632547.54s F: 1.0s]

Now you can set debug level to 0 and use module.

 

 

 

 

ver. 1.0a

Initial release, for test purposes only:
- read data from serial port
- checksum on received serial packets
- extracting data from serial stream
- simulating transmission to Earthworm ring (automatic timing correction for GPS week rollover)
- tested on Earthworm 7.8 (Ubuntu 16.04.1) and Earthworm 7.10 (Raspberry Raspbian 10) with PL2302 usb-to-serial adapter

edata2ew_1_0a.tar.gz

On edata2ew_tty.d you can set main parameters such tty port and bitrate.
 

TtyName /dev/ttyUSB0 	# TTY port for edata
Speed 	115200 		# baud rate (default 115200)

 

Extract archive on ~/ew/earthworm_7.10/src/data_sources (you'll find new folder edata2ew), then make -f makefile.unix clean and  make -f makefile.unix:

 

pi@raspberrypi:~/ew/earthworm_7.10/src/mycustom/edata2ew $ make -f makefile.unix
gcc -g -pthread -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unknown-pragmas -Wno-pragmas -Wformat -Wdeclaration-after-statement -D_LINUX -Dlinux -D_INTEL -D_USE_SCHED -D_USE_PTHREADS -D_USE_TERMIOS -D_FILE_OFFSET_BITS=64 -I/home/pi/ew/earthworm_7.10/include -Wno-implicit-int -Wno-format-contains-nul -g -D_LINUX -Dlinux -D_INTEL -D_USE_SCHED -D_USE_PTHREADS -D_USE_TERMIOS -D_FILE_OFFSET_BITS=64 -I/home/pi/ew/earthworm_7.10/include -c -o edata2ew.o edata2ew.c
edata2ew.c: In function ‘main’:
edata2ew.c:342:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
unsigned char t;
^~~~~~~~
edata2ew.c:421:15: warning: pointer targets in assignment from ‘char *’ to ‘unsigned char *’ differ in signedness [-Wpointer-sign]
DATA_ptr = RxBuffer_ptr;
^
edata2ew.c:434:14: warning: pointer targets in assignment from ‘char *’ to ‘unsigned char *’ differ in signedness [-Wpointer-sign]
SUM_ptr = RxBuffer_ptr; // get pointer copy for checksum (later)
^
edata2ew.c:470:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
unsigned short checksum, chkcmp;
^~~~~~~~
edata2ew.c:473:24: warning: comparison of distinct pointer types lacks a cast
while(RxBuffer_ptr < SUM_ptr)
^
edata2ew.c:598:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("%d samples on current block (@%d SPS)...\r\n", block_DATA.SizeofDAT, DeviceConfig.sample_rate);
~^ ~~~~~~~~~~~~~~~~~~~~
%ld
edata2ew.c:342:16: warning: unused variable ‘t’ [-Wunused-variable]
unsigned char t;
^
edata2ew.c:241:27: warning: unused variable ‘rb_counter’ [-Wunused-variable]
static int rc,cb_rc, rb, rb_counter;
^~~~~~~~~~
edata2ew.c:241:23: warning: unused variable ‘rb’ [-Wunused-variable]
static int rc,cb_rc, rb, rb_counter;
^~
edata2ew.c:241:16: warning: unused variable ‘cb_rc’ [-Wunused-variable]
static int rc,cb_rc, rb, rb_counter;
^~~~~
edata2ew.c:241:13: warning: unused variable ‘rc’ [-Wunused-variable]
static int rc,cb_rc, rb, rb_counter;
^~
edata2ew.c:237:13: warning: unused variable ‘reclogo’ [-Wunused-variable]
MSG_LOGO reclogo; // logo of retrieved message
^~~~~~~
edata2ew.c:236:13: warning: unused variable ‘recsize’ [-Wunused-variable]
long recsize; // size of retrieved message
^~~~~~~
edata2ew.c:235:14: warning: unused variable ‘timeLastBeat’ [-Wunused-variable]
time_t timeLastBeat; // time last heartbeat was sent
^~~~~~~~~~~~
edata2ew.c:234:10: warning: unused variable ‘timeNow’ [-Wunused-variable]
time_t timeNow; // current system time
^~~~~~~
At top level:
edata2ew.c:241:13: warning: ‘rc’ defined but not used [-Wunused-variable]
static int rc,cb_rc, rb, rb_counter;
^~
edata2ew.c:241:16: warning: ‘cb_rc’ defined but not used [-Wunused-variable]
static int rc,cb_rc, rb, rb_counter;
^~~~~
edata2ew.c:241:23: warning: ‘rb’ defined but not used [-Wunused-variable]
static int rc,cb_rc, rb, rb_counter;
^~
edata2ew.c:241:27: warning: ‘rb_counter’ defined but not used [-Wunused-variable]
static int rc,cb_rc, rb, rb_counter;
^~~~~~~~~~
edata2ew.c:701:22: warning: ‘nLOC’ defined but not used [-Wunused-variable]
static unsigned char nLOC = 0; // contatore location attive
^~~~
edata2ew.c:204:13: warning: ‘msg_txt’ defined but not used [-Wunused-variable]
static char msg_txt[180];
^~~~~~~
edata2ew.c:196:14: warning: ‘Text’ defined but not used [-Wunused-variable]
static char Text[150]; /* string for log/error messages */
^~~~
edata2ew.c:128:13: warning: ‘Buffer’ defined but not used [-Wunused-variable]
static char Buffer[BUF_SIZE]; /* character string to hold event message */
^~~~~~
gcc -o /home/pi/ew/earthworm_7.10/bin/edata2ew -g -pthread -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unknown-pragmas -Wno-pragmas -Wformat -Wdeclaration-after-statement -D_LINUX -Dlinux -D_INTEL -D_USE_SCHED -D_USE_PTHREADS -D_USE_TERMIOS -D_FILE_OFFSET_BITS=64 -I/home/pi/ew/earthworm_7.10/include -Wno-implicit-int -Wno-format-contains-nul -g edata2ew.o /home/pi/ew/earthworm_7.10/lib/lockfile.o /home/pi/ew/earthworm_7.10/lib/lockfile_ew.o -L/home/pi/ew/earthworm_7.10/lib -lew_mt -lm -lpthread
pi@raspberrypi:~/ew/earthworm_7.10/src/mycustom/edata2ew $ 

 

Let's say you already set edata2ew_tty.d, then:

 

pi@raspberrypi:~/ew/earthworm_7.10/src/mycustom/edata2ew $ edata2ew edata2ew_tty.d
sptr = <ChannelNames HHE,HHN,HHZ, HXY # Assign channel names>
strlen 1 = 60
strlen 2 = 48
stmnum = 0 @4
stmnum = 1 @8
stmnum = 2 @12
stmnum = 3 @17
[edata2ew] Read configuration file...
Edata2EW configuration:
sw. ver.: 1.0a
serial port: /dev/ttyUSB0
bitrate: 115200 [bit/s]
station code: SEAB
station network: NC
set bitrate to 115200...
puntatore porta seriale <4> su /dev/ttyUSB0
found MOD packet (192 bytes) ...
found DATA packet...
found SUM packet...
let's check checksum...
checksum pass!
components: 3
100 SPS, 4 bytes/sample
block timestamp (from MOD.ltime): 1003275920 seconds
updated time: 1622591120 seconds
20210601234520.00 UTC
1200 samples on current block (@300 SPS)...
sending trace SEAB.ch1.NC.-- (100) [1622591120.000 --> 1622591120.990]
sending trace SEAB.ch2.NC.-- (100) [1622591120.000 --> 1622591120.990]
sending trace SEAB.ch3.NC.-- (100) [1622591120.000 --> 1622591120.990]
found MOD packet (192 bytes) ...
found DATA packet...
found SUM packet...
let's check checksum...
checksum pass!
block timestamp (from MOD.ltime): 1003275921 seconds
updated time: 1622591121 seconds
20210601234521.00 UTC
1200 samples on current block (@300 SPS)...
sending trace SEAB.ch1.NC.-- (100) [1622591121.000 --> 1622591121.990]
sending trace SEAB.ch2.NC.-- (100) [1622591121.000 --> 1622591121.990]
sending trace SEAB.ch3.NC.-- (100) [1622591121.000 --> 1622591121.990]
^C
pi@raspberrypi:~/ew/earthworm_7.10/src/mycustom/edata2ew $

Obviously, please don't take care of many errors and debug messages you'll find in code....

In example above I set station code to SEAB, network to NC: I collect 3 channels per data packet (channels 1,2,3) at 100 SPS (so 300 samples/packet), I read (wrong) data due I have an old GPS so after a little check I add rollover offset (1024 weeks).
 

Here logfile create by Earthworm routines:

pi@raspberrypi:~/ew/earthworm_7.10/src/mycustom/edata2ew $ cat $EW_LOG/edata2ew_tty_20210525.log
-------------------------------------------------------
edata2ew_tty: startup at UTC_20210525_16:02:50
This program is using the MT-Safe version of logit.
-------------------------------------------------------
edata2ew ver.1.0a
edata2ew: Read command file <edata2ew_tty.d>
serial port /dev/ttyUSB0 (@115200 bit/s)
Station: NC.SEAB
found device: ED 2400-270
ver.: V02.26
S/N: #1114
channels: 3
sampling rate: 100 SPS (4 bytes/sample)