dsm-api-v2
|
00001 /* 00002 This file is part of the digitalSTROM ds485-core library. 00003 00004 Copyright (C) 2010 digitalSTROM.org, Schlieren, Switzerland 00005 00006 digitalSTROM ds485-core library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation version 2 00009 of the License. 00010 00011 digitalSTROM ds485-core library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with digitalSTROM ds485-core library; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef _ds485_h 00022 #define _ds485_h 00023 00024 #include <digitalSTROM/ds.h> 00025 #include <digitalSTROM/ds485-const.h> 00026 #define DS485_MAX_PAYLOAD_SIZE 127 00027 #define DS485_MAX_PAYLOAD_SIZE_RAW DS485_MAX_PAYLOAD_SIZE + 1 00028 #define DS485_CONTAINER_DATA_LENGTH DS485_MAX_PAYLOAD_SIZE 00029 #define DS485_CONTAINER_SIZE (sizeof(ds485_container_t) - (DS485_CONTAINER_DATA_LENGTH)) 00030 00034 typedef enum { 00035 DS485_STATE_ISOLATED = 1, 00036 DS485_STATE_JOIN, 00037 DS485_STATE_CONNECTED, 00038 DS485_STATE_ACTIVE, 00039 DS485_STATE_DISCONNECTED, 00040 } bus_state_t; 00041 00045 typedef enum { 00046 DS485_CONTAINER_REQUEST = 1, 00047 DS485_CONTAINER_RESPONSE, 00048 DS485_CONTAINER_EVENT 00049 } container_type_t; 00050 00051 typedef enum { 00052 DS485_FLAG_NONE = 1, 00053 DS485_FLAG_BROADCAST = 2, 00054 } container_flags_t; 00055 00059 typedef struct { 00060 dsid_t destinationId; 00061 dsid_t sourceId; 00062 container_type_t containerType; 00063 container_flags_t containerFlags; 00064 uint8_t length; 00065 union { 00066 struct { 00067 unsigned char transactionId; 00068 unsigned char data[DS485_MAX_PAYLOAD_SIZE]; 00069 }; 00070 unsigned char raw_data[DS485_MAX_PAYLOAD_SIZE_RAW]; 00071 }; 00072 #ifdef SWIG 00073 } ds485_container_t; 00074 #else 00075 } __attribute__ ((packed)) ds485_container_t; 00076 #endif 00077 00081 typedef struct { 00082 /* TX */ 00083 uint32_t txToken; 00084 uint16_t txStartupRequest; 00085 uint16_t txStartupResponse; 00086 uint16_t txJoinRequest; 00087 uint16_t txJoinResponse; 00088 uint16_t txGetAddressRequest; 00089 uint16_t txGetAddressResponse; 00090 uint16_t txSetAddressRequest; 00091 uint16_t txSetAddressResponse; 00092 uint16_t txSetSuccessorAddressRequest; 00093 uint16_t txSetSuccessorAddressResponse; 00094 uint16_t txResponse; 00095 uint16_t txDataRequest; 00096 uint16_t txDataResponse; 00097 uint16_t txDataEvent; 00098 /* RX */ 00099 uint16_t rxResponse; 00100 uint16_t rxDataRequest; 00101 uint16_t rxDataResponse; 00102 uint16_t rxDataEvent; 00103 /* Actions */ 00104 uint16_t startRegisterStation; 00105 uint16_t doneRegisterStation; 00106 uint16_t enterOperational; 00107 uint16_t successorLost; 00108 } DS485Statistics; 00109 00110 /*** 00111 * External references - have to be supplied by platform module 00112 */ 00113 00117 #define RX_FLAG_CRC_ERROR 0x01 00118 #define RX_FLAG_FRAME_ERROR 0x02 00119 #define RX_FLAG_PROTOCOL_ERROR 0x04 00120 #define RX_FLAG_NOTFORME 0x10 00121 #define RX_FLAG_INVALID_ADDRESS 0x80 00122 00123 #define RX_FLAG_ERRORS (RX_FLAG_CRC_ERROR | RX_FLAG_FRAME_ERROR | RX_FLAG_PROTOCOL_ERROR) 00124 00128 #define DS485_FILTER_ALL_RESPONSES 0x01 00129 00130 #endif