|
57 | 57 | // =======================================
|
58 | 58 | CSimpleUDP g_udp; // UDP resource
|
59 | 59 | ExampleDatabase g_database; // The example database that stores current values.
|
| 60 | +bool g_bbmdEnabled; // Flag for whether bbmd was enabled or not. Users can enable bbmd by pressing 'b' after the application has started |
60 | 61 |
|
61 | 62 | // Constants
|
62 | 63 | // =======================================
|
63 |
| -const std::string APPLICATION_VERSION = "0.0.17"; // See CHANGELOG.md for a full list of changes. |
| 64 | +const std::string APPLICATION_VERSION = "0.0.18"; // See CHANGELOG.md for a full list of changes. |
64 | 65 | const uint32_t MAX_RENDER_BUFFER_LENGTH = 1024 * 20;
|
65 | 66 |
|
66 | 67 |
|
@@ -128,6 +129,8 @@ int main(int argc, char** argv)
|
128 | 129 | std::cout << "FYI: Default to use device instance= " << g_database.device.instance << std::endl;
|
129 | 130 | }
|
130 | 131 |
|
| 132 | + // Initialize global flags |
| 133 | + g_bbmdEnabled = false; |
131 | 134 |
|
132 | 135 | // 1. Load the CAS BACnet stack functions
|
133 | 136 | // ---------------------------------------------------------------------------
|
@@ -576,9 +579,6 @@ int main(int argc, char** argv)
|
576 | 579 | std::cerr << "Failed to add NetworkPort" << std::endl;
|
577 | 580 | return -1;
|
578 | 581 | }
|
579 |
| - fpSetPropertyEnabled(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_NETWORK_PORT, g_database.networkPort.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_BBMD_ACCEPT_FD_REGISTRATIONS, true); |
580 |
| - fpSetPropertyEnabled(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_NETWORK_PORT, g_database.networkPort.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_BBMD_BROADCAST_DISTRIBUTION_TABLE, true); |
581 |
| - fpSetPropertyEnabled(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_NETWORK_PORT, g_database.networkPort.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_BBMD_FOREIGN_DEVICE_TABLE, true); |
582 | 582 |
|
583 | 583 | uint8_t ipPortConcat[6];
|
584 | 584 | memcpy(ipPortConcat, g_database.networkPort.IPAddress, 4);
|
@@ -709,7 +709,17 @@ bool DoUserInput()
|
709 | 709 | }
|
710 | 710 |
|
711 | 711 | fpAddBDTEntry(bbmdIpAddress, 6, bbmdIpMask, 4);
|
712 |
| - fpSetBBMD(g_database.device.instance, g_database.networkPort.instance); |
| 712 | + |
| 713 | + if (!g_bbmdEnabled) { |
| 714 | + // BBMD Properties of the Network Port Object, only enable if another BBMD is added to the BDT table |
| 715 | + fpSetPropertyEnabled(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_NETWORK_PORT, g_database.networkPort.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_BBMD_ACCEPT_FD_REGISTRATIONS, true); |
| 716 | + fpSetPropertyEnabled(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_NETWORK_PORT, g_database.networkPort.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_BBMD_BROADCAST_DISTRIBUTION_TABLE, true); |
| 717 | + fpSetPropertyEnabled(g_database.device.instance, CASBACnetStackExampleConstants::OBJECT_TYPE_NETWORK_PORT, g_database.networkPort.instance, CASBACnetStackExampleConstants::PROPERTY_IDENTIFIER_BBMD_FOREIGN_DEVICE_TABLE, true); |
| 718 | + fpSetBBMD(g_database.device.instance, g_database.networkPort.instance); |
| 719 | + |
| 720 | + g_bbmdEnabled = true; |
| 721 | + } |
| 722 | + |
713 | 723 | break;
|
714 | 724 | }
|
715 | 725 | case 'i': {
|
@@ -851,7 +861,7 @@ uint16_t CallbackReceiveMessage(uint8_t* message, const uint16_t maxMessageLengt
|
851 | 861 |
|
852 | 862 | // Process the message as JSON
|
853 | 863 | static char jsonRenderBuffer[MAX_RENDER_BUFFER_LENGTH];
|
854 |
| - if (fpDecodeAsJSON((char*)message, bytesRead, jsonRenderBuffer, MAX_RENDER_BUFFER_LENGTH) > 0) { |
| 864 | + if (fpDecodeAsJSON((char*)message, bytesRead, jsonRenderBuffer, MAX_RENDER_BUFFER_LENGTH, CASBACnetStackExampleConstants::NETWORK_TYPE_IP) > 0) { |
855 | 865 | std::cout << "---------------------" << std::endl;
|
856 | 866 | std::cout << jsonRenderBuffer << std::endl;
|
857 | 867 | std::cout << "---------------------" << std::endl;
|
@@ -919,7 +929,7 @@ uint16_t CallbackSendMessage(const uint8_t* message, const uint16_t messageLengt
|
919 | 929 |
|
920 | 930 | // Get the JSON rendered version of the just sent message
|
921 | 931 | static char jsonRenderBuffer[MAX_RENDER_BUFFER_LENGTH];
|
922 |
| - if (fpDecodeAsJSON((char*)message, messageLength, jsonRenderBuffer, MAX_RENDER_BUFFER_LENGTH) > 0) { |
| 932 | + if (fpDecodeAsJSON((char*)message, messageLength, jsonRenderBuffer, MAX_RENDER_BUFFER_LENGTH, networkType) > 0) { |
923 | 933 | std::cout << "---------------------" << std::endl;
|
924 | 934 | std::cout << jsonRenderBuffer << std::endl;
|
925 | 935 | std::cout << "---------------------" << std::endl;
|
@@ -1879,6 +1889,16 @@ bool GetObjectName(const uint32_t deviceInstance, const uint16_t objectType, con
|
1879 | 1889 | *valueElementCount = (uint32_t) stringSize;
|
1880 | 1890 | return true;
|
1881 | 1891 | }
|
| 1892 | + else if (objectType == CASBACnetStackExampleConstants::OBJECT_TYPE_ANALOG_OUTPUT && objectInstance == g_database.analogOutput.instance) { |
| 1893 | + stringSize = g_database.analogOutput.objectName.size(); |
| 1894 | + if (stringSize > maxElementCount) { |
| 1895 | + std::cerr << "Error - not enough space to store full name of objectType=[" << objectType << "], objectInstance=[" << objectInstance << " ]" << std::endl; |
| 1896 | + return false; |
| 1897 | + } |
| 1898 | + memcpy(value, g_database.analogOutput.objectName.c_str(), stringSize); |
| 1899 | + *valueElementCount = (uint32_t)stringSize; |
| 1900 | + return true; |
| 1901 | + } |
1882 | 1902 | else if (objectType == 389 ) {
|
1883 | 1903 | std::string name = "This is an example of the name";
|
1884 | 1904 | stringSize = name.size();
|
|
0 commit comments