Commit f9515d84 authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Optional libmseed


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@102 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 61622526
......@@ -166,6 +166,9 @@ int nmxp_data_parse_date(const char *pstr_date, struct tm *ret_tm);
time_t nmxp_data_tm_to_time(struct tm *tm);
/* THIS DO NOT WORK ;-) */
#ifdef HAVE_LIBMSEED
/*! \brief Initialize a structure NMXP_DATA_SEED
*
* \param data_seed Pointer to a NMXP_DATA_SEED structure.
......@@ -184,12 +187,14 @@ int nmxp_data_seed_init(NMXP_DATA_SEED *data_seed);
*/
int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed);
#endif
/*! \brief Swap 2 bytes.
*
* \param in Variable length 2 bytes.
*
* */
*/
void nmxp_data_swap_2b (int16_t *in);
......@@ -197,7 +202,7 @@ void nmxp_data_swap_2b (int16_t *in);
*
* \param in Variable length 3 bytes.
*
* */
*/
void nmxp_data_swap_3b (unsigned char *in);
......@@ -205,7 +210,7 @@ void nmxp_data_swap_3b (unsigned char *in);
*
* \param in Variable length 4 bytes.
*
* */
*/
void nmxp_data_swap_4b (int32_t *in);
......@@ -213,9 +218,20 @@ void nmxp_data_swap_4b (int32_t *in);
*
* \param in Variable length 8 bytes.
*
* */
*/
void nmxp_data_swap_8b (int64_t *in);
/*! \brief Determine the byte order of the host machine.
* Due to the lack of portable defines to determine host byte order this
* run-time test is provided. The code below actually tests for
* little-endianess, the only other alternative is assumed to be big endian.
*
* \retval 0 if the host is little endian.
* \retval 1 otherwise.
*/
int nmxp_data_bigendianhost ();
#endif
......@@ -11,6 +11,8 @@
#include "nmxp.h"
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......
......@@ -24,7 +24,11 @@
#include <time.h>
#include <unistd.h>
#include "config.h"
#ifdef HAVE_LIBMSEED
#include <libmseed.h>
#endif
int nmxp_openSocket(char *hostname, int portNum)
......@@ -335,7 +339,7 @@ NMXP_DATA_PROCESS *nmxp_processCompressedDataFunc(char* buffer_data, int length_
int prev_xn;
// TOREMOVE int my_order = get_my_wordorder();
int my_host_is_bigendian = ms_bigendianhost();
int my_host_is_bigendian = nmxp_data_bigendianhost();
nmxp_log(0, 1, "my_host_is_bigendian %d\n", my_host_is_bigendian);
memcpy(&nmx_oldest_sequence_number, buffer_data, 4);
......
......@@ -17,7 +17,11 @@
#include <string.h>
#include <errno.h>
#include "config.h"
#ifdef HAVE_LIBMSEED
#include <libmseed.h>
#endif
int nmxp_data_init(NMXP_DATA_PROCESS *pd) {
......@@ -48,7 +52,7 @@ int nmxp_data_unpack_bundle (int *outdata, unsigned char *indata, int *prev)
int i, j, k=0;
unsigned char cbits;
/* TOREMOVE int my_order = get_my_wordorder(); */
int my_host_is_bigendian = ms_bigendianhost();
int my_host_is_bigendian = nmxp_data_bigendianhost();
cbits = (unsigned char)indata[0];
if (cbits == 9) return (-1);
......@@ -394,6 +398,8 @@ int nmxp_data_seed_init(NMXP_DATA_SEED *data_seed) {
return 0;
}
#ifdef HAVE_LIBMSEED
/* Private function for writing mini-seed records */
static void nmxp_data_msr_write_handler (char *record, int reclen, void *pdata_seed) {
NMXP_DATA_SEED *data_seed = pdata_seed;
......@@ -406,6 +412,7 @@ int nmxp_data_seed_init(NMXP_DATA_SEED *data_seed) {
}
}
int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed) {
int ret =0;
......@@ -432,7 +439,7 @@ int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed) {
msr->encoding = DE_STEIM1; /* Steim 1 compression */
// TODO
// msr->byteorder = 0; /* big endian byte order */
msr->byteorder = ms_bigendianhost ();
msr->byteorder = nmxp_data_bigendianhost ();
int sizetoallocate = sizeof(int) * (pd->nSamp + 1);
msr->datasamples = malloc (sizetoallocate);
......@@ -453,6 +460,8 @@ int nmxp_data_msr_pack(NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed) {
return ret;
}
#endif
void nmxp_data_swap_2b (int16_t *in) {
......@@ -502,3 +511,8 @@ void nmxp_data_swap_8b (int64_t *in) {
*(p+4) = tmp;
}
int nmxp_data_bigendianhost () {
int16_t host = 1;
return !(*((int8_t *)(&host)));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment