Skip to content

Commit 780953d

Browse files
Update 5x (#49)
* Updated to use stack version 5.1.2 and removed submodules * Project clean up and added example of Out Of Service * Version bump to 1.0.0
1 parent 29d774f commit 780953d

13 files changed

+1559
-1527
lines changed

.gitmodules

-3
This file was deleted.

BACnetServerExample/BACnetServerExample.cpp

+99-11
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ time_t g_warmStartTimer; // Timer used for delaying the warm start.
6363

6464
// Constants
6565
// =======================================
66-
const std::string APPLICATION_VERSION = "0.0.26"; // See CHANGELOG.md for a full list of changes.
66+
const std::string APPLICATION_VERSION = "1.0.0"; // See CHANGELOG.md for a full list of changes.
6767
const uint32_t MAX_RENDER_BUFFER_LENGTH = 1024 * 20;
6868

6969

7070
// Callback Functions to Register to the DLL
7171
// Message Functions
72-
uint16_t CallbackReceiveMessage(uint8_t* message, const uint16_t maxMessageLength, uint8_t* receivedConnectionString, const uint8_t maxConnectionStringLength, uint8_t* receivedConnectionStringLength, uint8_t* networkType);
72+
uint16_t CallbackReceiveMessage(uint8_t* message, const uint16_t maxMessageLength, uint8_t* sourceConnectionString, uint8_t* sourceConnectionStringLength, uint8_t* destinationConnectionString, uint8_t* destinationConnectionStringLength, const uint8_t maxConnectionStringLength, uint8_t* networkType);
7373
uint16_t CallbackSendMessage(const uint8_t* message, const uint16_t messageLength, const uint8_t* connectionString, const uint8_t connectionStringLength, const uint8_t networkType, bool broadcast);
7474

7575
// System Functions
@@ -201,7 +201,7 @@ int main(int argc, char** argv)
201201
}
202202

203203
// Call the DLLs loop function which checks for messages and processes them.
204-
fpLoop();
204+
fpTick();
205205

206206
// Handle any user input.
207207
// Note: User input in this example is used for the following:
@@ -655,6 +655,18 @@ bool SetupDevice() {
655655
}
656656
std::cout << "OK" << std::endl;
657657

658+
// AnalogInput - OutOfService Example (AI)
659+
std::cout << "Added AnalogInput OutOfService Example. analogInputOutOfService.instance=[" << g_exampleDatabase.analogInputOutOfService.instance << "]... ";
660+
if (!fpAddObject(g_exampleDatabase.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT, g_exampleDatabase.analogInputOutOfService.instance)) {
661+
std::cerr << "Failed to add AnalogInput OutOfService Example" << std::endl;
662+
return -1;
663+
}
664+
665+
// Make out of service writable
666+
fpSetPropertyWritable(g_exampleDatabase.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT, g_exampleDatabase.analogInputOutOfService.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_OUT_OF_SERVICE, true);
667+
668+
std::cout << "OK" << std::endl;
669+
658670
// Add the Network Port Object
659671
std::cout << "Added NetworkPort. networkPort.instance=[" << g_exampleDatabase.networkPort.instance << "]... ";
660672
if (!fpAddNetworkPortObject(g_exampleDatabase.device.instance, g_exampleDatabase.networkPort.instance, CASBACnetStackExampleConstants::NETWORK_TYPE_IPV4, CASBACnetStackExampleConstants::PROTOCOL_LEVEL_BACNET_APPLICATION, CASBACnetStackExampleConstants::NETWORK_PORT_LOWEST_PROTOCOL_LAYER)) {
@@ -879,14 +891,14 @@ bool DoUserInput()
879891
}
880892

881893
// Callback used by the BACnet Stack to check if there is a message to process
882-
uint16_t CallbackReceiveMessage(uint8_t* message, const uint16_t maxMessageLength, uint8_t* receivedConnectionString, const uint8_t maxConnectionStringLength, uint8_t* receivedConnectionStringLength, uint8_t* networkType)
894+
uint16_t CallbackReceiveMessage(uint8_t* message, const uint16_t maxMessageLength, uint8_t* sourceConnectionString, uint8_t* sourceConnectionStringLength, uint8_t* destinationConnectionString, uint8_t* destinationConnectionStringLength, const uint8_t maxConnectionStringLength, uint8_t* networkType)
883895
{
884896
// Check parameters
885897
if (message == NULL || maxMessageLength == 0) {
886898
std::cerr << "Invalid input buffer" << std::endl;
887899
return 0;
888900
}
889-
if (receivedConnectionString == NULL || maxConnectionStringLength == 0) {
901+
if (sourceConnectionString == NULL || maxConnectionStringLength == 0) {
890902
std::cerr << "Invalid connection string buffer" << std::endl;
891903
return 0;
892904
}
@@ -905,14 +917,14 @@ uint16_t CallbackReceiveMessage(uint8_t* message, const uint16_t maxMessageLengt
905917
std::cout << std::endl << "FYI: Received message from [" << ipAddress << ":" << port << "], length [" << bytesRead << "]" << std::endl;
906918

907919
// Convert the IP Address to the connection string
908-
if (!ChipkinCommon::ChipkinConvert::IPAddressToBytes(ipAddress, receivedConnectionString, maxConnectionStringLength)) {
920+
if (!ChipkinCommon::ChipkinConvert::IPAddressToBytes(ipAddress, sourceConnectionString, maxConnectionStringLength)) {
909921
std::cerr << "Failed to convert the ip address into a connectionString" << std::endl;
910922
return 0;
911923
}
912-
receivedConnectionString[4] = port / 256;
913-
receivedConnectionString[5] = port % 256;
924+
sourceConnectionString[4] = port / 256;
925+
sourceConnectionString[5] = port % 256;
914926

915-
*receivedConnectionStringLength = 6;
927+
*sourceConnectionStringLength = 6;
916928
*networkType = CASBACnetStackExampleConstants::NETWORK_TYPE_IP;
917929

918930
/*
@@ -1108,6 +1120,13 @@ bool CallbackGetPropertyBool(uint32_t deviceInstance, uint16_t objectType, uint3
11081120
return true;
11091121
}
11101122
}
1123+
// AnalogInput - OutOfService Example
1124+
else if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_OUT_OF_SERVICE) {
1125+
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInputOutOfService.instance) {
1126+
*value = g_exampleDatabase.analogInputOutOfService.outOfService;
1127+
return true;
1128+
}
1129+
}
11111130
return false;
11121131
}
11131132

@@ -1134,6 +1153,13 @@ bool CallbackGetPropertyCharString(const uint32_t deviceInstance, const uint16_t
11341153
return true;
11351154
}
11361155
}
1156+
else if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInputOutOfService.instance) {
1157+
if (g_exampleDatabase.analogInputOutOfService.description.size() <= maxElementCount) {
1158+
memcpy(value, g_exampleDatabase.analogInputOutOfService.description.c_str(), g_exampleDatabase.analogInputOutOfService.description.size());
1159+
*valueElementCount = (uint32_t)g_exampleDatabase.analogInputOutOfService.description.size();
1160+
return true;
1161+
}
1162+
}
11371163
return false;
11381164
}
11391165
// Example of Character String Value Object Present Value property
@@ -1309,6 +1335,16 @@ bool CallbackGetPropertyEnum(uint32_t deviceInstance, uint16_t objectType, uint3
13091335
*value = g_exampleDatabase.analogInput.reliability;
13101336
return true;
13111337
}
1338+
// Analog Input - OutOfService Example
1339+
else if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInputOutOfService.instance) {
1340+
if (g_exampleDatabase.analogInputOutOfService.outOfService) {
1341+
*value = g_exampleDatabase.analogInputOutOfService.tempReliability;
1342+
}
1343+
else {
1344+
*value = g_exampleDatabase.analogInputOutOfService.reliability;
1345+
}
1346+
return true;
1347+
}
13121348
}
13131349
// Network Port Object - FdBbmdAddress Host Type
13141350
else if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_FD_BBMD_ADDRESS) {
@@ -1322,6 +1358,11 @@ bool CallbackGetPropertyEnum(uint32_t deviceInstance, uint16_t objectType, uint3
13221358
*value = g_exampleDatabase.analogInput.units;
13231359
return true;
13241360
}
1361+
// Analog Input - OutOfService Example
1362+
else if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInputOutOfService.instance) {
1363+
*value = g_exampleDatabase.analogInputOutOfService.units;
1364+
return true;
1365+
}
13251366
}
13261367

13271368
// Debug for customer
@@ -1451,6 +1492,16 @@ bool CallbackGetPropertyReal(uint32_t deviceInstance, uint16_t objectType, uint3
14511492
*value = g_exampleDatabase.CreatedAnalogValueData[objectInstance].value;
14521493
return true;
14531494
}
1495+
// Check if this is for the analog input out of service example
1496+
else if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInputOutOfService.instance) {
1497+
if (g_exampleDatabase.analogInputOutOfService.outOfService) {
1498+
*value = g_exampleDatabase.analogInputOutOfService.tempPresentValue;
1499+
}
1500+
else {
1501+
*value = g_exampleDatabase.analogInputOutOfService.presentValue;
1502+
}
1503+
return true;
1504+
}
14541505
}
14551506
// Example of Analog Output Priority Array property
14561507
else if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_PRIORITY_ARRAY) {
@@ -1470,7 +1521,7 @@ bool CallbackGetPropertyReal(uint32_t deviceInstance, uint16_t objectType, uint3
14701521
}
14711522
}
14721523
else if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_COV_INCURMENT && objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInput.instance) {
1473-
*value = g_exampleDatabase.analogInput.covIncurment;
1524+
*value = g_exampleDatabase.analogInput.covIncrement;
14741525
return true;
14751526
}
14761527
else if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_MAX_PRES_VALUE && objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_VALUE && objectInstance == g_exampleDatabase.analogValue.instance) {
@@ -1693,6 +1744,16 @@ bool CallbackSetPropertyBitString(const uint32_t deviceInstance, const uint16_t
16931744
// Callback used by the BACnet Stack to set Boolean property values to the user
16941745
bool CallbackSetPropertyBool(const uint32_t deviceInstance, const uint16_t objectType, const uint32_t objectInstance, const uint32_t propertyIdentifier, const bool value, const bool useArrayIndex, const uint32_t propertyArrayIndex, const uint8_t priority, uint32_t* errorCode)
16951746
{
1747+
if (deviceInstance == g_exampleDatabase.device.instance) {
1748+
// AnalogInput - OutOfService Example
1749+
if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_OUT_OF_SERVICE) {
1750+
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInputOutOfService.instance) {
1751+
g_exampleDatabase.analogInputOutOfService.outOfService = value;
1752+
return true;
1753+
}
1754+
}
1755+
}
1756+
16961757
return false;
16971758
}
16981759

@@ -1785,6 +1846,15 @@ bool CallbackSetPropertyEnum(const uint32_t deviceInstance, const uint16_t objec
17851846
return true;
17861847
}
17871848
}
1849+
else if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_RELIABILITY) {
1850+
// Example of setting reliability to an object that is OutOfService
1851+
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInputOutOfService.instance) {
1852+
if (g_exampleDatabase.analogInputOutOfService.outOfService) {
1853+
g_exampleDatabase.analogInputOutOfService.tempReliability = value;
1854+
return true;
1855+
}
1856+
}
1857+
}
17881858
}
17891859
return false;
17901860
}
@@ -1936,10 +2006,17 @@ bool CallbackSetPropertyReal(const uint32_t deviceInstance, const uint16_t objec
19362006
g_exampleDatabase.CreatedAnalogValueData[objectInstance].value = value;
19372007
return true;
19382008
}
2009+
// Example of setting presentValue to an object that is OutOfService
2010+
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInputOutOfService.instance) {
2011+
if (g_exampleDatabase.analogInputOutOfService.outOfService) {
2012+
g_exampleDatabase.analogInputOutOfService.tempPresentValue = value;
2013+
return true;
2014+
}
2015+
}
19392016
}
19402017
else if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_COV_INCURMENT) {
19412018
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInput.instance) {
1942-
g_exampleDatabase.analogInput.covIncurment = value;
2019+
g_exampleDatabase.analogInput.covIncrement = value;
19432020
return true;
19442021
}
19452022
}
@@ -2248,6 +2325,16 @@ bool GetObjectName(const uint32_t deviceInstance, const uint16_t objectType, con
22482325
*valueElementCount = (uint32_t) stringSize;
22492326
return true;
22502327
}
2328+
else if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_exampleDatabase.analogInputOutOfService.instance) {
2329+
stringSize = g_exampleDatabase.analogInputOutOfService.objectName.size();
2330+
if (stringSize > maxElementCount) {
2331+
std::cerr << "Error - not enough space to store full name of objectType=[" << objectType << "], objectInstance=[" << objectInstance << " ]" << std::endl;
2332+
return false;
2333+
}
2334+
memcpy(value, g_exampleDatabase.analogInputOutOfService.objectName.c_str(), stringSize);
2335+
*valueElementCount = (uint32_t)stringSize;
2336+
return true;
2337+
}
22512338
else {
22522339
// Check if the value is an Analog Value and check if it was a created object
22532340
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_VALUE && g_exampleDatabase.CreatedAnalogValueData.count(objectInstance) > 0) {
@@ -2412,3 +2499,4 @@ bool HookTextMessage(const uint32_t sourceDeviceIdentifier, const bool useMessag
24122499
return false;
24132500
}
24142501

2502+

0 commit comments

Comments
 (0)