Skip to content

Instantly share code, notes, and snippets.

@funvill
Last active July 31, 2018 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funvill/52f8e736fa31e3c4e325efad7deeed1e to your computer and use it in GitHub Desktop.
Save funvill/52f8e736fa31e3c4e325efad7deeed1e to your computer and use it in GitHub Desktop.
Sending a BACnet I-AM via BACnet stack 1.x version
// http://bacnetstack.com/
// To be a good BACnet Server we should announce our-self when joining a network.
// Generate the IAM message and send it.
char packet[MAXIMUM_BACNET_MESSAGE];
unsigned short payloadSize = fpIAm(SETTING_SERVER_BACNET_NETWORK, (unsigned char *)&deviceOffset, sizeof(unsigned int), packet, MAXIMUM_BACNET_MESSAGE, deviceOffset);
if (payloadSize > 0) {
// Generate the connection string.
BYTE connectionString[10];
sscanf_s("255.255.255.255", "%d.%d.%d.%d", &connectionString[0], &connectionString[1], &connectionString[2], &connectionString[3]);
connectionString[4] = SETTING_BACNET_UDP_PORT / 256;
connectionString[5] = SETTING_BACNET_UDP_PORT % 256;
// Send the message
if (!SendUDPMessage(NULL, connectionString, 6, (BYTE *)packet, payloadSize, true)) {
printf("Error: Could not send foreign device registration message\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment