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)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* Telepathy emulation library
|
||||
* Telepathy emulation library (header)
|
||||
*
|
||||
* Copyright 2000, 2001 Dan Levitt <dan@boba-fett.net>
|
||||
* 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_ */
|
||||
|
||||
@@ -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 ]
|
||||
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -54,6 +54,8 @@
|
||||
|
||||
#if defined( HB_OS_DOS )
|
||||
|
||||
#include "telepath.ch"
|
||||
|
||||
HB_FUNC( __TP_INITPORTSPEED )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -63,8 +63,9 @@
|
||||
|
||||
#if defined( HB_OS_OS2 )
|
||||
|
||||
#include <os2.h>
|
||||
#include "telepath.ch"
|
||||
|
||||
#include <os2.h>
|
||||
#include <stdio.h>
|
||||
|
||||
HB_FUNC( __TP_INITPORTSPEED )
|
||||
|
||||
@@ -59,6 +59,8 @@
|
||||
|
||||
#if defined( HB_OS_UNIX )
|
||||
|
||||
#include "telepath.ch"
|
||||
|
||||
#include <stdio.h> /* Standard input/output definitions */
|
||||
#include <string.h> /* String function definitions */
|
||||
#include <unistd.h> /* UNIX standard function definitions */
|
||||
|
||||
@@ -60,6 +60,8 @@
|
||||
|
||||
#if defined( HB_OS_WIN )
|
||||
|
||||
#include "telepath.ch"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
HB_FUNC( __TP_INITPORTSPEED )
|
||||
|
||||
Reference in New Issue
Block a user