- Main Page
- Classes
- Files
- Related Pages

# include/nmxp_data.h File Reference

Data for Nanometrics Protocol Library. More...

`#include <stdint.h>`
`#include <stdio.h>`
`#include <time.h>`

Include dependency graph for nmxp_data.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Classes
struct | NMXP_TM_T
| struct tm plus ten thousandth second field More...
struct | NMXP_MESSAGE_HEADER
| Header for all messages. More...
struct | NMXP_DATA_PROCESS
| Parameter structure for functions that process data. More...
struct | NMXP_DATA_SEED
| Parameter structure for functions that handle mini-seed records. More...
## Defines
#define | NMXP_DATA_H 1
#define | NMX_SIGNATURE 0x7abcde0f
#define | NMXP_DATA_IS_LEAP(yr) ( yr%400==0 || (yr%4==0 && yr%100!=0) )
#define | NETWORK_LENGTH 10
| Length in bytes of channel strings.
#define | STATION_LENGTH 10
| Length in bytes of station strings.
#define | CHANNEL_LENGTH 10
| Length in bytes of channel strings.
#define | NMXP_DATA_TRIM_EXCLUDE_FIRST 2
#define | NMXP_DATA_TRIM_EXCLUDE_LAST 4
## Enumerations
enum | NMXP_SHUTDOWN_REASON { NMXP_SHUTDOWN_NORMAL = 1, NMXP_SHUTDOWN_ERROR = 2, NMXP_SHUTDOWN_TIMEOUT = 3 }
| Defines the type for reason of shutdown. More...
enum | NMXP_MSG_CLIENT { NMXP_MSG_CONNECT = 100, NMXP_MSG_REQUESTPENDING = 110, NMXP_MSG_CANCELREQUEST = 205, NMXP_MSG_TERMINATESUBSCRIPTION = 200, NMXP_MSG_ADDTIMESERIESCHANNELS = 120, NMXP_MSG_ADDSOHCHANNELS = 121, NMXP_MSG_ADDSERIALCHANNELS = 124, NMXP_MSG_ADDTRIGGERCHANNELS = 122, NMXP_MSG_ADDEVENTS = 123, NMXP_MSG_REMOVETIMESERIESCHANNELS = 130, NMXP_MSG_REMOVESOHCHANNELS = 131, NMXP_MSG_REMOVESERIALCHANNELS = 134, NMXP_MSG_REMOVETRIGGERCHANNELS = 132, NMXP_MSG_REMOVEEVENTS = 133, NMXP_MSG_CONNECTREQUEST = 206, NMXP_MSG_CHANNELLISTREQUEST = 209, NMXP_MSG_PRECISLISTREQUEST = 203, NMXP_MSG_CHANNELINFOREQUEST = 226, NMXP_MSG_DATASIZEREQUEST = 229, NMXP_MSG_DATAREQUEST = 227, NMXP_MSG_TRIGGERREQUEST = 231, NMXP_MSG_EVENTREQUEST = 232 }
| Defines the client message types. More...
enum | NMXP_MSG_SERVER { NMXP_MSG_CHANNELLIST = 150, NMXP_MSG_ERROR = 190, NMXP_MSG_COMPRESSED = 1, NMXP_MSG_DECOMPRESSED = 4, NMXP_MSG_TRIGGER = 5, NMXP_MSG_EVENT = 6, NMXP_MSG_READY = 208, NMXP_MSG_PRECISLIST = 253, NMXP_MSG_CHANNELHEADER = 256, NMXP_MSG_DATASIZE = 257, NMXP_MSG_NAQSEVENT = 260, NMXP_MSG_NAQSTRIGGER = 259 }
| Defines the server message types. More...
## Functions
int | nmxp_data_init (NMXP_DATA_PROCESS *pd)
| Initialize a structure NMXP_DATA_PROCESS.
int | nmxp_data_unpack_bundle (int32_t *outdata, unsigned char *indata, int32_t *prev)
| Unpack a 17-byte Nanometrics compressed data bundle.
int | nmxp_data_to_str (char *out_str, double time_d)
| Convert epoch in string.
int | nmxp_data_trim (NMXP_DATA_PROCESS *pd, double trim_start_time, double trim_end_time, unsigned char exclude_bitmap)
| Trim data within a time interval.
time_t | nmxp_data_gmtime_now ()
| Return number of epochs in GMT.
double | nmxp_data_latency (NMXP_DATA_PROCESS *pd)
| Compute latency from current time and struct NMXP_DATA_PROCESS.
int | nmxp_data_log (NMXP_DATA_PROCESS *pd, int flag_sample)
| Print info about struct NMXP_DATA_PROCESS.
int | nmxp_data_parse_date (const char *pstr_date, NMXP_TM_T *ret_tmt)
| Parse string and set value in ret_tm.
double | nmxp_data_tm_to_time (NMXP_TM_T *tmt)
| Wrapper for timegm.
int | nmxp_data_seed_init (NMXP_DATA_SEED *data_seed)
| Initialize a structure NMXP_DATA_SEED.
int | nmxp_data_msr_pack (NMXP_DATA_PROCESS *pd, NMXP_DATA_SEED *data_seed, void *pmsr)
| Write mini-seed records from a NMXP_DATA_PROCESS structure.
void | nmxp_data_swap_2b (int16_t *in)
| Swap 2 bytes.
void | nmxp_data_swap_3b (unsigned char *in)
| Swap 3 bytes.
void | nmxp_data_swap_4b (int32_t *in)
| Swap 4 bytes.
void | nmxp_data_swap_8b (double *in)
| Swap 8 bytes.
int | nmxp_data_bigendianhost ()
| 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.

## Detailed Description

Data for Nanometrics Protocol Library.

Author: Matteo Quintiliani Istituto Nazionale di Geofisica e Vulcanologia - Italy quintiliani@ingv.it

Id

## Define Documentation

#define NMXP_DATA_H 1

#define NMX_SIGNATURE 0x7abcde0f

First 4 bytes of all messages.

#define NMXP_DATA_IS_LEAP | ( | yr |  | ) | ( yr%400==0 || (yr%4==0 && yr%100!=0) )

#define NETWORK_LENGTH 10

Length in bytes of channel strings.

#define STATION_LENGTH 10

Length in bytes of station strings.

#define CHANNEL_LENGTH 10

Length in bytes of channel strings.

#define NMXP_DATA_TRIM_EXCLUDE_FIRST 2

#define NMXP_DATA_TRIM_EXCLUDE_LAST 4

## Enumeration Type Documentation

enum NMXP_SHUTDOWN_REASON

Defines the type for reason of shutdown.

Enumerator:

  NMXP_SHUTDOWN_NORMAL |
  NMXP_SHUTDOWN_ERROR |
  NMXP_SHUTDOWN_TIMEOUT |

enum NMXP_MSG_CLIENT

Defines the client message types.

Enumerator:

  NMXP_MSG_CONNECT |
  NMXP_MSG_REQUESTPENDING |
  NMXP_MSG_CANCELREQUEST |
  NMXP_MSG_TERMINATESUBSCRIPTION |
  NMXP_MSG_ADDTIMESERIESCHANNELS |
  NMXP_MSG_ADDSOHCHANNELS |
  NMXP_MSG_ADDSERIALCHANNELS |
  NMXP_MSG_ADDTRIGGERCHANNELS |
  NMXP_MSG_ADDEVENTS |
  NMXP_MSG_REMOVETIMESERIESCHANNELS |
  NMXP_MSG_REMOVESOHCHANNELS |
  NMXP_MSG_REMOVESERIALCHANNELS |
  NMXP_MSG_REMOVETRIGGERCHANNELS |
  NMXP_MSG_REMOVEEVENTS |
  NMXP_MSG_CONNECTREQUEST |
  NMXP_MSG_CHANNELLISTREQUEST |
  NMXP_MSG_PRECISLISTREQUEST |
  NMXP_MSG_CHANNELINFOREQUEST |
  NMXP_MSG_DATASIZEREQUEST |
  NMXP_MSG_DATAREQUEST |
  NMXP_MSG_TRIGGERREQUEST |
  NMXP_MSG_EVENTREQUEST |

enum NMXP_MSG_SERVER

Defines the server message types.

Enumerator:

  NMXP_MSG_CHANNELLIST |
  NMXP_MSG_ERROR |
  NMXP_MSG_COMPRESSED |
  NMXP_MSG_DECOMPRESSED |
  NMXP_MSG_TRIGGER |
  NMXP_MSG_EVENT |
  NMXP_MSG_READY |
  NMXP_MSG_PRECISLIST |
  NMXP_MSG_CHANNELHEADER |
  NMXP_MSG_DATASIZE |
  NMXP_MSG_NAQSEVENT |
  NMXP_MSG_NAQSTRIGGER |

## Function Documentation

int nmxp_data_init | ( | NMXP_DATA_PROCESS * | pd | ) |

Initialize a structure NMXP_DATA_PROCESS.

Parameters:

  | pd | Pointer to a NMXP_DATA_PROCESS structure.

int nmxp_data_unpack_bundle | ( | int32_t * | outdata,
|  | unsigned char * | indata,
|  | int32_t * | prev |
| ) |  |  |

Unpack a 17-byte Nanometrics compressed data bundle.

Parameters:

  `[out]` | outdata |
  | indata |
  | prev |

Returns:
  Number of unpacked data samples, -1 if null bundle.

Author: Doug Neuhauser UC Berkeley Seismological Laboratory doug@seismo.berkeley.edu

int nmxp_data_to_str | ( | char * | out_str,
|  | double | time_d |
| ) |  |  |

Convert epoch in string.

int nmxp_data_trim | ( | NMXP_DATA_PROCESS * | pd,
|  | double | trim_start_time,
|  | double | trim_end_time,
|  | unsigned char | exclude_bitmap |
| ) |  |  |

Trim data within a time interval.

Parameters:

  | pd | Pointer to struct NMXP_DATA_PROCESS
  | trim_start_time | Start time.
  | trim_end_time | End time.
  | exclude_bitmap | Bitmap for excluding or not the first and/or the last sample.

Return values:

  | 2 | On success, data has not been trimmed.
  | 1 | On success, data has been trimmed.
  | 0 | On error.

time_t nmxp_data_gmtime_now | ( |  | ) |

Return number of epochs in GMT.

double nmxp_data_latency | ( | NMXP_DATA_PROCESS * | pd | ) |

Compute latency from current time and struct NMXP_DATA_PROCESS.

Parameters:

  | pd | Pointer to struct NMXP_DATA_PROCESS

int nmxp_data_log | ( | NMXP_DATA_PROCESS * | pd,
|  | int | flag_sample |
| ) |  |  |

Print info about struct NMXP_DATA_PROCESS.

Parameters:

  | pd | Pointer to struct NMXP_DATA_PROCESS
  | flag_sample | If it is not equal to zero sample values will be printed

int nmxp_data_parse_date | ( | const char * | pstr_date,
|  | NMXP_TM_T * | ret_tmt |
| ) |  |  |

Parse string and set value in ret_tm.

double nmxp_data_tm_to_time | ( | NMXP_TM_T * | tmt | ) |

Wrapper for timegm.

int nmxp_data_seed_init | ( | NMXP_DATA_SEED * | data_seed | ) |

Initialize a structure NMXP_DATA_SEED.

Parameters:

  | data_seed | Pointer to a NMXP_DATA_SEED structure.

int nmxp_data_msr_pack | ( | NMXP_DATA_PROCESS * | pd,
|  | NMXP_DATA_SEED * | data_seed,
|  | void * | pmsr |
| ) |  |  |

Write mini-seed records from a NMXP_DATA_PROCESS structure.

Parameters:

  | pd | Pointer to struct NMXP_DATA_PROCESS.
  | data_seed | Pointer to struct NMXP_DATA_SEED.
  | pmsr | Pointer to mini-SEED record.

Warning:
  pmsr is used like (void *) but it has to be a pointer to MSRecord !!!

Returns:
  Returns the number records created on success and -1 on error. Return value of msr_pack().

void nmxp_data_swap_2b | ( | int16_t * | in | ) |

Swap 2 bytes.

Parameters:

  | in | Variable length 2 bytes.

void nmxp_data_swap_3b | ( | unsigned char * | in | ) |

Swap 3 bytes.

Parameters:

  | in | Variable length 3 bytes.

void nmxp_data_swap_4b | ( | int32_t * | in | ) |

Swap 4 bytes.

Parameters:

  | in | Variable length 4 bytes.

void nmxp_data_swap_8b | ( | double * | in | ) |

Swap 8 bytes.

Parameters:

  | in | Variable length 8 bytes.

int nmxp_data_bigendianhost | ( |  | ) |

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.

Return values:

  | 0 | if the host is little endian.
  | 1 | otherwise.