MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_stream.h File Reference

MRTKLIB Stream Module — stream I/O abstraction layer. More...

Include dependency graph for mrtk_stream.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  stream_tag
struct  strconv_t
struct  strsvr_t

Macros

#define STR_NONE   0 /* stream type: none */
#define STR_SERIAL   1 /* stream type: serial */
#define STR_FILE   2 /* stream type: file */
#define STR_TCPSVR   3 /* stream type: TCP server */
#define STR_TCPCLI   4 /* stream type: TCP client */
#define STR_NTRIPSVR   5 /* stream type: NTRIP server */
#define STR_NTRIPCLI   6 /* stream type: NTRIP client */
#define STR_FTP   7 /* stream type: ftp */
#define STR_HTTP   8 /* stream type: http */
#define STR_NTRIPCAS   9 /* stream type: NTRIP caster */
#define STR_UDPSVR   10 /* stream type: UDP server */
#define STR_UDPCLI   11 /* stream type: UDP client */
#define STR_MEMBUF   12 /* stream type: memory buffer */
#define MAXRCVFMT   12 /* max number of receiver format */
#define STR_MODE_R   0x1 /* stream mode: read */
#define STR_MODE_W   0x2 /* stream mode: write */
#define STR_MODE_RW   0x3 /* stream mode: read/write */
#define MSG_DISCONN   "$_DISCONNECT\r\n" /* disconnect message */

Typedefs

typedef struct stream_tag stream_t

Functions

void strinitcom (void)
 Initialize stream communication system.
void strinit (stream_t *stream)
 Initialize stream structure.
void strlock (stream_t *stream)
 Lock stream.
void strunlock (stream_t *stream)
 Unlock stream.
int stropen (stream_t *stream, int type, int mode, const char *path)
 Open stream.
void strclose (stream_t *stream)
 Close stream.
int strread (stream_t *stream, uint8_t *buff, int n)
 Read data from stream.
int strwrite (stream_t *stream, uint8_t *buff, int n)
 Write data to stream.
void strsync (stream_t *stream1, stream_t *stream2)
 Sync streams.
int strstat (stream_t *stream, char *msg)
 Get stream status.
int strstatx (stream_t *stream, char *msg)
 Get stream extended status.
void strsum (stream_t *stream, uint64_t *inb, int *inr, uint64_t *outb, int *outr)
 Get stream statistics summary.
void strsetopt (const int *opt)
 Set stream options.
gtime_t strgettime (stream_t *stream)
 Get stream time.
void strsendnmea (stream_t *stream, const sol_t *sol)
 Send NMEA request to stream.
void strsendcmd (stream_t *stream, const char *cmd)
 Send receiver command to stream.
void strsettimeout (stream_t *stream, int toinact, int tirecon)
 Set stream timeout.
void strsetdir (const char *dir)
 Set FTP/HTTP local directory.
void strsetproxy (const char *addr)
 Set HTTP/NTRIP proxy address.
void strsetntripver (int ver)
 Set default NTRIP version for new connections.
void strsvrinit (strsvr_t *svr, int nout)
int strsvrstart (strsvr_t *svr, int *opts, int *strs, char **paths, char **logs, strconv_t **conv, char **cmds, char **cmds_priodic, const double *nmeapos)
void strsvrstop (strsvr_t *svr, char **cmds)
void strsvrstat (strsvr_t *svr, int *stat, int *log_stat, uint64_t *byte, int *bps, char *msg)
 Get stream server status.
strconv_t * strconvnew (int itype, int otype, const char *msgs, int staid, int stasel, const char *opt)
void strconvfree (strconv_t *conv)

Variables

const char * formatstrs []

Detailed Description

MRTKLIB Stream Module — stream I/O abstraction layer.

This header provides the stream_t type and related types (strconv_t, strsvr_t) for managing various I/O streams (file, serial, TCP, NTRIP, UDP, FTP/HTTP, memory buffer).

Note
Functions declared here are implemented in mrtk_stream.c.

Definition in file mrtk_stream.h.

Macro Definition Documentation

◆ MAXRCVFMT

#define MAXRCVFMT   12 /* max number of receiver format */

Definition at line 57 of file mrtk_stream.h.

Referenced by close_strfile(), free_strfile(), gen_strfile(), input_strfile(), and open_strfile().

◆ MSG_DISCONN

#define MSG_DISCONN   "$_DISCONNECT\r\n" /* disconnect message */

Definition at line 63 of file mrtk_stream.h.

◆ STR_FILE

#define STR_FILE   2 /* stream type: file */

◆ STR_FTP

#define STR_FTP   7 /* stream type: ftp */

Definition at line 50 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strread(), strstat(), strstatx(), and strwrite().

◆ STR_HTTP

#define STR_HTTP   8 /* stream type: http */

Definition at line 51 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strread(), strstat(), strstatx(), and strwrite().

◆ STR_MEMBUF

#define STR_MEMBUF   12 /* stream type: memory buffer */

Definition at line 55 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strread(), strstat(), strstatx(), and strwrite().

◆ STR_MODE_R

#define STR_MODE_R   0x1 /* stream mode: read */

◆ STR_MODE_RW

#define STR_MODE_RW   0x3 /* stream mode: read/write */

Definition at line 61 of file mrtk_stream.h.

Referenced by strsvrstart().

◆ STR_MODE_W

#define STR_MODE_W   0x2 /* stream mode: write */

◆ STR_NONE

#define STR_NONE   0 /* stream type: none */

Definition at line 43 of file mrtk_stream.h.

Referenced by strsvrstart().

◆ STR_NTRIPCAS

#define STR_NTRIPCAS   9 /* stream type: NTRIP caster */

Definition at line 52 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strread(), strstat(), strstatx(), and strwrite().

◆ STR_NTRIPCLI

#define STR_NTRIPCLI   6 /* stream type: NTRIP client */

Definition at line 49 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strread(), strsettimeout(), strstat(), strstatx(), and strwrite().

◆ STR_NTRIPSVR

#define STR_NTRIPSVR   5 /* stream type: NTRIP server */

Definition at line 48 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strread(), strsettimeout(), strstat(), strstatx(), and strwrite().

◆ STR_SERIAL

#define STR_SERIAL   1 /* stream type: serial */

Definition at line 44 of file mrtk_stream.h.

Referenced by set_brate(), strclose(), stropen(), strread(), strstat(), strstatx(), and strwrite().

◆ STR_TCPCLI

#define STR_TCPCLI   4 /* stream type: TCP client */

Definition at line 47 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strread(), strsettimeout(), strstat(), strstatx(), and strwrite().

◆ STR_TCPSVR

#define STR_TCPSVR   3 /* stream type: TCP server */

Definition at line 46 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strread(), strstat(), strstatx(), and strwrite().

◆ STR_UDPCLI

#define STR_UDPCLI   11 /* stream type: UDP client */

Definition at line 54 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strstat(), strstatx(), and strwrite().

◆ STR_UDPSVR

#define STR_UDPSVR   10 /* stream type: UDP server */

Definition at line 53 of file mrtk_stream.h.

Referenced by strclose(), stropen(), strread(), strstat(), and strstatx().

Typedef Documentation

◆ stream_t

typedef struct stream_tag stream_t

Function Documentation

◆ strclose()

void strclose ( stream_t * stream)

Close stream.

Parameters
[in,out]streamstream struct

Definition at line 3233 of file mrtk_stream.c.

References closefile(), closeftp(), closemembuf(), closentrip(), closentripc(), closeserial(), closetcpcli(), closetcpsvr(), closeudpcli(), closeudpsvr(), stream_tag::inr, stream_tag::mode, stream_tag::msg, stream_tag::outr, stream_tag::path, stream_tag::port, stream_tag::state, STR_FILE, STR_FTP, STR_HTTP, STR_MEMBUF, STR_NTRIPCAS, STR_NTRIPCLI, STR_NTRIPSVR, STR_SERIAL, STR_TCPCLI, STR_TCPSVR, STR_UDPCLI, STR_UDPSVR, strlock(), strunlock(), trace(), tracet(), and stream_tag::type.

Referenced by rtksvrclosestr(), rtksvrstart(), rtksvrthread(), set_brate(), strsvrstart(), and strsvrthread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strconvfree()

void strconvfree ( strconv_t * conv)

Definition at line 123 of file mrtk_streamsvr.c.

References free, free_raw(), free_rtcm(), strconv_t::out, strconv_t::raw, and strconv_t::rtcm.

Here is the call graph for this function:

◆ strconvnew()

strconv_t * strconvnew ( int itype,
int otype,
const char * msgs,
int staid,
int stasel,
const char * opt )

Definition at line 72 of file mrtk_streamsvr.c.

References calloc, strconv_t::ephsat, free, free_rtcm(), init_raw(), init_rtcm(), strconv_t::itype, strconv_t::msgs, strconv_t::nmsg, raw_t::opt, rtcm_t::opt, strconv_t::otype, strconv_t::out, strconv_t::raw, strconv_t::rtcm, rtcm_t::staid, strconv_t::stasel, strconv_t::tick, tickget(), and strconv_t::tint.

Here is the call graph for this function:

◆ strgettime()

gtime_t strgettime ( stream_t * stream)

Get stream time.

Parameters
[in]streamstream struct
Returns
stream time

Definition at line 3690 of file mrtk_stream.c.

References stream_tag::mode, stream_tag::port, file_t::start, STR_FILE, STR_MODE_R, file_t::time, timeadd(), timeget(), stream_tag::type, and utc2gpst().

Referenced by rtksvrstart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strinit()

void strinit ( stream_t * stream)

Initialize stream structure.

Parameters
[in,out]streamstream struct

Definition at line 3049 of file mrtk_stream.c.

References stream_tag::inb, stream_tag::inbt, stream_tag::inr, stream_tag::lock, stream_tag::mode, stream_tag::msg, stream_tag::outb, stream_tag::outbt, stream_tag::outr, stream_tag::path, stream_tag::port, rtk_initlock, stream_tag::state, stream_tag::tact, stream_tag::tick_i, stream_tag::tick_o, tracet(), and stream_tag::type.

Referenced by rtksvrinit(), and strsvrinit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strinitcom()

void strinitcom ( void )

Initialize stream communication system.

Definition at line 3043 of file mrtk_stream.c.

References tracet().

Referenced by rtksvrstart(), and strsvrstart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strlock()

void strlock ( stream_t * stream)

Lock stream.

Parameters
[in,out]streamstream struct

Definition at line 3313 of file mrtk_stream.c.

References stream_tag::lock, and rtk_lock.

Referenced by strclose(), strread(), strstat(), strstatx(), strsum(), and strwrite().

Here is the caller graph for this function:

◆ stropen()

int stropen ( stream_t * stream,
int type,
int mode,
const char * path )

Open stream.

Parameters
[in,out]streamstream struct
[in]typestream type (STR_???)
[in]modestream mode (STR_MODE_?)
[in]pathstream path
Returns
status (0:error,1:ok)

Definition at line 3173 of file mrtk_stream.c.

References stream_tag::inb, stream_tag::inbt, stream_tag::inr, stream_tag::mode, stream_tag::msg, openfile(), openftp(), openmembuf(), openntrip(), openntripc(), openserial(), opentcpcli(), opentcpsvr(), openudpcli(), openudpsvr(), stream_tag::outb, stream_tag::outbt, stream_tag::outr, stream_tag::path, stream_tag::port, stream_tag::state, STR_FILE, STR_FTP, STR_HTTP, STR_MEMBUF, STR_NTRIPCAS, STR_NTRIPCLI, STR_NTRIPSVR, STR_SERIAL, STR_TCPCLI, STR_TCPSVR, STR_UDPCLI, STR_UDPSVR, stream_tag::tick_i, stream_tag::tick_o, tickget(), tracet(), and stream_tag::type.

Referenced by rtksvropenstr(), rtksvrstart(), set_brate(), and strsvrstart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strread()

int strread ( stream_t * stream,
uint8_t * buff,
int n )

Read data from stream.

Parameters
[in,out]streamstream struct
[out]buffdata buffer
[in]nmax data length (bytes)
Returns
data length (bytes)

Definition at line 3324 of file mrtk_stream.c.

References stream_tag::inb, stream_tag::inbt, stream_tag::inr, stream_tag::mode, stream_tag::msg, stream_tag::port, readfile(), readftp(), readmembuf(), readntrip(), readntripc(), readserial(), readtcpcli(), readtcpsvr(), readudpsvr(), STR_FILE, STR_FTP, STR_HTTP, STR_MEMBUF, STR_MODE_R, STR_NTRIPCAS, STR_NTRIPCLI, STR_NTRIPSVR, STR_SERIAL, STR_TCPCLI, STR_TCPSVR, STR_UDPSVR, strlock(), strunlock(), stream_tag::tact, stream_tag::tick_i, tickget(), tirate, tracet(), and stream_tag::type.

Referenced by rtksvrthread(), and strsvrthread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strsendcmd()

void strsendcmd ( stream_t * stream,
const char * cmd )

Send receiver command to stream.

Parameters
[in,out]streamstream struct
[in]cmdreceiver command

Definition at line 3760 of file mrtk_stream.c.

References gen_hex(), gen_nvs(), gen_stq(), gen_ubx(), set_brate(), sleepms(), strwrite(), and tracet().

Referenced by periodic_cmd(), periodic_cmd(), rtksvrstart(), rtksvrstop(), send_nmea(), strsvrstart(), and strsvrstop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strsendnmea()

void strsendnmea ( stream_t * stream,
const sol_t * sol )

Send NMEA request to stream.

Parameters
[in,out]streamstream struct
[in]solsolution data

Definition at line 3703 of file mrtk_stream.c.

References outnmea_gga(), sol_t::rr, strwrite(), and tracet().

Referenced by send_nmea(), and strsvrthread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strsetdir()

void strsetdir ( const char * dir)

Set FTP/HTTP local directory.

Parameters
[in]dirlocal directory

Definition at line 3658 of file mrtk_stream.c.

References localdir, and tracet().

Here is the call graph for this function:

◆ strsetntripver()

void strsetntripver ( int ver)

Set default NTRIP version for new connections.

Parameters
[in]verNTRIP version (0:auto, 1:v1, 2:v2)

When set to auto (0), the client tries NTRIP v2 first and falls back to v1 if the caster does not support it. Per-stream override is available via the ?ver=N query parameter in the stream path.

Definition at line 3678 of file mrtk_stream.c.

References ntrip_ver_default, and tracet().

Here is the call graph for this function:

◆ strsetopt()

void strsetopt ( const int * opt)

Set stream options.

Parameters
[in]optstream options (timeout/reconnect/rate/buffsize/fswapmargin)

Definition at line 3620 of file mrtk_stream.c.

References buffsize, fswapmargin, ticonnect, tirate, toinact, and tracet().

Referenced by strsvrstart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strsetproxy()

void strsetproxy ( const char * addr)

Set HTTP/NTRIP proxy address.

Parameters
[in]addrproxy address

Definition at line 3668 of file mrtk_stream.c.

References proxyaddr, and tracet().

Here is the call graph for this function:

◆ strsettimeout()

void strsettimeout ( stream_t * stream,
int toinact,
int tirecon )

Set stream timeout.

Parameters
[in,out]streamstream struct
[in]toinactinactive timeout (ms) (0:no timeout)
[in]tireconreconnect interval (ms)

Definition at line 3637 of file mrtk_stream.c.

References stream_tag::port, STR_NTRIPCLI, STR_NTRIPSVR, STR_TCPCLI, tcpcli_t::tirecon, tcpcli_t::toinact, toinact, tracet(), and stream_tag::type.

Here is the call graph for this function:

◆ strstat()

int strstat ( stream_t * stream,
char * msg )

Get stream status.

Parameters
[in]streamstream struct
[out]msgstatus message (NULL: no output)
Returns
stream status (-1:error,0:close,1:wait,2:connect,3:active)

Definition at line 3458 of file mrtk_stream.c.

References MAXSTRMSG, stream_tag::msg, stream_tag::port, stream_tag::state, statefile(), stateftp(), statemembuf(), statentrip(), statentripc(), stateserial(), statetcpcli(), statetcpsvr(), stateudpcli(), stateudpsvr(), STR_FILE, STR_FTP, STR_HTTP, STR_MEMBUF, STR_NTRIPCAS, STR_NTRIPCLI, STR_NTRIPSVR, STR_SERIAL, STR_TCPCLI, STR_TCPSVR, STR_UDPCLI, STR_UDPSVR, strlock(), strunlock(), stream_tag::tact, tickget(), TINTACT, tracet(), and stream_tag::type.

Referenced by rtksvrsstat(), and strsvrstat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strstatx()

int strstatx ( stream_t * stream,
char * msg )

Get stream extended status.

Parameters
[in]streamstream struct
[out]msgstatus message (NULL: no output)
Returns
stream status

Definition at line 3523 of file mrtk_stream.c.

References stream_tag::port, stream_tag::state, statexfile(), statexftp(), statexmembuf(), statexntrip(), statexntripc(), statexserial(), statextcpcli(), statextcpsvr(), statexudpcli(), statexudpsvr(), STR_FILE, STR_FTP, STR_HTTP, STR_MEMBUF, STR_NTRIPCAS, STR_NTRIPCLI, STR_NTRIPSVR, STR_SERIAL, STR_TCPCLI, STR_TCPSVR, STR_UDPCLI, STR_UDPSVR, strlock(), strunlock(), stream_tag::tact, tickget(), TINTACT, tracet(), and stream_tag::type.

Here is the call graph for this function:

◆ strsum()

void strsum ( stream_t * stream,
uint64_t * inb,
int * inr,
uint64_t * outb,
int * outr )

Get stream statistics summary.

Parameters
[in]streamstream struct
[out]inbinput bytes (NULL: not output)
[out]inrinput rate (bps) (NULL: not output)
[out]outboutput bytes (NULL: not output)
[out]outroutput rate (bps) (NULL: not output)

Definition at line 3589 of file mrtk_stream.c.

References stream_tag::inb, stream_tag::inr, stream_tag::outb, stream_tag::outr, strlock(), strunlock(), and tracet().

Referenced by strsvrstat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strsvrinit()

void strsvrinit ( strsvr_t * svr,
int nout )

Definition at line 584 of file mrtk_streamsvr.c.

References strsvr_t::buff, strsvr_t::buffsize, strsvr_t::cmds_periodic, strsvr_t::conv, strsvr_t::cycle, strsvr_t::lock, strsvr_t::nmeacycle, strsvr_t::nmeapos, strsvr_t::npb, strsvr_t::nstr, strsvr_t::pbuf, strsvr_t::relayback, rtk_initlock, strsvr_t::state, strsvr_t::stream, strinit(), strsvr_t::strlog, strsvr_t::thread, strsvr_t::tick, and tracet().

Here is the call graph for this function:

◆ strsvrstart()

int strsvrstart ( strsvr_t * svr,
int * opts,
int * strs,
char ** paths,
char ** logs,
strconv_t ** conv,
char ** cmds,
char ** cmds_priodic,
const double * nmeapos )

◆ strsvrstat()

void strsvrstat ( strsvr_t * svr,
int * stat,
int * log_stat,
uint64_t * byte,
int * bps,
char * msg )

Get stream server status.

Parameters
[in]svrstream server
[out]statstatus of each stream [svr->nstr]
[out]log_statstatus of each stream log [svr->nstr]
[out]bytebytes received (stream 0) / sent (others) [svr->nstr]
[out]bpsbit rate received / sent [svr->nstr]
[out]msgstatus messages

Definition at line 760 of file mrtk_streamsvr.c.

References MAXSTRMSG, strsvr_t::nstr, strsvr_t::stream, strsvr_t::strlog, strstat(), strsum(), and tracet().

Here is the call graph for this function:

◆ strsvrstop()

void strsvrstop ( strsvr_t * svr,
char ** cmds )

Definition at line 738 of file mrtk_streamsvr.c.

References strsvr_t::nstr, strsvr_t::state, strsvr_t::stream, strsendcmd(), strsvr_t::thread, and tracet().

Here is the call graph for this function:

◆ strsync()

void strsync ( stream_t * stream1,
stream_t * stream2 )

Sync streams.

Parameters
[in,out]stream1stream struct 1
[in,out]stream2stream struct 2

Definition at line 3297 of file mrtk_stream.c.

References stream_tag::port, STR_FILE, syncfile(), and stream_tag::type.

Referenced by rtksvrstart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strunlock()

void strunlock ( stream_t * stream)

Unlock stream.

Parameters
[in,out]streamstream struct

Definition at line 3314 of file mrtk_stream.c.

References stream_tag::lock, and rtk_unlock.

Referenced by strclose(), strread(), strstat(), strstatx(), strsum(), and strwrite().

Here is the caller graph for this function:

◆ strwrite()

int strwrite ( stream_t * stream,
uint8_t * buff,
int n )

Write data to stream.

Parameters
[in,out]streamstream struct
[in]buffdata buffer
[in]ndata length (bytes)
Returns
bytes written (0: nothing written or error; some stream types return -1 on error)

Definition at line 3394 of file mrtk_stream.c.

Referenced by strsendcmd(), and strsendnmea().

Here is the caller graph for this function:

Variable Documentation

◆ formatstrs

const char* formatstrs[]
extern

Definition at line 80 of file mrtk_stream.c.

Referenced by setopt_file().