Skip to content

Commit bab2954

Browse files
Added Example for DateTimeValue Object + Release prep (#23)
* Fixed Add BDT entry error * Updated README * Added DateTimeValue object to example * Updated README for release * Removed SetBBMD for initial start up Co-authored-by: Steven Smethurst <49768603+ssmethurst@users.noreply.github.com>
1 parent 0aef91a commit bab2954

File tree

6 files changed

+81
-9
lines changed

6 files changed

+81
-9
lines changed

BACnetServerExample/BACnetServerExample.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,19 @@ int main(int argc, char** argv)
583583
ipPortConcat[4] = g_database.networkPort.BACnetIPUDPPort / 256;
584584
ipPortConcat[5] = g_database.networkPort.BACnetIPUDPPort % 256;
585585
fpAddBDTEntry(ipPortConcat, 6, g_database.networkPort.IPSubnetMask, 4); // First BDT Entry must be server device
586-
fpSetBBMD(g_database.device.instance, g_database.networkPort.instance);
586+
587587

588588
std::cout << "OK" << std::endl;
589+
590+
// Add the DateTimeValue Object
591+
std::cout << "Added DateTimeValue. dateTimeValue.instance=[" << g_database.dateTimeValue.instance << "]... ";
592+
if (!fpAddObject(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_DATETIME_VALUE, g_database.dateTimeValue.instance)) {
593+
std::cerr << "Failed to add DateTimeValue" << std::endl;
594+
return -1;
595+
}
589596

597+
std::cout << "OK" << std::endl;
598+
590599
// 5. Send I-Am of this device
591600
// ---------------------------------------------------------------------------
592601
// To be a good citizen on a BACnet network. We should announce ourself when we start up.
@@ -1116,6 +1125,17 @@ bool CallbackGetPropertyDate(const uint32_t deviceInstance, const uint16_t objec
11161125
return true;
11171126
}
11181127
}
1128+
// Example of DateTime Value Object Present Value property
1129+
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_DATETIME_VALUE && objectInstance == 60) {
1130+
if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_PRESENT_VALUE) {
1131+
*year = g_database.dateTimeValue.presentValueYear;
1132+
*month = g_database.dateTimeValue.presentValueMonth;
1133+
*day = g_database.dateTimeValue.presentValueDay;
1134+
*weekday = g_database.dateTimeValue.presentValueWeekDay;
1135+
return true;
1136+
}
1137+
}
1138+
11191139
return false;
11201140
}
11211141

@@ -1365,6 +1385,16 @@ bool CallbackGetPropertyTime(const uint32_t deviceInstance, const uint16_t objec
13651385
return true;
13661386
}
13671387
}
1388+
// Example of DateTime Value Object Present Value property
1389+
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_DATETIME_VALUE && objectInstance == 60) {
1390+
if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_PRESENT_VALUE) {
1391+
*hour = g_database.dateTimeValue.presentValueHour;
1392+
*minute = g_database.dateTimeValue.presentValueMinute;
1393+
*second = g_database.dateTimeValue.presentValueSecond;
1394+
*hundrethSeconds = g_database.dateTimeValue.presentValueHundredthSeconds;
1395+
return true;
1396+
}
1397+
}
13681398
return false;
13691399
}
13701400

@@ -2009,6 +2039,16 @@ bool GetObjectName(const uint32_t deviceInstance, const uint16_t objectType, con
20092039
*valueElementCount = (uint32_t) stringSize;
20102040
return true;
20112041
}
2042+
else if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_DATETIME_VALUE && objectInstance == g_database.dateTimeValue.instance) {
2043+
stringSize = g_database.dateTimeValue.objectName.size();
2044+
if (stringSize > maxElementCount) {
2045+
std::cerr << "Error - not enough space to store full name of objectType=[" << objectType << "], objectInstance=[" << objectInstance <<" ]" << std::endl;
2046+
return false;
2047+
}
2048+
memcpy(value, g_database.dateTimeValue.objectName.c_str(), stringSize);
2049+
*valueElementCount = (uint32_t) stringSize;
2050+
return true;
2051+
}
20122052
else {
20132053
// Check if the value is an Analog Value and check if it was a created object
20142054
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_VALUE && g_database.CreatedAnalogValueData.count(objectInstance) > 0) {

BACnetServerExample/CASBACnetStackExampleConstants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class CASBACnetStackExampleConstants {
7171
//static const uint16_t OBJECT_TYPE_DATEPATTERN_VALUE = 41;
7272
static const uint16_t OBJECT_TYPE_DATE_VALUE = 42;
7373
//static const uint16_t OBJECT_TYPE_DATETIMEPATTERN_VALUE = 43;
74-
//static const uint16_t OBJECT_TYPE_DATETIME_VALUE = 44;
74+
static const uint16_t OBJECT_TYPE_DATETIME_VALUE = 44;
7575
static const uint16_t OBJECT_TYPE_INTEGER_VALUE = 45;
7676
static const uint16_t OBJECT_TYPE_LARGE_ANALOG_VALUE = 46;
7777
static const uint16_t OBJECT_TYPE_OCTETSTRING_VALUE = 47;

BACnetServerExample/CASBACnetStackExampleDatabase.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ void ExampleDatabase::Setup() {
167167
this->networkPort.FdBbmdAddressHostIp[3] = 126;
168168
this->networkPort.FdBbmdAddressPort = 47809;
169169
this->networkPort.FdSubscriptionLifetime = 3600;
170+
this->dateTimeValue.instance = 60;
171+
this->dateTimeValue.objectName = "DateTimeValue " + ExampleDatabase::GetColorName();
172+
this->dateTimeValue.presentValueYear = 122;
173+
this->dateTimeValue.presentValueMonth = 1;
174+
this->dateTimeValue.presentValueDay = 28;
175+
this->dateTimeValue.presentValueWeekDay = 5;
176+
this->dateTimeValue.presentValueHour = 16;
177+
this->dateTimeValue.presentValueMinute = 53;
178+
this->dateTimeValue.presentValueSecond = 47;
179+
this->dateTimeValue.presentValueHundredthSeconds = 55;
170180
this->LoadNetworkPortProperties() ;
171181
}
172182

BACnetServerExample/CASBACnetStackExampleDatabase.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,19 @@ struct CreatedAnalogValue {
249249
}
250250
};
251251

252+
class ExampleDatabaseDateTimeValue : public ExampleDatabaseBaseObject
253+
{
254+
public:
255+
uint8_t presentValueYear;
256+
uint8_t presentValueMonth;
257+
uint8_t presentValueDay;
258+
uint8_t presentValueWeekDay;
259+
uint8_t presentValueHour;
260+
uint8_t presentValueMinute;
261+
uint8_t presentValueSecond;
262+
uint8_t presentValueHundredthSeconds;
263+
};
264+
252265
class ExampleDatabase {
253266

254267
public:
@@ -273,6 +286,7 @@ class ExampleDatabase {
273286
ExampleDatabasePositiveIntegerValue positiveIntegerValue;
274287
ExampleDatabaseTimeValue timeValue;
275288
ExampleDatabaseNetworkPort networkPort;
289+
ExampleDatabaseDateTimeValue dateTimeValue;
276290

277291
// Storage for create objects
278292
std::map<uint32_t, CreatedAnalogValue> CreatedAnalogValueData;

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Version 0.0.x
44

5+
### 0.0.15.x (2021-Jan-28)
6+
- Added DateTimeValue to example
7+
- Updated CAS BACnet Stack to version v3.27.0.0
8+
59
### 0.0.14.x (2021-Jan-20)
610
- Added LogDebugMessage callback to example
711
- Updated CAS BACnet Stack to version v3.26.0.0

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ Pre-configured with the following example BACnet device and objects:
3939
- positive_integer_value: 48 (PositiveIntegerValue Turquoise)
4040
- time_value: 50 (TimeValue Umber)
4141
- NetworkPort: 56 (NetworkPort Vermilion)
42+
- dateTimeValue: 60 (DateTimeValue White)
4243

4344
The following keyboard commands can be issued in the server window:
4445

45-
- **q**: Quit and exit the server
46-
- **i**: Increment the analog_value property Diamond by 1.1
47-
- **r**: Toggle the analog input reliability status
48-
- **f**: Send foreign device registration
49-
- **h**: Display help menu
46+
- **b**: Add (B)roadcast Distribution Table entry
47+
- **i**: (i)ncrement Analog Value: 2 by 1.1
48+
- **r**: Toggle the Analog Input: 0 (r)eliability status
49+
- **f**: Send Register (foreign) device message
50+
- **h**: (h)elp
51+
- **m**: Send text (m)essage
52+
- **q**: (q)uit
5053

5154
## Command arguments
5255

@@ -63,12 +66,13 @@ For the example server to run properly, please enable all object types and featu
6366
## Example Output
6467

6568
```txt
66-
CAS BACnet Stack Server Example v0.0.14.0
69+
CAS BACnet Stack Server Example v0.0.15.0
6770
https://github.com/chipkin/BACnetServerExampleCPP
6871
6972
FYI: Default to use device instance= 389999
7073
FYI: Loading CAS BACnet Stack functions... OK
71-
FYI: CAS BACnet Stack version: 3.26.1.0
74+
75+
FYI: CAS BACnet Stack version: 3.27.0.0
7276
FYI: Connecting UDP Resource to port=[47808]... OK, Connected to port
7377
FYI: Registering the Callback Functions with the CAS BACnet Stack
7478
Setting up server device. device.instance=[389999]

0 commit comments

Comments
 (0)