码迷,mamicode.com
首页 > 其他好文 > 详细

基于RTKLIB构建高并发通信测试工具

时间:2017-10-13 18:00:57      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:creat   string   指针   include   turn   nload   ret   oid   基础   

1、 RTKLIB基础动态库生成

RTKLIB是全球导航卫星系统GNSS(global navigation satellite system)的标准&精密定位开源程序包,由日本东京海洋大学的高须知二开发。在博文《RTKLIB编译及RTCM数据读取样例》中,笔者详细介绍了RTKLIB基础库的编译方法及注意细节,并给出了RTCM数据读取的DEMO,读者可适当参考。

2、 基于RTKLIB构建高并发通信测试工具DEMO

RTKLIB动态库的基础上,笔者利用其稳定的数据通信功能,尝试进行了高并发通信测试工具的编译工作,模拟了500个NtripClient客户端并发测试,样例代码如下所示。

技术分享
 1 void strsvr(int i)
 2 {
 3        strsvr_t *svr = (strsvr_t *)malloc(sizeof(strsvr_t));
 4  
 5        int opt[8] = { 10000, 10000, 1000, 32768, 10, 1000, 30, 0 };
 6        int strs[1] = { STR_NTRIPCLI };
 7        double nemapos[3] = { 0 };
 8        char *path[1];
 9        for (int i = 0; i < 1; i++)
10               path[i] = malloc(sizeof(char) * 1024);
11        path[0] = "a:a@127.0.0.1:10001/RTCM ";   
12        char cmd[4][1024] = { 0 };
13        char cmds_p[4][1024] = { 0 };
14        strconv_t *conv[4] = { 0 };
15        strsvrinit(svr, 0);
16        strsvrstart(svr, opt, strs, &path, conv, cmd, cmds_p, nemapos);
17  
18        while (1)
19        {             
20               trace(0, "thread:%d,tick:%d,rec:%d,cnt:%d\n", i, svr->stream[0].tick_i,svr->stream[0].inb, svr->stream[0].tickcnt);
21               sleepms(30000);
22        }      
23 }
24 extern int ThreadStart(LPTHREAD_START_ROUTINE t, LPVOID p)
25 {
26        DWORD dwReceiveGpsDataThreadID; 
27        HANDLE  hReceiveDataThread;
28        if (!(hReceiveDataThread = CreateThread(NULL,0,t,p,0,   &dwReceiveGpsDataThreadID)))
29        {
30               CloseHandle(hReceiveDataThread);
31               return 0;
32        }
33        return 1;
34 }
35 int main(char argv)
36 {      
37        traceopen("log.txt");
38        tracelevel(1);
39        for (int i = 0; i < 500; i++)
40        {
41               ThreadStart((LPTHREAD_START_ROUTINE)strsvr1, (LPVOID)i); Sleep(5);
42        }      
43        getchar();
44        traceclose();
45        return 0;
46 }
View Code

其中,strsvr函数是并发测试的基础函数,负责完成数据通信功能和日志记录功能;ThreadStart函数是创建线程的函数,用于创建线程,t为方法指针,p为参数指针。

值得注意的的是RTKLIB中,不同通信协议和模式的通信路径path参数的格式具有特定的要求,具体内容可参考stropen函数的注释,如下所示。

技术分享
  1 /* open stream -----------------------------------------------------------------
  2 *
  3 * open stream to read or write data from or to virtual devices.
  4 *
  5 * args   : stream_t *stream IO  stream
  6 *          int type         I   stream type
  7 *                                 STR_SERIAL   = serial device
  8 *                                 STR_FILE     = file (record and playback)
  9 *                                 STR_TCPSVR   = TCP server
 10 *                                 STR_TCPCLI   = TCP client
 11 *                                 STR_NTRIPSVR = NTRIP server
 12 *                                 STR_NTRIPCLI = NTRIP client
 13 *                                 STR_NTRIPC_S = NTRIP caster server
 14 *                                 STR_NTRIPC_C = NTRIP caster client
 15 *                                 STR_UDPSVR   = UDP server (read only)
 16 *                                 STR_UDPCLI   = UDP client (write only)
 17 *                                 STR_MEMBUF   = memory buffer (FIFO)
 18 *                                 STR_FTP      = download by FTP (raed only)
 19 *                                 STR_HTTP     = download by HTTP (raed only)
 20 *          int mode         I   stream mode (STR_MODE_???)
 21 *                                 STR_MODE_R   = read only
 22 *                                 STR_MODE_W   = write only
 23 *                                 STR_MODE_RW  = read and write
 24 *          char *path       I   stream path (see below)
 25 *
 26 * return : status (0:error,1:ok)
 27 *
 28 * notes  : see reference [1] for NTRIP
 29 *          STR_FTP/HTTP needs "wget" in command search paths
 30 *
 31 * stream path ([] options):
 32 *
 33 *   STR_SERIAL   port[:brate[:bsize[:parity[:stopb[:fctr[#port]]]]]]
 34 *                    port  = COM??  (windows)
 35 *                            tty??? (linuex, omit /dev/)
 36 *                    brate = bit rate     (bps)
 37 *                    bsize = bit size     (7|8)
 38 *                    parity= parity       (n|o|e)
 39 *                    stopb = stop bits    (1|2)
 40 *                    fctr  = flow control (off|rts)
 41 *                    port  = tcp server port to output received stream
 42 *
 43 *   STR_FILE     path[::T][::+start][::xseppd][::S=swap][::P={4|8}]
 44 *                    path  = file path
 45 *                            (can include keywords defined by )
 46 *                    ::T   = enable time tag
 47 *                    start = replay start offset (s)
 48 *                    speed = replay speed factor
 49 *                    swap  = output swap interval (hr) (0: no swap)
 50 *                    ::P={4|8} = file pointer size (4:32bit,8:64bit)
 51 *
 52 *   STR_TCPSVR   :port
 53 *                    port  = TCP server port to accept
 54 *
 55 *   STR_TCPCLI   addr:port
 56 *                    addr  = TCP server address to connect
 57 *                    port  = TCP server port to connect
 58 *
 59 *   STR_NTRIPSVR [:passwd@]addr[:port]/mponit[:string]
 60 *                    addr  = NTRIP caster address to connect
 61 *                    port  = NTRIP caster server port to connect
 62 *                    passwd= NTRIP caster server password to connect
 63 *                    mpoint= NTRIP mountpoint
 64 *                    string= NTRIP server string
 65 *
 66 *   STR_NTRIPCLI [user[:passwd]@]addr[:port]/mpoint
 67 *                    addr  = NTRIP caster address to connect
 68 *                    port  = NTRIP caster client port to connect
 69 *                    user  = NTRIP caster client user to connect
 70 *                    passwd= NTRIP caster client password to connect
 71 *                    mpoint= NTRIP mountpoint
 72 *
 73 *   STR_NTRIPC_S [:passwd@][:port]/mpoint
 74 *                    port  = NTRIP caster server port to accept
 75 *                    passwd= NTRIP caster server password to accept
 76 *                    mpoint= NTRIP mountpoint
 77 *
 78 *   STR_NTRIPC_C [user[:passwd]@][:port]/mpoint
 79 *                    port  = NTRIP caster client port to accept
 80 *                    user  = NTRIP caster client user to accept
 81 *                    passwd= NTRIP caster client password to accept
 82 *                    mpoint= NTRIP mountpoint
 83 *
 84 *   STR_UDPSVR   :port
 85 *                    port  = UDP server port to receive
 86 *
 87 *   STR_UDPCLI   addr:port
 88 *                    addr  = UDP server or broadcast address to send
 89 *                    port  = UDP server or broadcast port to send
 90 *
 91 *   STR_MEMBUF   [size]
 92 *                    size  = FIFO size (bytes) ("":4096)
 93 *
 94 *   STR_FTP      [user[:passwd]@]addr/path[::T=poff[,tint[,toff,tret]]]]
 95 *                    user  = FTP server user
 96 *                    passwd= FTP server password
 97 *                    addr  = FTP server address
 98 *                    path  = FTP server file path
 99 *                    poff  = time offset for path extension (s)
100 *                    tint  = download interval (s)
101 *                    toff  = download time offset (s)
102 *                    tret  = download retry interval (s) (0:no retry)
103 *
104 *   STR_HTTP     addr/path[::T=poff[,tint[,toff,tret]]]]
105 *                    addr  = HTTP server address
106 *                    path  = HTTP server file path
107 *                    poff  = time offset for path extension (s)
108 *                    tint  = download interval (s)
109 *                    toff  = download time offset (s)
110 *                    tret  = download retry interval (s) (0:no retry)
111 *
112 *-----------------------------------------------------------------------------*/
View Code

 

基于RTKLIB构建高并发通信测试工具

标签:creat   string   指针   include   turn   nload   ret   oid   基础   

原文地址:http://www.cnblogs.com/whugreyhound/p/7662241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!