Skip to content

Commit 6e9b6e1

Browse files
authored
Merge pull request #2 from chipkin/MSI.StateText
Msi.state text
2 parents c137deb + 4fe3d5b commit 6e9b6e1

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

BACnetServerExample/BACnetServerExample.cpp

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int main()
8686
return 0;
8787
}
8888
std::cout << "OK" << std::endl;
89-
std::cout << "FYI: BACnet Stack version: " << fpGetAPIMajorVersion() << "." << fpGetAPIMinorVersion() << "." << fpGetAPIPatchVersion() << "." << fpGetAPIBuildVersion() << std::endl;
89+
std::cout << "FYI: CAS BACnet Stack version: " << fpGetAPIMajorVersion() << "." << fpGetAPIMinorVersion() << "." << fpGetAPIPatchVersion() << "." << fpGetAPIBuildVersion() << std::endl;
9090

9191
// 2. Connect the UDP resource to the BACnet Port
9292
// ---------------------------------------------------------------------------
@@ -157,10 +157,7 @@ int main()
157157

158158
// Enable the services that this device supports
159159
// Some services are mandatory for BACnet devices and are already enabled.
160-
// These are:
161-
// Read Property
162-
// Who Is
163-
// Who Has
160+
// These are: Read Property, Who Is, Who Has
164161
//
165162
// Any other services need to be enabled as below.
166163

@@ -241,6 +238,7 @@ int main()
241238
return false;
242239
}
243240

241+
244242
// Update Writable Device Properties
245243
// UTC Offset
246244
if (!fpSetPropertyWritable(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_DEVICE, g_database.device.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_UTC_OFFSET, true)) {
@@ -288,7 +286,7 @@ int main()
288286
fpSetPropertySubscribable(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT, g_database.analogInput.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_PRESENT_VALUE, true);
289287
fpSetPropertyWritable(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT, g_database.analogInput.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_COV_INCURMENT, true);
290288

291-
// Enable the description property
289+
// Enable the description, and Reliabiliyty property
292290
fpSetPropertyByObjectTypeEnabled(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_DESCRIPTION, true);
293291
fpSetPropertyByObjectTypeEnabled(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_RELIABILITY, true);
294292

@@ -347,6 +345,7 @@ int main()
347345
std::cerr << "Failed to add MultiStateInput" << std::endl;
348346
return -1;
349347
}
348+
fpSetPropertyByObjectTypeEnabled(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_MULTI_STATE_INPUT, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_STATE_TEXT, true);
350349
std::cout << "OK" << std::endl;
351350

352351
// MultiStateOutput (MSO)
@@ -454,8 +453,6 @@ int main()
454453
}
455454
std::cout << "OK" << std::endl;
456455

457-
458-
459456
// 4. Send I-Am of this device
460457
// ---------------------------------------------------------------------------
461458
// To be a good citizen on a BACnet network. We should annouce ourselfs when we start up.
@@ -528,7 +525,7 @@ bool DoUserInput()
528525
case 'i': {
529526
// Increment the Analog Value
530527
g_database.analogValue.presentValue += 1.1f;
531-
std::cout << "Incrementing Analog Output to " << g_database.analogValue.presentValue << std::endl;
528+
std::cout << "Incrementing Analog Value to " << g_database.analogValue.presentValue << std::endl;
532529

533530
// Notify the stack that this data point was updated so the stack can check for logic
534531
// that may need to run on the data. Example: check if COV (change of value) occurred.
@@ -555,6 +552,9 @@ bool DoUserInput()
555552
}
556553
break;
557554
}
555+
case 'd': {
556+
}
557+
558558
case 'h':
559559
default: {
560560
// Print the Help
@@ -564,8 +564,9 @@ bool DoUserInput()
564564
std::cout << "https://github.com/chipkin/BACnetServerExampleCPP" << std::endl << std::endl;
565565

566566
std::cout << "Help:" << std::endl;
567-
std::cout << "i - (i)ncrement Analog Value " << g_database.analogValue.instance << " by 1.1" << std::endl;
568-
std::cout << "r - Toggle the Analog Input (r)eliability status" << std::endl;
567+
std::cout << "i - (i)ncrement Analog Value:2" << g_database.analogValue.instance << " by 1.1" << std::endl;
568+
std::cout << "r - Toggle the Analog Input:0 (r)eliability status" << std::endl;
569+
// std::cout << "d - (d)ebug" << std::endl;
569570
std::cout << "h - (h)elp" << std::endl;
570571
std::cout << "q - (q)uit" << std::endl;
571572
std::cout << std::endl;
@@ -834,6 +835,13 @@ bool CallbackGetPropertyCharString(const uint32_t deviceInstance, const uint16_t
834835
*valueElementCount = snprintf(value, maxElementCount, "Example custom property 512 + 3");
835836
return true;
836837
}
838+
else if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_MULTI_STATE_INPUT && propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_STATE_TEXT && objectInstance == g_database.multiStateInput.instance) {
839+
if (useArrayIndex && propertyArrayIndex > 0 && propertyArrayIndex <= g_database.multiStateInput.numberOfStates) {
840+
// 0 is number of dates.
841+
*valueElementCount = snprintf(value, maxElementCount, g_database.multiStateInput.stateText[propertyArrayIndex-1].c_str());
842+
return true;
843+
}
844+
}
837845
return false;
838846
}
839847

@@ -915,6 +923,18 @@ bool CallbackGetPropertyEnum(uint32_t deviceInstance, uint16_t objectType, uint3
915923
return true;
916924
}
917925
}
926+
927+
928+
929+
// Debug for customer
930+
if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_SYSTEM_STATUS &&
931+
objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_DEVICE)
932+
{
933+
std::cout << "Debug: Device:System Status" << std::endl;
934+
*value = 1;
935+
return true;
936+
}
937+
918938

919939
// We could not answer this request.
920940
return false;
@@ -1007,6 +1027,7 @@ bool CallbackGetPropertyInt(uint32_t deviceInstance, uint16_t objectType, uint32
10071027
// Callback used by the BACnet Stack to get Real property values from the user
10081028
bool CallbackGetPropertyReal(uint32_t deviceInstance, uint16_t objectType, uint32_t objectInstance, uint32_t propertyIdentifier, float* value, bool useArrayIndex, uint32_t propertyArrayIndex)
10091029
{
1030+
10101031
// Example of Analog Input / Value Object Present Value property
10111032
if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_PRESENT_VALUE) {
10121033
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_INPUT && objectInstance == g_database.analogInput.instance) {
@@ -1157,6 +1178,12 @@ bool CallbackGetPropertyUInt(uint32_t deviceInstance, uint16_t objectType, uint3
11571178
return true;
11581179
}
11591180
}
1181+
else if (propertyIdentifier == CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_STATE_TEXT) {
1182+
if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_MULTI_STATE_INPUT && objectInstance == g_database.multiStateInput.instance) {
1183+
*value = g_database.multiStateInput.numberOfStates;
1184+
return true;
1185+
}
1186+
}
11601187
return false;
11611188
}
11621189

BACnetServerExample/CASBACnetStackExampleConstants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class CASBACnetStackExampleConstants {
9595
static const uint32_t PROPERTY_IDENTIFIER_PRESENT_VALUE = 85;
9696
static const uint32_t PROPERTY_IDENTIFIER_PRIORITY_ARRAY = 87;
9797
static const uint32_t PROPERTY_IDENTIFIER_RELIABILITY = 103;
98+
static const uint32_t PROPERTY_IDENTIFIER_STATE_TEXT = 110;
99+
static const uint32_t PROPERTY_IDENTIFIER_STATUS_FLAGS = 111;
100+
static const uint32_t PROPERTY_IDENTIFIER_SYSTEM_STATUS = 112;
98101
static const uint32_t PROPERTY_IDENTIFIER_UTC_OFFSET = 119;
99102
static const uint32_t PROPERTY_IDENTIFIER_BIT_TEXT = 343;
100103

BACnetServerExample/CASBACnetStackExampleDatabase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ void ExampleDatabase::Setup() {
7272
this->device.UTCOffset = 0;
7373
this->device.currentTimeOffset = 0;
7474
this->device.description = "Chipkin test BACnet IP Server device";
75+
// BACnetDeviceStatus ::= ENUMERATED { operational (0), operational-read-only (1), download-required (2),
76+
// download-in-progress (3), non-operational (4), backup-in-progress (5) }
77+
this->device.systemStatus = 0; // operational (0), non-operational (4)
7578

7679

7780
// Set the object name properites.

BACnetServerExample/CASBACnetStackExampleDatabase.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,23 @@ class ExampleDatabaseDevice : public ExampleDatabaseBaseObject
9292
int UTCOffset;
9393
int64_t currentTimeOffset;
9494
std::string description;
95+
uint32_t systemStatus;
9596
};
9697

9798
class ExampleDatabaseMultiStateInput : public ExampleDatabaseBaseObject
9899
{
99100
public:
100101
uint32_t presentValue ;
101102
uint32_t numberOfStates;
103+
std::vector<std::string> stateText;
102104

103105
ExampleDatabaseMultiStateInput() {
104106
this->presentValue = 1 ; // A value of zero is invalid.
105107
this->numberOfStates = 3;
108+
109+
this->stateText.push_back("One");
110+
this->stateText.push_back("Two");
111+
this->stateText.push_back("Three");
106112
}
107113
};
108114

0 commit comments

Comments
 (0)