From: Martin H. <mh...@us...> - 2005-03-23 13:06:56
|
Update of /cvsroot/opengtoolkit/serial/c_source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32524/c_source Modified Files: lvserial.cpp Log Message: Added additional features to the CommOptions function and changed the handshake settings, so they match more the behaviour of the mode command. Index: lvserial.cpp =================================================================== RCS file: /cvsroot/opengtoolkit/serial/c_source/lvserial.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** lvserial.cpp 21 Mar 2005 01:40:13 -0000 1.3 --- lvserial.cpp 23 Mar 2005 13:06:32 -0000 1.4 *************** *** 2509,2512 **** --- 2509,2513 ---- { PCOMM pComm; //pointer to the serial port COMM structure + DCB dcb; //DCB data structure _ASSERT(gpCommList); *************** *** 2525,2529 **** //any of the given characters at pcTermCharacter terminates //the read operation - pComm->lTeminationMode = COMM_TERM_CHAR; if (pcTermCharacter == NULL) --- 2526,2529 ---- *************** *** 2539,2542 **** --- 2539,2545 ---- } + //enable termination + pComm->lTeminationMode = COMM_TERM_CHAR; + if (pComm->pcTermination != NULL) pComm->pcTermination = (char *)malloc(lNumberOfTermChar+1); *************** *** 2566,2569 **** --- 2569,2591 ---- } + //if there is only one termination character, we change + //the DCB termination character. + if (lNumberOfTermChar == 1) + { + if (!GetCommState(pComm->hC, &dcb)) + { + _ASSERT(0); + return COMM_ERR_SYSTEM; + } + + dcb.EofChar = *pcTermCharacter; + + if (!SetCommState(pComm->hC, &dcb)) + { + _ASSERT(0); + return COMM_ERR_SYSTEM; + } + } + return COMM_SUCCESS; } *************** *** 2593,2596 **** --- 2615,2619 ---- long lNumberOfTermChar) { + DCB dcb; //DCB data structure PCOMM pComm; //pointer to the serial port COMM structure int iErrPos; //error position in the regex when copiling *************** *** 2620,2626 **** } - //store the termination mode - pComm->lTeminationMode = lTerminationMode; - if (lTerminationMode != COMM_TERM_NONE) { --- 2643,2646 ---- *************** *** 2636,2639 **** --- 2656,2662 ---- return COMM_ERR_ARGUMENT; + //store the termination mode + pComm->lTeminationMode = lTerminationMode; + if (pComm->pcTermination != NULL) pComm->pcTermination = (char *)malloc(lNumberOfTermChar+1); *************** *** 2681,2684 **** --- 2704,2710 ---- else { + //store the termination mode + pComm->lTeminationMode = lTerminationMode; + //read termination is disabled and we can free the memory for the //termination characters if they where allocated previously. *************** *** 2691,2694 **** --- 2717,2740 ---- } + //if there is only one termination character, we change + //the DCB termination character. + if (lNumberOfTermChar == 1 && + lTerminationMode != COMM_TERM_REGEX) + { + if (!GetCommState(pComm->hC, &dcb)) + { + _ASSERT(0); + return COMM_ERR_SYSTEM; + } + + dcb.EofChar = *pcTermination; + + if (!SetCommState(pComm->hC, &dcb)) + { + _ASSERT(0); + return COMM_ERR_SYSTEM; + } + } + return COMM_SUCCESS; } *************** *** 2990,2994 **** long CommOptions(HANDLE hComm, char *pszOptions) { ! DCB dcb; COMMTIMEOUTS Timeouts; //the OS serial port timeout values structure PCOMM pComm; //pointer to the COMM structure --- 3036,3040 ---- long CommOptions(HANDLE hComm, char *pszOptions) { ! DCB dcb; //DCB data structure COMMTIMEOUTS Timeouts; //the OS serial port timeout values structure PCOMM pComm; //pointer to the COMM structure *************** *** 3005,3008 **** --- 3051,3055 ---- int aiOffsets[18]; //found offsets in the subject string int iMatches; //number of found matches + int boSimpleHandshake; //simple form with handshake detected _ASSERT(gpCommList); *************** *** 3030,3039 **** } ! //At first, we try to detect the simple form of the option string ! //<baudrate>,<parity>,<databits>,<stopbits> pRegEx = pcre_compile( ! "(?i)(\\d+),([neoms]),([5-8]),([12])", ! 0, (const char **)&pszError, &iErrorOffset, --- 3077,3139 ---- } ! //At first, we try to detect the simple form with handshake ! //<baudrate>,<parity>,<databits>,<stopbits>,<handshake> ! pRegEx = pcre_compile( ! "(?i)(\\d+),([neoms]),(\\d{1,2}),([\\d\\.]{1,4}),([xp])", ! 0, ! (const char **)&pszError, ! &iErrorOffset, ! NULL); ! ! _ASSERT(pRegEx); ! ! iOptionsLength = (int)strlen(pszOptions); ! iOffset = 0; ! ! iMatches = pcre_exec( ! pRegEx, ! NULL, ! pszOptions, ! iOptionsLength, ! iOffset, ! PCRE_NOTEMPTY, ! aiOffsets, ! 18); + //if we detect the simple form with handshake, we set the + //boSimpleHandshake to true and set only the handshake + //parameters in the DCB. + if (iMatches > 0) + { + boSimpleHandshake = TRUE; + switch (*(pszOptions+aiOffsets[9])) + { + case 'x': + case 'X': + dcb.fInX = dcb.fOutX = TRUE; + dcb.fOutxDsrFlow = dcb.fOutxCtsFlow = FALSE; + dcb.fDtrControl = DTR_CONTROL_ENABLE; + dcb.fRtsControl = RTS_CONTROL_ENABLE; + break; + case 'p': + case 'P': + dcb.fInX = dcb.fOutX = FALSE; + dcb.fOutxDsrFlow = dcb.fOutxCtsFlow = TRUE; + dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; + dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; + break; + } + } + else + boSimpleHandshake = FALSE; + + //free the compiled regex + pcre_free(pRegEx); + + //Second, we try to detect the simple form (ignore the handshake) + //<baudrate>,<parity>,<databits>,<stopbits> pRegEx = pcre_compile( ! "(?i)(\\d+),([neoms]),(\\d{1,2}),([\\d\\.]{1,4})", ! 0, (const char **)&pszError, &iErrorOffset, *************** *** 3057,3063 **** if (iMatches > 0) { ! //the options string contains the simple form and we got ! //all the options through the regular expression. Now we ! //store the new configuration into the DCB structure. //store the baud rate --- 3157,3169 ---- if (iMatches > 0) { ! //the options string contains the simple form. ! ! if (!boSimpleHandshake) ! { ! dcb.fInX = dcb.fOutX = FALSE; ! dcb.fOutxDsrFlow = dcb.fOutxCtsFlow = FALSE; ! dcb.fDtrControl = DTR_CONTROL_ENABLE; ! dcb.fRtsControl = RTS_CONTROL_ENABLE; ! } //store the baud rate *************** *** 3202,3208 **** dcb.fOutX = TRUE; dcb.fOutxCtsFlow = FALSE; ! dcb.fRtsControl = RTS_CONTROL_DISABLE; dcb.fOutxDsrFlow = FALSE; ! dcb.fDtrControl = DTR_CONTROL_DISABLE; break; case 'r': --- 3308,3314 ---- dcb.fOutX = TRUE; dcb.fOutxCtsFlow = FALSE; ! dcb.fRtsControl = RTS_CONTROL_ENABLE; dcb.fOutxDsrFlow = FALSE; ! dcb.fDtrControl = DTR_CONTROL_ENABLE; break; case 'r': *************** *** 3213,3217 **** dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; dcb.fOutxDsrFlow = FALSE; ! dcb.fDtrControl = DTR_CONTROL_DISABLE; break; case 'd': --- 3319,3323 ---- dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; dcb.fOutxDsrFlow = FALSE; ! dcb.fDtrControl = DTR_CONTROL_ENABLE; break; case 'd': *************** *** 3220,3224 **** dcb.fOutX = FALSE; dcb.fOutxCtsFlow = FALSE; ! dcb.fRtsControl = RTS_CONTROL_DISABLE; dcb.fOutxDsrFlow = TRUE; dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; --- 3326,3339 ---- dcb.fOutX = FALSE; dcb.fOutxCtsFlow = FALSE; ! dcb.fRtsControl = RTS_CONTROL_ENABLE; ! dcb.fOutxDsrFlow = TRUE; ! dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; ! break; ! case 'p': ! case 'P': ! dcb.fInX = FALSE; ! dcb.fOutX = FALSE; ! dcb.fOutxCtsFlow = TRUE; ! dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; dcb.fOutxDsrFlow = TRUE; dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; *************** *** 3228,3241 **** } } ! else if (_strnicmp(pszOptions+aiOffsets[0], "xon", 3) == 0) { //set the XON character dcb.XonChar = (char)atoi(pszOptions+aiOffsets[6]); } ! else if (_strnicmp(pszOptions+aiOffsets[0], "xoff", 4) == 0) { //set the XOFF character dcb.XoffChar = (char)atoi(pszOptions+aiOffsets[6]); } else if (_strnicmp(pszOptions+aiOffsets[0], "data", 4) == 0) { --- 3343,3404 ---- } } ! else if (_strnicmp(pszOptions+aiOffsets[0], "xonc", 3) == 0) { //set the XON character dcb.XonChar = (char)atoi(pszOptions+aiOffsets[6]); } ! else if (_strnicmp(pszOptions+aiOffsets[0], "xoffc", 4) == 0) { //set the XOFF character dcb.XoffChar = (char)atoi(pszOptions+aiOffsets[6]); } + else if (_strnicmp(pszOptions+aiOffsets[0], "xon", 3) == 0) + { + if (_strnicmp(pszOptions+aiOffsets[6],"on",2) == 0) + dcb.fInX = dcb.fOutX = TRUE; + else if (_strnicmp(pszOptions+aiOffsets[6],"off",3) == 0) + dcb.fInX = dcb.fOutX = FALSE; + } + else if (_strnicmp(pszOptions+aiOffsets[0], "odsr", 3) == 0) + { + if (_strnicmp(pszOptions+aiOffsets[6],"on",2) == 0) + dcb.fOutxDsrFlow = TRUE; + else if (_strnicmp(pszOptions+aiOffsets[6],"off",3) == 0) + dcb.fOutxDsrFlow = FALSE; + } + else if (_strnicmp(pszOptions+aiOffsets[0], "octs", 3) == 0) + { + if (_strnicmp(pszOptions+aiOffsets[6],"on",2) == 0) + dcb.fOutxCtsFlow = TRUE; + else if (_strnicmp(pszOptions+aiOffsets[6],"off",3) == 0) + dcb.fOutxCtsFlow = FALSE; + } + else if (_strnicmp(pszOptions+aiOffsets[0], "dtr", 3) == 0) + { + if (_strnicmp(pszOptions+aiOffsets[6],"on",2) == 0) + dcb.fDtrControl = DTR_CONTROL_ENABLE; + else if (_strnicmp(pszOptions+aiOffsets[6],"off",3) == 0) + dcb.fDtrControl = DTR_CONTROL_DISABLE; + else if (_strnicmp(pszOptions+aiOffsets[6],"hs",2) == 0) + dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; + } + else if (_strnicmp(pszOptions+aiOffsets[0], "rts", 3) == 0) + { + if (_strnicmp(pszOptions+aiOffsets[6],"on",2) == 0) + dcb.fRtsControl = DTR_CONTROL_ENABLE; + else if (_strnicmp(pszOptions+aiOffsets[6],"off",3) == 0) + dcb.fRtsControl = DTR_CONTROL_DISABLE; + else if (_strnicmp(pszOptions+aiOffsets[6],"hs",2) == 0) + dcb.fRtsControl = DTR_CONTROL_HANDSHAKE; + else if (_strnicmp(pszOptions+aiOffsets[6],"ts",2) == 0) + dcb.fRtsControl = RTS_CONTROL_TOGGLE; + } + else if (_strnicmp(pszOptions+aiOffsets[0], "idsr", 3) == 0) + { + if (_strnicmp(pszOptions+aiOffsets[6],"on",2) == 0) + dcb.fDsrSensitivity = TRUE; + else if (_strnicmp(pszOptions+aiOffsets[6],"off",3) == 0) + dcb.fDsrSensitivity = FALSE; + } else if (_strnicmp(pszOptions+aiOffsets[0], "data", 4) == 0) { *************** *** 5030,5034 **** return; ! _ASSERT(DSCheckPtr(halsPorts)); //clean up the incoming array --- 5193,5197 ---- return; ! _ASSERT(!DSCheckPtr(halsPorts)); //clean up the incoming array |