2010-05-12 02:26 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/external/minizip/ioapi.h
! fixed FreeBSD and HAIKU builds
* harbour/src/rtl/fserr.c
* added translation for EPERM
* harbour/include/Makefile
+ harbour/include/hbapicom.h
* harbour/src/rtl/Makefile
+ harbour/src/rtl/hbcom.c
+ added Harbour multiplatform serial port C API (hb_com*() functions).
implemented code for *nixes, MS-Windows and OS2. DOS is not supported
yet. Please make test on different platforms.
; few notes about this code:
termios (*nix) based builds:
- reading LSR is not supported
- duration in break signal is fixed (at least 0.25 seconds, and not
more that 0.5 seconds)
- DTR/DSR hardware flow control is not supported
- setting error character is not supported
- discard card is supported only on few platforms
- checking input/output flow state is not supported
- if some platforms do not support some termio extensions then
compile time warnings TODO_* should be generated.
MS-Windows builds:
- discard card is not supported
OS2 builds:
- checking for input flow state is not supported
- discard card is not supported
In all builds not all RS-232 hardware flags/state are available.
OS2 build supports most of them,
This code needs to be extensively tested. I wrote it without any
serious tests. Especially OS2 builds should be verified by OS2
users. I wrote this port using only documentation which OS2 API
available in the Internet.
DOS is not supported yet though it's possible to compile termio code
for *nixes with DJGPP. Anyhow it would be very nice if we can add
our own DOS serial port code. I would like to ask if any of you
has low level serial port code in C for DOS (i.e. used with Clipper)
and can send it to us so we can use it with Harbour. I have my
own serial port library for Clipper but it's written in assembler
and it's much wider then sth what we need so it cannot be easy
adopted for Harbour.
* harbour/contrib/hbct/Makefile
+ harbour/contrib/hbct/ctcom1.c
+ harbour/contrib/hbct/ctcom.ch
+ harbour/contrib/hbct/ctcom2.c
+ added CT3 compatible COM_*() functions.
+ added CT3 compatible XMOBLOCK(), XMOCHECK(), ZEROINSERT() and
ZEROREMOVE() functions.
+ added new CT COM function:
COM_DEVNAME( <nComPort> [, <cNewName> ] ) -> <cPrevName>
which can be used to specify device name for given port in modern
systems which do not give direct hardware access for the process.
; few notes about CT3 COM_*() functions in Harbour.
In COM_OPEN() only 1-st parameter is significant, input/output buffer
sizes and trap mode parameters are ignored. In modern OS-es such
functionality is controlled by OS and usually buffered read/write
is always enabled. The sizes of IO buffers can be used only as
suggested IO buffer size for OS in some systems. It's possible that
these additional parameters will be used in DOS builds in the future.
COM_READ() does not support 2-nd parameter <lNoDelete>. It can be
implemented but because we do not have direct access to OS buffers
then we will have to emulate it ourselves what is rather inefficient.
Anyhow I can implement it if users think it's critical.
In COM_CRC() I fixed few CT3 bugs so it's not bug compatible with CT3,
i.e. it works correctly for 8 bit and smaller polynomials instead of
returning 0 or supports much larger polynomials up to 64bits.
For 16/17 bit polynomials it gives the same results as CT3 so for most
common usage it should be binary compatible with CT3.
In ZEROREMOVE() I fixed decoding some wrong CCITT strings which does
not have trailing 0 so it returns empty string "" for such corrupted
data. If someone needs original CT3 behavior for some broken code then
is can be enabled by HB_CT3_ZEROREMOVE_BUG macro.
I haven't implemented few functions.
COM_GETIO(), COM_SETIO(), COM_GETIRQ(), COM_SETIRQ() are not portable
and can be implemented only for really few platforms, i.e. for DOS
when/if we add support for serial ports to Harbour DOS builds.
Similar functionality for all other platforms gives our new function
COM_DEVNAME().
COM_KEY(), COM_SKEY() and COM_EVENT() are also not implemented.
To make them well we should add support for asynchronous events to HVM
and such extension is still unavailable. Some simulation can be
implemented using idle tasks but this can be done also by final
Harbour users so I decided to not make it.
Please test it - I've never used CT3 COM_*() API with Clipper.
* harbour/contrib/hbct/dummy.c
* removed dummy CT3 serial communication functions
; such files with dummy functions introduces very serious problems for
user code because they do not respect original module granularity
effectively breaking overloading only chosen functions so it breaks
also some real Clipper code.
This commit is contained in:
@@ -17,6 +17,106 @@
|
||||
past entries belonging to author(s): Viktor Szakats.
|
||||
*/
|
||||
|
||||
2010-05-12 02:26 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
|
||||
* harbour/external/minizip/ioapi.h
|
||||
! fixed FreeBSD and HAIKU builds
|
||||
|
||||
* harbour/src/rtl/fserr.c
|
||||
* added translation for EPERM
|
||||
|
||||
* harbour/include/Makefile
|
||||
+ harbour/include/hbapicom.h
|
||||
* harbour/src/rtl/Makefile
|
||||
+ harbour/src/rtl/hbcom.c
|
||||
+ added Harbour multiplatform serial port C API (hb_com*() functions).
|
||||
implemented code for *nixes, MS-Windows and OS2. DOS is not supported
|
||||
yet. Please make test on different platforms.
|
||||
; few notes about this code:
|
||||
termios (*nix) based builds:
|
||||
- reading LSR is not supported
|
||||
- duration in break signal is fixed (at least 0.25 seconds, and not
|
||||
more that 0.5 seconds)
|
||||
- DTR/DSR hardware flow control is not supported
|
||||
- setting error character is not supported
|
||||
- discard card is supported only on few platforms
|
||||
- checking input/output flow state is not supported
|
||||
- if some platforms do not support some termio extensions then
|
||||
compile time warnings TODO_* should be generated.
|
||||
MS-Windows builds:
|
||||
- discard card is not supported
|
||||
OS2 builds:
|
||||
- checking for input flow state is not supported
|
||||
- discard card is not supported
|
||||
In all builds not all RS-232 hardware flags/state are available.
|
||||
OS2 build supports most of them,
|
||||
|
||||
This code needs to be extensively tested. I wrote it without any
|
||||
serious tests. Especially OS2 builds should be verified by OS2
|
||||
users. I wrote this port using only documentation which OS2 API
|
||||
available in the Internet.
|
||||
|
||||
DOS is not supported yet though it's possible to compile termio code
|
||||
for *nixes with DJGPP. Anyhow it would be very nice if we can add
|
||||
our own DOS serial port code. I would like to ask if any of you
|
||||
has low level serial port code in C for DOS (i.e. used with Clipper)
|
||||
and can send it to us so we can use it with Harbour. I have my
|
||||
own serial port library for Clipper but it's written in assembler
|
||||
and it's much wider then sth what we need so it cannot be easy
|
||||
adopted for Harbour.
|
||||
|
||||
* harbour/contrib/hbct/Makefile
|
||||
+ harbour/contrib/hbct/ctcom1.c
|
||||
+ harbour/contrib/hbct/ctcom.ch
|
||||
+ harbour/contrib/hbct/ctcom2.c
|
||||
+ added CT3 compatible COM_*() functions.
|
||||
+ added CT3 compatible XMOBLOCK(), XMOCHECK(), ZEROINSERT() and
|
||||
ZEROREMOVE() functions.
|
||||
+ added new CT COM function:
|
||||
COM_DEVNAME( <nComPort> [, <cNewName> ] ) -> <cPrevName>
|
||||
which can be used to specify device name for given port in modern
|
||||
systems which do not give direct hardware access for the process.
|
||||
; few notes about CT3 COM_*() functions in Harbour.
|
||||
In COM_OPEN() only 1-st parameter is significant, input/output buffer
|
||||
sizes and trap mode parameters are ignored. In modern OS-es such
|
||||
functionality is controlled by OS and usually buffered read/write
|
||||
is always enabled. The sizes of IO buffers can be used only as
|
||||
suggested IO buffer size for OS in some systems. It's possible that
|
||||
these additional parameters will be used in DOS builds in the future.
|
||||
COM_READ() does not support 2-nd parameter <lNoDelete>. It can be
|
||||
implemented but because we do not have direct access to OS buffers
|
||||
then we will have to emulate it ourselves what is rather inefficient.
|
||||
Anyhow I can implement it if users think it's critical.
|
||||
In COM_CRC() I fixed few CT3 bugs so it's not bug compatible with CT3,
|
||||
i.e. it works correctly for 8 bit and smaller polynomials instead of
|
||||
returning 0 or supports much larger polynomials up to 64bits.
|
||||
For 16/17 bit polynomials it gives the same results as CT3 so for most
|
||||
common usage it should be binary compatible with CT3.
|
||||
In ZEROREMOVE() I fixed decoding some wrong CCITT strings which does
|
||||
not have trailing 0 so it returns empty string "" for such corrupted
|
||||
data. If someone needs original CT3 behavior for some broken code then
|
||||
is can be enabled by HB_CT3_ZEROREMOVE_BUG macro.
|
||||
|
||||
I haven't implemented few functions.
|
||||
COM_GETIO(), COM_SETIO(), COM_GETIRQ(), COM_SETIRQ() are not portable
|
||||
and can be implemented only for really few platforms, i.e. for DOS
|
||||
when/if we add support for serial ports to Harbour DOS builds.
|
||||
Similar functionality for all other platforms gives our new function
|
||||
COM_DEVNAME().
|
||||
COM_KEY(), COM_SKEY() and COM_EVENT() are also not implemented.
|
||||
To make them well we should add support for asynchronous events to HVM
|
||||
and such extension is still unavailable. Some simulation can be
|
||||
implemented using idle tasks but this can be done also by final
|
||||
Harbour users so I decided to not make it.
|
||||
|
||||
Please test it - I've never used CT3 COM_*() API with Clipper.
|
||||
|
||||
* harbour/contrib/hbct/dummy.c
|
||||
* removed dummy CT3 serial communication functions
|
||||
; such files with dummy functions introduces very serious problems for
|
||||
user code because they do not respect original module granularity
|
||||
effectively breaking overloading only chosen functions so it breaks
|
||||
also some real Clipper code.
|
||||
|
||||
2010-05-11 22:22 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* contrib/hbziparc/Makefile
|
||||
* contrib/hbziparc/hbziparc.prg
|
||||
|
||||
@@ -30,6 +30,8 @@ C_SOURCES := \
|
||||
count.c \
|
||||
ctc.c \
|
||||
ctchksum.c \
|
||||
ctcom1.c \
|
||||
ctcom2.c \
|
||||
ctcrypt.c \
|
||||
ctmath.c \
|
||||
ctmath2.c \
|
||||
@@ -115,6 +117,7 @@ PRG_SOURCES := \
|
||||
|
||||
PRG_HEADERS := \
|
||||
ct.ch \
|
||||
ctcom.ch \
|
||||
ctdisk.ch \
|
||||
cterror.ch \
|
||||
ctextern.ch \
|
||||
|
||||
98
harbour/contrib/hbct/ctcom.ch
Normal file
98
harbour/contrib/hbct/ctcom.ch
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* constant values for CT3 serial communication COM_*() functions
|
||||
*
|
||||
* Copyright 2010 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
||||
* www - http://www.harbour-project.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
||||
*
|
||||
* As a special exception, the Harbour Project gives permission for
|
||||
* additional uses of the text contained in its release of Harbour.
|
||||
*
|
||||
* The exception is that, if you link the Harbour libraries with other
|
||||
* files to produce an executable, this does not by itself cause the
|
||||
* resulting executable to be covered by the GNU General Public License.
|
||||
* Your use of that executable is in no way restricted on account of
|
||||
* linking the Harbour library code into it.
|
||||
*
|
||||
* This exception does not however invalidate any other reasons why
|
||||
* the executable file might be covered by the GNU General Public License.
|
||||
*
|
||||
* This exception applies only to the code released by the Harbour
|
||||
* Project under the name Harbour. If you copy code from other
|
||||
* Harbour Project or Free Software Foundation releases into a copy of
|
||||
* Harbour, as the General Public License permits, the exception does
|
||||
* not apply to the code that you add in this way. To avoid misleading
|
||||
* anyone as to the status of such modified files, you must delete
|
||||
* this exception notice from them.
|
||||
*
|
||||
* If you write modifications of your own for Harbour, it is your choice
|
||||
* whether to permit this exception to apply to your modifications.
|
||||
* If you do not wish that, delete this exception notice.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* COM_MCR() */
|
||||
#define MCR_ERROR 0 /* Parameter error */
|
||||
#define MCR_DTR 1 /* Data terminal ready (DTR) */
|
||||
#define MCR_RTS 2 /* Request to send (RTS) */
|
||||
#define MCR_OUT_1 4 /* OUT 1 */
|
||||
#define MCR_OUT_2 8 /* OUT 2 */
|
||||
#define MCR_LOOP 16 /* LOOP */
|
||||
|
||||
|
||||
/* COM_MSR() */
|
||||
#define MSR_ERROR 0 /* Parameter error */
|
||||
#define MSR_DELTA_CTS 1 /* DELTA ready to send (DCTS) */
|
||||
#define MSR_DELTA_DSR 2 /* DELTA data terminal ready (DDSR) */
|
||||
#define MSR_TERI 4 /* Trailing edge RING (TERI) */
|
||||
#define MSR_DELTA_DCD 8 /* DELTA data carrier detected (DDCD) */
|
||||
#define MSR_CTS 16 /* Clear to send (CTS) */
|
||||
#define MSR_DSR 32 /* Data terminal ready (DSR) */
|
||||
#define MSR_RI 64 /* RING indicator (RI) */
|
||||
#define MSR_DCD 128 /* Data carrier detected (DCD) */
|
||||
|
||||
|
||||
/* COM_LSR() */
|
||||
#define LSR_ERROR 0 /* Parameter error */
|
||||
#define LSR_DATA_READY 1 /* Data ready */
|
||||
#define LSR_OVERRUN_ERR 2 /* Overflow error */
|
||||
#define LSR_PARITY_ERR 4 /* Parity error */
|
||||
#define LSR_FRAMING_ERR 8 /* Framing error */
|
||||
#define LSR_BREAK 16 /* BREAK recognized */
|
||||
#define LSR_TRANS_HOLD_EMPTY 32 /* Transmission holder register empty */
|
||||
#define LSR_TRANS_EMPTY 64 /* TX shift register empty */
|
||||
|
||||
|
||||
/* COM_SMODE() */
|
||||
#define SMODE_EMPTY 1 /* Sending buffer empty */
|
||||
#define SMODE_SOFT 2 /* Wait for software handshake release(XON) */
|
||||
#define SMODE_HARD 4 /* Wait for hardware handshake release(CTS) */
|
||||
#define SMODE_RFLUSH 8 /* Deleted from remote station */
|
||||
|
||||
|
||||
/* COM_CRC() polynomials */
|
||||
#define Parity 3 /* 2^1 + 1^0 */
|
||||
#define LCR_8 257 /* 2^8 + 1^0 */
|
||||
#define CRC_12 5011 /* 2^12 + 2^11 + 2^3 + 2^2 + 2^1 + 1^0 */
|
||||
#define CRC_16_X25 69665 /* 2^16 + 2^12 + 2^5 + 1^0 */
|
||||
#define CRC_16 98309 /* 2^16 + 2^15 + 2^2 + 1^0 */
|
||||
524
harbour/contrib/hbct/ctcom1.c
Normal file
524
harbour/contrib/hbct/ctcom1.c
Normal file
@@ -0,0 +1,524 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* CT3 serial communication COM_*() functions
|
||||
*
|
||||
* Copyright 2010 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
||||
* www - http://www.harbour-project.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
||||
*
|
||||
* As a special exception, the Harbour Project gives permission for
|
||||
* additional uses of the text contained in its release of Harbour.
|
||||
*
|
||||
* The exception is that, if you link the Harbour libraries with other
|
||||
* files to produce an executable, this does not by itself cause the
|
||||
* resulting executable to be covered by the GNU General Public License.
|
||||
* Your use of that executable is in no way restricted on account of
|
||||
* linking the Harbour library code into it.
|
||||
*
|
||||
* This exception does not however invalidate any other reasons why
|
||||
* the executable file might be covered by the GNU General Public License.
|
||||
*
|
||||
* This exception applies only to the code released by the Harbour
|
||||
* Project under the name Harbour. If you copy code from other
|
||||
* Harbour Project or Free Software Foundation releases into a copy of
|
||||
* Harbour, as the General Public License permits, the exception does
|
||||
* not apply to the code that you add in this way. To avoid misleading
|
||||
* anyone as to the status of such modified files, you must delete
|
||||
* this exception notice from them.
|
||||
*
|
||||
* If you write modifications of your own for Harbour, it is your choice
|
||||
* whether to permit this exception to apply to your modifications.
|
||||
* If you do not wish that, delete this exception notice.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hbapi.h"
|
||||
#include "hbapiitm.h"
|
||||
#include "hbapicom.h"
|
||||
#include "ctcom.ch"
|
||||
|
||||
static int hb_ctComCharParam( int iParam )
|
||||
{
|
||||
const char * pszParam = hb_parc( iParam );
|
||||
|
||||
if( pszParam )
|
||||
{
|
||||
if( hb_parclen( iParam ) > 0 )
|
||||
return ( unsigned char ) pszParam[ 0 ];
|
||||
}
|
||||
else if( HB_ISNUM( iParam ) )
|
||||
return ( unsigned char ) hb_parni( iParam );
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void hb_ctComTestMSR( int iLine )
|
||||
{
|
||||
HB_BOOL fResult;
|
||||
int iMSR;
|
||||
|
||||
if( hb_comMSR( hb_parni( 1 ), &iMSR ) != -1 )
|
||||
fResult = ( iMSR & iLine ) != 0;
|
||||
else
|
||||
fResult = HB_FALSE;
|
||||
|
||||
hb_retl( fResult );
|
||||
}
|
||||
|
||||
/* COM_COUNT( <nComPort> ) -> <nCharactersInInputBuffer>
|
||||
*/
|
||||
HB_FUNC( COM_COUNT )
|
||||
{
|
||||
hb_retni( hb_comInputCount( hb_parni( 1 ) ) );
|
||||
}
|
||||
|
||||
/* COM_SCOUNT( <nComPort> ) -> <nCharactersInOutputBuffer>
|
||||
*/
|
||||
HB_FUNC( COM_SCOUNT )
|
||||
{
|
||||
hb_retni( hb_comOutputCount( hb_parni( 1 ) ) );
|
||||
}
|
||||
|
||||
/* COM_FLUSH( <nComPort> ) -> <lInputBufferCleared>
|
||||
*/
|
||||
HB_FUNC( COM_FLUSH )
|
||||
{
|
||||
hb_retl( hb_comFlush( hb_parni( 1 ), HB_COM_IFLUSH ) != -1 );
|
||||
}
|
||||
|
||||
/* COM_SFLUSH( <nComPort> ) -> <lOutputBufferCleared>
|
||||
*/
|
||||
HB_FUNC( COM_SFLUSH )
|
||||
{
|
||||
hb_retl( hb_comFlush( hb_parni( 1 ), HB_COM_OFLUSH ) != -1 );
|
||||
}
|
||||
|
||||
/* COM_CTS( <nComPort> ) -> <lCTSActive>
|
||||
*/
|
||||
HB_FUNC( COM_CTS )
|
||||
{
|
||||
hb_ctComTestMSR( HB_COM_MSR_CTS );
|
||||
}
|
||||
|
||||
/* COM_DCD( <nComPort> ) -> <lDCDActive>
|
||||
*/
|
||||
HB_FUNC( COM_DCD )
|
||||
{
|
||||
hb_ctComTestMSR( HB_COM_MSR_DCD );
|
||||
}
|
||||
|
||||
/* COM_DSR( <nComPort> ) -> <lDSRActive>
|
||||
*/
|
||||
HB_FUNC( COM_DSR )
|
||||
{
|
||||
hb_ctComTestMSR( HB_COM_MSR_DSR );
|
||||
}
|
||||
|
||||
/* COM_RING( <nComPort> ) -> <lActiveRing>
|
||||
*/
|
||||
HB_FUNC( COM_RING )
|
||||
{
|
||||
hb_ctComTestMSR( HB_COM_MSR_RI );
|
||||
}
|
||||
|
||||
/* COM_RTS( <nComPort>, [<lNewRTSStatus>] ) -> <lOldRTSStatus>
|
||||
*/
|
||||
HB_FUNC( COM_RTS )
|
||||
{
|
||||
int iMCR, iClr = 0, iSet = 0;
|
||||
|
||||
if( HB_ISLOG( 2 ) )
|
||||
{
|
||||
if( hb_parl( 2 ) )
|
||||
iSet = HB_COM_MCR_RTS;
|
||||
else
|
||||
iClr = HB_COM_MCR_RTS;
|
||||
}
|
||||
hb_comMCR( hb_parni( 1 ), &iMCR, iClr, iSet );
|
||||
hb_retl( ( iMCR & HB_COM_MCR_DTR ) != 0 );
|
||||
}
|
||||
|
||||
/* COM_DTR( <nComPort>, [<lNewDTRStatus>] ) -> <lOldDTRStatus>
|
||||
*/
|
||||
HB_FUNC( COM_DTR )
|
||||
{
|
||||
int iMCR, iClr = 0, iSet = 0;
|
||||
|
||||
if( HB_ISLOG( 2 ) )
|
||||
{
|
||||
if( hb_parl( 2 ) )
|
||||
iSet = HB_COM_MCR_DTR;
|
||||
else
|
||||
iClr = HB_COM_MCR_DTR;
|
||||
}
|
||||
hb_comMCR( hb_parni( 1 ), &iMCR, iClr, iSet );
|
||||
hb_retl( ( iMCR & HB_COM_MCR_DTR ) != 0 );
|
||||
}
|
||||
|
||||
/* COM_MCR( <nComPort>, [<nMCR>] ) -> <nMCR> (MCR_*)
|
||||
*/
|
||||
HB_FUNC( COM_MCR )
|
||||
{
|
||||
int iMCR, iClr, iSet;
|
||||
|
||||
if( HB_ISNUM( 2 ) )
|
||||
{
|
||||
iClr = 0xff;
|
||||
iSet = hb_parni( 2 ) & 0xff;
|
||||
}
|
||||
else
|
||||
iClr = iSet = 0;
|
||||
|
||||
if( hb_comMCR( hb_parni( 1 ), &iMCR, iClr, iSet ) == -1 )
|
||||
iMCR = MCR_ERROR;
|
||||
|
||||
hb_retni( iMCR );
|
||||
}
|
||||
|
||||
/* COM_MSR( <nComPort> ) -> <nMSR> (MSR_*)
|
||||
*/
|
||||
HB_FUNC( COM_MSR )
|
||||
{
|
||||
int iMSR;
|
||||
|
||||
if( hb_comMSR( hb_parni( 1 ), &iMSR ) == -1 )
|
||||
iMSR = MSR_ERROR;
|
||||
|
||||
hb_retni( iMSR );
|
||||
}
|
||||
|
||||
/* COM_LSR( <nComPort> ) -> <nLSR> (LSR_*)
|
||||
*/
|
||||
HB_FUNC( COM_LSR )
|
||||
{
|
||||
int iLSR;
|
||||
|
||||
if( hb_comLSR( hb_parni( 1 ), &iLSR ) == -1 )
|
||||
iLSR = LSR_ERROR;
|
||||
|
||||
hb_retni( iLSR );
|
||||
}
|
||||
|
||||
/* COM_BREAK( <nComPort>, <nDurationInMilliSecs>=100 ) -> <lSuccess>
|
||||
*/
|
||||
HB_FUNC( COM_BREAK )
|
||||
{
|
||||
hb_retl( hb_comSendBreak( hb_parni( 1 ), hb_parnidef( 2, 100 ) ) != 0 );
|
||||
}
|
||||
|
||||
/* COM_HARD( <nComPort>, [<lNewHandshake>], [<lDTR/DSR>] ) -> <lOldHandshake>
|
||||
*/
|
||||
HB_FUNC( COM_HARD )
|
||||
{
|
||||
int iPort = hb_parni( 1 ), iFlow, iMask;
|
||||
HB_BOOL fResult = HB_FALSE;
|
||||
|
||||
if( hb_comFlowControl( iPort, &iFlow, -1 ) != -1 )
|
||||
{
|
||||
iMask = hb_parl( 3 ) ? ( HB_COM_FLOW_IDTRDSR | HB_COM_FLOW_ODTRDSR ) :
|
||||
( HB_COM_FLOW_IRTSCTS | HB_COM_FLOW_ORTSCTS );
|
||||
fResult = ( iFlow & iMask ) == iMask;
|
||||
|
||||
if( HB_ISLOG( 2 ) )
|
||||
{
|
||||
iFlow &= ~( HB_COM_FLOW_IDTRDSR | HB_COM_FLOW_ODTRDSR |
|
||||
HB_COM_FLOW_IRTSCTS | HB_COM_FLOW_ORTSCTS );
|
||||
if( hb_parl( 2 ) )
|
||||
iFlow |= iMask;
|
||||
hb_comFlowControl( iPort, NULL, iFlow );
|
||||
}
|
||||
}
|
||||
hb_retl( fResult );
|
||||
}
|
||||
|
||||
/* COM_SOFT( <nComPort>, [<lNewHandshake>],
|
||||
[<cXONchar>], [<cXOFFchar>] ) -> <lOldHandshake>
|
||||
*/
|
||||
HB_FUNC( COM_SOFT )
|
||||
{
|
||||
int iPort = hb_parni( 1 ), iFlow, iMask;
|
||||
HB_BOOL fResult = HB_FALSE;
|
||||
|
||||
if( hb_comFlowControl( iPort, &iFlow, -1 ) != -1 )
|
||||
{
|
||||
iMask = ( HB_COM_FLOW_XON | HB_COM_FLOW_XOFF );
|
||||
fResult = ( iFlow & iMask ) == iMask;
|
||||
|
||||
if( HB_ISLOG( 2 ) )
|
||||
{
|
||||
if( hb_parl( 2 ) )
|
||||
iFlow |= iMask;
|
||||
else
|
||||
iFlow &= ~iMask;
|
||||
hb_comFlowControl( iPort, NULL, iFlow );
|
||||
}
|
||||
if( hb_pcount() > 2 )
|
||||
hb_comFlowChars( iPort, hb_ctComCharParam( 3 ), hb_ctComCharParam( 4 ) );
|
||||
}
|
||||
hb_retl( fResult );
|
||||
}
|
||||
|
||||
/* COM_SOFT_R( <nComPort>, [<lXOFFFlag>] ) -> <lXOFFFlag>
|
||||
*/
|
||||
HB_FUNC( COM_SOFT_R )
|
||||
{
|
||||
HB_BOOL fResult = HB_FALSE;
|
||||
int iPort = hb_parni( 1 ), iMode;
|
||||
|
||||
if( HB_ISLOG( 2 ) )
|
||||
hb_comFlowSet( iPort, HB_COM_FL_SOFT |
|
||||
( hb_parl( 2 ) ? HB_COM_FL_OOFF : HB_COM_FL_OON ) );
|
||||
|
||||
iMode = hb_comOutputState( iPort );
|
||||
if( iMode > 0 )
|
||||
fResult = ( iMode & HB_COM_TX_XOFF ) != 0;
|
||||
|
||||
hb_retl( fResult );
|
||||
}
|
||||
|
||||
/* COM_SOFT_S( <nComPort> ) -> <lXOFFFlag>
|
||||
*/
|
||||
HB_FUNC( COM_SOFT_S )
|
||||
{
|
||||
HB_BOOL fResult = HB_FALSE;
|
||||
int iMode = hb_comInputState( hb_parni( 1 ) );
|
||||
|
||||
if( iMode > 0 )
|
||||
fResult = ( iMode & HB_COM_RX_XOFF ) != 0;
|
||||
|
||||
hb_retl( fResult );
|
||||
}
|
||||
|
||||
/* COM_ERRCHR( <nComPort>, [<nErrorCharacter|cErrorCharacter>] ) -> <lChanged>
|
||||
*/
|
||||
HB_FUNC( COM_ERRCHR )
|
||||
{
|
||||
hb_retl( hb_comErrorChar( hb_parni( 1 ), hb_ctComCharParam( 2 ) ) != -1 );
|
||||
}
|
||||
|
||||
/* COM_REMOTE( <nComPort>, [<nCharacter|cCharacter>] ) -> <lActive>
|
||||
*/
|
||||
HB_FUNC( COM_REMOTE )
|
||||
{
|
||||
hb_retl( hb_comDiscardChar( hb_parni( 1 ), hb_ctComCharParam( 2 ) ) > 0 );
|
||||
}
|
||||
|
||||
/* COM_SMODE( <nComPort> ) -> <nSendMode>
|
||||
*/
|
||||
HB_FUNC( COM_SMODE )
|
||||
{
|
||||
int iMode = hb_comOutputState( hb_parni( 1 ) ), iResult = 0;
|
||||
|
||||
if( iMode > 0 )
|
||||
{
|
||||
if( iMode & HB_COM_TX_EMPTY )
|
||||
iResult |= SMODE_EMPTY;
|
||||
if( iMode & HB_COM_TX_XOFF )
|
||||
iResult |= SMODE_SOFT;
|
||||
if( iMode & ( HB_COM_TX_CTS | HB_COM_TX_DSR | HB_COM_TX_DCD ) )
|
||||
iResult |= SMODE_HARD;
|
||||
if( iMode & HB_COM_TX_RFLUSH )
|
||||
iResult |= SMODE_RFLUSH;
|
||||
}
|
||||
|
||||
hb_retni( iResult );
|
||||
}
|
||||
|
||||
/* COM_EVENT( <nComPort>, <nMode> ) -> <nCode>
|
||||
*/
|
||||
HB_FUNC( COM_EVENT )
|
||||
{
|
||||
/* TODO: unsupported */
|
||||
hb_retni( 0 );
|
||||
}
|
||||
|
||||
/* COM_KEY( <nComPort>, [<nKeyValue1>], [<nKeyValue2>] ) -> <lActive>
|
||||
*/
|
||||
HB_FUNC( COM_KEY )
|
||||
{
|
||||
/* TODO: unsupported */
|
||||
hb_retl( HB_FALSE );
|
||||
}
|
||||
|
||||
/* COM_SKEY( [<nComPort>], [<nKeyValue1|cKeyValue1>],
|
||||
* [<nKeyValue2|cKeyValue2>] ) -> <lActive>
|
||||
*/
|
||||
HB_FUNC( COM_SKEY )
|
||||
{
|
||||
/* TODO: unsupported */
|
||||
hb_retl( HB_FALSE );
|
||||
}
|
||||
|
||||
|
||||
/* COM_INIT( <nComPort>, [<nBaudRate>=300], [<cParity:E,O,M,S,N>=N],
|
||||
* [<nDataLength:7,8>=8], [<nStopBits:1,2>=1] ) -> <lInitialized>
|
||||
*/
|
||||
HB_FUNC( COM_INIT )
|
||||
{
|
||||
int iPort = hb_parni( 1 ),
|
||||
iBaud = hb_parnidef( 2, 300 ),
|
||||
iParity = hb_parcx( 3 )[ 0 ],
|
||||
iSize = hb_parnidef( 4, 8 ),
|
||||
iStop = hb_parnidef( 5, 1 );
|
||||
|
||||
hb_retl( hb_comInit( iPort, iBaud, iParity, iSize, iStop ) != -1 );
|
||||
}
|
||||
|
||||
/* COM_OPEN( <nComPort>, [<nBufferIn>=100] [, <nBufferOut>=0],
|
||||
* [<lTrapMode>] ) -> <lStatus>
|
||||
*/
|
||||
HB_FUNC( COM_OPEN )
|
||||
{
|
||||
/* TODO: add support for <nBufferIn> */
|
||||
/* TODO: add support for <nBufferOut> */
|
||||
/* TODO: add support for <lTrapMode> */
|
||||
|
||||
hb_retl( hb_comOpen( hb_parni( 1 ) ) != -1 );
|
||||
}
|
||||
|
||||
/* COM_CLOSE( <nComPort> ) -> <lClosed>
|
||||
*/
|
||||
HB_FUNC( COM_CLOSE )
|
||||
{
|
||||
int iPort = hb_parni( 1 );
|
||||
|
||||
hb_comFlush( iPort, HB_COM_IOFLUSH );
|
||||
hb_retl( hb_comClose( iPort ) != -1 );
|
||||
}
|
||||
|
||||
/* COM_READ( <nComPort>, [<nLength>], [<lNoDelete>] ) -> <cCharacterstring>
|
||||
*/
|
||||
HB_FUNC( COM_READ )
|
||||
{
|
||||
char buffer[ 1024 ];
|
||||
char * data;
|
||||
long lLen, lRecv;
|
||||
int iPort = hb_parni( 1 );
|
||||
|
||||
/* TODO: add support for <lNoDelete> */
|
||||
|
||||
if( HB_ISNUM( 2 ) )
|
||||
lLen = hb_parnl( 2 );
|
||||
else
|
||||
{
|
||||
lLen = hb_comInputCount( iPort );
|
||||
if( lLen < ( long ) sizeof( buffer ) >> 1 )
|
||||
lLen = sizeof( buffer );
|
||||
else
|
||||
lLen <<= 2;
|
||||
}
|
||||
if( lLen <= ( long ) sizeof( buffer ) )
|
||||
data = buffer;
|
||||
else
|
||||
data = ( char * ) hb_xgrab( lLen + 1 );
|
||||
|
||||
lRecv = hb_comRecv( iPort, buffer, lLen, 0 );
|
||||
if( lRecv < 0 )
|
||||
lRecv = 0;
|
||||
|
||||
if( data == buffer )
|
||||
hb_retclen( data, lRecv );
|
||||
else if( lLen > 16 && ( lLen >> 2 ) > lRecv )
|
||||
{
|
||||
hb_retclen( data, lRecv );
|
||||
hb_xfree( data );
|
||||
}
|
||||
else
|
||||
hb_retclen_buffer( data, lRecv );
|
||||
}
|
||||
|
||||
/* COM_SEND( <nComPort>, <cString|nChar> ) -> <nNotSendLength>
|
||||
*/
|
||||
HB_FUNC( COM_SEND )
|
||||
{
|
||||
const char * data = hb_parc( 2 );
|
||||
long lLen = 0;
|
||||
char buffer;
|
||||
|
||||
/* TODO: add automatic drain call for ports open without send buffer */
|
||||
|
||||
if( data )
|
||||
lLen = ( long ) hb_parclen( 2 );
|
||||
else if( HB_ISNUM( 2 ) )
|
||||
{
|
||||
buffer = ( unsigned char ) hb_parni( 2 );
|
||||
data = &buffer;
|
||||
lLen = 1;
|
||||
}
|
||||
|
||||
if( lLen )
|
||||
{
|
||||
long lResult = hb_comSend( hb_parni( 1 ), data, lLen, 0 );
|
||||
if( lResult > 0 )
|
||||
lLen -= lResult;
|
||||
}
|
||||
|
||||
hb_retnl( lLen );
|
||||
}
|
||||
|
||||
/* COM_NUM() -> <nMaxCom>
|
||||
*/
|
||||
HB_FUNC( COM_NUM )
|
||||
{
|
||||
hb_retni( hb_comLastNum() );
|
||||
}
|
||||
|
||||
|
||||
/* COM_GETIO( <nComPort> ) -> <nIOPort> | -1
|
||||
*/
|
||||
HB_FUNC( COM_GETIO )
|
||||
{
|
||||
/* TODO! */
|
||||
}
|
||||
|
||||
/* COM_SETIO( <nComPort>, <nIOPort|cIOPort> ) -> <lChanged>
|
||||
*/
|
||||
HB_FUNC( COM_SETIO )
|
||||
{
|
||||
/* TODO! */
|
||||
}
|
||||
|
||||
/* COM_GETIRQ( <nComPort> ) -> <nIRQ> | -1
|
||||
*/
|
||||
HB_FUNC( COM_GETIRQ )
|
||||
{
|
||||
/* TODO! */
|
||||
}
|
||||
|
||||
/* COM_SETIRQ( <nComPort>, <nIRQ|cIRQ> ) -> <lChanged>
|
||||
*/
|
||||
HB_FUNC( COM_SETIRQ )
|
||||
{
|
||||
/* TODO! */
|
||||
}
|
||||
|
||||
/* COM_DEVNAME( <nComPort> [, <cNewName> ] ) -> <cPrevName>
|
||||
*/
|
||||
HB_FUNC( COM_DEVNAME )
|
||||
{
|
||||
int iPort = hb_parni( 1 );
|
||||
const char * szDevName = hb_parc( 2 );
|
||||
char buffer[ HB_COM_DEV_NAME_MAX ];
|
||||
|
||||
hb_retc( hb_comGetDevice( iPort, buffer, sizeof( buffer ) ) );
|
||||
if( szDevName )
|
||||
hb_comSetDevice( iPort, szDevName );
|
||||
}
|
||||
398
harbour/contrib/hbct/ctcom2.c
Normal file
398
harbour/contrib/hbct/ctcom2.c
Normal file
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* CT3 serial communication functions not directly operating on
|
||||
* serial devices
|
||||
*
|
||||
* Copyright 2010 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
||||
* www - http://www.harbour-project.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
||||
*
|
||||
* As a special exception, the Harbour Project gives permission for
|
||||
* additional uses of the text contained in its release of Harbour.
|
||||
*
|
||||
* The exception is that, if you link the Harbour libraries with other
|
||||
* files to produce an executable, this does not by itself cause the
|
||||
* resulting executable to be covered by the GNU General Public License.
|
||||
* Your use of that executable is in no way restricted on account of
|
||||
* linking the Harbour library code into it.
|
||||
*
|
||||
* This exception does not however invalidate any other reasons why
|
||||
* the executable file might be covered by the GNU General Public License.
|
||||
*
|
||||
* This exception applies only to the code released by the Harbour
|
||||
* Project under the name Harbour. If you copy code from other
|
||||
* Harbour Project or Free Software Foundation releases into a copy of
|
||||
* Harbour, as the General Public License permits, the exception does
|
||||
* not apply to the code that you add in this way. To avoid misleading
|
||||
* anyone as to the status of such modified files, you must delete
|
||||
* this exception notice from them.
|
||||
*
|
||||
* If you write modifications of your own for Harbour, it is your choice
|
||||
* whether to permit this exception to apply to your modifications.
|
||||
* If you do not wish that, delete this exception notice.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hbapi.h"
|
||||
#include "hbapiitm.h"
|
||||
#include "hbapigt.h"
|
||||
#include "hbchksum.h"
|
||||
|
||||
|
||||
/* COM_DOSCON( <cString>, [<nLine>], [<nColumn>] ) -> <cNull>
|
||||
*/
|
||||
HB_FUNC( COM_DOSCON )
|
||||
{
|
||||
HB_SIZE nLen = hb_parclen( 1 );
|
||||
|
||||
if( nLen > 0 )
|
||||
{
|
||||
if( HB_ISNUM( 2 ) || HB_ISNUM( 3 ) )
|
||||
{
|
||||
int iRow, iCol;
|
||||
|
||||
hb_gtGetPos( &iRow, &iCol );
|
||||
if( HB_ISNUM( 2 ) )
|
||||
iRow = hb_parni( 1 );
|
||||
if( HB_ISNUM( 3 ) )
|
||||
iCol = hb_parni( 2 );
|
||||
hb_gtSetPos( iRow, iCol );
|
||||
}
|
||||
hb_gtWriteCon( hb_parc( 1 ), nLen );
|
||||
}
|
||||
hb_retc_null();
|
||||
}
|
||||
|
||||
/* COM_CRC( <cString>, [<nStart>], [<nPolynomial>] ) -> <nCRC>
|
||||
*/
|
||||
HB_FUNC( COM_CRC )
|
||||
{
|
||||
HB_MAXUINT crc = hb_parnint( 2 );
|
||||
const char * szString = hb_parc( 1 );
|
||||
|
||||
if( szString )
|
||||
{
|
||||
HB_MAXUINT nPolynomial = ( HB_MAXUINT ) hb_parnint( 3 );
|
||||
|
||||
if( nPolynomial == 0 )
|
||||
nPolynomial = 0x11021; /* CRC_16_X25 */
|
||||
|
||||
/* NOTE: warning this function is not bug compatible with CT3.
|
||||
* It fixes few problems in original CT3 implementation
|
||||
* i.e. it works correctly for 8 bit and smaller polynomials
|
||||
* instead of returning 0 or supports much larger polynomials
|
||||
* up to 64bits.
|
||||
* For 16/17 bit polynomials it gives the same results as CT3
|
||||
* so for most common usage it should be binary compatible
|
||||
* with CT3. [druzus]
|
||||
*/
|
||||
crc = hb_crcct( crc, szString, hb_parclen( 1 ), nPolynomial );
|
||||
}
|
||||
hb_retnint( crc );
|
||||
}
|
||||
|
||||
static char s_xmoblock_sum( const char * szData, HB_SIZE nLen )
|
||||
{
|
||||
unsigned char uc = 0;
|
||||
while( nLen-- )
|
||||
uc += ( unsigned char ) *szData++;
|
||||
return ( char ) uc;
|
||||
}
|
||||
|
||||
/* XMOBLOCK( <cString>, <nBlockNumber>, [<lCRC>], [<nMode>] ) -> <cXModemBlock>
|
||||
*/
|
||||
HB_FUNC( XMOBLOCK )
|
||||
{
|
||||
const char * szData;
|
||||
HB_SIZE nLen, nSize;
|
||||
char * pszBlock;
|
||||
int iBlock;
|
||||
HB_BOOL fCRC;
|
||||
|
||||
szData = hb_parc( 1 );
|
||||
nLen = hb_parclen( 1 );
|
||||
iBlock = hb_parni( 2 );
|
||||
fCRC = hb_parl( 3 );
|
||||
nSize = hb_parni( 4 ) == 2 ? 1024 : 128;
|
||||
|
||||
iBlock &= 0xFF;
|
||||
if( nLen > nSize )
|
||||
nLen = nSize;
|
||||
pszBlock = ( char * ) hb_xgrab( nSize + ( fCRC ? 6 : 5 ) );
|
||||
pszBlock[ 0 ] = nSize == 128 ? 1 : 2;
|
||||
pszBlock[ 1 ] = ( char ) iBlock;
|
||||
pszBlock[ 2 ] = ( char ) ( 0xFF - iBlock );
|
||||
if( szData )
|
||||
memcpy( pszBlock + 3, szData, nLen );
|
||||
if( nLen < nSize )
|
||||
memset( pszBlock + nLen + 3, 0, nSize - nLen );
|
||||
if( fCRC )
|
||||
{
|
||||
HB_U16 crc = ( HB_U16 ) hb_crcct( 0, pszBlock + 3, nSize, 0x11021 );
|
||||
HB_PUT_BE_UINT16( &pszBlock[ 3 + nSize ], crc );
|
||||
nSize += 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
pszBlock[ 3 + nSize ] = s_xmoblock_sum( szData, nLen );
|
||||
nSize += 4;
|
||||
}
|
||||
hb_retclen_buffer( pszBlock, nSize );
|
||||
}
|
||||
|
||||
/* XMOCHECK( <cString>, [<lCRC>] ) -> <nBlockNumber>|-1
|
||||
*/
|
||||
HB_FUNC( XMOCHECK )
|
||||
{
|
||||
HB_SIZE nLen = hb_parclen( 1 ), nSize;
|
||||
int iResult = -1;
|
||||
|
||||
if( nLen >= 132 )
|
||||
{
|
||||
const char * szBlock = hb_parc( 1 );
|
||||
HB_BOOL fCRC = hb_parl( 2 );
|
||||
|
||||
if( *szBlock == 0x01 )
|
||||
nSize = 128;
|
||||
else if( *szBlock == 0x02 )
|
||||
nSize = 1024;
|
||||
else
|
||||
nSize = nLen;
|
||||
if( nLen == nSize + ( fCRC ? 5 : 4 ) &&
|
||||
( unsigned char ) szBlock[ 1 ] +
|
||||
( unsigned char ) szBlock[ 2 ] == 0xFF )
|
||||
{
|
||||
if( fCRC ?
|
||||
hb_crcct( 0, szBlock + 3, nSize + 2, 0x11021 ) == 0 :
|
||||
s_xmoblock_sum( szBlock + 3, nSize ) == szBlock[ 3 + nSize ] )
|
||||
iResult = ( unsigned char ) szBlock[ 1 ];
|
||||
}
|
||||
}
|
||||
hb_retni( iResult );
|
||||
}
|
||||
|
||||
/* ZEROINSERT( <cString> ) -> <cDataBlock>
|
||||
*/
|
||||
HB_FUNC( ZEROINSERT )
|
||||
{
|
||||
PHB_ITEM pString = hb_param( 1, HB_IT_STRING );
|
||||
|
||||
if( pString )
|
||||
{
|
||||
const char * szText;
|
||||
HB_SIZE nLen, nBits, n;
|
||||
unsigned int uiVal;
|
||||
int i, j;
|
||||
|
||||
szText = hb_itemGetCPtr( pString );
|
||||
nLen = hb_itemGetCLen( pString );
|
||||
uiVal = 0;
|
||||
nBits = 0;
|
||||
uiVal = 0;
|
||||
/* NOTE: trailing zero accessed intentionally */
|
||||
for( n = 0; n <= nLen; ++n )
|
||||
{
|
||||
uiVal |= ( unsigned char ) szText[ n ];
|
||||
for( i = 0; i < 8; ++i )
|
||||
{
|
||||
if( ( uiVal & 0xF800 ) == 0xF800 )
|
||||
{
|
||||
uiVal &= 0xF7FF;
|
||||
++nBits;
|
||||
}
|
||||
uiVal <<= 1;
|
||||
}
|
||||
}
|
||||
if( nBits )
|
||||
{
|
||||
HB_SIZE nDest = nLen + ( ( nBits + 7 ) >> 3 );
|
||||
char * pszDest = ( char * ) hb_xgrab( nDest + 1 );
|
||||
unsigned char c = 0;
|
||||
|
||||
nBits = n = 0;
|
||||
i = 1;
|
||||
j = 8;
|
||||
uiVal = ( unsigned char ) szText[ n ];
|
||||
uiVal <<= 8;
|
||||
while( nBits < nDest )
|
||||
{
|
||||
if( --i == 0 )
|
||||
{
|
||||
if( ++n < nLen )
|
||||
{
|
||||
uiVal |= ( unsigned char ) szText[ n ];
|
||||
i = 8;
|
||||
}
|
||||
}
|
||||
if( ( uiVal & 0xF800 ) == 0xF800 )
|
||||
{
|
||||
c = ( c << 1 ) | 1;
|
||||
if( --j == 0 )
|
||||
{
|
||||
pszDest[ nBits++ ] = c;
|
||||
j = 8;
|
||||
}
|
||||
uiVal &= 0xF7FF;
|
||||
}
|
||||
c <<= 1;
|
||||
if( uiVal & 0x8000 )
|
||||
c |= 1;
|
||||
if( --j == 0 )
|
||||
{
|
||||
pszDest[ nBits++ ] = c;
|
||||
j = 8;
|
||||
}
|
||||
uiVal <<= 1;
|
||||
}
|
||||
|
||||
hb_retclen_buffer( pszDest, nDest );
|
||||
}
|
||||
else
|
||||
hb_itemReturn( pString );
|
||||
}
|
||||
else
|
||||
hb_retc_null();
|
||||
}
|
||||
|
||||
/* ZEROREMOVE( <cDataBlock> ) -> cString
|
||||
*/
|
||||
HB_FUNC( ZEROREMOVE )
|
||||
{
|
||||
PHB_ITEM pString = hb_param( 1, HB_IT_STRING );
|
||||
|
||||
if( pString )
|
||||
{
|
||||
const char * szText;
|
||||
HB_SIZE nLen, nDest, nBits, n;
|
||||
int i, j, l;
|
||||
unsigned char ucVal;
|
||||
|
||||
szText = hb_itemGetCPtr( pString );
|
||||
nLen = hb_itemGetCLen( pString );
|
||||
j = 8;
|
||||
l = 0;
|
||||
ucVal = 0;
|
||||
|
||||
for( n = nDest = nBits = 0; n < nLen; ++n )
|
||||
{
|
||||
unsigned char c = szText[ n ];
|
||||
|
||||
for( i = 0; i < 8; ++i )
|
||||
{
|
||||
if( l == 5 )
|
||||
{
|
||||
if( c & 0x80 )
|
||||
{
|
||||
/* wrong string encoding which does not confirm
|
||||
* CCITT specification.
|
||||
*/
|
||||
hb_retc_null();
|
||||
return;
|
||||
}
|
||||
l = 0;
|
||||
++nBits;
|
||||
}
|
||||
else
|
||||
{
|
||||
ucVal <<= 1;
|
||||
if( c & 0x80 )
|
||||
{
|
||||
++l;
|
||||
ucVal |= 1;
|
||||
}
|
||||
else
|
||||
l = 0;
|
||||
if( --j == 0 )
|
||||
{
|
||||
ucVal = 0;
|
||||
++nDest;
|
||||
j = 8;
|
||||
}
|
||||
}
|
||||
c <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTE: CT3 decodes some wrong CCITT strings which does not have
|
||||
* trailing 0 instead of returning empty string "", i.e.:
|
||||
* ? Len( ZeroRemove( Chr( 31 ) ) )
|
||||
* ? Len( ZeroRemove( Chr( 31 ) + Chr( 31 ) ) )
|
||||
* this implementation fixed this bug but if you need strict
|
||||
* CT3 behavior for compatibility in some broken code then
|
||||
* you can disable this fix setting HB_CT3_ZEROREMOVE_BUG
|
||||
* macro. [druzus]
|
||||
*/
|
||||
#ifdef HB_CT3_ZEROREMOVE_BUG
|
||||
if( l == 5 )
|
||||
{
|
||||
++nLen;
|
||||
++nDest;
|
||||
ucVal = 0;
|
||||
}
|
||||
if( ucVal != 0 )
|
||||
#else
|
||||
if( ucVal != 0 || l == 5 )
|
||||
#endif
|
||||
|
||||
hb_retc_null();
|
||||
else if( nBits )
|
||||
{
|
||||
char * pszDest = ( char * ) hb_xgrab( nDest + 1 );
|
||||
|
||||
j = 8;
|
||||
l = 0;
|
||||
ucVal = 0;
|
||||
for( n = nDest = 0; n < nLen; ++n )
|
||||
{
|
||||
unsigned char c = szText[ n ];
|
||||
|
||||
for( i = 0; i < 8; ++i )
|
||||
{
|
||||
if( l == 5 )
|
||||
l = 0;
|
||||
else
|
||||
{
|
||||
ucVal <<= 1;
|
||||
if( c & 0x80 )
|
||||
{
|
||||
++l;
|
||||
ucVal |= 1;
|
||||
}
|
||||
else
|
||||
l = 0;
|
||||
if( --j == 0 )
|
||||
{
|
||||
pszDest[ nDest++ ] = ucVal;
|
||||
j = 8;
|
||||
}
|
||||
}
|
||||
c <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
hb_retclen_buffer( pszDest, nDest );
|
||||
}
|
||||
else
|
||||
hb_itemReturn( pString );
|
||||
}
|
||||
else
|
||||
hb_retc_null();
|
||||
}
|
||||
@@ -101,47 +101,6 @@ HB_FUNC( TRAPINPUT ) {;}
|
||||
HB_FUNC( TRAPSHIFT ) {;}
|
||||
HB_FUNC( VGA28 ) {;}
|
||||
HB_FUNC( VGA50 ) {;}
|
||||
/* Introduction Serial Communications */
|
||||
HB_FUNC( COM_BREAK ) {;}
|
||||
HB_FUNC( COM_CLOSE ) {;}
|
||||
HB_FUNC( COM_COUNT ) {;}
|
||||
HB_FUNC( COM_CRC ) {;}
|
||||
HB_FUNC( COM_CTS ) {;}
|
||||
HB_FUNC( COM_DCD ) {;}
|
||||
HB_FUNC( COM_DOSCON ) {;}
|
||||
HB_FUNC( COM_DSR ) {;}
|
||||
HB_FUNC( COM_DTR ) {;}
|
||||
HB_FUNC( COM_ERRCHR ) {;}
|
||||
HB_FUNC( COM_EVENT ) {;}
|
||||
HB_FUNC( COM_FLUSH ) {;}
|
||||
HB_FUNC( COM_GETIO ) {;}
|
||||
HB_FUNC( COM_GETIRQ ) {;}
|
||||
HB_FUNC( COM_HARD ) {;}
|
||||
HB_FUNC( COM_INIT ) {;}
|
||||
HB_FUNC( COM_KEY ) {;}
|
||||
HB_FUNC( COM_LSR ) {;}
|
||||
HB_FUNC( COM_MCR ) {;}
|
||||
HB_FUNC( COM_MSR ) {;}
|
||||
HB_FUNC( COM_NUM ) {;}
|
||||
HB_FUNC( COM_OPEN ) {;}
|
||||
HB_FUNC( COM_READ ) {;}
|
||||
HB_FUNC( COM_REMOTE ) {;}
|
||||
HB_FUNC( COM_RING ) {;}
|
||||
HB_FUNC( COM_RTS ) {;}
|
||||
HB_FUNC( COM_SCOUNT ) {;}
|
||||
HB_FUNC( COM_SEND ) {;}
|
||||
HB_FUNC( COM_SETIO ) {;}
|
||||
HB_FUNC( COM_SETIRQ ) {;}
|
||||
HB_FUNC( COM_SFLUSH ) {;}
|
||||
HB_FUNC( COM_SKEY ) {;}
|
||||
HB_FUNC( COM_SMODE ) {;}
|
||||
HB_FUNC( COM_SOFT ) {;}
|
||||
HB_FUNC( COM_SOFT_R ) {;}
|
||||
HB_FUNC( COM_SOFT_S ) {;}
|
||||
HB_FUNC( XMOBLOCK ) {;}
|
||||
HB_FUNC( XMOCHECK ) {;}
|
||||
HB_FUNC( ZEROINSERT ) {;}
|
||||
HB_FUNC( ZEROREMOVE ) {;}
|
||||
/* Introduction Video Functions */
|
||||
HB_FUNC( EGAPALETTE ) {;}
|
||||
HB_FUNC( FONTLOAD ) {;}
|
||||
|
||||
@@ -1351,7 +1351,7 @@ HB_FUNC( NETIO_SRVSTATUS )
|
||||
|
||||
if( !conn )
|
||||
iStatus = -1;
|
||||
else if( conn->sd != HB_NO_SOCKET )
|
||||
else if( conn->sd == HB_NO_SOCKET )
|
||||
iStatus = -2;
|
||||
else if( conn->stop )
|
||||
iStatus = -3;
|
||||
|
||||
4
harbour/external/minizip/ioapi.h
vendored
4
harbour/external/minizip/ioapi.h
vendored
@@ -46,7 +46,9 @@
|
||||
#if defined( __BORLANDC__ ) || \
|
||||
defined( __WATCOMC__ ) || \
|
||||
defined( __MINGW32CE__ ) || \
|
||||
defined( HB_OS_DARWIN )
|
||||
defined( HB_OS_BSD ) || \
|
||||
defined( HB_OS_DARWIN ) || \
|
||||
defined( HB_OS_HAIKU )
|
||||
# define USE_FILE32API
|
||||
#endif
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ C_HEADERS := \
|
||||
hbapi.h \
|
||||
hbapicdp.h \
|
||||
hbapicls.h \
|
||||
hbapicom.h \
|
||||
hbapidbg.h \
|
||||
hbapierr.h \
|
||||
hbapifs.h \
|
||||
@@ -57,6 +58,7 @@ C_HEADERS := \
|
||||
hbsocket.h \
|
||||
hbstack.h \
|
||||
hbsxfunc.h \
|
||||
hbtask.h \
|
||||
hbthread.h \
|
||||
hbtrace.h \
|
||||
hbtypes.h \
|
||||
|
||||
154
harbour/include/hbapicom.h
Normal file
154
harbour/include/hbapicom.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* serial communication functions and constant values
|
||||
*
|
||||
* Copyright 2010 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
||||
* www - http://www.harbour-project.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
||||
*
|
||||
* As a special exception, the Harbour Project gives permission for
|
||||
* additional uses of the text contained in its release of Harbour.
|
||||
*
|
||||
* The exception is that, if you link the Harbour libraries with other
|
||||
* files to produce an executable, this does not by itself cause the
|
||||
* resulting executable to be covered by the GNU General Public License.
|
||||
* Your use of that executable is in no way restricted on account of
|
||||
* linking the Harbour library code into it.
|
||||
*
|
||||
* This exception does not however invalidate any other reasons why
|
||||
* the executable file might be covered by the GNU General Public License.
|
||||
*
|
||||
* This exception applies only to the code released by the Harbour
|
||||
* Project under the name Harbour. If you copy code from other
|
||||
* Harbour Project or Free Software Foundation releases into a copy of
|
||||
* Harbour, as the General Public License permits, the exception does
|
||||
* not apply to the code that you add in this way. To avoid misleading
|
||||
* anyone as to the status of such modified files, you must delete
|
||||
* this exception notice from them.
|
||||
*
|
||||
* If you write modifications of your own for Harbour, it is your choice
|
||||
* whether to permit this exception to apply to your modifications.
|
||||
* If you do not wish that, delete this exception notice.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HB_APICOM_H_
|
||||
#define HB_APICOM_H_
|
||||
|
||||
#include "hbapi.h"
|
||||
|
||||
#define HB_COM_PORT_MAX 256
|
||||
|
||||
#define HB_COM_DEV_NAME_MAX 64
|
||||
|
||||
#define HB_COM_ANY -1
|
||||
#define HB_COM_DISABLED 0
|
||||
#define HB_COM_ENABLED 1
|
||||
#define HB_COM_OPEN 2
|
||||
|
||||
#define HB_COM_IFLUSH 1
|
||||
#define HB_COM_OFLUSH 2
|
||||
#define HB_COM_IOFLUSH 3
|
||||
|
||||
#define HB_COM_MCR_DTR 0x01 /* Data terminal ready (DTR) TIOCM_DTR */
|
||||
#define HB_COM_MCR_RTS 0x02 /* Request to send (RTS) TIOCM_RTS */
|
||||
#define HB_COM_MCR_OUT_1 0x04 /* OUT 1 */
|
||||
#define HB_COM_MCR_OUT_2 0x08 /* OUT 2 */
|
||||
#define HB_COM_MCR_LOOP 0x10 /* LOOP */
|
||||
|
||||
#define HB_COM_MSR_DELTA_CTS 0x01 /* DELTA ready to send (DCTS) */
|
||||
#define HB_COM_MSR_DELTA_DSR 0x02 /* DELTA data terminal ready (DDSR) */
|
||||
#define HB_COM_MSR_TERI 0x04 /* Trailing edge RING (TERI) */
|
||||
#define HB_COM_MSR_DELTA_DCD 0x08 /* DELTA data carrier detected (DDCD) */
|
||||
#define HB_COM_MSR_CTS 0x10 /* Clear to send (CTS) TIOCM_CTS */
|
||||
#define HB_COM_MSR_DSR 0x20 /* Data terminal ready (DSR) TIOCM_DSR */
|
||||
#define HB_COM_MSR_RI 0x40 /* RING indicator (RI) TIOCM_RI */
|
||||
#define HB_COM_MSR_DCD 0x80 /* Data carrier detected (DCD) TIOCM_CD */
|
||||
|
||||
#define HB_COM_LSR_DATA_READY 0x01 /* Data ready */
|
||||
#define HB_COM_LSR_OVERRUN_ERR 0x02 /* Overflow error */
|
||||
#define HB_COM_LSR_PARITY_ERR 0x04 /* Parity error */
|
||||
#define HB_COM_LSR_FRAMING_ERR 0x08 /* Framing error */
|
||||
#define HB_COM_LSR_BREAK 0x10 /* BREAK recognized */
|
||||
#define HB_COM_LSR_TRANS_HOLD_EMPTY 0x20 /* Transmission holder register empty */
|
||||
#define HB_COM_LSR_TRANS_EMPTY 0x40 /* TX shift register empty */
|
||||
|
||||
#define HB_COM_FLOW_IRTSCTS 0x01
|
||||
#define HB_COM_FLOW_ORTSCTS 0x02
|
||||
#define HB_COM_FLOW_IDTRDSR 0x04
|
||||
#define HB_COM_FLOW_ODTRDSR 0x08
|
||||
#define HB_COM_FLOW_DCD 0x10
|
||||
#define HB_COM_FLOW_XOFF 0x20 /* XON/XOFF on input */
|
||||
#define HB_COM_FLOW_XON 0x40 /* XON/XOFF on output */
|
||||
|
||||
#define HB_COM_FL_OOFF 0x01
|
||||
#define HB_COM_FL_OON 0x02
|
||||
#define HB_COM_FL_IOFF 0x04
|
||||
#define HB_COM_FL_ION 0x08
|
||||
#define HB_COM_FL_SOFT 0x10
|
||||
#define HB_COM_FL_RTSCTS 0x20
|
||||
#define HB_COM_FL_DTRDSR 0x40
|
||||
#define HB_COM_FL_DCD 0x80
|
||||
|
||||
#define HB_COM_TX_CTS 0x01
|
||||
#define HB_COM_TX_DSR 0x02
|
||||
#define HB_COM_TX_DCD 0x04
|
||||
#define HB_COM_TX_XOFF 0x08
|
||||
#define HB_COM_TX_EMPTY 0x10
|
||||
#define HB_COM_TX_RFLUSH 0x20
|
||||
|
||||
#define HB_COM_RX_XOFF 0x01
|
||||
|
||||
#define HB_COM_ERR_WRONGPORT 1
|
||||
#define HB_COM_ERR_CLOSED 2
|
||||
#define HB_COM_ERR_TIMEOUT 3
|
||||
#define HB_COM_ERR_NOSUPPORT 4
|
||||
#define HB_COM_ERR_PARAMVALUE 5
|
||||
#define HB_COM_ERR_BUSY 6
|
||||
#define HB_COM_ERR_OTHER 7
|
||||
|
||||
|
||||
extern int hb_comLastNum( void );
|
||||
extern int hb_comOpen( int iPort );
|
||||
extern int hb_comClose( int iPort );
|
||||
extern int hb_comInit( int iPort, int iBaud, int iParity, int iSize, int iStop );
|
||||
extern long hb_comSend( int iPort, const void * data, long len, HB_MAXINT timeout );
|
||||
extern long hb_comRecv( int iPort, void * data, long len, HB_MAXINT timeout );
|
||||
extern int hb_comGetError( int iPort );
|
||||
extern int hb_comGetOsError( int iPort );
|
||||
extern int hb_comInputCount( int iPort );
|
||||
extern int hb_comOutputCount( int iPort );
|
||||
extern int hb_comFlush( int iPort, int iType );
|
||||
extern int hb_comMCR( int iPort, int * piValue, int iClr, int iSet );
|
||||
extern int hb_comMSR( int iPort, int * piValue );
|
||||
extern int hb_comLSR( int iPort, int * piValue );
|
||||
extern int hb_comSendBreak( int iPort, int iDurationInMilliSecs );
|
||||
extern int hb_comFlowControl( int iPort, int *piFlow, int iFlow );
|
||||
extern int hb_comFlowSet( int iPort, int iFlow );
|
||||
extern int hb_comFlowChars( int iPort, int iXONchar, int iXOFFchar );
|
||||
extern int hb_comDiscardChar( int iPort, int iChar );
|
||||
extern int hb_comErrorChar( int iPort, int iChar );
|
||||
extern int hb_comOutputState( int iPort );
|
||||
extern int hb_comInputState( int iPort );
|
||||
extern int hb_comSetDevice( int iPort, const char * szDevName );
|
||||
extern const char * hb_comGetDevice( int iPort, char * buffer, int size );
|
||||
|
||||
#endif /* HB_APICOM_H_ */
|
||||
@@ -72,6 +72,7 @@ C_SOURCES := \
|
||||
hbbfish.c \
|
||||
hbbit.c \
|
||||
hbbyte.c \
|
||||
hbcom.c \
|
||||
hbcrc.c \
|
||||
hbdyn.c \
|
||||
hbdynhb.c \
|
||||
|
||||
@@ -84,6 +84,9 @@ static HB_ERRCODE hb_errnoToDosError( int ErrCode )
|
||||
case EACCES:
|
||||
#if defined( ETXTBSY )
|
||||
case ETXTBSY:
|
||||
#endif
|
||||
#if defined( EPERM )
|
||||
case EPERM:
|
||||
#endif
|
||||
return 5; /* Access denied */
|
||||
case EBADF:
|
||||
|
||||
2947
harbour/src/rtl/hbcom.c
Normal file
2947
harbour/src/rtl/hbcom.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user