|
MRTKLIB 0.7.14
Modernized GNSS Positioning Library
|
MRTKLIB Stream Module — stream I/O abstraction layer. More...
#include "mrtklib/mrtk_foundation.h"#include "mrtklib/mrtk_rcvraw.h"#include "mrtklib/mrtk_rtcm.h"#include "mrtklib/mrtk_sol.h"#include "mrtklib/mrtk_time.h"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 [] |
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).
Definition in file mrtk_stream.h.
| #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().
| #define MSG_DISCONN "$_DISCONNECT\r\n" /* disconnect message */ |
Definition at line 63 of file mrtk_stream.h.
| #define STR_FILE 2 /* stream type: file */ |
Definition at line 45 of file mrtk_stream.h.
Referenced by rtksvrstart(), strclose(), strgettime(), stropen(), strread(), strstat(), strstatx(), strsvrstart(), strsync(), and strwrite().
| #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().
| #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().
| #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().
| #define STR_MODE_R 0x1 /* stream mode: read */ |
Definition at line 59 of file mrtk_stream.h.
Referenced by openfile(), openfile_(), openserial(), rtksvrstart(), strgettime(), strread(), and strsvrstart().
| #define STR_MODE_RW 0x3 /* stream mode: read/write */ |
Definition at line 61 of file mrtk_stream.h.
Referenced by strsvrstart().
| #define STR_MODE_W 0x2 /* stream mode: write */ |
Definition at line 60 of file mrtk_stream.h.
Referenced by openfile(), openfile_(), openserial(), rtksvropenstr(), rtksvrstart(), strsvrstart(), and strwrite().
| #define STR_NONE 0 /* stream type: none */ |
Definition at line 43 of file mrtk_stream.h.
Referenced by strsvrstart().
| #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().
| #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().
| #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().
| #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().
| #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().
| #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().
| #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().
| #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 struct stream_tag stream_t |
| void strclose | ( | stream_t * | stream | ) |
Close stream.
| [in,out] | stream | stream 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().
| 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.
| 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.
Get stream time.
| [in] | stream | stream struct |
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().
| void strinit | ( | stream_t * | stream | ) |
Initialize stream structure.
| [in,out] | stream | stream 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().
| void strinitcom | ( | void | ) |
Initialize stream communication system.
Definition at line 3043 of file mrtk_stream.c.
References tracet().
Referenced by rtksvrstart(), and strsvrstart().
| void strlock | ( | stream_t * | stream | ) |
Lock stream.
| [in,out] | stream | stream 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().
| int stropen | ( | stream_t * | stream, |
| int | type, | ||
| int | mode, | ||
| const char * | path ) |
Open stream.
| [in,out] | stream | stream struct |
| [in] | type | stream type (STR_???) |
| [in] | mode | stream mode (STR_MODE_?) |
| [in] | path | stream path |
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().
| int strread | ( | stream_t * | stream, |
| uint8_t * | buff, | ||
| int | n ) |
Read data from stream.
| [in,out] | stream | stream struct |
| [out] | buff | data buffer |
| [in] | n | max 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().
| void strsendcmd | ( | stream_t * | stream, |
| const char * | cmd ) |
Send receiver command to stream.
| [in,out] | stream | stream struct |
| [in] | cmd | receiver 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().
Send NMEA request to stream.
| [in,out] | stream | stream struct |
| [in] | sol | solution 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().
| void strsetdir | ( | const char * | dir | ) |
Set FTP/HTTP local directory.
| [in] | dir | local directory |
Definition at line 3658 of file mrtk_stream.c.
References localdir, and tracet().
| void strsetntripver | ( | int | ver | ) |
Set default NTRIP version for new connections.
| [in] | ver | NTRIP 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().
| void strsetopt | ( | const int * | opt | ) |
Set stream options.
| [in] | opt | stream 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().
| void strsetproxy | ( | const char * | addr | ) |
Set HTTP/NTRIP proxy address.
| [in] | addr | proxy address |
Definition at line 3668 of file mrtk_stream.c.
References proxyaddr, and tracet().
| void strsettimeout | ( | stream_t * | stream, |
| int | toinact, | ||
| int | tirecon ) |
Set stream timeout.
| [in,out] | stream | stream struct |
| [in] | toinact | inactive timeout (ms) (0:no timeout) |
| [in] | tirecon | reconnect 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.
| int strstat | ( | stream_t * | stream, |
| char * | msg ) |
Get stream status.
| [in] | stream | stream struct |
| [out] | msg | status message (NULL: no output) |
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().
| int strstatx | ( | stream_t * | stream, |
| char * | msg ) |
Get stream extended status.
| [in] | stream | stream struct |
| [out] | msg | status message (NULL: no output) |
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.
| void strsum | ( | stream_t * | stream, |
| uint64_t * | inb, | ||
| int * | inr, | ||
| uint64_t * | outb, | ||
| int * | outr ) |
Get stream statistics summary.
| [in] | stream | stream struct |
| [out] | inb | input bytes (NULL: not output) |
| [out] | inr | input rate (bps) (NULL: not output) |
| [out] | outb | output bytes (NULL: not output) |
| [out] | outr | output 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().
| 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().
| int strsvrstart | ( | strsvr_t * | svr, |
| int * | opts, | ||
| int * | strs, | ||
| char ** | paths, | ||
| char ** | logs, | ||
| strconv_t ** | conv, | ||
| char ** | cmds, | ||
| char ** | cmds_priodic, | ||
| const double * | nmeapos ) |
Definition at line 656 of file mrtk_streamsvr.c.
References strsvr_t::buff, strsvr_t::buffsize, strsvr_t::cmds_periodic, strsvr_t::conv, strsvr_t::cycle, free, malloc, MAXSTRPATH, stream_tag::msg, strsvr_t::nmeacycle, strsvr_t::nmeapos, strsvr_t::nstr, strsvr_t::pbuf, strsvr_t::relayback, sleepms(), strsvr_t::state, STR_FILE, STR_MODE_R, STR_MODE_RW, STR_MODE_W, STR_NONE, strclose(), strsvr_t::stream, strinitcom(), strsvr_t::strlog, stropen(), strsendcmd(), strsetopt(), strsvrthread(), strwrite(), strsvr_t::thread, and tracet().
| void strsvrstat | ( | strsvr_t * | svr, |
| int * | stat, | ||
| int * | log_stat, | ||
| uint64_t * | byte, | ||
| int * | bps, | ||
| char * | msg ) |
Get stream server status.
| [in] | svr | stream server |
| [out] | stat | status of each stream [svr->nstr] |
| [out] | log_stat | status of each stream log [svr->nstr] |
| [out] | byte | bytes received (stream 0) / sent (others) [svr->nstr] |
| [out] | bps | bit rate received / sent [svr->nstr] |
| [out] | msg | status 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().
| 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().
Sync streams.
| [in,out] | stream1 | stream struct 1 |
| [in,out] | stream2 | stream 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().
| void strunlock | ( | stream_t * | stream | ) |
Unlock stream.
| [in,out] | stream | stream 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().
| int strwrite | ( | stream_t * | stream, |
| uint8_t * | buff, | ||
| int | n ) |
Write data to stream.
| [in,out] | stream | stream struct |
| [in] | buff | data buffer |
| [in] | n | data length (bytes) |
Definition at line 3394 of file mrtk_stream.c.
Referenced by strsendcmd(), and strsendnmea().
|
extern |
Definition at line 80 of file mrtk_stream.c.
Referenced by setopt_file().