Thread: [Com0com-cvs] hub4com comhub.cpp, 1.3, 1.4 comhub.h, 1.3, 1.4 hub4com.cpp, 1.5, 1.6
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
From: Vyacheslav F. <vf...@us...> - 2007-12-19 13:46:43
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv5379 Modified Files: comhub.cpp comhub.h hub4com.cpp Log Message: Added ability to send data received from port to the same port Index: hub4com.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** hub4com.cpp 14 May 2007 12:06:37 -0000 1.5 --- hub4com.cpp 19 Dec 2007 13:46:36 -0000 1.6 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.6 2007/12/19 13:46:36 vfrolov + * Added ability to send data received from port to the same port + * * Revision 1.5 2007/05/14 12:06:37 vfrolov * Added read interval timeout option *************** *** 36,40 **** * Initial revision * - * */ --- 39,42 ---- *************** *** 49,53 **** cerr << "Usage:" << endl ! << " " << pProgName << " [options] \\\\.\\<port0> [options] \\\\.\\<port1> ..." << endl << endl << "Common options:" << endl --- 51,55 ---- cerr << "Usage:" << endl ! << " " << pProgName << " [options] \\\\.\\<port0> [options] [\\\\.\\<port1> ...]" << endl << endl << "Common options:" << endl *************** *** 88,99 **** << endl << "Route options:" << endl ! << " --route=<LstR>:<LstL> - send data received from any ports from <LstR> to" << endl ! << " all ports from <LstL>." << endl ! << " --bi-route=<LstR>:<LstL> - send data received from any ports from <LstR> to" << endl ! << " all ports from <LstL> and vice versa." << endl ! << " --no-route=<LstR>:<LstL> - do not send data received from any ports from" << endl << " <LstR> to ports from <LstL>." << endl << endl ! << " The syntax of <LstR> and <LstL> above: <P1>[,<P2>...]" << endl << " The <Pn> above is a zero based position number of port or All." << endl << " If no any route option specified, then the options --route=0:All --route=1:0" << endl --- 90,104 ---- << endl << "Route options:" << endl ! << " --route=<LstR>:<LstL> - send data received from any port from <LstR> to" << endl ! << " all ports (except this port) from <LstL>." << endl ! << " --bi-route=<LstR>:<LstL> - send data received from any port from <LstR> to" << endl ! << " all ports (except this port) from <LstL> and vice" << endl ! << " versa." << endl ! << " --echo-route=<Lst> - send data received from any port from <Lst> back" << endl ! << " to this port." << endl ! << " --no-route=<LstR>:<LstL> - do not send data received from any port from" << endl << " <LstR> to ports from <LstL>." << endl << endl ! << " The syntax of <LstR>, <LstL> and <Lst> above: <P1>[,<P2>...]" << endl << " The <Pn> above is a zero based position number of port or All." << endl << " If no any route option specified, then the options --route=0:All --route=1:0" << endl *************** *** 105,112 **** --- 110,148 ---- << " " << pProgName << " --route=All:All \\\\.\\CNCB0 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl << " " << pProgName << " --baud=9600 \\\\.\\COM1 --baud=19200 \\\\.\\CNCB1" << endl + << " " << pProgName << " --echo-route=0 \\\\.\\COM2" << endl ; exit(1); } /////////////////////////////////////////////////////////////// + static BOOL EchoRoute(ComHub &hub, const char *pList) + { + char *pTmpList = _strdup(pList); + + if (!pTmpList) { + cerr << "No enough memory." << endl; + exit(2); + } + + BOOL res = TRUE; + char *pSave; + + for (char *p = STRTOK_R(pTmpList, ",", &pSave) ; p ; p = STRTOK_R(NULL, ",", &pSave)) { + int i; + + if (_stricmp(p, "All") == 0) { + i = -1; + } else if (!StrToInt(p, &i) || i < 0 || i >= hub.NumPorts()) { + res = FALSE; + break; + } + + hub.RouteData(i, i, FALSE, FALSE); + } + + free(pTmpList); + + return res; + } + /////////////////////////////////////////////////////////////// static BOOL Route(ComHub &hub, const char *pListFrom, const char *pListTo, BOOL noRoute) { *************** *** 144,148 **** } ! hub.RouteData(iFrom, iTo, noRoute); } } --- 180,184 ---- } ! hub.RouteData(iFrom, iTo, noRoute, TRUE); } } *************** *** 284,287 **** --- 320,327 ---- defaultRouteData = FALSE; Route(hub, pParam, FALSE, TRUE); + } else + if ((pParam = GetParam(pArg, "echo-route=")) != NULL) { + defaultRouteData = FALSE; + EchoRoute(hub, pParam); } else { cerr << "Unknown option " << pArg << endl; *************** *** 290,299 **** } ! if (plugged < 2) ! Usage(argv[0]); ! if (defaultRouteData) { ! hub.RouteData(0, -1, FALSE); ! hub.RouteData(1, 0, FALSE); } --- 330,341 ---- } ! if (plugged < 2) { ! if (plugged < 1) ! Usage(argv[0]); ! } ! else if (defaultRouteData) { ! hub.RouteData(0, -1, FALSE, TRUE); ! hub.RouteData(1, 0, FALSE, TRUE); } Index: comhub.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comhub.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** comhub.h 5 Feb 2007 09:33:20 -0000 1.3 --- comhub.h 19 Dec 2007 13:46:36 -0000 1.4 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.4 2007/12/19 13:46:36 vfrolov + * Added ability to send data received from port to the same port + * * Revision 1.3 2007/02/05 09:33:20 vfrolov * Implemented internal flow control *************** *** 29,33 **** * Initial revision * - * */ --- 32,35 ---- *************** *** 54,63 **** void LostReport() const; ! void RouteData(int iFrom, int iTo, BOOL noRoute) { ! Route(routeDataMap, iFrom, iTo, noRoute); } ! void RouteFlowControl(int iFrom, int iTo, BOOL noRoute) { ! Route(routeFlowControlMap, iFrom, iTo, noRoute); } --- 56,65 ---- void LostReport() const; ! void RouteData(int iFrom, int iTo, BOOL noRoute, BOOL noEcho) { ! Route(routeDataMap, iFrom, iTo, noRoute, noEcho); } ! void RouteFlowControl(int iFrom, int iTo, BOOL noRoute, BOOL noEcho) { ! Route(routeFlowControlMap, iFrom, iTo, noRoute, noEcho); } *************** *** 67,71 **** private: ! void Route(ComPortMap &map, int iFrom, int iTo, BOOL noRoute) const; ComPorts ports; --- 69,73 ---- private: ! void Route(ComPortMap &map, int iFrom, int iTo, BOOL noRoute, BOOL noEcho) const; ComPorts ports; Index: comhub.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comhub.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** comhub.cpp 5 Feb 2007 09:33:20 -0000 1.3 --- comhub.cpp 19 Dec 2007 13:46:36 -0000 1.4 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.4 2007/12/19 13:46:36 vfrolov + * Added ability to send data received from port to the same port + * * Revision 1.3 2007/02/05 09:33:20 vfrolov * Implemented internal flow control *************** *** 29,33 **** * Initial revision * - * */ --- 32,35 ---- *************** *** 132,136 **** } ! void ComHub::Route(ComPortMap &map, int iFrom, int iTo, BOOL noRoute) const { if (iFrom < 0) { --- 134,138 ---- } ! void ComHub::Route(ComPortMap &map, int iFrom, int iTo, BOOL noRoute, BOOL noEcho) const { if (iFrom < 0) { *************** *** 138,144 **** if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! Route(map, iF, iT, noRoute); } else { ! Route(map, iF, iTo, noRoute); } } --- 140,146 ---- if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! Route(map, iF, iT, noRoute, noEcho); } else { ! Route(map, iF, iTo, noRoute, noEcho); } } *************** *** 146,153 **** if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! Route(map, iFrom, iT, noRoute); } else ! if (iFrom != iTo || noRoute) { ComPortPair pair(ports.at(iFrom), ports.at(iTo)); --- 148,155 ---- if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! Route(map, iFrom, iT, noRoute, noEcho); } else ! if (iFrom != iTo || !noEcho || noRoute) { ComPortPair pair(ports.at(iFrom), ports.at(iTo)); |