Skip to content

Commit

Permalink
Added Example for DateTimeValue Object + Release prep (#23)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
justin-wong-ce and ssmethurst authored Feb 1, 2022
1 parent 0aef91a commit bab2954
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 9 deletions.
42 changes: 41 additions & 1 deletion BACnetServerExample/BACnetServerExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,19 @@ int main(int argc, char** argv)
ipPortConcat[4] = g_database.networkPort.BACnetIPUDPPort / 256;
ipPortConcat[5] = g_database.networkPort.BACnetIPUDPPort % 256;
fpAddBDTEntry(ipPortConcat, 6, g_database.networkPort.IPSubnetMask, 4); // First BDT Entry must be server device
fpSetBBMD(g_database.device.instance, g_database.networkPort.instance);


std::cout << "OK" << std::endl;

// Add the DateTimeValue Object
std::cout << "Added DateTimeValue. dateTimeValue.instance=[" << g_database.dateTimeValue.instance << "]... ";
if (!fpAddObject(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_DATETIME_VALUE, g_database.dateTimeValue.instance)) {
std::cerr << "Failed to add DateTimeValue" << std::endl;
return -1;
}

std::cout << "OK" << std::endl;

// 5. Send I-Am of this device
// ---------------------------------------------------------------------------
// To be a good citizen on a BACnet network. We should announce ourself when we start up.
Expand Down Expand Up @@ -1116,6 +1125,17 @@ bool CallbackGetPropertyDate(const uint32_t deviceInstance, const uint16_t objec
return true;
}
}
// Example of DateTime Value Object Present Value property
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_DATETIME_VALUE && objectInstance == 60) {
if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_PRESENT_VALUE) {
*year = g_database.dateTimeValue.presentValueYear;
*month = g_database.dateTimeValue.presentValueMonth;
*day = g_database.dateTimeValue.presentValueDay;
*weekday = g_database.dateTimeValue.presentValueWeekDay;
return true;
}
}

return false;
}

Expand Down Expand Up @@ -1365,6 +1385,16 @@ bool CallbackGetPropertyTime(const uint32_t deviceInstance, const uint16_t objec
return true;
}
}
// Example of DateTime Value Object Present Value property
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_DATETIME_VALUE && objectInstance == 60) {
if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_PRESENT_VALUE) {
*hour = g_database.dateTimeValue.presentValueHour;
*minute = g_database.dateTimeValue.presentValueMinute;
*second = g_database.dateTimeValue.presentValueSecond;
*hundrethSeconds = g_database.dateTimeValue.presentValueHundredthSeconds;
return true;
}
}
return false;
}

Expand Down Expand Up @@ -2009,6 +2039,16 @@ bool GetObjectName(const uint32_t deviceInstance, const uint16_t objectType, con
*valueElementCount = (uint32_t) stringSize;
return true;
}
else if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_DATETIME_VALUE && objectInstance == g_database.dateTimeValue.instance) {
stringSize = g_database.dateTimeValue.objectName.size();
if (stringSize > maxElementCount) {
std::cerr << "Error - not enough space to store full name of objectType=[" << objectType << "], objectInstance=[" << objectInstance <<" ]" << std::endl;
return false;
}
memcpy(value, g_database.dateTimeValue.objectName.c_str(), stringSize);
*valueElementCount = (uint32_t) stringSize;
return true;
}
else {
// Check if the value is an Analog Value and check if it was a created object
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_VALUE && g_database.CreatedAnalogValueData.count(objectInstance) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion BACnetServerExample/CASBACnetStackExampleConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CASBACnetStackExampleConstants {
//static const uint16_t OBJECT_TYPE_DATEPATTERN_VALUE = 41;
static const uint16_t OBJECT_TYPE_DATE_VALUE = 42;
//static const uint16_t OBJECT_TYPE_DATETIMEPATTERN_VALUE = 43;
//static const uint16_t OBJECT_TYPE_DATETIME_VALUE = 44;
static const uint16_t OBJECT_TYPE_DATETIME_VALUE = 44;
static const uint16_t OBJECT_TYPE_INTEGER_VALUE = 45;
static const uint16_t OBJECT_TYPE_LARGE_ANALOG_VALUE = 46;
static const uint16_t OBJECT_TYPE_OCTETSTRING_VALUE = 47;
Expand Down
10 changes: 10 additions & 0 deletions BACnetServerExample/CASBACnetStackExampleDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ void ExampleDatabase::Setup() {
this->networkPort.FdBbmdAddressHostIp[3] = 126;
this->networkPort.FdBbmdAddressPort = 47809;
this->networkPort.FdSubscriptionLifetime = 3600;
this->dateTimeValue.instance = 60;
this->dateTimeValue.objectName = "DateTimeValue " + ExampleDatabase::GetColorName();
this->dateTimeValue.presentValueYear = 122;
this->dateTimeValue.presentValueMonth = 1;
this->dateTimeValue.presentValueDay = 28;
this->dateTimeValue.presentValueWeekDay = 5;
this->dateTimeValue.presentValueHour = 16;
this->dateTimeValue.presentValueMinute = 53;
this->dateTimeValue.presentValueSecond = 47;
this->dateTimeValue.presentValueHundredthSeconds = 55;
this->LoadNetworkPortProperties() ;
}

Expand Down
14 changes: 14 additions & 0 deletions BACnetServerExample/CASBACnetStackExampleDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ struct CreatedAnalogValue {
}
};

class ExampleDatabaseDateTimeValue : public ExampleDatabaseBaseObject
{
public:
uint8_t presentValueYear;
uint8_t presentValueMonth;
uint8_t presentValueDay;
uint8_t presentValueWeekDay;
uint8_t presentValueHour;
uint8_t presentValueMinute;
uint8_t presentValueSecond;
uint8_t presentValueHundredthSeconds;
};

class ExampleDatabase {

public:
Expand All @@ -273,6 +286,7 @@ class ExampleDatabase {
ExampleDatabasePositiveIntegerValue positiveIntegerValue;
ExampleDatabaseTimeValue timeValue;
ExampleDatabaseNetworkPort networkPort;
ExampleDatabaseDateTimeValue dateTimeValue;

// Storage for create objects
std::map<uint32_t, CreatedAnalogValue> CreatedAnalogValueData;
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Version 0.0.x

### 0.0.15.x (2021-Jan-28)
- Added DateTimeValue to example
- Updated CAS BACnet Stack to version v3.27.0.0

### 0.0.14.x (2021-Jan-20)
- Added LogDebugMessage callback to example
- Updated CAS BACnet Stack to version v3.26.0.0
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ Pre-configured with the following example BACnet device and objects:
- positive_integer_value: 48 (PositiveIntegerValue Turquoise)
- time_value: 50 (TimeValue Umber)
- NetworkPort: 56 (NetworkPort Vermilion)
- dateTimeValue: 60 (DateTimeValue White)

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

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

## Command arguments

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

```txt
CAS BACnet Stack Server Example v0.0.14.0
CAS BACnet Stack Server Example v0.0.15.0
https://github.com/chipkin/BACnetServerExampleCPP
FYI: Default to use device instance= 389999
FYI: Loading CAS BACnet Stack functions... OK
FYI: CAS BACnet Stack version: 3.26.1.0
FYI: CAS BACnet Stack version: 3.27.0.0
FYI: Connecting UDP Resource to port=[47808]... OK, Connected to port
FYI: Registering the Callback Functions with the CAS BACnet Stack
Setting up server device. device.instance=[389999]
Expand Down

0 comments on commit bab2954

Please sign in to comment.