knx
ETS configurable knx-stack
application_program_object.cpp
Go to the documentation of this file.
2 #include "bits.h"
3 #include "data_property.h"
4 #include "callback_property.h"
5 #include "dptconvert.h"
6 #include <cstring>
7 
9 #if MASK_VERSION == 0x091A
10  : TableObject(memory, 0x0100, 0x0100)
11 #else
12  : TableObject(memory)
13 #endif
14 {
15  Property* properties[] =
16  {
20  [](ApplicationProgramObject * io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t {
21  if (start == 0)
22  {
23  uint16_t currentNoOfElements = 1;
24  pushWord(currentNoOfElements, data);
25  return 1;
26  }
27 
28  data[0] = 0;
29  return 1;
30  })
31  };
32 
33  TableObject::initializeProperties(sizeof(properties), properties);
34 }
35 
36 uint8_t* ApplicationProgramObject::save(uint8_t* buffer)
37 {
38  uint8_t programVersion[5];
39  property(PID_PROG_VERSION)->read(programVersion);
40  buffer = pushByteArray(programVersion, 5, buffer);
41 
42  return TableObject::save(buffer);
43 }
44 
45 const uint8_t* ApplicationProgramObject::restore(const uint8_t* buffer)
46 {
47  uint8_t programVersion[5];
48  buffer = popByteArray(programVersion, 5, buffer);
49  property(PID_PROG_VERSION)->write(programVersion);
50 
51  return TableObject::restore(buffer);
52 }
53 
55 {
56  return TableObject::saveSize() + 5; // sizeof(programVersion)
57 }
58 
59 uint8_t* ApplicationProgramObject::data(uint32_t addr)
60 {
61  return TableObject::data() + addr;
62 }
63 
64 uint8_t ApplicationProgramObject::getByte(uint32_t addr)
65 {
66  return *(TableObject::data() + addr);
67 }
68 
69 uint16_t ApplicationProgramObject::getWord(uint32_t addr)
70 {
72 }
73 
74 uint32_t ApplicationProgramObject::getInt(uint32_t addr)
75 {
77 }
78 
80 {
81  switch (encoding)
82  {
83  case Float_Enc_DPT9:
84  return float16FromPayload(TableObject::data() + addr, 0);
85  break;
86 
88  return float32FromPayload(TableObject::data() + addr, 0);
89  break;
90 
92  return float64FromPayload(TableObject::data() + addr, 0);
93  break;
94 
95  default:
96  return 0;
97  break;
98  }
99 }
uint8_t * pushByteArray(const uint8_t *src, uint32_t size, uint8_t *data)
Definition: bits.cpp:82
const uint8_t * popByteArray(uint8_t *dst, uint32_t size, const uint8_t *data)
Definition: bits.cpp:48
uint8_t * pushWord(uint16_t w, uint8_t *data)
Definition: bits.cpp:64
uint16_t getWord(const uint8_t *data)
Definition: bits.cpp:91
uint32_t getInt(const uint8_t *data)
Definition: bits.cpp:96
ParameterFloatEncodings
Definition: bits.h:149
@ Float_Enc_DPT9
Definition: bits.h:150
@ Float_Enc_IEEE754Double
Definition: bits.h:152
@ Float_Enc_IEEE754Single
Definition: bits.h:151
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
uint8_t * save(uint8_t *buffer) override
This method is called when the object should save its state to the buffer.
double getFloat(uint32_t addr, ParameterFloatEncodings encoding)
Property * property(PropertyID id)
Gets property with PropertyID id if it exists and nullptr otherwise.
Definition: memory.h:37
virtual uint8_t read(uint16_t start, uint8_t count, uint8_t *data) const =0
virtual uint8_t write(uint16_t start, uint8_t count, const uint8_t *data)=0
This class provides common functionality for interface objects that are configured by ETS with MemorW...
Definition: table_object.h:13
void initializeProperties(size_t propertiesSize, Property **properties) override
Intializes the Property-array the the supplied values.
uint8_t * data()
returns the internal data of the interface object.
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
uint16_t saveSize() override
uint8_t * save(uint8_t *buffer) override
This method is called when the object should save its state to the buffer.
double float64FromPayload(const uint8_t *payload, int index)
double float16FromPayload(const uint8_t *payload, int index)
float float32FromPayload(const uint8_t *payload, int index)
@ OT_APPLICATION_PROG
Application program object.
@ PID_OBJECT_TYPE
Interface Object Type independent Properties.
Definition: property.h:72
@ PID_PEI_TYPE
Definition: property.h:83
@ PID_PROG_VERSION
Definition: property.h:80
@ PDT_UNSIGNED_INT
length: 2
Definition: property.h:22
@ PDT_GENERIC_05
length: 5
Definition: property.h:39
@ PDT_UNSIGNED_CHAR
length: 1
Definition: property.h:20
@ WriteLv0
Definition: property.h:247
@ WriteLv3
Definition: property.h:250
@ ReadLv3
Definition: property.h:246