1、 RTKLIB基础动态库生成
RTKLIB是全球导航卫星系统GNSS(global navigation satellite system)的标准&精密定位开源程序包,由日本东京海洋大学的高须知二开发。在博文《RTKLIB编译及RTCM数据读取样例》中,笔者详细介绍了RTKLIB基础库的编译方法及注意细节,并给出了RTCM数据读取的DEMO,读者可适当参考。
2、 基于RTKLIB构建高并发通信测试工具DEMO
在RTKLIB动态库的基础上,笔者利用其稳定的数据通信功能,尝试进行了高并发通信测试工具的编译工作,模拟了500个NtripClient客户端并发测试,样例代码如下所示。
void strsvr(int i)
{
strsvr_t *svr = (strsvr_t *)malloc(sizeof(strsvr_t));
int opt[] = { , , , , , , , };
int strs[] = { STR_NTRIPCLI };
double nemapos[] = { };
char *path[];
for (int i = ; i < ; i++)
path[i] = malloc(sizeof(char) * );
path[] = "a:[email protected]:10001/RTCM ";
char cmd[][] = { };
char cmds_p[][] = { };
strconv_t *conv[] = { };
strsvrinit(svr, );
strsvrstart(svr, opt, strs, &path, conv, cmd, cmds_p, nemapos);
while ()
{
trace(, "thread:%d,tick:%d,rec:%d,cnt:%d\n", i, svr->stream[].tick_i,svr->stream[].inb, svr->stream[].tickcnt);
sleepms();
}
}
extern int ThreadStart(LPTHREAD_START_ROUTINE t, LPVOID p)
{
DWORD dwReceiveGpsDataThreadID;
HANDLE hReceiveDataThread;
if (!(hReceiveDataThread = CreateThread(NULL,,t,p,, &dwReceiveGpsDataThreadID)))
{
CloseHandle(hReceiveDataThread);
return ;
}
return ;
}
int main(char argv)
{
traceopen("log.txt");
tracelevel();
for (int i = ; i < ; i++)
{
ThreadStart((LPTHREAD_START_ROUTINE)strsvr1, (LPVOID)i); Sleep();
}
getchar();
traceclose();
return ;
}
其中,strsvr函数是并发测试的基础函数,负责完成数据通信功能和日志记录功能;ThreadStart函数是创建线程的函数,用于创建线程,t为方法指针,p为参数指针。
值得注意的的是RTKLIB中,不同通信协议和模式的通信路径path参数的格式具有特定的要求,具体内容可参考stropen函数的注释,如下所示。
/* open stream -----------------------------------------------------------------
*
* open stream to read or write data from or to virtual devices.
*
* args : stream_t *stream IO stream
* int type I stream type
* STR_SERIAL = serial device
* STR_FILE = file (record and playback)
* STR_TCPSVR = TCP server
* STR_TCPCLI = TCP client
* STR_NTRIPSVR = NTRIP server
* STR_NTRIPCLI = NTRIP client
* STR_NTRIPC_S = NTRIP caster server
* STR_NTRIPC_C = NTRIP caster client
* STR_UDPSVR = UDP server (read only)
* STR_UDPCLI = UDP client (write only)
* STR_MEMBUF = memory buffer (FIFO)
* STR_FTP = download by FTP (raed only)
* STR_HTTP = download by HTTP (raed only)
* int mode I stream mode (STR_MODE_???)
* STR_MODE_R = read only
* STR_MODE_W = write only
* STR_MODE_RW = read and write
* char *path I stream path (see below)
*
* return : status (0:error,1:ok)
*
* notes : see reference [1] for NTRIP
* STR_FTP/HTTP needs "wget" in command search paths
*
* stream path ([] options):
*
* STR_SERIAL port[:brate[:bsize[:parity[:stopb[:fctr[#port]]]]]]
* port = COM?? (windows)
* tty??? (linuex, omit /dev/)
* brate = bit rate (bps)
* bsize = bit size (7|8)
* parity= parity (n|o|e)
* stopb = stop bits (1|2)
* fctr = flow control (off|rts)
* port = tcp server port to output received stream
*
* STR_FILE path[::T][::+start][::xseppd][::S=swap][::P={4|8}]
* path = file path
* (can include keywords defined by )
* ::T = enable time tag
* start = replay start offset (s)
* speed = replay speed factor
* swap = output swap interval (hr) (0: no swap)
* ::P={4|8} = file pointer size (4:32bit,8:64bit)
*
* STR_TCPSVR :port
* port = TCP server port to accept
*
* STR_TCPCLI addr:port
* addr = TCP server address to connect
* port = TCP server port to connect
*
* STR_NTRIPSVR [:passwd@]addr[:port]/mponit[:string]
* addr = NTRIP caster address to connect
* port = NTRIP caster server port to connect
* passwd= NTRIP caster server password to connect
* mpoint= NTRIP mountpoint
* string= NTRIP server string
*
* STR_NTRIPCLI [user[:passwd]@]addr[:port]/mpoint
* addr = NTRIP caster address to connect
* port = NTRIP caster client port to connect
* user = NTRIP caster client user to connect
* passwd= NTRIP caster client password to connect
* mpoint= NTRIP mountpoint
*
* STR_NTRIPC_S [:passwd@][:port]/mpoint
* port = NTRIP caster server port to accept
* passwd= NTRIP caster server password to accept
* mpoint= NTRIP mountpoint
*
* STR_NTRIPC_C [user[:passwd]@][:port]/mpoint
* port = NTRIP caster client port to accept
* user = NTRIP caster client user to accept
* passwd= NTRIP caster client password to accept
* mpoint= NTRIP mountpoint
*
* STR_UDPSVR :port
* port = UDP server port to receive
*
* STR_UDPCLI addr:port
* addr = UDP server or broadcast address to send
* port = UDP server or broadcast port to send
*
* STR_MEMBUF [size]
* size = FIFO size (bytes) ("":4096)
*
* STR_FTP [user[:passwd]@]addr/path[::T=poff[,tint[,toff,tret]]]]
* user = FTP server user
* passwd= FTP server password
* addr = FTP server address
* path = FTP server file path
* poff = time offset for path extension (s)
* tint = download interval (s)
* toff = download time offset (s)
* tret = download retry interval (s) (0:no retry)
*
* STR_HTTP addr/path[::T=poff[,tint[,toff,tret]]]]
* addr = HTTP server address
* path = HTTP server file path
* poff = time offset for path extension (s)
* tint = download interval (s)
* toff = download time offset (s)
* tret = download retry interval (s) (0:no retry)
*
*-----------------------------------------------------------------------------*/