File: modemtest.cc

package info (click to toggle)
wvstreams 4.0.2-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,420 kB
  • ctags: 6,518
  • sloc: cpp: 52,544; sh: 5,770; ansic: 810; makefile: 461; tcl: 114; perl: 18
file content (62 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Worldvisions Weaver Software:
 *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
 *
 * WvModem test program.  Acts almost like a comm program, using WvLog to
 * display everything received from the modem.  It should respond to AT
 * commands.
 */
#include "wvmodem.h"
#include "wvistreamlist.h"
#include "wvlog.h"
#include "strutils.h"

int main(int argc, char **argv)
{
    WvLog log("modemtest"), modemlog("Rx");

    if (argc < 2)
    {
	log("usage: modemtest <devname>\n");
	return 1;
    }
    
    WvModem modem(argv[1], 19200);
    unsigned char buf[1024];
    size_t len;
    bool last_carrier = false, carrier;
    
    WvIStreamList l;
    l.append(wvcon, false);
    l.append(&modem, false);
    
    while (modem.isok() && wvcon->isok())
    {
	carrier = modem.carrier();
	if (last_carrier != carrier)
	{
	    log("Modem %s\n", carrier ? "CONNECTED" : "DISCONNECTED" );
	    last_carrier = carrier;
	}
	
	if (!l.select(100))
	    continue;
	
	if (wvcon->select(0))
	{
	    len = wvcon->read(buf, sizeof(buf));
	    replace_char(buf, '\n', '\r', len);
	    modem.write(buf, len);
	}
	else if (modem.select(0))
	{
	    len = modem.read(buf, sizeof(buf));
	    modemlog.write(buf, len);
	}
    }
    
    if (!modem.isok() && modem.geterr())
	log(WvLog::Error, "modem device: %s\n", modem.errstr());
    
    return 0;
}