From ef7c07ab591cd882ed22987012c30b9d517000cc Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 9 Aug 2009 15:50:56 +0000 Subject: [PATCH] 2009-08-09 17:49 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbtpathy/telepath.ch * contrib/hbtpathy/tests/testtp.prg * contrib/hbtpathy/tpwin.c * contrib/hbtpathy/tpos2.c * contrib/hbtpathy/tpunix.c * contrib/hbtpathy/tpdos.c * contrib/hbtpathy/telepath.prg + Added self-guards to header. ! Converted all comments to ANSI C. + Added note to header that it's used from C code. ! Put negative macro values into parantheses. ! Fixed bad typo in test program which broke it for all platforms. % Minor optimization to TP_REOPEN(). ! Moved internal structure macros from header to .prg. + Added comment for FILE() usage in TP_OPEN(). ! Fixed to not use FILE() to check for port existance on non-*nix platforms. (maybe this works on OS/2 and it can be readded there, I don't know). ! Using manifest constants instead of literals in few places. ; After these changes, hbtpathy works on Windows platform. (made basic test only) --- harbour/ChangeLog | 23 ++++ harbour/contrib/hbtpathy/telepath.ch | 127 +++++++++++----------- harbour/contrib/hbtpathy/telepath.prg | 41 ++++--- harbour/contrib/hbtpathy/tests/testtp.prg | 2 +- harbour/contrib/hbtpathy/tpdos.c | 2 + harbour/contrib/hbtpathy/tpos2.c | 3 +- harbour/contrib/hbtpathy/tpunix.c | 2 + harbour/contrib/hbtpathy/tpwin.c | 2 + 8 files changed, 117 insertions(+), 85 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 6670d4269e..b89bdcafb6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,29 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-08-09 17:49 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbtpathy/telepath.ch + * contrib/hbtpathy/tests/testtp.prg + * contrib/hbtpathy/tpwin.c + * contrib/hbtpathy/tpos2.c + * contrib/hbtpathy/tpunix.c + * contrib/hbtpathy/tpdos.c + * contrib/hbtpathy/telepath.prg + + Added self-guards to header. + ! Converted all comments to ANSI C. + + Added note to header that it's used from C code. + ! Put negative macro values into parantheses. + ! Fixed bad typo in test program which broke it for all platforms. + % Minor optimization to TP_REOPEN(). + ! Moved internal structure macros from header to .prg. + + Added comment for FILE() usage in TP_OPEN(). + ! Fixed to not use FILE() to check for port existance on non-*nix + platforms. (maybe this works on OS/2 and it can be readded there, + I don't know). + ! Using manifest constants instead of literals in few places. + ; After these changes, hbtpathy works on Windows platform. + (made basic test only) + 2009-08-09 17:00 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * utils/hbmk2/examples/contribf.hbc * contrib/hbtpathy/Makefile diff --git a/harbour/contrib/hbtpathy/telepath.ch b/harbour/contrib/hbtpathy/telepath.ch index 14c57a561d..02483c1e00 100644 --- a/harbour/contrib/hbtpathy/telepath.ch +++ b/harbour/contrib/hbtpathy/telepath.ch @@ -4,7 +4,7 @@ /* * Harbour Project source code: - * Telepathy emulation library + * Telepathy emulation library (header) * * Copyright 2000, 2001 Dan Levitt * www - http://www.harbour-project.org @@ -50,77 +50,72 @@ * */ +#ifndef TELEPATH_CH_ +#define TELEPATH_CH_ + +/* NOTE: This file is also used by C code. */ #define TP_MAXPORTS 8 -#define TPFP_NAME 1 // Structure of ports array -#define TPFP_HANDLE 2 -#define TPFP_BAUD 3 -#define TPFP_DBITS 4 -#define TPFP_PARITY 5 -#define TPFP_SBITS 6 -#define TPFP_OC 7 // Open/Close Flag -#define TPFP_INBUF 8 -#define TPFP_INBUF_SIZE 9 // Size of input buffer +/* Error code definitions */ +#define TE_PARAM ( -1 ) /* Bad parameter */ +#define TE_NOPORT ( -2 ) /* No such port */ +#define TE_CLOSED ( -3 ) /* Port not open */ +#define TE_CONFL ( -4 ) /* IRQ conflict */ +#define TE_TMOUT ( -5 ) /* Timeout */ +#define TE_NDCD ( -6 ) /* Lost DCD */ +#define TE_ESCAPE ( -7 ) /* User escape */ +#define TE_LENGTH ( -8 ) /* Length limit */ +#define TE_CANCEL ( -9 ) /* Input canceled */ +#define TE_NOHDL ( -10 ) /* Out of handles */ +#define TE_UCANCEL ( -50 ) /* Canceled by user */ +#define TE_RCANCEL ( -51 ) /* Canceled by remote */ +#define TE_STARTTM ( -52 ) /* Timeout waiting to start */ +#define TE_BLOCKTM ( -53 ) /* Timeout waiting for block */ +#define TE_ACKTM ( -54 ) /* Timeout waiting for acknowledge */ +#define TE_SENDTM ( -55 ) /* Timeout waiting to send */ +#define TE_CLEARTM ( -56 ) /* Timeout waiting for sender to stop */ +#define TE_NAK ( -57 ) /* Negative acknowledge */ +#define TE_BADACK ( -58 ) /* Bad acknowledge character */ +#define TE_BADBLK ( -59 ) /* Bad block format */ +#define TE_LONGBLK ( -60 ) /* Long block received */ +#define TE_ERRMAX ( -61 ) /* Too many errors */ +#define TE_DUPBLK ( -62 ) /* Duplicate block */ +#define TE_PROTO ( -63 ) /* Protocol failure */ +#define TE_CKSUM ( -64 ) /* Checksum error */ +#define TE_HDRTM ( -65 ) /* Timeout waiting for Zmodem header */ -// Error code definitions -#define TE_PARAM -1 // Bad parameter -#define TE_NOPORT -2 // No such port -#define TE_CLOSED -3 // Port not open -#define TE_CONFL -4 // IRQ conflict -#define TE_TMOUT -5 // Timeout -#define TE_NDCD -6 // Lost DCD -#define TE_ESCAPE -7 // User escape -#define TE_LENGTH -8 // Length limit -#define TE_CANCEL -9 // Input canceled -#define TE_NOHDL -10 // Out of handles +#define TE_DISKFULL ( -100 ) /* Disk full */ +#define TE_NOFILE ( -102 ) /* File not found */ +#define TE_NOPATH ( -103 ) /* Path not found */ +#define TE_MFILE ( -104 ) /* Too many open files */ +#define TE_ACCESS ( -105 ) /* Access denied */ -#define TE_UCANCEL -50 // Canceled by user -#define TE_RCANCEL -51 // Canceled by remote -#define TE_STARTTM -52 // Timeout waiting to start -#define TE_BLOCKTM -53 // Timeout waiting for block -#define TE_ACKTM -54 // Timeout waiting for acknowledge -#define TE_SENDTM -55 // Timeout waiting to send -#define TE_CLEARTM -56 // Timeout waiting for sender to stop -#define TE_NAK -57 // Negative acknowledge -#define TE_BADACK -58 // Bad acknowledge character -#define TE_BADBLK -59 // Bad block format -#define TE_LONGBLK -60 // Long block received -#define TE_ERRMAX -61 // Too many errors -#define TE_DUPBLK -62 // Duplicate block -#define TE_PROTO -63 // Protocol failure -#define TE_CKSUM -64 // Checksum error -#define TE_HDRTM -65 // Timeout waiting for Zmodem header +/* File transfer status */ +#define TXS_START 1 /* Start of transfer */ +#define TXS_SFILE 2 /* Start of file */ +#define TXS_NEWNAME 3 /* File renamed */ +#define TXS_SDATA 4 /* Start of file data */ +#define TXS_BLOCK 5 /* End of block */ +#define TXS_ERROR 6 /* Error */ +#define TXS_ABFILE 7 /* Aborting file */ +#define TXS_ABORT 8 /* Aborting transfer */ +#define TXS_WEND 9 /* Waiting for end of file */ +#define TXS_EFILE 10 /* End of file */ +#define TXS_END 11 /* End of transfer */ -#define TE_DISKFULL -100 // Disk full -#define TE_NOFILE -102 // File not found -#define TE_NOPATH -103 // Path not found -#define TE_MFILE -104 // Too many open files -#define TE_ACCESS -105 // Access denied +#define TP_32MAGIC 0x2144DF1C -// File transfer status -#define TXS_START 1 // Start of transfer -#define TXS_SFILE 2 // Start of file -#define TXS_NEWNAME 3 // File renamed -#define TXS_SDATA 4 // Start of file data -#define TXS_BLOCK 5 // End of block -#define TXS_ERROR 6 // Error -#define TXS_ABFILE 7 // Aborting file -#define TXS_ABORT 8 // Aborting transfer -#define TXS_WEND 9 // Waiting for end of file -#define TXS_EFILE 10 // End of file -#define TXS_END 11 // End of transfer +/* Handshaking flags for tp_hshk() */ +#define THS_RDSR 1 /* Require DSR */ +#define THS_RCTS 2 /* Require CTS */ +#define THS_RXOFF 4 /* Respect XON/XOFF */ +#define THS_RDCD 8 /* Require DCD */ +#define THS_ADTR 16 /* Assert DTR */ +#define THS_CDTR 32 /* Flow control with DTR */ +#define THS_ARTS 64 /* Assert RTS */ +#define THS_CRTS 128 /* Flow control with RTS */ +#define THS_SXOFF 256 /* Send XON/XOFF */ -#define TP_32MAGIC 558161692 - -// Handshaking flags for tp_hshk() -#define THS_RDSR 1 // Require DSR -#define THS_RCTS 2 // Require CTS -#define THS_RXOFF 4 // Respect XON/XOFF -#define THS_RDCD 8 // Require DCD -#define THS_ADTR 16 // Assert DTR -#define THS_CDTR 32 // Flow control with DTR -#define THS_ARTS 64 // Assert RTS -#define THS_CRTS 128 // Flow control with RTS -#define THS_SXOFF 256 // Send XON/XOFF +#endif /* TELEPATH_CH_ */ diff --git a/harbour/contrib/hbtpathy/telepath.prg b/harbour/contrib/hbtpathy/telepath.prg index c816266b21..75db629851 100644 --- a/harbour/contrib/hbtpathy/telepath.prg +++ b/harbour/contrib/hbtpathy/telepath.prg @@ -63,6 +63,17 @@ #include "telepath.ch" +#define TPFP_NAME 1 /* Structure of ports array */ +#define TPFP_HANDLE 2 +#define TPFP_BAUD 3 +#define TPFP_DBITS 4 +#define TPFP_PARITY 5 +#define TPFP_SBITS 6 +#define TPFP_OC 7 /* Open/Close Flag */ +#define TPFP_INBUF 8 +#define TPFP_INBUF_SIZE 9 /* Size of input buffer */ + + THREAD STATIC t_aPorts // Array with port info THREAD STATIC t_nErrorCode := 0 // Error code from last operation, 0 if no error @@ -149,9 +160,6 @@ FUNCTION tp_reopen( nPort, nInSize, nOutSize ) LOCAL nBaud, nData, cParity, nStop, cPortName - DEFAULT nInSize TO 1536 - DEFAULT nOutSize TO 1536 - IF ! isport( nPort ) .OR. Empty( t_aPorts[ nPort, TPFP_NAME ] ) RETURN TE_NOPORT ENDIF @@ -166,9 +174,10 @@ FUNCTION tp_reopen( nPort, nInSize, nOutSize ) FUNCTION tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortname ) - LOCAL nRes, lPortExist + LOCAL nRes #if defined( __PLATFORM__UNIX ) + LOCAL lPortExist LOCAL nFileCase LOCAL nDirCase #endif @@ -182,26 +191,24 @@ FUNCTION tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortn /* Serial ports name are made up of cPortName + nPort if nPort is not NIL */ #if defined( __PLATFORM__UNIX ) - DEFAULT cPortName TO "/dev/ttyS" + iif( ISNUMBER( nPort ), hb_NToS( nPort - 1 ), "" ) + DEFAULT cPortName TO "/dev/ttyS" + iif( ISNUMBER( nPort ), hb_ntos( nPort - 1 ), "" ) #else - DEFAULT cPortName TO "COM" + iif( ISNUMBER( nPort ), hb_NToS( nPort ), "" ) + DEFAULT cPortName TO "COM" + iif( ISNUMBER( nPort ), hb_ntos( nPort ), "" ) #endif #if defined( __PLATFORM__UNIX ) nFileCase := Set( _SET_FILECASE, 0 ) nDirCase := Set( _SET_DIRCASE, 0 ) - #endif - lPortExist := File( cPortname ) + lPortExist := File( cPortname ) /* Must be File(), hb_FileExists() won't work */ - #if defined( __PLATFORM__UNIX ) Set( _SET_FILECASE, nFileCase ) Set( _SET_DIRCASE, nDirCase ) - #endif - IF ! lPortExist - RETURN TE_NOPORT - ENDIF + IF ! lPortExist + RETURN TE_NOPORT + ENDIF + #endif IF ! isport( nPort ) RETURN TE_NOPORT @@ -216,14 +223,14 @@ FUNCTION tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortn t_aPorts[ nPort, TPFP_INBUF ] := "" t_aPorts[ nPort, TPFP_INBUF_SIZE ] := nInSize - #if defined( __PLATFORM__UNIX ) // Maybe we should have a __tp_Open() on every platform + #if defined( __PLATFORM__UNIX ) t_aPorts[ nPort, TPFP_HANDLE ] := __tp_Open( cPortname ) #else - t_aPorts[ nPort, TPFP_HANDLE ] := FOpen( cPortname, FO_READWRITE ) + t_aPorts[ nPort, TPFP_HANDLE ] := FOpen( cPortname, FO_READWRITE ) // FO_EXCLUSIVE #endif - IF t_aPorts[ nPort, TPFP_HANDLE ] >= 0 + IF t_aPorts[ nPort, TPFP_HANDLE ] != F_ERROR /* low level C functions are prefixed __tp_ */ IF ( nRes := __tp_InitPortSpeed( t_aPorts[ nPort, TPFP_HANDLE ] ,; @@ -586,7 +593,7 @@ FUNCTION tp_ctrldtr( nPort, nParamNewval ) LOCAL nph, nnewval, noldval IF ! isopenport( nPort ) - RETURN -1 + RETURN TE_PARAM ENDIF nph := t_aPorts[ nPort, TPFP_HANDLE ] diff --git a/harbour/contrib/hbtpathy/tests/testtp.prg b/harbour/contrib/hbtpathy/tests/testtp.prg index 9aa2c437d7..7222217481 100644 --- a/harbour/contrib/hbtpathy/tests/testtp.prg +++ b/harbour/contrib/hbtpathy/tests/testtp.prg @@ -67,7 +67,7 @@ */ function main - ? tp_open( 1,, 9600, 8, "N", 1 ) + ? tp_open( 1,,, 9600, 8, "N", 1 ) tp_send( 1, "Hi there Bob", 1 ) // One second timeout tp_inkey( .5 ) ? tp_recv( 1 ) diff --git a/harbour/contrib/hbtpathy/tpdos.c b/harbour/contrib/hbtpathy/tpdos.c index 99bc912daf..b678b38e5a 100644 --- a/harbour/contrib/hbtpathy/tpdos.c +++ b/harbour/contrib/hbtpathy/tpdos.c @@ -54,6 +54,8 @@ #if defined( HB_OS_DOS ) +#include "telepath.ch" + HB_FUNC( __TP_INITPORTSPEED ) { } diff --git a/harbour/contrib/hbtpathy/tpos2.c b/harbour/contrib/hbtpathy/tpos2.c index 40c6ff8657..e09a579ed1 100644 --- a/harbour/contrib/hbtpathy/tpos2.c +++ b/harbour/contrib/hbtpathy/tpos2.c @@ -63,8 +63,9 @@ #if defined( HB_OS_OS2 ) -#include +#include "telepath.ch" +#include #include HB_FUNC( __TP_INITPORTSPEED ) diff --git a/harbour/contrib/hbtpathy/tpunix.c b/harbour/contrib/hbtpathy/tpunix.c index 4d60af7902..236eb3f0d4 100644 --- a/harbour/contrib/hbtpathy/tpunix.c +++ b/harbour/contrib/hbtpathy/tpunix.c @@ -59,6 +59,8 @@ #if defined( HB_OS_UNIX ) +#include "telepath.ch" + #include /* Standard input/output definitions */ #include /* String function definitions */ #include /* UNIX standard function definitions */ diff --git a/harbour/contrib/hbtpathy/tpwin.c b/harbour/contrib/hbtpathy/tpwin.c index 4e39b75d51..9f0b7c520d 100644 --- a/harbour/contrib/hbtpathy/tpwin.c +++ b/harbour/contrib/hbtpathy/tpwin.c @@ -60,6 +60,8 @@ #if defined( HB_OS_WIN ) +#include "telepath.ch" + #include HB_FUNC( __TP_INITPORTSPEED )