knx
ETS configurable knx-stack
ip_parameter_object.cpp
Go to the documentation of this file.
1 #include "ip_parameter_object.h"
2 #ifdef USE_IP
3 #include "device_object.h"
4 #include "platform.h"
5 #include "bits.h"
6 #include "data_property.h"
7 #include "callback_property.h"
8 
9 // 224.0.23.12
10 #define DEFAULT_MULTICAST_ADDR ((uint32_t)0xE000170C)
11 
12 IpParameterObject::IpParameterObject(DeviceObject& deviceObject, Platform& platform): _deviceObject(deviceObject),
13  _platform(platform)
14 {
15  Property* properties[] =
16  {
20  [](IpParameterObject * io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t
21  {
22  if (start == 0)
23  {
24  uint16_t currentNoOfElements = 1;
25  pushWord(currentNoOfElements, data);
26  return 1;
27  }
28  // TODO: get property of deviceobject and use it
29  pushWord(io->_deviceObject.individualAddress(), data);
30  return 1;
31  },
32  [](IpParameterObject * io, uint16_t start, uint8_t count, const uint8_t* data) -> uint8_t
33  {
34  io->_deviceObject.individualAddress(getWord(data));
35  return 1;
36  }),
37 #ifdef KNX_TUNNELING
39  new DataProperty(PID_CUSTOM_RESERVED_TUNNELS_CTRL, true, PDT_UNSIGNED_CHAR, KNX_TUNNELING, ReadLv3 | WriteLv3), // custom propertiy to control the stacks behaviour for reserverd tunnels, not in Spec (PID >= 200)
40  new DataProperty(PID_CUSTOM_RESERVED_TUNNELS_IP, true, PDT_UNSIGNED_LONG, KNX_TUNNELING, ReadLv3 | WriteLv3), // custom propertiy to control the stacks behaviour for reserverd tunnels, not in Spec (PID >= 200)
41 #endif
44  new DataProperty(PID_IP_CAPABILITIES, true, PDT_BITSET8, 0, ReadLv3 | WriteLv1), // must be set by application due to capabilities of the used ip stack
46  [](IpParameterObject * io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t
47  {
48  if (start == 0)
49  {
50  uint16_t currentNoOfElements = 1;
51  pushWord(currentNoOfElements, data);
52  return 1;
53  }
54 
55  pushInt(htonl(io->_platform.currentIpAddress()), data);
56  return 1;
57  }),
59  [](IpParameterObject * io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t
60  {
61  if (start == 0)
62  {
63  uint16_t currentNoOfElements = 1;
64  pushWord(currentNoOfElements, data);
65  return 1;
66  }
67 
68  pushInt(htonl(io->_platform.currentSubnetMask()), data);
69  return 1;
70  }),
72  [](IpParameterObject * io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t
73  {
74  if (start == 0)
75  {
76  uint16_t currentNoOfElements = 1;
77  pushWord(currentNoOfElements, data);
78  return 1;
79  }
80 
81  pushInt(htonl(io->_platform.currentDefaultGateway()), data);
82  return 1;
83  }),
88  [](IpParameterObject * io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t
89  {
90  if (start == 0)
91  {
92  uint16_t currentNoOfElements = 1;
93  pushWord(currentNoOfElements, data);
94  return 1;
95  }
96 
97  io->_platform.macAddress(data);
98  return 1;
99  }),
101  [](IpParameterObject * io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t
102  {
103  if (start == 0)
104  {
105  uint16_t currentNoOfElements = 1;
106  pushWord(currentNoOfElements, data);
107  return 1;
108  }
109 
110  pushInt(DEFAULT_MULTICAST_ADDR, data);
111  return 1;
112  }),
113  new DataProperty(PID_ROUTING_MULTICAST_ADDRESS, true, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv3, DEFAULT_MULTICAST_ADDR),
114  new DataProperty(PID_TTL, true, PDT_UNSIGNED_CHAR, 1, ReadLv3 | WriteLv3, (uint8_t)16),
116  [](IpParameterObject * io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t
117  {
118  if (start == 0)
119  {
120  uint16_t currentNoOfElements = 1;
121  pushWord(currentNoOfElements, data);
122  return 1;
123  }
124 
125  pushWord(0x1, data);
126  return 1;
127  }),
129  };
130  initializeProperties(sizeof(properties), properties);
131 }
132 
133 uint16_t* IpParameterObject::additionalIndivualAddresses(uint8_t& numAddresses)
134 {
135 #ifdef KNX_TUNNELING
136  numAddresses = KNX_TUNNELING;
137 #else
138  numAddresses = 0;
139 #endif
141 }
142 
143 #endif
uint8_t * pushInt(uint32_t i, uint8_t *data)
Definition: bits.cpp:72
uint8_t * pushWord(uint16_t w, uint8_t *data)
Definition: bits.cpp:64
uint16_t getWord(const uint8_t *data)
Definition: bits.cpp:91
uint16_t individualAddress()
const uint8_t * propertyData(PropertyID id)
virtual void initializeProperties(size_t propertiesSize, Property **properties)
Intializes the Property-array the the supplied values.
uint16_t * additionalIndivualAddresses(uint8_t &numAddresses)
IpParameterObject(DeviceObject &deviceObject, Platform &platform)
virtual uint32_t currentIpAddress()
Definition: platform.cpp:68
virtual uint32_t currentSubnetMask()
Definition: platform.cpp:73
virtual uint32_t currentDefaultGateway()
Definition: platform.cpp:78
virtual void macAddress(uint8_t *data)
Definition: platform.cpp:83
@ OT_IP_PARAMETER
KNXnet/IP Parameter Object.
@ PID_MAC_ADDRESS
Definition: property.h:128
@ PID_FRIENDLY_NAME
Definition: property.h:140
@ PID_CURRENT_DEFAULT_GATEWAY
Definition: property.h:123
@ PID_PROJECT_INSTALLATION_ID
KNXnet/IP Parameter Object.
Definition: property.h:115
@ PID_ADDITIONAL_INDIVIDUAL_ADDRESSES
Definition: property.h:117
@ PID_DEFAULT_GATEWAY
Definition: property.h:126
@ PID_SUBNET_MASK
Definition: property.h:125
@ PID_CURRENT_IP_ASSIGNMENT_METHOD
Definition: property.h:118
@ PID_KNXNETIP_DEVICE_CAPABILITIES
Definition: property.h:132
@ PID_IP_ADDRESS
Definition: property.h:124
@ PID_OBJECT_TYPE
Interface Object Type independent Properties.
Definition: property.h:72
@ PID_TTL
Definition: property.h:131
@ PID_CURRENT_SUBNET_MASK
Definition: property.h:122
@ PID_CUSTOM_RESERVED_TUNNELS_IP
Definition: property.h:143
@ PID_SYSTEM_SETUP_MULTICAST_ADDRESS
Definition: property.h:129
@ PID_CURRENT_IP_ADDRESS
Definition: property.h:121
@ PID_KNX_INDIVIDUAL_ADDRESS
Definition: property.h:116
@ PID_CUSTOM_RESERVED_TUNNELS_CTRL
Definition: property.h:142
@ PID_ROUTING_MULTICAST_ADDRESS
Definition: property.h:130
@ PID_IP_ASSIGNMENT_METHOD
Definition: property.h:119
@ PID_IP_CAPABILITIES
Definition: property.h:120
@ PDT_BITSET16
length: 3
Definition: property.h:60
@ PDT_UNSIGNED_LONG
length: 4
Definition: property.h:27
@ PDT_GENERIC_06
length: 6
Definition: property.h:40
@ PDT_BITSET8
length: 3
Definition: property.h:59
@ PDT_UNSIGNED_INT
length: 2
Definition: property.h:22
@ PDT_UNSIGNED_CHAR
length: 1
Definition: property.h:20
@ WriteLv0
Definition: property.h:247
@ WriteLv3
Definition: property.h:250
@ ReadLv3
Definition: property.h:246
@ WriteLv1
Definition: property.h:248