Index: Source/APIHeader/HilTransport.h =================================================================== --- Source/APIHeader/HilTransport.h (revision 5813) +++ Source/APIHeader/HilTransport.h (working copy) @@ -1,30 +1,32 @@ /******************************************************************************* - + Copyright (c) Hilscher GmbH. All Rights Reserved. - + ******************************************************************************* - + Filename: - $Id: HilTransport.h 2858 2011-09-09 10:55:34Z Holger $ + $Id: HilTransport.h 2780 2011-05-23 13:53:17Z michaelst $ Last Modification: - $Author: Holger $ - $Date: 2011-09-09 12:55:34 +0200 (Fr, 09 Sep 2011) $ - $Revision: 2858 $ - + $Author: michaelst $ + $Date: 2011-05-23 15:53:17 +0200 (Mo, 23 Mai 2011) $ + $Revision: 2780 $ + Targets: OSIndependent : yes - + Description: Definition for the universal Hilscher Transport Header prepended, to all - data, send via a communication channel like USB/TCP/Serial. - + data, send via a communication channel like USB/TCP/Serial. + Changes: - + Version Date Author Description --------------------------------------------------------------------------- - 8 24.06.2009 MT HIL_TRANSPORT_BASIC_FEATURES_U structure changed data type from - uint32_t to unsigned int - 7 22.07.2008 PL New transport type HIL_TRANSPORT_TYPE_KEEP_ALIVE added + 11 02.10.2013 MT Added HIL_TRANSPORT_FEATURES_PERMANENT_CONNECTION + 10 23.05.2011 MS Added transport types HIL_TRANSPORT_TYPE_INX, HIL_TRANSPORT_TYPE_NETANALYZER, HIL_TRANSPORT_TYPE_NETPLC + 9 28.06.2010 SD New types for 64-bit support + 8 24.06.2009 MT HIL_TRANSPORT_BASIC_FEATURES_U structure changed data type from uint32_t to unsigned int + 7 22.07.2008 PL New transport type HIL_TRANSPORT_TYPE_KEEP_ALIVE added 6 15.04.2008 MT New error code (state) HIL_TSTATE_BUFFEROVERFLOW_ERROR added 5 07.05.2007 MT New header definitions adjusted to standard c data types 4 04.04.2007 RM Default state definitions included @@ -31,34 +33,34 @@ 3 22.03.2007 RM Definition changed to fit new data structure 2 16.03.2007 RM Header reworked 1 06.03.2007 MT created - + *******************************************************************************/ #ifndef __HILTRANSPORT__H #define __HILTRANSPORT__H +#include + /*****************************************************************************/ -/*! \file HilTransport.h +/*! \file HilTransport.h * Definition for the universal Hilscher Transport Header */ /*****************************************************************************/ -#include - #define HIL_TRANSPORT_IP_PORT 50111 /**< IP Port number used for transport */ #define HIL_TRANSPORT_COOKIE 0xA55A5AA5UL /**< Cookie for HIL_TRANSPORT_HEADER */ #define HIL_TRANSPORT_PACKETID "netX" /**< Packet ID */ -#define HIL_TRANSPORT_STATE_OK 0x00 /**< Packet received successfully */ +#define HIL_TRANSPORT_STATE_OK 0x00 /**< Packet received successfully */ #define HIL_TSTATE_CHECKSUM_ERROR 0x10 /**< Packet checksum error */ #define HIL_TSTATE_LENGTH_INCOMPLETE 0x11 /**< Packet length incomplete */ -#define HIL_TSTATE_DATA_TYPE_UNKNOWN 0x12 /**< Packet data type unknown */ -#define HIL_TSTATE_DEVICE_UNKNOWN 0x13 /**< Device unknown */ +#define HIL_TSTATE_DATA_TYPE_UNKNOWN 0x12 /**< Packet data type unknown */ +#define HIL_TSTATE_DEVICE_UNKNOWN 0x13 /**< Device unknown */ #define HIL_TSTATE_CHANNEL_UNKNOWN 0x14 /**< Channel unknown */ #define HIL_TSTATE_SEQUENCE_ERROR 0x15 /**< Sequence number out of sync */ #define HIL_TSTATE_BUFFEROVERFLOW_ERROR 0x16 /**< Buffer overflow in receiver */ -#define HIL_TSTATE_RESOURCE_ERROR 0x17 /**< Out of internal resources +#define HIL_TSTATE_RESOURCE_ERROR 0x17 /**< Out of internal resources (e.g. parallel services exceeded) */ #define HIL_TSTATE_KEEP_ALIVE_ERROR 0x20 /**< Keep Alive ComID was incorrect */ @@ -65,14 +67,18 @@ /*****************************************************************************/ /* Transport data types */ /*****************************************************************************/ -#define HIL_TRANSPORT_TYPE_QUERYSERVER 0x0000 /**< Admim Command -> Query basic server information */ -#define HIL_TRANSPORT_TYPE_QUERYDEVICE 0x0001 /**< Admim Command -> Query device specific information */ -#define HIL_TRANSPORT_TYPE_RCX_PACKET 0x0100 /**< Packet Type for transfering a RCX Packet */ -#define HIL_TRANSPORT_TYPE_MARSHALLER 0x0200 /**< Packet Type for function marshalling */ -#define HIL_TRANSPORT_TYPE_NETANA_MARSHALLER 0x0400 /**< Packet Type for function netANALYZER marshalling */ -#define HIL_TRANSPORT_TYPE_ACKNOWLEDGE 0x8000 /**< Packet Type for acknowledging succesful send */ -#define HIL_TRANSPORT_TYPE_KEEP_ALIVE 0xFFFF /**< Packet Type for heart beat packet */ +#define HIL_TRANSPORT_TYPE_QUERYSERVER 0x0000 /**< Admim command: query basic server information */ +#define HIL_TRANSPORT_TYPE_QUERYDEVICE 0x0001 /**< Admim command: query device specific information */ +#define HIL_TRANSPORT_TYPE_RCX_PACKET 0x0100 /**< Transport type for rcX packets */ +#define HIL_TRANSPORT_TYPE_MARSHALLER 0x0200 /**< Transport type for cifX API calls */ +#define HIL_TRANSPORT_TYPE_INX 0x0300 /**< Transport type for INX API calls */ +#define HIL_TRANSPORT_TYPE_NETANALYZER 0x0400 /**< Transport type for netANALYZER API calls */ +#define HIL_TRANSPORT_TYPE_NETPLC 0x0500 /**< Transport type for netPLC API calls */ +#define HIL_TRANSPORT_TYPE_ACKNOWLEDGE 0x8000 /**< Transport type for acknowledging succesful sends */ +#define HIL_TRANSPORT_TYPE_KEEP_ALIVE 0xFFFF /**< Transport type for connection keepalive transfers */ +#define HIL_TRANSPORT_TRANSACTION_DEVICE 0x8000 /**< Transaction ID was generated by Device/Target */ + /*****************************************************************************/ /*! Structure preceeding every data packet sent to netX based devices. * This structure is independent from the transmission channel. */ @@ -100,8 +106,9 @@ #define HIL_ADMIN_S_OK 0 /*!< No error */ /* Features flag definition (used in QueryServer command) */ -#define HIL_TRANSPORT_FEATURES_KEEPALIVE 0x00000001 /*!< Device supports keep-alive */ -#define HIL_TRANSPORT_FEATURES_NXAPI 0x00000002 /*!< Device supports NXAPI marshalling */ +#define HIL_TRANSPORT_FEATURES_KEEPALIVE 0x00000001 /*!< Device supports keep-alive */ +#define HIL_TRANSPORT_FEATURES_NXAPI 0x00000002 /*!< Device supports NXAPI marshalling */ +#define HIL_TRANSPORT_FEATURES_PERMANENT_CONNECTION 0x80000000 /*!< Device has a steady connection (does not drop on remote device resets) */ #define HIL_TRANSPORT_QUERYSERVER_NAMELEN 32 /*****************************************************************************/ @@ -109,18 +116,18 @@ /*****************************************************************************/ typedef struct HIL_TRANSPORT_ADMIN_QUERYSERVER_DATA_Ttag { - uint32_t ulStructVersion; /*!< Structure Version, currently 1 */ - char szServerName[HIL_TRANSPORT_QUERYSERVER_NAMELEN]; /*!< NULL Terminated Server name */ - uint32_t ulVersionMajor; /*!< Major Version of Server */ - uint32_t ulVersionMinor; /*!< Minor Version of Server */ - uint32_t ulVersionBuild; /*!< Build Version of Server */ - uint32_t ulVersionRevision; /*!< Major Version of Server */ - uint32_t ulFeatures; /*!< Features flag */ - uint32_t ulParallelServices; /*!< Number of parallel services */ - uint32_t ulBufferSize; /*!< Maximum of bytes in a data packet */ - uint32_t ulDatatypeCnt; /*!< Number of supported data types */ + uint32_t ulStructVersion; /*!< Structure Version, currently 1 */ + char szServerName[HIL_TRANSPORT_QUERYSERVER_NAMELEN]; /*!< NULL Terminated Server name */ + uint32_t ulVersionMajor; /*!< Major Version of Server */ + uint32_t ulVersionMinor; /*!< Minor Version of Server */ + uint32_t ulVersionBuild; /*!< Build Version of Server */ + uint32_t ulVersionRevision; /*!< Major Version of Server */ + uint32_t ulFeatures; /*!< Features flag */ + uint32_t ulParallelServices; /*!< Number of parallel services */ + uint32_t ulBufferSize; /*!< Maximum of bytes in a data packet */ + uint32_t ulDatatypeCnt; /*!< Number of supported data types */ uint16_t ausDataTypes[1]; /*!< Array of supported data types */ - + } HIL_TRANSPORT_ADMIN_QUERYSERVER_DATA_T, *PHIL_TRANSPORT_ADMIN_QUERYSERVER_DATA_T; /*****************************************************************************/ @@ -130,7 +137,7 @@ { HIL_TRANSPORT_HEADER tHeader; HIL_TRANSPORT_ADMIN_QUERYSERVER_DATA_T tData; - + } HIL_TRANSPORT_ADMIN_QUERYSERVER_T, *PHIL_TRANSPORT_ADMIN_QUERYSERVER_T; @@ -151,7 +158,7 @@ uint16_t usDataType; /*!< Data type the info is requested for */ uint16_t usReserved; /*!< unused/reserved, set to zero */ uint32_t ulOption; /*!< Option to query */ - + } HIL_TRANSPORT_ADMIN_QUERYDEVICE_REQ_DATA_T, *PHIL_TRANSPORT_ADMIN_QUERYDEVICE_REQ_DATA_T; /*****************************************************************************/ @@ -161,7 +168,7 @@ { HIL_TRANSPORT_HEADER tHeader; HIL_TRANSPORT_ADMIN_QUERYDEVICE_REQ_DATA_T tData; - + } HIL_TRANSPORT_ADMIN_QUERYDEVICE_REQ_T, *PHIL_TRANSPORT_ADMIN_QUERYDEVICE_REQ_T; @@ -175,7 +182,7 @@ uint32_t ulOption; /**< Requested option */ uint32_t ulError; /**< Error code for te request( If ulError is set -> following data will be supressed */ uint32_t ulDeviceCnt; /**< Number of supported devices */ - + } HIL_TRANSPORT_ADMIN_QUERYDEVICECNT_CNF_DATA_T, *PHIL_TRANSPORT_ADMIN_QUERYDEVICECNT_CNF_DATA_T; /*****************************************************************************/ @@ -185,7 +192,7 @@ { HIL_TRANSPORT_HEADER tHeader; HIL_TRANSPORT_ADMIN_QUERYDEVICECNT_CNF_DATA_T tData; - + } HIL_TRANSPORT_ADMIN_QUERYDEVICECNT_CNF_T, *PHIL_TRANSPORT_ADMIN_QUERYDEVICECNT_CNF_T; /*****************************************************************************/ @@ -198,7 +205,7 @@ uint32_t ulOption; /**< Requested option */ uint32_t ulError; /**< Error code for te request( If ulError is set -> following data will be supressed */ uint32_t ulChannelCnt; /**< Number of supported channels on device passed via bDevice */ - + } HIL_TRANSPORT_ADMIN_QUERYCHANNELCNT_CNF_DATA_T, *PHIL_TRANSPORT_ADMIN_QUERYCHANNELCNT_CNF_DATA_T; /*****************************************************************************/ @@ -208,7 +215,7 @@ { HIL_TRANSPORT_HEADER tHeader; HIL_TRANSPORT_ADMIN_QUERYCHANNELCNT_CNF_DATA_T tData; - + } HIL_TRANSPORT_ADMIN_QUERYCHANNELCNT_CNF_T, *PHIL_TRANSPORT_ADMIN_QUERYCHANNELCNT_CNF_T; /*****************************************************************************/ @@ -231,7 +238,7 @@ uint16_t usDeviceClass; /**< Device class */ uint8_t bHwRevision; /**< HW Revision */ uint8_t bHwCompatibility; /**< HW compatibility */ - + } HIL_TRANSPORT_ADMIN_QUERYDEVICEINFO_CNF_DATA_T, *PHIL_TRANSPORT_ADMIN_QUERYDEVICEINFO_CNF_DATA_T; /*****************************************************************************/ @@ -241,7 +248,7 @@ { HIL_TRANSPORT_HEADER tHeader; HIL_TRANSPORT_ADMIN_QUERYDEVICEINFO_CNF_DATA_T tData; - + } HIL_TRANSPORT_ADMIN_QUERYDEVICEINFO_CNF_T, *PHIL_TRANSPORT_ADMIN_QUERYDEVICEINFO_CNF_T; @@ -259,14 +266,14 @@ uint16_t usConformanceClass; /**< Conformance class */ uint16_t usReserved1; /**< Reserved field 1 */ uint8_t szFWName[64]; /**< Null-terminated firmware name */ - uint16_t usFWMajor; /**< Firmware version (major) */ - uint16_t usFWMinor; /**< Firmware version (minor) */ - uint16_t usFWBuild; /**< Firmware version (build) */ - uint16_t usFWRev; /**< Firmware version (revision) */ + uint16_t usFWMajor; /**< Firmware version (major) */ + uint16_t usFWMinor; /**< Firmware version (minor) */ + uint16_t usFWBuild; /**< Firmware version (build) */ + uint16_t usFWRev; /**< Firmware version (revision) */ uint16_t usYear; /**< Build data of firmware (year) */ uint8_t bMonth; /**< Build data of firmware (month) */ uint8_t bDay; /**< Build data of firmware (day) */ - + } HIL_TRANSPORT_ADMIN_QUERYCHANNELINFO_CNF_DATA_T, *PHIL_TRANSPORT_ADMIN_QUERYCHANNELINFO_CNF_DATA_T; /*****************************************************************************/ @@ -276,7 +283,7 @@ { HIL_TRANSPORT_HEADER tHeader; HIL_TRANSPORT_ADMIN_QUERYCHANNELINFO_CNF_DATA_T tData; - + } HIL_TRANSPORT_ADMIN_QUERYCHANNELINFO_CNF_T, *PHIL_TRANSPORT_ADMIN_QUERYCHANNELINFO_CNF_T; /*****************************************************************************/ @@ -302,7 +309,7 @@ { HIL_TRANSPORT_HEADER tHeader; HIL_TRANSPORT_KEEPALIVE_DATA_T tData; - + } HIL_TRANSPORT_KEEPALIVE_T, *PHIL_TRANSPORT_KEEPALIVE_T; #endif /* __HILTRANSPORT__H */ Index: Source/cifxapi.c =================================================================== --- Source/cifxapi.c (revision 5813) +++ Source/cifxapi.c (working copy) @@ -928,6 +928,8 @@ int32_t lRet = CIFX_FUNCTION_NOT_AVAILABLE; CIFX_TRANSPORT_DEVICE_INST_T* ptcifXTransportDev = (CIFX_TRANSPORT_DEVICE_INST_T*)hSysdevice; CIFX_DRV_FUNCTION_TABLE_T* ptCifXFctTable = (CIFX_DRV_FUNCTION_TABLE_T*)ptcifXTransportDev->ptCifXFctTable; + uint32_t ulFeatures = HilTransportGetFeatures(ptcifXTransportDev->hNetXTransportDeviceHandle); + int fExpectReconnect = (ulFeatures & HIL_TRANSPORT_FEATURES_PERMANENT_CONNECTION) ? 0 : 1; CHECK_SYS_HANDLE( hSysdevice); ATTACH_DEVICE( ptcifXTransportDev->hNetXTransportDeviceHandle); @@ -939,11 +941,14 @@ } DETACH_DEVICE( ptcifXTransportDev->hNetXTransportDeviceHandle); - if ((ptCifXFctTable->pfnxSysdeviceReset) && (lRet == CIFX_NO_ERROR)) + if(fExpectReconnect) { - if (NXT_NO_ERROR != netXTransportScheduleReconnect( ptcifXTransportDev->hNetXTransportDeviceHandle, ulTimeout)) + if(ptCifXFctTable->pfnxSysdeviceReset) { - lRet = CIFX_DEV_RESET_TIMEOUT; + if (NXT_NO_ERROR != netXTransportScheduleReconnect( ptcifXTransportDev->hNetXTransportDeviceHandle, ulTimeout)) + { + lRet = CIFX_DEV_RESET_TIMEOUT; + } } } netXTransportDeRegisterReconnect( ptcifXTransportDev->hNetXTransportDeviceHandle); @@ -1324,6 +1329,8 @@ int32_t lRet = CIFX_FUNCTION_NOT_AVAILABLE; CIFX_TRANSPORT_DEVICE_INST_T* ptcifXTransportDev = (CIFX_TRANSPORT_DEVICE_INST_T*)hChannel; CIFX_DRV_FUNCTION_TABLE_T* ptCifXFctTable = (CIFX_DRV_FUNCTION_TABLE_T*)ptcifXTransportDev->ptCifXFctTable; + uint32_t ulFeatures = HilTransportGetFeatures(ptcifXTransportDev->hNetXTransportDeviceHandle); + int fExpectReconnect = (ulFeatures & HIL_TRANSPORT_FEATURES_PERMANENT_CONNECTION) ? 0 : 1; CHECK_CHANNEL_HANDLE( hChannel); ATTACH_DEVICE( ptcifXTransportDev->hNetXTransportDeviceHandle); @@ -1330,6 +1337,7 @@ if (ptCifXFctTable->pfnxChannelReset) { + netXTransportRegisterReconnect( ptcifXTransportDev->hNetXTransportDeviceHandle); lRet = ptCifXFctTable->pfnxChannelReset( ptcifXTransportDev->hChannelHandle, ulResetMode, ulTimeout); @@ -1336,6 +1344,32 @@ } DETACH_DEVICE( ptcifXTransportDev->hNetXTransportDeviceHandle); + if(CIFX_CHANNELINIT == ulResetMode) + { + /* ATTENTION: Some devices drop connection after channel Init (e.g. netX based devices + with TCP/IP when channel also resets TCP/IP stack */ + if( (NXT_RECV_TIMEOUT == lRet) || + (NXT_TRANSACTION_CANCELLED == lRet) ) + { + fExpectReconnect = 1; + } else + { + fExpectReconnect = 0; + } + } + + if(fExpectReconnect) + { + if(ptCifXFctTable->pfnxSysdeviceReset) + { + if (NXT_NO_ERROR != netXTransportScheduleReconnect( ptcifXTransportDev->hNetXTransportDeviceHandle, ulTimeout)) + { + lRet = CIFX_DEV_RESET_TIMEOUT; + } + } + } + netXTransportDeRegisterReconnect( ptcifXTransportDev->hNetXTransportDeviceHandle); + return lRet; }