running the indent on the files.
This commit is contained in:
@@ -38,60 +38,42 @@ extern "C" {
|
|||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
/* unconfirmed requests */
|
/* unconfirmed requests */
|
||||||
void Send_WhoIs(
|
void Send_WhoIs(int32_t low_limit, int32_t high_limit);
|
||||||
int32_t low_limit,
|
|
||||||
int32_t high_limit);
|
|
||||||
|
|
||||||
void Send_WhoHas_Object(
|
void Send_WhoHas_Object(int32_t low_limit,
|
||||||
int32_t low_limit,
|
|
||||||
int32_t high_limit,
|
int32_t high_limit,
|
||||||
BACNET_OBJECT_TYPE object_type,
|
BACNET_OBJECT_TYPE object_type, uint32_t object_instance);
|
||||||
uint32_t object_instance);
|
|
||||||
|
|
||||||
void Send_WhoHas_Name(
|
void Send_WhoHas_Name(int32_t low_limit,
|
||||||
int32_t low_limit,
|
int32_t high_limit, char *object_name);
|
||||||
int32_t high_limit,
|
|
||||||
char *object_name);
|
|
||||||
|
|
||||||
void Send_I_Have(
|
void Send_I_Have(uint32_t device_id,
|
||||||
uint32_t device_id,
|
|
||||||
BACNET_OBJECT_TYPE object_type,
|
BACNET_OBJECT_TYPE object_type,
|
||||||
uint32_t object_instance,
|
uint32_t object_instance, char *object_name);
|
||||||
char *object_name);
|
|
||||||
|
|
||||||
/* returns the invoke ID for confirmed request, or 0 if failed */
|
/* returns the invoke ID for confirmed request, or 0 if failed */
|
||||||
uint8_t Send_Read_Property_Request(
|
uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */
|
||||||
uint32_t device_id, /* destination device */
|
|
||||||
BACNET_OBJECT_TYPE object_type,
|
BACNET_OBJECT_TYPE object_type,
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID object_property,
|
BACNET_PROPERTY_ID object_property, int32_t array_index);
|
||||||
int32_t array_index);
|
|
||||||
|
|
||||||
/* returns the invoke ID for confirmed request, or 0 if failed */
|
/* returns the invoke ID for confirmed request, or 0 if failed */
|
||||||
uint8_t Send_Write_Property_Request(
|
uint8_t Send_Write_Property_Request(uint32_t device_id, // destination device
|
||||||
uint32_t device_id, // destination device
|
|
||||||
BACNET_OBJECT_TYPE object_type,
|
BACNET_OBJECT_TYPE object_type,
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID object_property,
|
BACNET_PROPERTY_ID object_property,
|
||||||
BACNET_APPLICATION_DATA_VALUE * object_value,
|
BACNET_APPLICATION_DATA_VALUE * object_value,
|
||||||
uint8_t priority,
|
uint8_t priority, int32_t array_index);
|
||||||
int32_t array_index);
|
|
||||||
|
|
||||||
/* returns the invoke ID for confirmed request, or 0 if failed */
|
/* returns the invoke ID for confirmed request, or 0 if failed */
|
||||||
uint8_t Send_Reinitialize_Device_Request(
|
uint8_t Send_Reinitialize_Device_Request(uint32_t device_id,
|
||||||
uint32_t device_id,
|
BACNET_REINITIALIZED_STATE state, char *password);
|
||||||
BACNET_REINITIALIZED_STATE state,
|
|
||||||
char *password);
|
|
||||||
|
|
||||||
/* returns the invoke ID for confirmed request, or 0 if failed */
|
/* returns the invoke ID for confirmed request, or 0 if failed */
|
||||||
uint8_t Send_Device_Communication_Control_Request(
|
uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t timeDuration, /* 0=optional */
|
||||||
uint32_t device_id,
|
BACNET_COMMUNICATION_ENABLE_DISABLE state, char *password); /* NULL=optional */
|
||||||
uint16_t timeDuration, /* 0=optional */
|
|
||||||
BACNET_COMMUNICATION_ENABLE_DISABLE state,
|
|
||||||
char *password); /* NULL=optional */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -41,11 +41,9 @@
|
|||||||
#include "ao.h"
|
#include "ao.h"
|
||||||
#include "bacfile.h"
|
#include "bacfile.h"
|
||||||
|
|
||||||
void handler_atomic_read_file(
|
void handler_atomic_read_file(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||||
BACNET_CONFIRMED_SERVICE_DATA *service_data)
|
|
||||||
{
|
{
|
||||||
BACNET_ATOMIC_READ_FILE_DATA data;
|
BACNET_ATOMIC_READ_FILE_DATA data;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@@ -58,96 +56,64 @@ void handler_atomic_read_file(
|
|||||||
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||||
|
|
||||||
fprintf(stderr, "Received Atomic-Read-File Request!\n");
|
fprintf(stderr, "Received Atomic-Read-File Request!\n");
|
||||||
len = arf_decode_service_request(
|
len = arf_decode_service_request(service_request, service_len, &data);
|
||||||
service_request,
|
|
||||||
service_len,
|
|
||||||
&data);
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
fprintf(stderr, "Unable to decode Atomic-Read-File Request!\n");
|
fprintf(stderr, "Unable to decode Atomic-Read-File Request!\n");
|
||||||
// prepare a reply
|
// prepare a reply
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
src,
|
|
||||||
&my_address,
|
|
||||||
false, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
// bad decoding - send an abort
|
// bad decoding - send an abort
|
||||||
if (len < 0)
|
if (len < 0) {
|
||||||
{
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += abort_encode_apdu(
|
service_data->invoke_id, ABORT_REASON_OTHER);
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
|
||||||
ABORT_REASON_OTHER);
|
|
||||||
fprintf(stderr, "Sending Abort!\n");
|
fprintf(stderr, "Sending Abort!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
} else if (service_data->segmented_message) {
|
||||||
else if (service_data->segmented_message)
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
{
|
|
||||||
pdu_len += abort_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
||||||
fprintf(stderr, "Sending Abort!\n");
|
fprintf(stderr, "Sending Abort!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
} else {
|
||||||
else
|
if (data.access == FILE_STREAM_ACCESS) {
|
||||||
{
|
|
||||||
if (data.access == FILE_STREAM_ACCESS)
|
|
||||||
{
|
|
||||||
if (data.type.stream.requestedOctetCount <
|
if (data.type.stream.requestedOctetCount <
|
||||||
octetstring_capacity(&data.fileData))
|
octetstring_capacity(&data.fileData)) {
|
||||||
{
|
if (bacfile_read_data(&data)) {
|
||||||
if (bacfile_read_data(&data))
|
pdu_len +=
|
||||||
{
|
arf_ack_encode_apdu(&Handler_Transmit_Buffer
|
||||||
pdu_len += arf_ack_encode_apdu(
|
[pdu_len], service_data->invoke_id, &data);
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
|
||||||
&data);
|
|
||||||
send = true;
|
send = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
send = true;
|
send = true;
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
pdu_len +=
|
||||||
{
|
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += abort_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
||||||
fprintf(stderr, "Sending Abort!\n");
|
fprintf(stderr, "Sending Abort!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
error_class = ERROR_CLASS_SERVICES;
|
error_class = ERROR_CLASS_SERVICES;
|
||||||
error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD;
|
error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD;
|
||||||
send = true;
|
send = true;
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (error)
|
if (error) {
|
||||||
{
|
pdu_len += bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += bacerror_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code);
|
||||||
error_class,
|
|
||||||
error_code);
|
|
||||||
fprintf(stderr, "Sending Error!\n");
|
fprintf(stderr, "Sending Error!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
}
|
||||||
if (send)
|
if (send) {
|
||||||
{
|
bytes_sent = datalink_send_pdu(src, // destination address
|
||||||
bytes_sent = datalink_send_pdu(
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
src, // destination address
|
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,11 +47,9 @@
|
|||||||
// that someone can read from us. It is common to
|
// that someone can read from us. It is common to
|
||||||
// use the description as the file name.
|
// use the description as the file name.
|
||||||
#if BACFILE
|
#if BACFILE
|
||||||
void handler_atomic_read_file_ack(
|
void handler_atomic_read_file_ack(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
|
||||||
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
BACNET_ATOMIC_READ_FILE_DATA data;
|
BACNET_ATOMIC_READ_FILE_DATA data;
|
||||||
@@ -62,39 +60,29 @@ void handler_atomic_read_file_ack(
|
|||||||
(void) src;
|
(void) src;
|
||||||
// get the file instance from the tsm data before freeing it
|
// get the file instance from the tsm data before freeing it
|
||||||
instance = bacfile_instance_from_tsm(service_data->invoke_id);
|
instance = bacfile_instance_from_tsm(service_data->invoke_id);
|
||||||
len = arf_ack_decode_service_request(
|
len = arf_ack_decode_service_request(service_request,
|
||||||
service_request,
|
service_len, &data);
|
||||||
service_len,
|
|
||||||
&data);
|
|
||||||
fprintf(stderr, "Received Read-File Ack!\n");
|
fprintf(stderr, "Received Read-File Ack!\n");
|
||||||
if ((len > 0) && (instance <= BACNET_MAX_INSTANCE))
|
if ((len > 0) && (instance <= BACNET_MAX_INSTANCE)) {
|
||||||
{
|
|
||||||
// write the data received to the file specified
|
// write the data received to the file specified
|
||||||
if (data.access == FILE_STREAM_ACCESS)
|
if (data.access == FILE_STREAM_ACCESS) {
|
||||||
{
|
|
||||||
pFilename = bacfile_name(instance);
|
pFilename = bacfile_name(instance);
|
||||||
if (pFilename)
|
if (pFilename) {
|
||||||
{
|
|
||||||
pFile = fopen(pFilename, "rb");
|
pFile = fopen(pFilename, "rb");
|
||||||
if (pFile)
|
if (pFile) {
|
||||||
{
|
|
||||||
(void) fseek(pFile,
|
(void) fseek(pFile,
|
||||||
data.type.stream.fileStartPosition,
|
data.type.stream.fileStartPosition, SEEK_SET);
|
||||||
SEEK_SET);
|
|
||||||
if (fwrite(octetstring_value(&data.fileData),
|
if (fwrite(octetstring_value(&data.fileData),
|
||||||
octetstring_length(&data.fileData),1,pFile) != 1)
|
octetstring_length(&data.fileData), 1,
|
||||||
|
pFile) != 1)
|
||||||
fprintf(stderr, "Failed to write to %s (%u)!\n",
|
fprintf(stderr, "Failed to write to %s (%u)!\n",
|
||||||
pFilename, instance);
|
pFilename, instance);
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (data.access == FILE_RECORD_ACCESS) {
|
||||||
else if (data.access == FILE_RECORD_ACCESS)
|
|
||||||
{
|
|
||||||
// FIXME: add handling for Record Access
|
// FIXME: add handling for Record Access
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,9 @@
|
|||||||
|
|
||||||
static char *My_Password = "AnnaRoseKarg";
|
static char *My_Password = "AnnaRoseKarg";
|
||||||
|
|
||||||
void handler_device_communication_control(
|
void handler_device_communication_control(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||||
BACNET_CONFIRMED_SERVICE_DATA *service_data)
|
|
||||||
{
|
{
|
||||||
uint16_t timeDuration = 0;
|
uint16_t timeDuration = 0;
|
||||||
BACNET_COMMUNICATION_ENABLE_DISABLE state = COMMUNICATION_ENABLE;
|
BACNET_COMMUNICATION_ENABLE_DISABLE state = COMMUNICATION_ENABLE;
|
||||||
@@ -55,91 +53,63 @@ void handler_device_communication_control(
|
|||||||
int bytes_sent = 0;
|
int bytes_sent = 0;
|
||||||
|
|
||||||
// decode the service request only
|
// decode the service request only
|
||||||
len = dcc_decode_service_request(
|
len = dcc_decode_service_request(service_request,
|
||||||
service_request,
|
service_len, &timeDuration, &state, &password);
|
||||||
service_len,
|
|
||||||
&timeDuration,
|
|
||||||
&state,
|
|
||||||
&password);
|
|
||||||
fprintf(stderr, "DeviceCommunicationControl!\n");
|
fprintf(stderr, "DeviceCommunicationControl!\n");
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"timeout=%u state=%u password=%s\n",
|
"timeout=%u state=%u password=%s\n",
|
||||||
(unsigned) timeDuration,
|
(unsigned) timeDuration,
|
||||||
(unsigned)state,
|
(unsigned) state, characterstring_value(&password));
|
||||||
characterstring_value(&password));
|
|
||||||
else
|
else
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Unable to decode request!\n");
|
"Unable to decode request!\n");
|
||||||
// prepare a reply
|
// prepare a reply
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
src,
|
|
||||||
&my_address,
|
|
||||||
false, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
// bad decoding or something we didn't understand - send an abort
|
// bad decoding or something we didn't understand - send an abort
|
||||||
if (len == -1)
|
if (len == -1) {
|
||||||
{
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += abort_encode_apdu(
|
service_data->invoke_id, ABORT_REASON_OTHER);
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
|
||||||
ABORT_REASON_OTHER);
|
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Sending Abort - could not decode.\n");
|
"Sending Abort - could not decode.\n");
|
||||||
}
|
} else if (service_data->segmented_message) {
|
||||||
else if (service_data->segmented_message)
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
{
|
|
||||||
pdu_len += abort_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Sending Abort - segmented message.\n");
|
"Sending Abort - segmented message.\n");
|
||||||
}
|
} else if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) {
|
||||||
else if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE)
|
pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
{
|
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
|
||||||
pdu_len += reject_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
|
||||||
REJECT_REASON_UNDEFINED_ENUMERATION);
|
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Sending Reject - undefined enumeration\n");
|
"Sending Reject - undefined enumeration\n");
|
||||||
}
|
} else {
|
||||||
else
|
if (characterstring_ansi_same(&password, My_Password)) {
|
||||||
{
|
pdu_len += encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||||
if (characterstring_ansi_same(&password,My_Password))
|
|
||||||
{
|
|
||||||
pdu_len += encode_simple_ack(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
|
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL);
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Sending Simple Ack!\n");
|
"Sending Simple Ack!\n");
|
||||||
dcc_set_status_duration(state, timeDuration);
|
dcc_set_status_duration(state, timeDuration);
|
||||||
}
|
} else {
|
||||||
else
|
pdu_len +=
|
||||||
{
|
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += bacerror_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
|
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
|
||||||
ERROR_CLASS_SERVICES,
|
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
|
||||||
ERROR_CODE_PASSWORD_FAILURE);
|
fprintf(stderr,
|
||||||
fprintf(stderr,"DeviceCommunicationControl: "
|
"DeviceCommunicationControl: "
|
||||||
"Sending Error - password failure.\n");
|
"Sending Error - password failure.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(src, // destination address
|
||||||
src, // destination address
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr, "DeviceCommunicationControl: "
|
fprintf(stderr, "DeviceCommunicationControl: "
|
||||||
"Failed to send PDU (%s)!\n",
|
"Failed to send PDU (%s)!\n", strerror(errno));
|
||||||
strerror(errno));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,8 @@
|
|||||||
#include "iam.h"
|
#include "iam.h"
|
||||||
#include "address.h"
|
#include "address.h"
|
||||||
|
|
||||||
void handler_i_am_add(
|
void handler_i_am_add(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src)
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
uint32_t device_id = 0;
|
uint32_t device_id = 0;
|
||||||
@@ -44,30 +42,20 @@ void handler_i_am_add(
|
|||||||
uint16_t vendor_id = 0;
|
uint16_t vendor_id = 0;
|
||||||
|
|
||||||
(void) service_len;
|
(void) service_len;
|
||||||
len = iam_decode_service_request(
|
len = iam_decode_service_request(service_request,
|
||||||
service_request,
|
&device_id, &max_apdu, &segmentation, &vendor_id);
|
||||||
&device_id,
|
|
||||||
&max_apdu,
|
|
||||||
&segmentation,
|
|
||||||
&vendor_id);
|
|
||||||
fprintf(stderr, "Received I-Am Request");
|
fprintf(stderr, "Received I-Am Request");
|
||||||
if (len != -1)
|
if (len != -1) {
|
||||||
{
|
|
||||||
fprintf(stderr, " from %u!\n", device_id);
|
fprintf(stderr, " from %u!\n", device_id);
|
||||||
address_add(device_id,
|
address_add(device_id, max_apdu, src);
|
||||||
max_apdu,
|
} else
|
||||||
src);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fprintf(stderr, "!\n");
|
fprintf(stderr, "!\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler_i_am_bind(
|
void handler_i_am_bind(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src)
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
uint32_t device_id = 0;
|
uint32_t device_id = 0;
|
||||||
@@ -76,17 +64,10 @@ void handler_i_am_bind(
|
|||||||
uint16_t vendor_id = 0;
|
uint16_t vendor_id = 0;
|
||||||
|
|
||||||
(void) service_len;
|
(void) service_len;
|
||||||
len = iam_decode_service_request(
|
len = iam_decode_service_request(service_request,
|
||||||
service_request,
|
&device_id, &max_apdu, &segmentation, &vendor_id);
|
||||||
&device_id,
|
|
||||||
&max_apdu,
|
|
||||||
&segmentation,
|
|
||||||
&vendor_id);
|
|
||||||
// only add address if requested to bind
|
// only add address if requested to bind
|
||||||
address_add_binding(device_id,
|
address_add_binding(device_id, max_apdu, src);
|
||||||
max_apdu,
|
|
||||||
src);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,31 +32,24 @@
|
|||||||
#include "bactext.h"
|
#include "bactext.h"
|
||||||
#include "ihave.h"
|
#include "ihave.h"
|
||||||
|
|
||||||
void handler_i_have(
|
void handler_i_have(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src)
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
BACNET_I_HAVE_DATA data;
|
BACNET_I_HAVE_DATA data;
|
||||||
|
|
||||||
(void) service_len;
|
(void) service_len;
|
||||||
(void) src;
|
(void) src;
|
||||||
len = ihave_decode_service_request(
|
len = ihave_decode_service_request(service_request,
|
||||||
service_request,
|
service_len, &data);
|
||||||
service_len,
|
if (len != -1) {
|
||||||
&data);
|
|
||||||
if (len != -1)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "I-Have: %s %d from %s %u!\r\n",
|
fprintf(stderr, "I-Have: %s %d from %s %u!\r\n",
|
||||||
bactext_object_type_name(data.object_id.type),
|
bactext_object_type_name(data.object_id.type),
|
||||||
data.object_id.instance,
|
data.object_id.instance,
|
||||||
bactext_object_type_name(data.device_id.type),
|
bactext_object_type_name(data.device_id.type),
|
||||||
data.device_id.instance);
|
data.device_id.instance);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
fprintf(stderr, "I-Have: received, but unable to decode!\n");
|
fprintf(stderr, "I-Have: received, but unable to decode!\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,9 @@
|
|||||||
|
|
||||||
static BACNET_CHARACTER_STRING My_Password;
|
static BACNET_CHARACTER_STRING My_Password;
|
||||||
|
|
||||||
void handler_reinitialize_device(
|
void handler_reinitialize_device(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||||
BACNET_CONFIRMED_SERVICE_DATA *service_data)
|
|
||||||
{
|
{
|
||||||
BACNET_REINITIALIZED_STATE state;
|
BACNET_REINITIALIZED_STATE state;
|
||||||
BACNET_CHARACTER_STRING password;
|
BACNET_CHARACTER_STRING password;
|
||||||
@@ -54,59 +52,40 @@ void handler_reinitialize_device(
|
|||||||
int bytes_sent = 0;
|
int bytes_sent = 0;
|
||||||
|
|
||||||
// decode the service request only
|
// decode the service request only
|
||||||
len = rd_decode_service_request(
|
len = rd_decode_service_request(service_request,
|
||||||
service_request,
|
service_len, &state, &password);
|
||||||
service_len,
|
|
||||||
&state,
|
|
||||||
&password);
|
|
||||||
fprintf(stderr, "ReinitializeDevice!\n");
|
fprintf(stderr, "ReinitializeDevice!\n");
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n",
|
fprintf(stderr, "ReinitializeDevice: state=%u password=%s\n",
|
||||||
(unsigned)state,
|
(unsigned) state, characterstring_value(&password));
|
||||||
characterstring_value(&password));
|
|
||||||
else
|
else
|
||||||
fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n");
|
fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n");
|
||||||
// prepare a reply
|
// prepare a reply
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
src,
|
|
||||||
&my_address,
|
|
||||||
false, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
// bad decoding or something we didn't understand - send an abort
|
// bad decoding or something we didn't understand - send an abort
|
||||||
if (len == -1)
|
if (len == -1) {
|
||||||
{
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += abort_encode_apdu(
|
service_data->invoke_id, ABORT_REASON_OTHER);
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
fprintf(stderr,
|
||||||
service_data->invoke_id,
|
"ReinitializeDevice: Sending Abort - could not decode.\n");
|
||||||
ABORT_REASON_OTHER);
|
} else if (service_data->segmented_message) {
|
||||||
fprintf(stderr,"ReinitializeDevice: Sending Abort - could not decode.\n");
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
}
|
|
||||||
else if (service_data->segmented_message)
|
|
||||||
{
|
|
||||||
pdu_len += abort_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
||||||
fprintf(stderr,"ReinitializeDevice: Sending Abort - segmented message.\n");
|
fprintf(stderr,
|
||||||
}
|
"ReinitializeDevice: Sending Abort - segmented message.\n");
|
||||||
else if (state >= MAX_BACNET_REINITIALIZED_STATE)
|
} else if (state >= MAX_BACNET_REINITIALIZED_STATE) {
|
||||||
{
|
pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += reject_encode_apdu(
|
service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION);
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
fprintf(stderr,
|
||||||
service_data->invoke_id,
|
"ReinitializeDevice: Sending Reject - undefined enumeration\n");
|
||||||
REJECT_REASON_UNDEFINED_ENUMERATION);
|
} else {
|
||||||
fprintf(stderr,"ReinitializeDevice: Sending Reject - undefined enumeration\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
characterstring_init_ansi(&My_Password, "Jesus");
|
characterstring_init_ansi(&My_Password, "Jesus");
|
||||||
if (characterstring_same(&password,&My_Password))
|
if (characterstring_same(&password, &My_Password)) {
|
||||||
{
|
pdu_len += encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += encode_simple_ack(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
|
SERVICE_CONFIRMED_REINITIALIZE_DEVICE);
|
||||||
fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n");
|
fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n");
|
||||||
@@ -114,22 +93,18 @@ void handler_reinitialize_device(
|
|||||||
/* Note: you can use a mix of state and password to do specific stuff */
|
/* Note: you can use a mix of state and password to do specific stuff */
|
||||||
/* Note: if you don't do something clever like actually restart,
|
/* Note: if you don't do something clever like actually restart,
|
||||||
you probably should clear any DCC status and timeouts */
|
you probably should clear any DCC status and timeouts */
|
||||||
}
|
} else {
|
||||||
else
|
pdu_len +=
|
||||||
{
|
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += bacerror_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
||||||
ERROR_CLASS_SERVICES,
|
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
|
||||||
ERROR_CODE_PASSWORD_FAILURE);
|
fprintf(stderr,
|
||||||
fprintf(stderr,"ReinitializeDevice: Sending Error - password failure.\n");
|
"ReinitializeDevice: Sending Error - password failure.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(src, // destination address
|
||||||
src, // destination address
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
|
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|||||||
@@ -45,11 +45,9 @@
|
|||||||
|
|
||||||
static uint8_t Temp_Buf[MAX_APDU] = { 0 };
|
static uint8_t Temp_Buf[MAX_APDU] = { 0 };
|
||||||
|
|
||||||
void handler_read_property(
|
void handler_read_property(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||||
BACNET_CONFIRMED_SERVICE_DATA *service_data)
|
|
||||||
{
|
{
|
||||||
BACNET_READ_PROPERTY_DATA data;
|
BACNET_READ_PROPERTY_DATA data;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@@ -61,159 +59,111 @@ void handler_read_property(
|
|||||||
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
|
BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT;
|
||||||
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||||
|
|
||||||
len = rp_decode_service_request(
|
len = rp_decode_service_request(service_request, service_len, &data);
|
||||||
service_request,
|
|
||||||
service_len,
|
|
||||||
&data);
|
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
fprintf(stderr, "Unable to decode Read-Property Request!\n");
|
fprintf(stderr, "Unable to decode Read-Property Request!\n");
|
||||||
// prepare a reply
|
// prepare a reply
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
src,
|
|
||||||
&my_address,
|
|
||||||
false, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
// bad decoding - send an abort
|
// bad decoding - send an abort
|
||||||
if (len == -1)
|
if (len == -1) {
|
||||||
{
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += abort_encode_apdu(
|
service_data->invoke_id, ABORT_REASON_OTHER);
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
|
||||||
ABORT_REASON_OTHER);
|
|
||||||
fprintf(stderr, "Sending Abort!\n");
|
fprintf(stderr, "Sending Abort!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
} else if (service_data->segmented_message) {
|
||||||
else if (service_data->segmented_message)
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
{
|
|
||||||
pdu_len += abort_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
||||||
fprintf(stderr, "Sending Abort!\n");
|
fprintf(stderr, "Sending Abort!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
} else {
|
||||||
else
|
switch (data.object_type) {
|
||||||
{
|
|
||||||
switch (data.object_type)
|
|
||||||
{
|
|
||||||
case OBJECT_DEVICE:
|
case OBJECT_DEVICE:
|
||||||
// FIXME: probably need a length limitation sent with encode
|
// FIXME: probably need a length limitation sent with encode
|
||||||
if (data.object_instance == Device_Object_Instance_Number())
|
if (data.object_instance == Device_Object_Instance_Number()) {
|
||||||
{
|
len = Device_Encode_Property_APDU(&Temp_Buf[0],
|
||||||
len = Device_Encode_Property_APDU(
|
|
||||||
&Temp_Buf[0],
|
|
||||||
data.object_property,
|
data.object_property,
|
||||||
data.array_index,
|
data.array_index, &error_class, &error_code);
|
||||||
&error_class,
|
if (len >= 0) {
|
||||||
&error_code);
|
|
||||||
if (len >= 0)
|
|
||||||
{
|
|
||||||
// encode the APDU portion of the packet
|
// encode the APDU portion of the packet
|
||||||
data.application_data = &Temp_Buf[0];
|
data.application_data = &Temp_Buf[0];
|
||||||
data.application_data_len = len;
|
data.application_data_len = len;
|
||||||
// FIXME: probably need a length limitation sent with encode
|
// FIXME: probably need a length limitation sent with encode
|
||||||
pdu_len += rp_ack_encode_apdu(
|
pdu_len +=
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
rp_ack_encode_apdu(&Handler_Transmit_Buffer
|
||||||
service_data->invoke_id,
|
[pdu_len], service_data->invoke_id, &data);
|
||||||
&data);
|
|
||||||
fprintf(stderr, "Sending Read Property Ack!\n");
|
fprintf(stderr, "Sending Read Property Ack!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
error = true;
|
error = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
error = true;
|
error = true;
|
||||||
break;
|
break;
|
||||||
case OBJECT_ANALOG_INPUT:
|
case OBJECT_ANALOG_INPUT:
|
||||||
if (Analog_Input_Valid_Instance(data.object_instance))
|
if (Analog_Input_Valid_Instance(data.object_instance)) {
|
||||||
{
|
len = Analog_Input_Encode_Property_APDU(&Temp_Buf[0],
|
||||||
len = Analog_Input_Encode_Property_APDU(
|
|
||||||
&Temp_Buf[0],
|
|
||||||
data.object_instance,
|
data.object_instance,
|
||||||
data.object_property,
|
data.object_property,
|
||||||
data.array_index,
|
data.array_index, &error_class, &error_code);
|
||||||
&error_class,
|
if (len >= 0) {
|
||||||
&error_code);
|
|
||||||
if (len >= 0)
|
|
||||||
{
|
|
||||||
// encode the APDU portion of the packet
|
// encode the APDU portion of the packet
|
||||||
data.application_data = &Temp_Buf[0];
|
data.application_data = &Temp_Buf[0];
|
||||||
data.application_data_len = len;
|
data.application_data_len = len;
|
||||||
// FIXME: probably need a length limitation sent with encode
|
// FIXME: probably need a length limitation sent with encode
|
||||||
pdu_len += rp_ack_encode_apdu(
|
pdu_len +=
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
rp_ack_encode_apdu(&Handler_Transmit_Buffer
|
||||||
service_data->invoke_id,
|
[pdu_len], service_data->invoke_id, &data);
|
||||||
&data);
|
|
||||||
fprintf(stderr, "Sending Read Property Ack!\n");
|
fprintf(stderr, "Sending Read Property Ack!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
error = true;
|
error = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
error = true;
|
error = true;
|
||||||
break;
|
break;
|
||||||
case OBJECT_ANALOG_OUTPUT:
|
case OBJECT_ANALOG_OUTPUT:
|
||||||
if (Analog_Output_Valid_Instance(data.object_instance))
|
if (Analog_Output_Valid_Instance(data.object_instance)) {
|
||||||
{
|
len = Analog_Output_Encode_Property_APDU(&Temp_Buf[0],
|
||||||
len = Analog_Output_Encode_Property_APDU(
|
|
||||||
&Temp_Buf[0],
|
|
||||||
data.object_instance,
|
data.object_instance,
|
||||||
data.object_property,
|
data.object_property,
|
||||||
data.array_index,
|
data.array_index, &error_class, &error_code);
|
||||||
&error_class,
|
if (len >= 0) {
|
||||||
&error_code);
|
|
||||||
if (len >= 0)
|
|
||||||
{
|
|
||||||
// encode the APDU portion of the packet
|
// encode the APDU portion of the packet
|
||||||
data.application_data = &Temp_Buf[0];
|
data.application_data = &Temp_Buf[0];
|
||||||
data.application_data_len = len;
|
data.application_data_len = len;
|
||||||
// FIXME: probably need a length limitation sent with encode
|
// FIXME: probably need a length limitation sent with encode
|
||||||
pdu_len += rp_ack_encode_apdu(
|
pdu_len +=
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
rp_ack_encode_apdu(&Handler_Transmit_Buffer
|
||||||
service_data->invoke_id,
|
[pdu_len], service_data->invoke_id, &data);
|
||||||
&data);
|
|
||||||
fprintf(stderr, "Sending Read Property Ack!\n");
|
fprintf(stderr, "Sending Read Property Ack!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
error = true;
|
error = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
error = true;
|
error = true;
|
||||||
break;
|
break;
|
||||||
#if BACFILE
|
#if BACFILE
|
||||||
case OBJECT_FILE:
|
case OBJECT_FILE:
|
||||||
if (bacfile_valid_instance(data.object_instance))
|
if (bacfile_valid_instance(data.object_instance)) {
|
||||||
{
|
len = bacfile_encode_property_apdu(&Temp_Buf[0],
|
||||||
len = bacfile_encode_property_apdu(
|
|
||||||
&Temp_Buf[0],
|
|
||||||
data.object_instance,
|
data.object_instance,
|
||||||
data.object_property,
|
data.object_property,
|
||||||
data.array_index,
|
data.array_index, &error_class, &error_code);
|
||||||
&error_class,
|
if (len >= 0) {
|
||||||
&error_code);
|
|
||||||
if (len >= 0)
|
|
||||||
{
|
|
||||||
// encode the APDU portion of the packet
|
// encode the APDU portion of the packet
|
||||||
data.application_data = &Temp_Buf[0];
|
data.application_data = &Temp_Buf[0];
|
||||||
data.application_data_len = len;
|
data.application_data_len = len;
|
||||||
// FIXME: probably need a length limitation sent with encode
|
// FIXME: probably need a length limitation sent with encode
|
||||||
pdu_len += rp_ack_encode_apdu(
|
pdu_len +=
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
rp_ack_encode_apdu(&Handler_Transmit_Buffer
|
||||||
service_data->invoke_id,
|
[pdu_len], service_data->invoke_id, &data);
|
||||||
&data);
|
|
||||||
fprintf(stderr, "Sending Read Property Ack!\n");
|
fprintf(stderr, "Sending Read Property Ack!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
error = true;
|
error = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
error = true;
|
error = true;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@@ -222,27 +172,19 @@ void handler_read_property(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (error)
|
if (error) {
|
||||||
{
|
pdu_len += bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += bacerror_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
|
||||||
error_class,
|
|
||||||
error_code);
|
|
||||||
fprintf(stderr, "Sending Read Property Error!\n");
|
fprintf(stderr, "Sending Read Property Error!\n");
|
||||||
send = true;
|
send = true;
|
||||||
}
|
}
|
||||||
if (send)
|
if (send) {
|
||||||
{
|
bytes_sent = datalink_send_pdu(src, // destination address
|
||||||
bytes_sent = datalink_send_pdu(
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
src, // destination address
|
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ static void PrintReadPropertyData(BACNET_READ_PROPERTY_DATA *data)
|
|||||||
bool first_value = true;
|
bool first_value = true;
|
||||||
bool print_brace = false;
|
bool print_brace = false;
|
||||||
|
|
||||||
if (data)
|
if (data) {
|
||||||
{
|
|
||||||
#if 0
|
#if 0
|
||||||
if (data->array_index == BACNET_ARRAY_ALL)
|
if (data->array_index == BACNET_ARRAY_ALL)
|
||||||
fprintf(stderr, "%s #%u %s\n",
|
fprintf(stderr, "%s #%u %s\n",
|
||||||
@@ -69,32 +68,24 @@ static void PrintReadPropertyData(BACNET_READ_PROPERTY_DATA *data)
|
|||||||
application_data = data->application_data;
|
application_data = data->application_data;
|
||||||
application_data_len = data->application_data_len;
|
application_data_len = data->application_data_len;
|
||||||
/* value? need to loop until all of the len is gone... */
|
/* value? need to loop until all of the len is gone... */
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
len = bacapp_decode_application_data(application_data,
|
||||||
len = bacapp_decode_application_data(
|
application_data_len, &value);
|
||||||
application_data,
|
if (first_value && (len < application_data_len)) {
|
||||||
application_data_len,
|
|
||||||
&value);
|
|
||||||
if (first_value && (len < application_data_len))
|
|
||||||
{
|
|
||||||
first_value = false;
|
first_value = false;
|
||||||
fprintf(stdout, "{");
|
fprintf(stdout, "{");
|
||||||
print_brace = true;
|
print_brace = true;
|
||||||
}
|
}
|
||||||
bacapp_print_value(stdout, &value, data->object_property);
|
bacapp_print_value(stdout, &value, data->object_property);
|
||||||
if (len)
|
if (len) {
|
||||||
{
|
if (len < application_data_len) {
|
||||||
if (len < application_data_len)
|
|
||||||
{
|
|
||||||
application_data += len;
|
application_data += len;
|
||||||
application_data_len -= len;
|
application_data_len -= len;
|
||||||
/* there's more! */
|
/* there's more! */
|
||||||
fprintf(stdout, ",");
|
fprintf(stdout, ",");
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (print_brace)
|
if (print_brace)
|
||||||
@@ -103,21 +94,17 @@ static void PrintReadPropertyData(BACNET_READ_PROPERTY_DATA *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler_read_property_ack(
|
void handler_read_property_ack(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
|
||||||
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
BACNET_READ_PROPERTY_DATA data;
|
BACNET_READ_PROPERTY_DATA data;
|
||||||
|
|
||||||
(void) src;
|
(void) src;
|
||||||
(void) service_data; /* we could use these... */
|
(void) service_data; /* we could use these... */
|
||||||
len = rp_ack_decode_service_request(
|
len = rp_ack_decode_service_request(service_request,
|
||||||
service_request,
|
service_len, &data);
|
||||||
service_len,
|
|
||||||
&data);
|
|
||||||
#if 0
|
#if 0
|
||||||
fprintf(stderr, "Received Read-Property Ack!\n");
|
fprintf(stderr, "Received Read-Property Ack!\n");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -35,10 +35,8 @@
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
void handler_who_has(
|
void handler_who_has(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src)
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
BACNET_WHO_HAS_DATA data;
|
BACNET_WHO_HAS_DATA data;
|
||||||
@@ -49,48 +47,36 @@ void handler_who_has(
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
(void) src;
|
(void) src;
|
||||||
len = whohas_decode_service_request(
|
len = whohas_decode_service_request(service_request,
|
||||||
service_request,
|
service_len, &data);
|
||||||
service_len,
|
if (len > 0) {
|
||||||
&data);
|
|
||||||
if (len > 0)
|
|
||||||
{
|
|
||||||
if ((data.low_limit == -1) || (data.high_limit == -1))
|
if ((data.low_limit == -1) || (data.high_limit == -1))
|
||||||
directed_to_me = true;
|
directed_to_me = true;
|
||||||
else if ((Device_Object_Instance_Number() >= (uint32_t)data.low_limit) &&
|
else if ((Device_Object_Instance_Number() >=
|
||||||
(Device_Object_Instance_Number() <= (uint32_t)data.high_limit))
|
(uint32_t) data.low_limit)
|
||||||
|
&& (Device_Object_Instance_Number() <=
|
||||||
|
(uint32_t) data.high_limit))
|
||||||
directed_to_me = true;
|
directed_to_me = true;
|
||||||
if (directed_to_me)
|
if (directed_to_me) {
|
||||||
{
|
|
||||||
/* do we have such an object? If so, send an I-Have.
|
/* do we have such an object? If so, send an I-Have.
|
||||||
note: we should have only 1 of such an object */
|
note: we should have only 1 of such an object */
|
||||||
if (data.object_name)
|
if (data.object_name) {
|
||||||
{
|
|
||||||
/* valid name in my device? */
|
/* valid name in my device? */
|
||||||
object_name = characterstring_value(&data.object.name);
|
object_name = characterstring_value(&data.object.name);
|
||||||
found = Device_Valid_Object_Name(
|
found = Device_Valid_Object_Name(object_name,
|
||||||
object_name,
|
&object_type, &object_instance);
|
||||||
&object_type,
|
|
||||||
&object_instance);
|
|
||||||
if (found)
|
if (found)
|
||||||
Send_I_Have(
|
Send_I_Have(Device_Object_Instance_Number(),
|
||||||
Device_Object_Instance_Number(),
|
object_type, object_instance, object_name);
|
||||||
object_type,
|
} else {
|
||||||
object_instance,
|
|
||||||
object_name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* valid object in my device? */
|
/* valid object in my device? */
|
||||||
object_name = Device_Valid_Object_Id(
|
object_name =
|
||||||
data.object.identifier.type,
|
Device_Valid_Object_Id(data.object.identifier.type,
|
||||||
data.object.identifier.instance);
|
data.object.identifier.instance);
|
||||||
if (object_name)
|
if (object_name)
|
||||||
Send_I_Have(
|
Send_I_Have(Device_Object_Instance_Number(),
|
||||||
Device_Object_Instance_Number(),
|
|
||||||
data.object.identifier.type,
|
data.object.identifier.type,
|
||||||
data.object.identifier.instance,
|
data.object.identifier.instance, object_name);
|
||||||
object_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,27 +37,21 @@
|
|||||||
/* global flag to send an I-Am */
|
/* global flag to send an I-Am */
|
||||||
bool I_Am_Request = true;
|
bool I_Am_Request = true;
|
||||||
|
|
||||||
void handler_who_is(
|
void handler_who_is(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src)
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int32_t low_limit = 0;
|
int32_t low_limit = 0;
|
||||||
int32_t high_limit = 0;
|
int32_t high_limit = 0;
|
||||||
|
|
||||||
(void) src;
|
(void) src;
|
||||||
len = whois_decode_service_request(
|
len = whois_decode_service_request(service_request,
|
||||||
service_request,
|
service_len, &low_limit, &high_limit);
|
||||||
service_len,
|
|
||||||
&low_limit,
|
|
||||||
&high_limit);
|
|
||||||
/* in our simple system, we just set a flag and let the main loop
|
/* in our simple system, we just set a flag and let the main loop
|
||||||
send the I-Am request. */
|
send the I-Am request. */
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
I_Am_Request = true;
|
I_Am_Request = true;
|
||||||
else if (len != -1)
|
else if (len != -1) {
|
||||||
{
|
|
||||||
if ((Device_Object_Instance_Number() >= (uint32_t) low_limit) &&
|
if ((Device_Object_Instance_Number() >= (uint32_t) low_limit) &&
|
||||||
(Device_Object_Instance_Number() <= (uint32_t) high_limit))
|
(Device_Object_Instance_Number() <= (uint32_t) high_limit))
|
||||||
I_Am_Request = true;
|
I_Am_Request = true;
|
||||||
|
|||||||
@@ -43,11 +43,9 @@
|
|||||||
#include "bacfile.h"
|
#include "bacfile.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void handler_write_property(
|
void handler_write_property(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||||
BACNET_CONFIRMED_SERVICE_DATA *service_data)
|
|
||||||
{
|
{
|
||||||
BACNET_WRITE_PROPERTY_DATA wp_data;
|
BACNET_WRITE_PROPERTY_DATA wp_data;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@@ -58,65 +56,45 @@ void handler_write_property(
|
|||||||
int bytes_sent = 0;
|
int bytes_sent = 0;
|
||||||
|
|
||||||
// decode the service request only
|
// decode the service request only
|
||||||
len = wp_decode_service_request(
|
len = wp_decode_service_request(service_request,
|
||||||
service_request,
|
service_len, &wp_data);
|
||||||
service_len,
|
|
||||||
&wp_data);
|
|
||||||
fprintf(stderr, "Received Write-Property Request!\n");
|
fprintf(stderr, "Received Write-Property Request!\n");
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
fprintf(stderr, "type=%u instance=%u property=%u index=%d\n",
|
fprintf(stderr, "type=%u instance=%u property=%u index=%d\n",
|
||||||
wp_data.object_type,
|
wp_data.object_type,
|
||||||
wp_data.object_instance,
|
wp_data.object_instance,
|
||||||
wp_data.object_property,
|
wp_data.object_property, wp_data.array_index);
|
||||||
wp_data.array_index);
|
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Unable to decode Write-Property Request!\n");
|
fprintf(stderr, "Unable to decode Write-Property Request!\n");
|
||||||
// prepare a reply
|
// prepare a reply
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], src, &my_address, false, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
src,
|
|
||||||
&my_address,
|
|
||||||
false, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
// bad decoding or something we didn't understand - send an abort
|
// bad decoding or something we didn't understand - send an abort
|
||||||
if (len == -1)
|
if (len == -1) {
|
||||||
{
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += abort_encode_apdu(
|
service_data->invoke_id, ABORT_REASON_OTHER);
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
|
||||||
ABORT_REASON_OTHER);
|
|
||||||
fprintf(stderr, "Sending Abort!\n");
|
fprintf(stderr, "Sending Abort!\n");
|
||||||
}
|
} else if (service_data->segmented_message) {
|
||||||
else if (service_data->segmented_message)
|
pdu_len += abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
{
|
|
||||||
pdu_len += abort_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED);
|
||||||
fprintf(stderr, "Sending Abort!\n");
|
fprintf(stderr, "Sending Abort!\n");
|
||||||
}
|
} else {
|
||||||
else
|
switch (wp_data.object_type) {
|
||||||
{
|
|
||||||
switch (wp_data.object_type)
|
|
||||||
{
|
|
||||||
case OBJECT_DEVICE:
|
case OBJECT_DEVICE:
|
||||||
if (Device_Write_Property(&wp_data,&error_class,&error_code))
|
if (Device_Write_Property(&wp_data, &error_class, &error_code)) {
|
||||||
{
|
pdu_len +=
|
||||||
pdu_len += encode_simple_ack(
|
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
fprintf(stderr, "Sending Write Property Simple Ack!\n");
|
fprintf(stderr, "Sending Write Property Simple Ack!\n");
|
||||||
}
|
} else {
|
||||||
else
|
pdu_len +=
|
||||||
{
|
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += bacerror_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
||||||
error_class,
|
|
||||||
error_code);
|
error_code);
|
||||||
fprintf(stderr, "Sending Write Property Error!\n");
|
fprintf(stderr, "Sending Write Property Error!\n");
|
||||||
}
|
}
|
||||||
@@ -124,49 +102,40 @@ void handler_write_property(
|
|||||||
case OBJECT_ANALOG_INPUT:
|
case OBJECT_ANALOG_INPUT:
|
||||||
error_class = ERROR_CLASS_PROPERTY;
|
error_class = ERROR_CLASS_PROPERTY;
|
||||||
error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||||
pdu_len += bacerror_encode_apdu(
|
pdu_len +=
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id,
|
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
error_class, error_code);
|
||||||
error_class,
|
|
||||||
error_code);
|
|
||||||
fprintf(stderr, "Sending Write Access Error!\n");
|
fprintf(stderr, "Sending Write Access Error!\n");
|
||||||
break;
|
break;
|
||||||
case OBJECT_ANALOG_OUTPUT:
|
case OBJECT_ANALOG_OUTPUT:
|
||||||
if (Analog_Output_Write_Property(&wp_data,&error_class,&error_code))
|
if (Analog_Output_Write_Property(&wp_data, &error_class,
|
||||||
{
|
&error_code)) {
|
||||||
pdu_len += encode_simple_ack(
|
pdu_len +=
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
SERVICE_CONFIRMED_WRITE_PROPERTY);
|
||||||
fprintf(stderr, "Sending Write Property Simple Ack!\n");
|
fprintf(stderr, "Sending Write Property Simple Ack!\n");
|
||||||
}
|
} else {
|
||||||
else
|
pdu_len +=
|
||||||
{
|
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += bacerror_encode_apdu(
|
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
service_data->invoke_id,
|
service_data->invoke_id,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
SERVICE_CONFIRMED_WRITE_PROPERTY, error_class,
|
||||||
error_class,
|
|
||||||
error_code);
|
error_code);
|
||||||
fprintf(stderr, "Sending Write Access Error!\n");
|
fprintf(stderr, "Sending Write Access Error!\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pdu_len += bacerror_encode_apdu(
|
pdu_len +=
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
service_data->invoke_id,
|
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
error_class, error_code);
|
||||||
error_class,
|
|
||||||
error_code);
|
|
||||||
fprintf(stderr, "Sending Unknown Object Error!\n");
|
fprintf(stderr, "Sending Unknown Object Error!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(src, // destination address
|
||||||
src, // destination address
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
|
||||||
|
|
||||||
|
|||||||
@@ -39,81 +39,62 @@ extern bool I_Am_Request;
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
void handler_unrecognized_service(
|
void handler_unrecognized_service(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS * dest,
|
BACNET_ADDRESS * dest,
|
||||||
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||||
|
|
||||||
void handler_who_is(
|
void handler_who_is(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src);
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src);
|
|
||||||
|
|
||||||
void handler_who_has(
|
void handler_who_has(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src);
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src);
|
|
||||||
|
|
||||||
void handler_i_am_add(
|
void handler_i_am_add(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src);
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src);
|
|
||||||
|
|
||||||
void handler_i_am_bind(
|
void handler_i_am_bind(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src);
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src);
|
|
||||||
|
|
||||||
void handler_read_property(
|
void handler_read_property(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS * src,
|
BACNET_ADDRESS * src,
|
||||||
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||||
|
|
||||||
void handler_read_property_ack(
|
void handler_read_property_ack(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS * src,
|
BACNET_ADDRESS * src,
|
||||||
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
|
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
|
||||||
|
|
||||||
void handler_write_property(
|
void handler_write_property(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS * src,
|
BACNET_ADDRESS * src,
|
||||||
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||||
|
|
||||||
void handler_atomic_read_file(
|
void handler_atomic_read_file(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS * src,
|
BACNET_ADDRESS * src,
|
||||||
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||||
|
|
||||||
void handler_atomic_read_file_ack(
|
void handler_atomic_read_file_ack(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS * src,
|
BACNET_ADDRESS * src,
|
||||||
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
|
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
|
||||||
|
|
||||||
void handler_reinitialize_device(
|
void handler_reinitialize_device(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS * src,
|
BACNET_ADDRESS * src,
|
||||||
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||||
|
|
||||||
void handler_device_communication_control(
|
void handler_device_communication_control(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS * src,
|
BACNET_ADDRESS * src,
|
||||||
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||||
|
|
||||||
void handler_i_have(
|
void handler_i_have(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src);
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -34,11 +34,9 @@
|
|||||||
#include "npdu.h"
|
#include "npdu.h"
|
||||||
#include "reject.h"
|
#include "reject.h"
|
||||||
|
|
||||||
void handler_unrecognized_service(
|
void handler_unrecognized_service(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS *dest,
|
BACNET_ADDRESS * dest, BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||||
BACNET_CONFIRMED_SERVICE_DATA *service_data)
|
|
||||||
{
|
{
|
||||||
BACNET_ADDRESS src;
|
BACNET_ADDRESS src;
|
||||||
int pdu_len = 0;
|
int pdu_len = 0;
|
||||||
@@ -49,23 +47,15 @@ void handler_unrecognized_service(
|
|||||||
datalink_get_my_address(&src);
|
datalink_get_my_address(&src);
|
||||||
|
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], dest, &src, false, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
dest,
|
|
||||||
&src,
|
|
||||||
false, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
// encode the APDU portion of the packet
|
// encode the APDU portion of the packet
|
||||||
pdu_len += reject_encode_apdu(
|
pdu_len += reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE);
|
||||||
service_data->invoke_id,
|
|
||||||
REJECT_REASON_UNRECOGNIZED_SERVICE);
|
|
||||||
|
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(dest, // destination address
|
||||||
dest, // destination address
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent > 0)
|
if (bytes_sent > 0)
|
||||||
fprintf(stderr, "Sent Reject!\n");
|
fprintf(stderr, "Sent Reject!\n");
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -41,12 +41,9 @@
|
|||||||
#include "handlers.h"
|
#include "handlers.h"
|
||||||
#include "txbuf.h"
|
#include "txbuf.h"
|
||||||
|
|
||||||
uint8_t Send_Device_Communication_Control_Request(
|
uint8_t Send_Device_Communication_Control_Request(uint32_t device_id, uint16_t timeDuration, /* 0=optional */
|
||||||
uint32_t device_id,
|
BACNET_COMMUNICATION_ENABLE_DISABLE state, char *password)
|
||||||
uint16_t timeDuration, /* 0=optional */
|
{ /* NULL=optional */
|
||||||
BACNET_COMMUNICATION_ENABLE_DISABLE state,
|
|
||||||
char *password) /* NULL=optional */
|
|
||||||
{
|
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
unsigned max_apdu = 0;
|
unsigned max_apdu = 0;
|
||||||
@@ -64,50 +61,36 @@ uint8_t Send_Device_Communication_Control_Request(
|
|||||||
/* is there a tsm available? */
|
/* is there a tsm available? */
|
||||||
if (status)
|
if (status)
|
||||||
status = tsm_transaction_available();
|
status = tsm_transaction_available();
|
||||||
if (status)
|
if (status) {
|
||||||
{
|
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
&my_address,
|
|
||||||
true, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
invoke_id = tsm_next_free_invokeID();
|
invoke_id = tsm_next_free_invokeID();
|
||||||
// load the data for the encoding
|
// load the data for the encoding
|
||||||
characterstring_init_ansi(&password_string, password);
|
characterstring_init_ansi(&password_string, password);
|
||||||
pdu_len += dcc_encode_apdu(
|
pdu_len += dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
invoke_id,
|
invoke_id,
|
||||||
timeDuration,
|
timeDuration, state, password ? &password_string : NULL);
|
||||||
state,
|
|
||||||
password?&password_string:NULL);
|
|
||||||
/* will it fit in the sender?
|
/* will it fit in the sender?
|
||||||
note: if there is a bottleneck router in between
|
note: if there is a bottleneck router in between
|
||||||
us and the destination, we won't know unless
|
us and the destination, we won't know unless
|
||||||
we have a way to check for that and update the
|
we have a way to check for that and update the
|
||||||
max_apdu in the address binding table. */
|
max_apdu in the address binding table. */
|
||||||
if ((unsigned)pdu_len < max_apdu)
|
if ((unsigned) pdu_len < max_apdu) {
|
||||||
{
|
tsm_set_confirmed_unsegmented_transaction(invoke_id,
|
||||||
tsm_set_confirmed_unsegmented_transaction(
|
&dest, &Handler_Transmit_Buffer[0], pdu_len);
|
||||||
invoke_id,
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest,
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len);
|
|
||||||
bytes_sent = datalink_send_pdu(
|
|
||||||
&dest, // destination address
|
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send DeviceCommunicationControl Request (%s)!\n",
|
fprintf(stderr,
|
||||||
|
"Failed to Send DeviceCommunicationControl Request (%s)!\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
} else
|
||||||
else
|
fprintf(stderr,
|
||||||
fprintf(stderr,"Failed to Send DeviceCommunicationControl Request "
|
"Failed to Send DeviceCommunicationControl Request "
|
||||||
"(exceeds destination maximum APDU)!\n");
|
"(exceeds destination maximum APDU)!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return invoke_id;
|
return invoke_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,11 +43,9 @@
|
|||||||
#include "txbuf.h"
|
#include "txbuf.h"
|
||||||
|
|
||||||
/* find a specific device, or use -1 for limit if you want unlimited */
|
/* find a specific device, or use -1 for limit if you want unlimited */
|
||||||
void Send_I_Have(
|
void Send_I_Have(uint32_t device_id,
|
||||||
uint32_t device_id,
|
|
||||||
BACNET_OBJECT_TYPE object_type,
|
BACNET_OBJECT_TYPE object_type,
|
||||||
uint32_t object_instance,
|
uint32_t object_instance, char *object_name)
|
||||||
char *object_name)
|
|
||||||
{
|
{
|
||||||
int pdu_len = 0;
|
int pdu_len = 0;
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
@@ -60,11 +58,7 @@ void Send_I_Have(
|
|||||||
/* Who-Has is a global broadcast */
|
/* Who-Has is a global broadcast */
|
||||||
datalink_get_broadcast_address(&dest);
|
datalink_get_broadcast_address(&dest);
|
||||||
/* encode the NPDU portion of the packet */
|
/* encode the NPDU portion of the packet */
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
NULL,
|
|
||||||
false, /* true for confirmed messages */
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
/* encode the APDU portion of the packet */
|
/* encode the APDU portion of the packet */
|
||||||
data.device_id.type = OBJECT_DEVICE;
|
data.device_id.type = OBJECT_DEVICE;
|
||||||
@@ -72,14 +66,11 @@ void Send_I_Have(
|
|||||||
data.object_id.type = object_type;
|
data.object_id.type = object_type;
|
||||||
data.object_id.instance = object_instance;
|
data.object_id.instance = object_instance;
|
||||||
characterstring_init_ansi(&data.object_name, object_name);
|
characterstring_init_ansi(&data.object_name, object_name);
|
||||||
pdu_len += ihave_encode_apdu(
|
pdu_len += ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data);
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
&data);
|
|
||||||
/* send the data */
|
/* send the data */
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest, // destination address
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send I-Have Reply (%s)!\n", strerror(errno));
|
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n",
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,10 +42,8 @@
|
|||||||
#include "handlers.h"
|
#include "handlers.h"
|
||||||
#include "txbuf.h"
|
#include "txbuf.h"
|
||||||
|
|
||||||
uint8_t Send_Reinitialize_Device_Request(
|
uint8_t Send_Reinitialize_Device_Request(uint32_t device_id,
|
||||||
uint32_t device_id,
|
BACNET_REINITIALIZED_STATE state, char *password)
|
||||||
BACNET_REINITIALIZED_STATE state,
|
|
||||||
char *password)
|
|
||||||
{
|
{
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
@@ -64,49 +62,34 @@ uint8_t Send_Reinitialize_Device_Request(
|
|||||||
/* is there a tsm available? */
|
/* is there a tsm available? */
|
||||||
if (status)
|
if (status)
|
||||||
status = tsm_transaction_available();
|
status = tsm_transaction_available();
|
||||||
if (status)
|
if (status) {
|
||||||
{
|
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
&my_address,
|
|
||||||
true, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
invoke_id = tsm_next_free_invokeID();
|
invoke_id = tsm_next_free_invokeID();
|
||||||
// load the data for the encoding
|
// load the data for the encoding
|
||||||
characterstring_init_ansi(&password_string, password);
|
characterstring_init_ansi(&password_string, password);
|
||||||
pdu_len += rd_encode_apdu(
|
pdu_len += rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
invoke_id, state, password ? &password_string : NULL);
|
||||||
invoke_id,
|
|
||||||
state,
|
|
||||||
password?&password_string:NULL);
|
|
||||||
/* will it fit in the sender?
|
/* will it fit in the sender?
|
||||||
note: if there is a bottleneck router in between
|
note: if there is a bottleneck router in between
|
||||||
us and the destination, we won't know unless
|
us and the destination, we won't know unless
|
||||||
we have a way to check for that and update the
|
we have a way to check for that and update the
|
||||||
max_apdu in the address binding table. */
|
max_apdu in the address binding table. */
|
||||||
if ((unsigned)pdu_len < max_apdu)
|
if ((unsigned) pdu_len < max_apdu) {
|
||||||
{
|
tsm_set_confirmed_unsegmented_transaction(invoke_id,
|
||||||
tsm_set_confirmed_unsegmented_transaction(
|
&dest, &Handler_Transmit_Buffer[0], pdu_len);
|
||||||
invoke_id,
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest,
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len);
|
|
||||||
bytes_sent = datalink_send_pdu(
|
|
||||||
&dest, // destination address
|
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send ReinitializeDevice Request (%s)!\n",
|
fprintf(stderr,
|
||||||
|
"Failed to Send ReinitializeDevice Request (%s)!\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
fprintf(stderr, "Failed to Send ReinitializeDevice Request "
|
fprintf(stderr, "Failed to Send ReinitializeDevice Request "
|
||||||
"(exceeds destination maximum APDU)!\n");
|
"(exceeds destination maximum APDU)!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return invoke_id;
|
return invoke_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,12 +43,10 @@
|
|||||||
#include "txbuf.h"
|
#include "txbuf.h"
|
||||||
|
|
||||||
/* returns invoke id of 0 if device is not bound or no tsm available */
|
/* returns invoke id of 0 if device is not bound or no tsm available */
|
||||||
uint8_t Send_Read_Property_Request(
|
uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */
|
||||||
uint32_t device_id, /* destination device */
|
|
||||||
BACNET_OBJECT_TYPE object_type,
|
BACNET_OBJECT_TYPE object_type,
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID object_property,
|
BACNET_PROPERTY_ID object_property, int32_t array_index)
|
||||||
int32_t array_index)
|
|
||||||
{
|
{
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
@@ -67,14 +65,9 @@ uint8_t Send_Read_Property_Request(
|
|||||||
/* is there a tsm available? */
|
/* is there a tsm available? */
|
||||||
if (status)
|
if (status)
|
||||||
status = tsm_transaction_available();
|
status = tsm_transaction_available();
|
||||||
if (status)
|
if (status) {
|
||||||
{
|
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
&my_address,
|
|
||||||
true, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
invoke_id = tsm_next_free_invokeID();
|
invoke_id = tsm_next_free_invokeID();
|
||||||
@@ -83,31 +76,23 @@ uint8_t Send_Read_Property_Request(
|
|||||||
data.object_instance = object_instance;
|
data.object_instance = object_instance;
|
||||||
data.object_property = object_property;
|
data.object_property = object_property;
|
||||||
data.array_index = array_index;
|
data.array_index = array_index;
|
||||||
pdu_len += rp_encode_apdu(
|
pdu_len += rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
invoke_id, &data);
|
||||||
invoke_id,
|
|
||||||
&data);
|
|
||||||
/* will it fit in the sender?
|
/* will it fit in the sender?
|
||||||
note: if there is a bottleneck router in between
|
note: if there is a bottleneck router in between
|
||||||
us and the destination, we won't know unless
|
us and the destination, we won't know unless
|
||||||
we have a way to check for that and update the
|
we have a way to check for that and update the
|
||||||
max_apdu in the address binding table. */
|
max_apdu in the address binding table. */
|
||||||
if ((unsigned)pdu_len < max_apdu)
|
if ((unsigned) pdu_len < max_apdu) {
|
||||||
{
|
tsm_set_confirmed_unsegmented_transaction(invoke_id,
|
||||||
tsm_set_confirmed_unsegmented_transaction(
|
&dest, &Handler_Transmit_Buffer[0], pdu_len);
|
||||||
invoke_id,
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest,
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len);
|
|
||||||
bytes_sent = datalink_send_pdu(
|
|
||||||
&dest, // destination address
|
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send ReadProperty Request (%s)!\n",
|
fprintf(stderr,
|
||||||
|
"Failed to Send ReadProperty Request (%s)!\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
fprintf(stderr, "Failed to Send ReadProperty Request "
|
fprintf(stderr, "Failed to Send ReadProperty Request "
|
||||||
"(exceeds destination maximum APDU)!\n");
|
"(exceeds destination maximum APDU)!\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,8 @@
|
|||||||
#include "txbuf.h"
|
#include "txbuf.h"
|
||||||
|
|
||||||
/* find a specific device, or use -1 for limit if you want unlimited */
|
/* find a specific device, or use -1 for limit if you want unlimited */
|
||||||
void Send_WhoHas_Name(
|
void Send_WhoHas_Name(int32_t low_limit,
|
||||||
int32_t low_limit,
|
int32_t high_limit, char *object_name)
|
||||||
int32_t high_limit,
|
|
||||||
char *object_name)
|
|
||||||
{
|
{
|
||||||
int pdu_len = 0;
|
int pdu_len = 0;
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
@@ -59,35 +57,27 @@ void Send_WhoHas_Name(
|
|||||||
/* Who-Has is a global broadcast */
|
/* Who-Has is a global broadcast */
|
||||||
datalink_get_broadcast_address(&dest);
|
datalink_get_broadcast_address(&dest);
|
||||||
/* encode the NPDU portion of the packet */
|
/* encode the NPDU portion of the packet */
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
NULL,
|
|
||||||
false, /* true for confirmed messages */
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
/* encode the APDU portion of the packet */
|
/* encode the APDU portion of the packet */
|
||||||
data.low_limit = low_limit;
|
data.low_limit = low_limit;
|
||||||
data.high_limit = high_limit;
|
data.high_limit = high_limit;
|
||||||
data.object_name = true;
|
data.object_name = true;
|
||||||
characterstring_init_ansi(&data.object.name, object_name);
|
characterstring_init_ansi(&data.object.name, object_name);
|
||||||
pdu_len += whohas_encode_apdu(
|
pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
&data);
|
&data);
|
||||||
/* send the data */
|
/* send the data */
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest, // destination address
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send Who-Has Request (%s)!\n", strerror(errno));
|
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find a specific device, or use -1 for limit if you want unlimited */
|
/* find a specific device, or use -1 for limit if you want unlimited */
|
||||||
void Send_WhoHas_Object(
|
void Send_WhoHas_Object(int32_t low_limit,
|
||||||
int32_t low_limit,
|
|
||||||
int32_t high_limit,
|
int32_t high_limit,
|
||||||
BACNET_OBJECT_TYPE object_type,
|
BACNET_OBJECT_TYPE object_type, uint32_t object_instance)
|
||||||
uint32_t object_instance)
|
|
||||||
{
|
{
|
||||||
int pdu_len = 0;
|
int pdu_len = 0;
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
@@ -100,11 +90,7 @@ void Send_WhoHas_Object(
|
|||||||
/* Who-Has is a global broadcast */
|
/* Who-Has is a global broadcast */
|
||||||
datalink_get_broadcast_address(&dest);
|
datalink_get_broadcast_address(&dest);
|
||||||
/* encode the NPDU portion of the packet */
|
/* encode the NPDU portion of the packet */
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, /* true for confirmed messages */
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
NULL,
|
|
||||||
false, /* true for confirmed messages */
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
/* encode the APDU portion of the packet */
|
/* encode the APDU portion of the packet */
|
||||||
data.low_limit = low_limit;
|
data.low_limit = low_limit;
|
||||||
@@ -112,14 +98,12 @@ void Send_WhoHas_Object(
|
|||||||
data.object_name = false;
|
data.object_name = false;
|
||||||
data.object.identifier.type = object_type;
|
data.object.identifier.type = object_type;
|
||||||
data.object.identifier.instance = object_instance;
|
data.object.identifier.instance = object_instance;
|
||||||
pdu_len += whohas_encode_apdu(
|
pdu_len += whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
&data);
|
&data);
|
||||||
/* send the data */
|
/* send the data */
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest, // destination address
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send Who-Has Request (%s)!\n", strerror(errno));
|
fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n",
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,7 @@
|
|||||||
#include "txbuf.h"
|
#include "txbuf.h"
|
||||||
|
|
||||||
/* find a specific device, or use -1 for limit if you want unlimited */
|
/* find a specific device, or use -1 for limit if you want unlimited */
|
||||||
void Send_WhoIs(
|
void Send_WhoIs(int32_t low_limit, int32_t high_limit)
|
||||||
int32_t low_limit,
|
|
||||||
int32_t high_limit)
|
|
||||||
{
|
{
|
||||||
int pdu_len = 0;
|
int pdu_len = 0;
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
@@ -58,23 +56,16 @@ void Send_WhoIs(
|
|||||||
datalink_get_broadcast_address(&dest);
|
datalink_get_broadcast_address(&dest);
|
||||||
|
|
||||||
// encode the NPDU portion of the packet
|
// encode the NPDU portion of the packet
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
NULL,
|
|
||||||
false, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
// encode the APDU portion of the packet
|
// encode the APDU portion of the packet
|
||||||
pdu_len += whois_encode_apdu(
|
pdu_len += whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
low_limit, high_limit);
|
||||||
low_limit,
|
|
||||||
high_limit);
|
|
||||||
|
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest, // destination address
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send Who-Is Request (%s)!\n", strerror(errno));
|
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,14 +43,12 @@
|
|||||||
#include "txbuf.h"
|
#include "txbuf.h"
|
||||||
|
|
||||||
/* returns the invoke ID for confirmed request, or zero on failure */
|
/* returns the invoke ID for confirmed request, or zero on failure */
|
||||||
uint8_t Send_Write_Property_Request(
|
uint8_t Send_Write_Property_Request(uint32_t device_id, // destination device
|
||||||
uint32_t device_id, // destination device
|
|
||||||
BACNET_OBJECT_TYPE object_type,
|
BACNET_OBJECT_TYPE object_type,
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID object_property,
|
BACNET_PROPERTY_ID object_property,
|
||||||
BACNET_APPLICATION_DATA_VALUE * object_value,
|
BACNET_APPLICATION_DATA_VALUE * object_value,
|
||||||
uint8_t priority,
|
uint8_t priority, int32_t array_index)
|
||||||
int32_t array_index)
|
|
||||||
{
|
{
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
@@ -69,14 +67,9 @@ uint8_t Send_Write_Property_Request(
|
|||||||
/* is there a tsm available? */
|
/* is there a tsm available? */
|
||||||
if (status)
|
if (status)
|
||||||
status = tsm_transaction_available();
|
status = tsm_transaction_available();
|
||||||
if (status)
|
if (status) {
|
||||||
{
|
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
&my_address,
|
|
||||||
true, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
invoke_id = tsm_next_free_invokeID();
|
invoke_id = tsm_next_free_invokeID();
|
||||||
@@ -87,35 +80,26 @@ uint8_t Send_Write_Property_Request(
|
|||||||
data.array_index = array_index;
|
data.array_index = array_index;
|
||||||
bacapp_copy(&data.value, object_value);
|
bacapp_copy(&data.value, object_value);
|
||||||
data.priority = priority;
|
data.priority = priority;
|
||||||
pdu_len += wp_encode_apdu(
|
pdu_len += wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
invoke_id, &data);
|
||||||
invoke_id,
|
|
||||||
&data);
|
|
||||||
/* will it fit in the sender?
|
/* will it fit in the sender?
|
||||||
note: if there is a bottleneck router in between
|
note: if there is a bottleneck router in between
|
||||||
us and the destination, we won't know unless
|
us and the destination, we won't know unless
|
||||||
we have a way to check for that and update the
|
we have a way to check for that and update the
|
||||||
max_apdu in the address binding table. */
|
max_apdu in the address binding table. */
|
||||||
if ((unsigned)pdu_len < max_apdu)
|
if ((unsigned) pdu_len < max_apdu) {
|
||||||
{
|
tsm_set_confirmed_unsegmented_transaction(invoke_id,
|
||||||
tsm_set_confirmed_unsegmented_transaction(
|
&dest, &Handler_Transmit_Buffer[0], pdu_len);
|
||||||
invoke_id,
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest,
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len);
|
|
||||||
bytes_sent = datalink_send_pdu(
|
|
||||||
&dest, // destination address
|
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send WriteProperty Request (%s)!\n",
|
fprintf(stderr,
|
||||||
|
"Failed to Send WriteProperty Request (%s)!\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
fprintf(stderr, "Failed to Send WriteProperty Request "
|
fprintf(stderr, "Failed to Send WriteProperty Request "
|
||||||
"(exceeds destination maximum APDU)!\n");
|
"(exceeds destination maximum APDU)!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return invoke_id;
|
return invoke_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,4 +28,3 @@
|
|||||||
#include "datalink.h"
|
#include "datalink.h"
|
||||||
|
|
||||||
uint8_t Handler_Transmit_Buffer[MAX_MPDU] = { 0 };
|
uint8_t Handler_Transmit_Buffer[MAX_MPDU] = { 0 };
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,7 @@ char *Analog_Input_Name(uint32_t object_instance)
|
|||||||
{
|
{
|
||||||
static char text_string[32] = ""; /* okay for single thread */
|
static char text_string[32] = ""; /* okay for single thread */
|
||||||
|
|
||||||
if (object_instance < MAX_ANALOG_INPUTS)
|
if (object_instance < MAX_ANALOG_INPUTS) {
|
||||||
{
|
|
||||||
sprintf(text_string, "ANALOG INPUT %u", object_instance);
|
sprintf(text_string, "ANALOG INPUT %u", object_instance);
|
||||||
return text_string;
|
return text_string;
|
||||||
}
|
}
|
||||||
@@ -76,13 +75,11 @@ char *Analog_Input_Name(uint32_t object_instance)
|
|||||||
|
|
||||||
/* return apdu length, or -1 on error */
|
/* return apdu length, or -1 on error */
|
||||||
/* assumption - object has already exists */
|
/* assumption - object has already exists */
|
||||||
int Analog_Input_Encode_Property_APDU(
|
int Analog_Input_Encode_Property_APDU(uint8_t * apdu,
|
||||||
uint8_t *apdu,
|
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID property,
|
BACNET_PROPERTY_ID property,
|
||||||
int32_t array_index,
|
int32_t array_index,
|
||||||
BACNET_ERROR_CLASS *error_class,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
|
||||||
BACNET_ERROR_CODE *error_code)
|
|
||||||
{
|
{
|
||||||
int apdu_len = 0; // return value
|
int apdu_len = 0; // return value
|
||||||
BACNET_BIT_STRING bit_string;
|
BACNET_BIT_STRING bit_string;
|
||||||
@@ -90,17 +87,16 @@ int Analog_Input_Encode_Property_APDU(
|
|||||||
float value = 3.14;
|
float value = 3.14;
|
||||||
|
|
||||||
(void) array_index;
|
(void) array_index;
|
||||||
switch (property)
|
switch (property) {
|
||||||
{
|
|
||||||
case PROP_OBJECT_IDENTIFIER:
|
case PROP_OBJECT_IDENTIFIER:
|
||||||
apdu_len = encode_tagged_object_id(&apdu[0], OBJECT_ANALOG_INPUT,
|
apdu_len = encode_tagged_object_id(&apdu[0], OBJECT_ANALOG_INPUT,
|
||||||
object_instance);
|
object_instance);
|
||||||
break;
|
break;
|
||||||
case PROP_OBJECT_NAME:
|
case PROP_OBJECT_NAME:
|
||||||
case PROP_DESCRIPTION:
|
case PROP_DESCRIPTION:
|
||||||
characterstring_init_ansi(&char_string, Analog_Input_Name(object_instance));
|
characterstring_init_ansi(&char_string,
|
||||||
apdu_len = encode_tagged_character_string(&apdu[0],
|
Analog_Input_Name(object_instance));
|
||||||
&char_string);
|
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
||||||
break;
|
break;
|
||||||
case PROP_OBJECT_TYPE:
|
case PROP_OBJECT_TYPE:
|
||||||
apdu_len = encode_tagged_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
|
apdu_len = encode_tagged_enumerated(&apdu[0], OBJECT_ANALOG_INPUT);
|
||||||
@@ -154,13 +150,10 @@ void testAnalogInput(Test * pTest)
|
|||||||
|
|
||||||
|
|
||||||
// FIXME: we should do a lot more testing here...
|
// FIXME: we should do a lot more testing here...
|
||||||
len = Analog_Input_Encode_Property_APDU(
|
len = Analog_Input_Encode_Property_APDU(&apdu[0],
|
||||||
&apdu[0],
|
|
||||||
instance,
|
instance,
|
||||||
PROP_OBJECT_IDENTIFIER,
|
PROP_OBJECT_IDENTIFIER,
|
||||||
BACNET_ARRAY_ALL,
|
BACNET_ARRAY_ALL, &error_class, &error_code);
|
||||||
&error_class,
|
|
||||||
&error_code);
|
|
||||||
ct_test(pTest, len >= 0);
|
ct_test(pTest, len >= 0);
|
||||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||||
@@ -192,5 +185,3 @@ int main(void)
|
|||||||
}
|
}
|
||||||
#endif /* TEST_ANALOG_INPUT */
|
#endif /* TEST_ANALOG_INPUT */
|
||||||
#endif /* TEST */
|
#endif /* TEST */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,13 +38,11 @@ unsigned Analog_Input_Count(void);
|
|||||||
uint32_t Analog_Input_Index_To_Instance(unsigned index);
|
uint32_t Analog_Input_Index_To_Instance(unsigned index);
|
||||||
char *Analog_Input_Name(uint32_t object_instance);
|
char *Analog_Input_Name(uint32_t object_instance);
|
||||||
|
|
||||||
int Analog_Input_Encode_Property_APDU(
|
int Analog_Input_Encode_Property_APDU(uint8_t * apdu,
|
||||||
uint8_t *apdu,
|
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID property,
|
BACNET_PROPERTY_ID property,
|
||||||
int32_t array_index,
|
int32_t array_index,
|
||||||
BACNET_ERROR_CLASS *error_class,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
|
||||||
BACNET_ERROR_CODE *error_code);
|
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
#include "ctest.h"
|
#include "ctest.h"
|
||||||
@@ -54,5 +52,4 @@ void testAnalogInput(Test * pTest);
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -46,7 +46,8 @@
|
|||||||
// Here is our Priority Array. They are supposed to be Real, but
|
// Here is our Priority Array. They are supposed to be Real, but
|
||||||
// we don't have that kind of memory, so we will use a single byte
|
// we don't have that kind of memory, so we will use a single byte
|
||||||
// and load a Real for returning the value when asked.
|
// and load a Real for returning the value when asked.
|
||||||
static uint8_t Analog_Output_Level[MAX_ANALOG_OUTPUTS][BACNET_MAX_PRIORITY];
|
static uint8_t
|
||||||
|
Analog_Output_Level[MAX_ANALOG_OUTPUTS][BACNET_MAX_PRIORITY];
|
||||||
// Writable out-of-service allows others to play with our Present Value
|
// Writable out-of-service allows others to play with our Present Value
|
||||||
// without changing the physical output
|
// without changing the physical output
|
||||||
static bool Analog_Output_Out_Of_Service[MAX_ANALOG_OUTPUTS];
|
static bool Analog_Output_Out_Of_Service[MAX_ANALOG_OUTPUTS];
|
||||||
@@ -58,15 +59,12 @@ void Analog_Output_Init(void)
|
|||||||
{
|
{
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
|
|
||||||
if (!Analog_Ouput_Initialized)
|
if (!Analog_Ouput_Initialized) {
|
||||||
{
|
|
||||||
Analog_Ouput_Initialized = true;
|
Analog_Ouput_Initialized = true;
|
||||||
|
|
||||||
// initialize all the analog output priority arrays to NULL
|
// initialize all the analog output priority arrays to NULL
|
||||||
for (i = 0; i < MAX_ANALOG_OUTPUTS; i++)
|
for (i = 0; i < MAX_ANALOG_OUTPUTS; i++) {
|
||||||
{
|
for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
|
||||||
for (j = 0; j < BACNET_MAX_PRIORITY; j++)
|
|
||||||
{
|
|
||||||
Analog_Output_Level[i][j] = AO_LEVEL_NULL;
|
Analog_Output_Level[i][j] = AO_LEVEL_NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,12 +124,9 @@ static float Analog_Output_Present_Value(uint32_t object_instance)
|
|||||||
|
|
||||||
Analog_Output_Init();
|
Analog_Output_Init();
|
||||||
index = Analog_Output_Instance_To_Index(object_instance);
|
index = Analog_Output_Instance_To_Index(object_instance);
|
||||||
if (index < MAX_ANALOG_OUTPUTS)
|
if (index < MAX_ANALOG_OUTPUTS) {
|
||||||
{
|
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
|
||||||
for (i = 0; i < BACNET_MAX_PRIORITY; i++)
|
if (Analog_Output_Level[index][i] != AO_LEVEL_NULL) {
|
||||||
{
|
|
||||||
if (Analog_Output_Level[index][i] != AO_LEVEL_NULL)
|
|
||||||
{
|
|
||||||
value = Analog_Output_Level[index][i];
|
value = Analog_Output_Level[index][i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -146,8 +141,7 @@ char *Analog_Output_Name(uint32_t object_instance)
|
|||||||
{
|
{
|
||||||
static char text_string[32] = ""; /* okay for single thread */
|
static char text_string[32] = ""; /* okay for single thread */
|
||||||
|
|
||||||
if (object_instance < MAX_ANALOG_OUTPUTS)
|
if (object_instance < MAX_ANALOG_OUTPUTS) {
|
||||||
{
|
|
||||||
sprintf(text_string, "ANALOG OUTPUT %u", object_instance);
|
sprintf(text_string, "ANALOG OUTPUT %u", object_instance);
|
||||||
return text_string;
|
return text_string;
|
||||||
}
|
}
|
||||||
@@ -156,13 +150,11 @@ char *Analog_Output_Name(uint32_t object_instance)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* return apdu len, or -1 on error */
|
/* return apdu len, or -1 on error */
|
||||||
int Analog_Output_Encode_Property_APDU(
|
int Analog_Output_Encode_Property_APDU(uint8_t * apdu,
|
||||||
uint8_t *apdu,
|
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID property,
|
BACNET_PROPERTY_ID property,
|
||||||
int32_t array_index,
|
int32_t array_index,
|
||||||
BACNET_ERROR_CLASS *error_class,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
|
||||||
BACNET_ERROR_CODE *error_code)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int apdu_len = 0; // return value
|
int apdu_len = 0; // return value
|
||||||
@@ -173,20 +165,20 @@ int Analog_Output_Encode_Property_APDU(
|
|||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
|
|
||||||
Analog_Output_Init();
|
Analog_Output_Init();
|
||||||
switch (property)
|
switch (property) {
|
||||||
{
|
|
||||||
case PROP_OBJECT_IDENTIFIER:
|
case PROP_OBJECT_IDENTIFIER:
|
||||||
apdu_len = encode_tagged_object_id(&apdu[0], OBJECT_ANALOG_OUTPUT,
|
apdu_len = encode_tagged_object_id(&apdu[0], OBJECT_ANALOG_OUTPUT,
|
||||||
object_instance);
|
object_instance);
|
||||||
break;
|
break;
|
||||||
case PROP_OBJECT_NAME:
|
case PROP_OBJECT_NAME:
|
||||||
case PROP_DESCRIPTION:
|
case PROP_DESCRIPTION:
|
||||||
characterstring_init_ansi(&char_string, Analog_Output_Name(object_instance));
|
characterstring_init_ansi(&char_string,
|
||||||
apdu_len = encode_tagged_character_string(&apdu[0],
|
Analog_Output_Name(object_instance));
|
||||||
&char_string);
|
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
||||||
break;
|
break;
|
||||||
case PROP_OBJECT_TYPE:
|
case PROP_OBJECT_TYPE:
|
||||||
apdu_len = encode_tagged_enumerated(&apdu[0], OBJECT_ANALOG_OUTPUT);
|
apdu_len =
|
||||||
|
encode_tagged_enumerated(&apdu[0], OBJECT_ANALOG_OUTPUT);
|
||||||
break;
|
break;
|
||||||
case PROP_PRESENT_VALUE:
|
case PROP_PRESENT_VALUE:
|
||||||
real_value = Analog_Output_Present_Value(object_instance);
|
real_value = Analog_Output_Present_Value(object_instance);
|
||||||
@@ -212,49 +204,44 @@ int Analog_Output_Encode_Property_APDU(
|
|||||||
case PROP_PRIORITY_ARRAY:
|
case PROP_PRIORITY_ARRAY:
|
||||||
// Array element zero is the number of elements in the array
|
// Array element zero is the number of elements in the array
|
||||||
if (array_index == BACNET_ARRAY_LENGTH_INDEX)
|
if (array_index == BACNET_ARRAY_LENGTH_INDEX)
|
||||||
apdu_len = encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY);
|
apdu_len =
|
||||||
|
encode_tagged_unsigned(&apdu[0], BACNET_MAX_PRIORITY);
|
||||||
// if no index was specified, then try to encode the entire list
|
// if no index was specified, then try to encode the entire list
|
||||||
// into one packet.
|
// into one packet.
|
||||||
else if (array_index == BACNET_ARRAY_ALL)
|
else if (array_index == BACNET_ARRAY_ALL) {
|
||||||
{
|
object_index =
|
||||||
object_index = Analog_Output_Instance_To_Index(object_instance);
|
Analog_Output_Instance_To_Index(object_instance);
|
||||||
for (i = 0; i < BACNET_MAX_PRIORITY; i++)
|
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
|
||||||
{
|
|
||||||
// FIXME: check if we have room before adding it to APDU
|
// FIXME: check if we have room before adding it to APDU
|
||||||
if (Analog_Output_Level[object_index][i] == AO_LEVEL_NULL)
|
if (Analog_Output_Level[object_index][i] == AO_LEVEL_NULL)
|
||||||
len = encode_tagged_null(&apdu[apdu_len]);
|
len = encode_tagged_null(&apdu[apdu_len]);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
real_value = Analog_Output_Level[object_index][i];
|
real_value = Analog_Output_Level[object_index][i];
|
||||||
len = encode_tagged_real(&apdu[apdu_len], real_value);
|
len = encode_tagged_real(&apdu[apdu_len], real_value);
|
||||||
}
|
}
|
||||||
// add it if we have room
|
// add it if we have room
|
||||||
if ((apdu_len + len) < MAX_APDU)
|
if ((apdu_len + len) < MAX_APDU)
|
||||||
apdu_len += len;
|
apdu_len += len;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_SERVICES;
|
*error_class = ERROR_CLASS_SERVICES;
|
||||||
*error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
|
*error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
|
||||||
apdu_len = -1;
|
apdu_len = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
object_index =
|
||||||
{
|
Analog_Output_Instance_To_Index(object_instance);
|
||||||
object_index = Analog_Output_Instance_To_Index(object_instance);
|
if (array_index <= BACNET_MAX_PRIORITY) {
|
||||||
if (array_index <= BACNET_MAX_PRIORITY)
|
if (Analog_Output_Level[object_index][array_index] ==
|
||||||
{
|
AO_LEVEL_NULL)
|
||||||
if (Analog_Output_Level[object_index][array_index] == AO_LEVEL_NULL)
|
|
||||||
len = encode_tagged_null(&apdu[apdu_len]);
|
len = encode_tagged_null(&apdu[apdu_len]);
|
||||||
else
|
else {
|
||||||
{
|
real_value =
|
||||||
real_value = Analog_Output_Level[object_index][array_index];
|
Analog_Output_Level[object_index][array_index];
|
||||||
len = encode_tagged_real(&apdu[apdu_len], real_value);
|
len = encode_tagged_real(&apdu[apdu_len], real_value);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
*error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
||||||
apdu_len = -1;
|
apdu_len = -1;
|
||||||
@@ -277,10 +264,8 @@ int Analog_Output_Encode_Property_APDU(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns true if successful
|
// returns true if successful
|
||||||
bool Analog_Output_Write_Property(
|
bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||||
BACNET_WRITE_PROPERTY_DATA *wp_data,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
|
||||||
BACNET_ERROR_CLASS *error_class,
|
|
||||||
BACNET_ERROR_CODE *error_code)
|
|
||||||
{
|
{
|
||||||
bool status = false; // return value
|
bool status = false; // return value
|
||||||
unsigned int object_index = 0;
|
unsigned int object_index = 0;
|
||||||
@@ -288,81 +273,63 @@ bool Analog_Output_Write_Property(
|
|||||||
uint8_t level = AO_LEVEL_NULL;
|
uint8_t level = AO_LEVEL_NULL;
|
||||||
|
|
||||||
Analog_Output_Init();
|
Analog_Output_Init();
|
||||||
if (!Analog_Output_Valid_Instance(wp_data->object_instance))
|
if (!Analog_Output_Valid_Instance(wp_data->object_instance)) {
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_OBJECT;
|
*error_class = ERROR_CLASS_OBJECT;
|
||||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode the some of the request
|
// decode the some of the request
|
||||||
switch (wp_data->object_property)
|
switch (wp_data->object_property) {
|
||||||
{
|
|
||||||
case PROP_PRESENT_VALUE:
|
case PROP_PRESENT_VALUE:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_REAL)
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_REAL) {
|
||||||
{
|
|
||||||
priority = wp_data->priority;
|
priority = wp_data->priority;
|
||||||
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
|
if (priority && (priority <= BACNET_MAX_PRIORITY) &&
|
||||||
(priority != 6 /* reserved */ ) &&
|
(priority != 6 /* reserved */ ) &&
|
||||||
(wp_data->value.type.Real >= 0.0) &&
|
(wp_data->value.type.Real >= 0.0) &&
|
||||||
(wp_data->value.type.Real <= 100.0))
|
(wp_data->value.type.Real <= 100.0)) {
|
||||||
{
|
|
||||||
level = (uint8_t) wp_data->value.type.Real;
|
level = (uint8_t) wp_data->value.type.Real;
|
||||||
object_index = Analog_Output_Instance_To_Index(
|
object_index =
|
||||||
wp_data->object_instance);
|
Analog_Output_Instance_To_Index(wp_data->
|
||||||
|
object_instance);
|
||||||
priority--;
|
priority--;
|
||||||
Analog_Output_Level[object_index][priority] = level;
|
Analog_Output_Level[object_index][priority] = level;
|
||||||
// if Out of Service is TRUE, then don't set the
|
// if Out of Service is TRUE, then don't set the
|
||||||
// physical output. This comment may apply to the
|
// physical output. This comment may apply to the
|
||||||
// main loop (i.e. check out of service before changing output)
|
// main loop (i.e. check out of service before changing output)
|
||||||
status = true;
|
status = true;
|
||||||
}
|
} else if (priority == 6) {
|
||||||
else if (priority == 6)
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
}
|
} else if (wp_data->value.tag == BACNET_APPLICATION_TAG_NULL) {
|
||||||
else if (wp_data->value.tag == BACNET_APPLICATION_TAG_NULL)
|
|
||||||
{
|
|
||||||
level = AO_LEVEL_NULL;
|
level = AO_LEVEL_NULL;
|
||||||
object_index = Analog_Output_Instance_To_Index(
|
object_index =
|
||||||
wp_data->object_instance);
|
Analog_Output_Instance_To_Index(wp_data->object_instance);
|
||||||
priority = wp_data->priority;
|
priority = wp_data->priority;
|
||||||
if (priority && (priority <= BACNET_MAX_PRIORITY))
|
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
|
||||||
{
|
|
||||||
priority--;
|
priority--;
|
||||||
Analog_Output_Level[object_index][priority] = level;
|
Analog_Output_Level[object_index][priority] = level;
|
||||||
status = true;
|
status = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PROP_OUT_OF_SERVICE:
|
case PROP_OUT_OF_SERVICE:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_BOOLEAN)
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||||
{
|
object_index =
|
||||||
object_index = Analog_Output_Instance_To_Index(
|
Analog_Output_Instance_To_Index(wp_data->object_instance);
|
||||||
wp_data->object_instance);
|
|
||||||
Analog_Output_Out_Of_Service[object_index] =
|
Analog_Output_Out_Of_Service[object_index] =
|
||||||
wp_data->value.type.Boolean;
|
wp_data->value.type.Boolean;
|
||||||
status = true;
|
status = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
@@ -395,13 +362,10 @@ void testAnalogOutput(Test * pTest)
|
|||||||
BACNET_ERROR_CODE error_code;
|
BACNET_ERROR_CODE error_code;
|
||||||
|
|
||||||
|
|
||||||
len = Analog_Output_Encode_Property_APDU(
|
len = Analog_Output_Encode_Property_APDU(&apdu[0],
|
||||||
&apdu[0],
|
|
||||||
instance,
|
instance,
|
||||||
PROP_OBJECT_IDENTIFIER,
|
PROP_OBJECT_IDENTIFIER,
|
||||||
BACNET_ARRAY_ALL,
|
BACNET_ARRAY_ALL, &error_class, &error_code);
|
||||||
&error_class,
|
|
||||||
&error_code);
|
|
||||||
ct_test(pTest, len != 0);
|
ct_test(pTest, len != 0);
|
||||||
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
|
||||||
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OBJECT_ID);
|
||||||
@@ -433,5 +397,3 @@ int main(void)
|
|||||||
}
|
}
|
||||||
#endif /* TEST_ANALOG_INPUT */
|
#endif /* TEST_ANALOG_INPUT */
|
||||||
#endif /* TEST */
|
#endif /* TEST */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,18 +40,14 @@ unsigned Analog_Output_Count(void);
|
|||||||
uint32_t Analog_Output_Index_To_Instance(unsigned index);
|
uint32_t Analog_Output_Index_To_Instance(unsigned index);
|
||||||
char *Analog_Output_Name(uint32_t object_instance);
|
char *Analog_Output_Name(uint32_t object_instance);
|
||||||
|
|
||||||
int Analog_Output_Encode_Property_APDU(
|
int Analog_Output_Encode_Property_APDU(uint8_t * apdu,
|
||||||
uint8_t *apdu,
|
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID property,
|
BACNET_PROPERTY_ID property,
|
||||||
int32_t array_index,
|
int32_t array_index,
|
||||||
BACNET_ERROR_CLASS *error_class,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
|
||||||
BACNET_ERROR_CODE *error_code);
|
|
||||||
|
|
||||||
bool Analog_Output_Write_Property(
|
bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||||
BACNET_WRITE_PROPERTY_DATA *wp_data,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
|
||||||
BACNET_ERROR_CLASS *error_class,
|
|
||||||
BACNET_ERROR_CODE *error_code);
|
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
#include "ctest.h"
|
#include "ctest.h"
|
||||||
@@ -61,5 +57,4 @@ void testAnalogOutput(Test * pTest);
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -39,14 +39,12 @@
|
|||||||
#include "arf.h"
|
#include "arf.h"
|
||||||
#include "awf.h"
|
#include "awf.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
uint32_t instance;
|
uint32_t instance;
|
||||||
char *filename;
|
char *filename;
|
||||||
} BACNET_FILE_LISTING;
|
} BACNET_FILE_LISTING;
|
||||||
|
|
||||||
static BACNET_FILE_LISTING BACnet_File_Listing[] =
|
static BACNET_FILE_LISTING BACnet_File_Listing[] = {
|
||||||
{
|
|
||||||
{0, "test.log"},
|
{0, "test.log"},
|
||||||
{1, "script.txt"},
|
{1, "script.txt"},
|
||||||
{2, "bacenum.h"},
|
{2, "bacenum.h"},
|
||||||
@@ -59,10 +57,8 @@ char *bacfile_name(uint32_t instance)
|
|||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
|
|
||||||
// linear search for file instance match
|
// linear search for file instance match
|
||||||
while (BACnet_File_Listing[index].filename)
|
while (BACnet_File_Listing[index].filename) {
|
||||||
{
|
if (BACnet_File_Listing[index].instance == instance) {
|
||||||
if (BACnet_File_Listing[index].instance == instance)
|
|
||||||
{
|
|
||||||
filename = BACnet_File_Listing[index].filename;
|
filename = BACnet_File_Listing[index].filename;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -82,8 +78,7 @@ uint32_t bacfile_count(void)
|
|||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
|
|
||||||
// linear search for file instance match
|
// linear search for file instance match
|
||||||
while (BACnet_File_Listing[index].filename)
|
while (BACnet_File_Listing[index].filename) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,10 +91,8 @@ uint32_t bacfile_index_to_instance(unsigned find_index)
|
|||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
|
|
||||||
// bounds checking...
|
// bounds checking...
|
||||||
while (BACnet_File_Listing[index].filename)
|
while (BACnet_File_Listing[index].filename) {
|
||||||
{
|
if (index == find_index) {
|
||||||
if (index == find_index)
|
|
||||||
{
|
|
||||||
instance = BACnet_File_Listing[index].instance;
|
instance = BACnet_File_Listing[index].instance;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -114,8 +107,7 @@ static long fsize(FILE *pFile)
|
|||||||
long size = 0;
|
long size = 0;
|
||||||
long origin = 0;
|
long origin = 0;
|
||||||
|
|
||||||
if (pFile)
|
if (pFile) {
|
||||||
{
|
|
||||||
origin = ftell(pFile);
|
origin = ftell(pFile);
|
||||||
fseek(pFile, 0L, SEEK_END);
|
fseek(pFile, 0L, SEEK_END);
|
||||||
size = ftell(pFile);
|
size = ftell(pFile);
|
||||||
@@ -131,11 +123,9 @@ static unsigned bacfile_file_size(uint32_t object_instance)
|
|||||||
unsigned file_size = 0;
|
unsigned file_size = 0;
|
||||||
|
|
||||||
pFilename = bacfile_name(object_instance);
|
pFilename = bacfile_name(object_instance);
|
||||||
if (pFilename)
|
if (pFilename) {
|
||||||
{
|
|
||||||
pFile = fopen(pFilename, "rb");
|
pFile = fopen(pFilename, "rb");
|
||||||
if (pFile)
|
if (pFile) {
|
||||||
{
|
|
||||||
file_size = fsize(pFile);
|
file_size = fsize(pFile);
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
}
|
}
|
||||||
@@ -145,44 +135,38 @@ static unsigned bacfile_file_size(uint32_t object_instance)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* return the number of bytes used, or -1 on error */
|
/* return the number of bytes used, or -1 on error */
|
||||||
int bacfile_encode_property_apdu(
|
int bacfile_encode_property_apdu(uint8_t * apdu,
|
||||||
uint8_t *apdu,
|
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID property,
|
BACNET_PROPERTY_ID property,
|
||||||
int32_t array_index,
|
int32_t array_index,
|
||||||
BACNET_ERROR_CLASS *error_class,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
|
||||||
BACNET_ERROR_CODE *error_code)
|
|
||||||
{
|
{
|
||||||
int apdu_len = 0; // return value
|
int apdu_len = 0; // return value
|
||||||
char text_string[32] = { "" };
|
char text_string[32] = { "" };
|
||||||
BACNET_CHARACTER_STRING char_string;
|
BACNET_CHARACTER_STRING char_string;
|
||||||
|
|
||||||
(void) array_index;
|
(void) array_index;
|
||||||
switch (property)
|
switch (property) {
|
||||||
{
|
|
||||||
case PROP_OBJECT_IDENTIFIER:
|
case PROP_OBJECT_IDENTIFIER:
|
||||||
apdu_len = encode_tagged_object_id(&apdu[0],
|
apdu_len = encode_tagged_object_id(&apdu[0],
|
||||||
OBJECT_FILE,
|
OBJECT_FILE, object_instance);
|
||||||
object_instance);
|
|
||||||
break;
|
break;
|
||||||
case PROP_OBJECT_NAME:
|
case PROP_OBJECT_NAME:
|
||||||
sprintf(text_string, "FILE %d", object_instance);
|
sprintf(text_string, "FILE %d", object_instance);
|
||||||
characterstring_init_ansi(&char_string, text_string);
|
characterstring_init_ansi(&char_string, text_string);
|
||||||
apdu_len = encode_tagged_character_string(&apdu[0],
|
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
||||||
&char_string);
|
|
||||||
break;
|
break;
|
||||||
case PROP_OBJECT_TYPE:
|
case PROP_OBJECT_TYPE:
|
||||||
apdu_len = encode_tagged_enumerated(&apdu[0], OBJECT_FILE);
|
apdu_len = encode_tagged_enumerated(&apdu[0], OBJECT_FILE);
|
||||||
break;
|
break;
|
||||||
case PROP_DESCRIPTION:
|
case PROP_DESCRIPTION:
|
||||||
characterstring_init_ansi(&char_string, bacfile_name(object_instance));
|
characterstring_init_ansi(&char_string,
|
||||||
apdu_len = encode_tagged_character_string(&apdu[0],
|
bacfile_name(object_instance));
|
||||||
&char_string);
|
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
||||||
break;
|
break;
|
||||||
case PROP_FILE_TYPE:
|
case PROP_FILE_TYPE:
|
||||||
characterstring_init_ansi(&char_string, "TEXT");
|
characterstring_init_ansi(&char_string, "TEXT");
|
||||||
apdu_len = encode_tagged_character_string(&apdu[0],
|
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
||||||
&char_string);
|
|
||||||
break;
|
break;
|
||||||
case PROP_FILE_SIZE:
|
case PROP_FILE_SIZE:
|
||||||
apdu_len = encode_tagged_unsigned(&apdu[0],
|
apdu_len = encode_tagged_unsigned(&apdu[0],
|
||||||
@@ -191,16 +175,9 @@ int bacfile_encode_property_apdu(
|
|||||||
case PROP_MODIFICATION_DATE:
|
case PROP_MODIFICATION_DATE:
|
||||||
// FIXME: get the actual value
|
// FIXME: get the actual value
|
||||||
apdu_len = encode_tagged_date(&apdu[0],
|
apdu_len = encode_tagged_date(&apdu[0],
|
||||||
2005,
|
2005, 12, 25, 7 /* sunday */ );
|
||||||
12,
|
|
||||||
25,
|
|
||||||
7 /* sunday */);
|
|
||||||
// FIXME: get the actual value
|
// FIXME: get the actual value
|
||||||
apdu_len += encode_tagged_time(&apdu[apdu_len],
|
apdu_len += encode_tagged_time(&apdu[apdu_len], 12, 0, 0, 0);
|
||||||
12,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0);
|
|
||||||
break;
|
break;
|
||||||
case PROP_ARCHIVE:
|
case PROP_ARCHIVE:
|
||||||
// FIXME: get the actual value: note it may be inverse...
|
// FIXME: get the actual value: note it may be inverse...
|
||||||
@@ -229,10 +206,8 @@ uint32_t bacfile_instance(char *filename)
|
|||||||
uint32_t instance = BACNET_MAX_INSTANCE + 1;
|
uint32_t instance = BACNET_MAX_INSTANCE + 1;
|
||||||
|
|
||||||
// linear search for filename match
|
// linear search for filename match
|
||||||
while (BACnet_File_Listing[index].filename)
|
while (BACnet_File_Listing[index].filename) {
|
||||||
{
|
if (strcmp(BACnet_File_Listing[index].filename, filename) == 0) {
|
||||||
if (strcmp(BACnet_File_Listing[index].filename,filename) == 0)
|
|
||||||
{
|
|
||||||
instance = BACnet_File_Listing[index].instance;
|
instance = BACnet_File_Listing[index].instance;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -248,8 +223,7 @@ uint32_t bacfile_instance(char *filename)
|
|||||||
// Another way would be to store the
|
// Another way would be to store the
|
||||||
// invokeID and file instance in a list or table
|
// invokeID and file instance in a list or table
|
||||||
// when the request was sent
|
// when the request was sent
|
||||||
uint32_t bacfile_instance_from_tsm(
|
uint32_t bacfile_instance_from_tsm(uint8_t invokeID)
|
||||||
uint8_t invokeID)
|
|
||||||
{
|
{
|
||||||
BACNET_NPDU_DATA npdu_data = { 0 }; // dummy for getting npdu length
|
BACNET_NPDU_DATA npdu_data = { 0 }; // dummy for getting npdu length
|
||||||
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
|
BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 };
|
||||||
@@ -265,36 +239,23 @@ uint32_t bacfile_instance_from_tsm(
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
int apdu_offset = 0;
|
int apdu_offset = 0;
|
||||||
|
|
||||||
found = tsm_get_transaction_pdu(
|
found = tsm_get_transaction_pdu(invokeID, &dest, &pdu[0], &pdu_len);
|
||||||
invokeID,
|
if (found) {
|
||||||
&dest,
|
apdu_offset = npdu_decode(&pdu[0], // data to decode
|
||||||
&pdu[0],
|
|
||||||
&pdu_len);
|
|
||||||
if (found)
|
|
||||||
{
|
|
||||||
apdu_offset = npdu_decode(
|
|
||||||
&pdu[0], // data to decode
|
|
||||||
NULL, // destination address - get the DNET/DLEN/DADR if in there
|
NULL, // destination address - get the DNET/DLEN/DADR if in there
|
||||||
NULL, // source address - get the SNET/SLEN/SADR if in there
|
NULL, // source address - get the SNET/SLEN/SADR if in there
|
||||||
&npdu_data); // amount of data to decode
|
&npdu_data); // amount of data to decode
|
||||||
if (!npdu_data.network_layer_message &&
|
if (!npdu_data.network_layer_message &&
|
||||||
((pdu[apdu_offset] & 0xF0) == PDU_TYPE_CONFIRMED_SERVICE_REQUEST))
|
((pdu[apdu_offset] & 0xF0) ==
|
||||||
{
|
PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
|
||||||
len = apdu_decode_confirmed_service_request(
|
len = apdu_decode_confirmed_service_request(&pdu[apdu_offset], // APDU data
|
||||||
&pdu[apdu_offset], // APDU data
|
|
||||||
pdu_len - apdu_offset,
|
pdu_len - apdu_offset,
|
||||||
&service_data,
|
&service_data,
|
||||||
&service_choice,
|
&service_choice, &service_request, &service_request_len);
|
||||||
&service_request,
|
if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) {
|
||||||
&service_request_len);
|
len = arf_decode_service_request(service_request,
|
||||||
if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE)
|
service_request_len, &data);
|
||||||
{
|
if (len > 0) {
|
||||||
len = arf_decode_service_request(
|
|
||||||
service_request,
|
|
||||||
service_request_len,
|
|
||||||
&data);
|
|
||||||
if (len > 0)
|
|
||||||
{
|
|
||||||
if (data.object_type == OBJECT_FILE)
|
if (data.object_type == OBJECT_FILE)
|
||||||
object_instance = data.object_instance;
|
object_instance = data.object_instance;
|
||||||
}
|
}
|
||||||
@@ -314,15 +275,12 @@ bool bacfile_read_data(BACNET_ATOMIC_READ_FILE_DATA *data)
|
|||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
pFilename = bacfile_name(data->object_instance);
|
pFilename = bacfile_name(data->object_instance);
|
||||||
if (pFilename)
|
if (pFilename) {
|
||||||
{
|
|
||||||
found = true;
|
found = true;
|
||||||
pFile = fopen(pFilename, "rb");
|
pFile = fopen(pFilename, "rb");
|
||||||
if (pFile)
|
if (pFile) {
|
||||||
{
|
|
||||||
(void) fseek(pFile,
|
(void) fseek(pFile,
|
||||||
data->type.stream.fileStartPosition,
|
data->type.stream.fileStartPosition, SEEK_SET);
|
||||||
SEEK_SET);
|
|
||||||
len = fread(octetstring_value(&data->fileData), 1,
|
len = fread(octetstring_value(&data->fileData), 1,
|
||||||
data->type.stream.requestedOctetCount, pFile);
|
data->type.stream.requestedOctetCount, pFile);
|
||||||
if (len < data->type.stream.requestedOctetCount)
|
if (len < data->type.stream.requestedOctetCount)
|
||||||
@@ -331,19 +289,14 @@ bool bacfile_read_data(BACNET_ATOMIC_READ_FILE_DATA *data)
|
|||||||
data->endOfFile = false;
|
data->endOfFile = false;
|
||||||
octetstring_truncate(&data->fileData, len);
|
octetstring_truncate(&data->fileData, len);
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
octetstring_truncate(&data->fileData, 0);
|
octetstring_truncate(&data->fileData, 0);
|
||||||
data->endOfFile = true;
|
data->endOfFile = true;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
octetstring_truncate(&data->fileData, 0);
|
octetstring_truncate(&data->fileData, 0);
|
||||||
data->endOfFile = true;
|
data->endOfFile = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,24 +56,20 @@ uint32_t bacfile_instance(char *filename);
|
|||||||
// Another way would be to store the
|
// Another way would be to store the
|
||||||
// invokeID and file instance in a list or table
|
// invokeID and file instance in a list or table
|
||||||
// when the request was sent
|
// when the request was sent
|
||||||
uint32_t bacfile_instance_from_tsm(
|
uint32_t bacfile_instance_from_tsm(uint8_t invokeID);
|
||||||
uint8_t invokeID);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// AtomicReadFile ACK helper
|
// AtomicReadFile ACK helper
|
||||||
bool bacfile_read_data(BACNET_ATOMIC_READ_FILE_DATA * data);
|
bool bacfile_read_data(BACNET_ATOMIC_READ_FILE_DATA * data);
|
||||||
|
|
||||||
// handling for read property service
|
// handling for read property service
|
||||||
int bacfile_encode_property_apdu(
|
int bacfile_encode_property_apdu(uint8_t * apdu,
|
||||||
uint8_t *apdu,
|
|
||||||
uint32_t object_instance,
|
uint32_t object_instance,
|
||||||
BACNET_PROPERTY_ID property,
|
BACNET_PROPERTY_ID property,
|
||||||
int32_t array_index,
|
int32_t array_index,
|
||||||
BACNET_ERROR_CLASS *error_class,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
|
||||||
BACNET_ERROR_CODE *error_code);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -121,8 +121,7 @@ bool Device_Set_Object_Name(const char *name, size_t length)
|
|||||||
{
|
{
|
||||||
bool status = false; /*return value */
|
bool status = false; /*return value */
|
||||||
|
|
||||||
if (length < sizeof(Object_Name))
|
if (length < sizeof(Object_Name)) {
|
||||||
{
|
|
||||||
memmove(Object_Name, name, length);
|
memmove(Object_Name, name, length);
|
||||||
Object_Name[length] = 0;
|
Object_Name[length] = 0;
|
||||||
status = true;
|
status = true;
|
||||||
@@ -151,8 +150,7 @@ bool Device_Set_Vendor_Name(const char *name, size_t length)
|
|||||||
{
|
{
|
||||||
bool status = false; /*return value */
|
bool status = false; /*return value */
|
||||||
|
|
||||||
if (length < sizeof(Vendor_Name))
|
if (length < sizeof(Vendor_Name)) {
|
||||||
{
|
|
||||||
memmove(Vendor_Name, name, length);
|
memmove(Vendor_Name, name, length);
|
||||||
Vendor_Name[length] = 0;
|
Vendor_Name[length] = 0;
|
||||||
status = true;
|
status = true;
|
||||||
@@ -180,8 +178,7 @@ bool Device_Set_Model_Name(const char *name, size_t length)
|
|||||||
{
|
{
|
||||||
bool status = false; /*return value */
|
bool status = false; /*return value */
|
||||||
|
|
||||||
if (length < sizeof(Model_Name))
|
if (length < sizeof(Model_Name)) {
|
||||||
{
|
|
||||||
memmove(Model_Name, name, length);
|
memmove(Model_Name, name, length);
|
||||||
Model_Name[length] = 0;
|
Model_Name[length] = 0;
|
||||||
status = true;
|
status = true;
|
||||||
@@ -199,8 +196,7 @@ bool Device_Set_Firmware_Revision(const char *name, size_t length)
|
|||||||
{
|
{
|
||||||
bool status = false; /*return value */
|
bool status = false; /*return value */
|
||||||
|
|
||||||
if (length < sizeof(Firmware_Revision))
|
if (length < sizeof(Firmware_Revision)) {
|
||||||
{
|
|
||||||
memmove(Firmware_Revision, name, length);
|
memmove(Firmware_Revision, name, length);
|
||||||
Firmware_Revision[length] = 0;
|
Firmware_Revision[length] = 0;
|
||||||
status = true;
|
status = true;
|
||||||
@@ -214,12 +210,12 @@ const char *Device_Application_Software_Version(void)
|
|||||||
return Application_Software_Version;
|
return Application_Software_Version;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device_Set_Application_Software_Version(const char *name, size_t length)
|
bool Device_Set_Application_Software_Version(const char *name,
|
||||||
|
size_t length)
|
||||||
{
|
{
|
||||||
bool status = false; /*return value */
|
bool status = false; /*return value */
|
||||||
|
|
||||||
if (length < sizeof(Application_Software_Version))
|
if (length < sizeof(Application_Software_Version)) {
|
||||||
{
|
|
||||||
memmove(Application_Software_Version, name, length);
|
memmove(Application_Software_Version, name, length);
|
||||||
Application_Software_Version[length] = 0;
|
Application_Software_Version[length] = 0;
|
||||||
status = true;
|
status = true;
|
||||||
@@ -237,8 +233,7 @@ bool Device_Set_Description(const char *name, size_t length)
|
|||||||
{
|
{
|
||||||
bool status = false; /*return value */
|
bool status = false; /*return value */
|
||||||
|
|
||||||
if (length < sizeof(Description))
|
if (length < sizeof(Description)) {
|
||||||
{
|
|
||||||
memmove(Description, name, length);
|
memmove(Description, name, length);
|
||||||
Description[length] = 0;
|
Description[length] = 0;
|
||||||
status = true;
|
status = true;
|
||||||
@@ -256,8 +251,7 @@ bool Device_Set_Location(const char *name, size_t length)
|
|||||||
{
|
{
|
||||||
bool status = false; /*return value */
|
bool status = false; /*return value */
|
||||||
|
|
||||||
if (length < sizeof(Location))
|
if (length < sizeof(Location)) {
|
||||||
{
|
|
||||||
memmove(Location, name, length);
|
memmove(Location, name, length);
|
||||||
Location[length] = 0;
|
Location[length] = 0;
|
||||||
status = true;
|
status = true;
|
||||||
@@ -333,47 +327,38 @@ unsigned Device_Object_List_Count(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Device_Object_List_Identifier(unsigned array_index,
|
bool Device_Object_List_Identifier(unsigned array_index,
|
||||||
int *object_type,
|
int *object_type, uint32_t * instance)
|
||||||
uint32_t *instance)
|
|
||||||
{
|
{
|
||||||
bool status = false;
|
bool status = false;
|
||||||
unsigned object_index = 0;
|
unsigned object_index = 0;
|
||||||
|
|
||||||
if (array_index == 1)
|
if (array_index == 1) {
|
||||||
{
|
|
||||||
*object_type = OBJECT_DEVICE;
|
*object_type = OBJECT_DEVICE;
|
||||||
*instance = Object_Instance_Number;
|
*instance = Object_Instance_Number;
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!status)
|
if (!status) {
|
||||||
{
|
|
||||||
// array index starts at 1, and 1 for the device object
|
// array index starts at 1, and 1 for the device object
|
||||||
object_index = array_index - 2;
|
object_index = array_index - 2;
|
||||||
if (object_index < Analog_Input_Count())
|
if (object_index < Analog_Input_Count()) {
|
||||||
{
|
|
||||||
*object_type = OBJECT_ANALOG_INPUT;
|
*object_type = OBJECT_ANALOG_INPUT;
|
||||||
*instance = Analog_Input_Index_To_Instance(object_index);
|
*instance = Analog_Input_Index_To_Instance(object_index);
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!status)
|
if (!status) {
|
||||||
{
|
|
||||||
object_index -= Analog_Input_Count();
|
object_index -= Analog_Input_Count();
|
||||||
if (object_index < Analog_Output_Count())
|
if (object_index < Analog_Output_Count()) {
|
||||||
{
|
|
||||||
*object_type = OBJECT_ANALOG_OUTPUT;
|
*object_type = OBJECT_ANALOG_OUTPUT;
|
||||||
*instance = Analog_Output_Index_To_Instance(object_index);
|
*instance = Analog_Output_Index_To_Instance(object_index);
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BACFILE
|
#if BACFILE
|
||||||
if (!status)
|
if (!status) {
|
||||||
{
|
|
||||||
object_index -= Analog_Output_Count();
|
object_index -= Analog_Output_Count();
|
||||||
if (object_index < bacfile_count())
|
if (object_index < bacfile_count()) {
|
||||||
{
|
|
||||||
*object_type = OBJECT_FILE;
|
*object_type = OBJECT_FILE;
|
||||||
*instance = bacfile_index_to_instance(object_index);
|
*instance = bacfile_index_to_instance(object_index);
|
||||||
status = true;
|
status = true;
|
||||||
@@ -384,10 +369,8 @@ bool Device_Object_List_Identifier(unsigned array_index,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device_Valid_Object_Name(
|
bool Device_Valid_Object_Name(const char *object_name,
|
||||||
const char *object_name,
|
int *object_type, uint32_t * object_instance)
|
||||||
int *object_type,
|
|
||||||
uint32_t *object_instance)
|
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
int type = 0;
|
int type = 0;
|
||||||
@@ -397,14 +380,11 @@ bool Device_Valid_Object_Name(
|
|||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
|
||||||
max_objects = Device_Object_List_Count();
|
max_objects = Device_Object_List_Count();
|
||||||
for (i = 0; i < max_objects; i++)
|
for (i = 0; i < max_objects; i++) {
|
||||||
{
|
|
||||||
check_id = Device_Object_List_Identifier(i, &type, &instance);
|
check_id = Device_Object_List_Identifier(i, &type, &instance);
|
||||||
if (check_id)
|
if (check_id) {
|
||||||
{
|
|
||||||
name = Device_Valid_Object_Id(type, instance);
|
name = Device_Valid_Object_Id(type, instance);
|
||||||
if (strcmp(name,object_name) == 0)
|
if (strcmp(name, object_name) == 0) {
|
||||||
{
|
|
||||||
found = true;
|
found = true;
|
||||||
if (object_type)
|
if (object_type)
|
||||||
*object_type = type;
|
*object_type = type;
|
||||||
@@ -419,14 +399,11 @@ bool Device_Valid_Object_Name(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* returns the name or NULL if not found */
|
/* returns the name or NULL if not found */
|
||||||
char *Device_Valid_Object_Id(
|
char *Device_Valid_Object_Id(int object_type, uint32_t object_instance)
|
||||||
int object_type,
|
|
||||||
uint32_t object_instance)
|
|
||||||
{
|
{
|
||||||
char *name = NULL; /* return value */
|
char *name = NULL; /* return value */
|
||||||
|
|
||||||
switch (object_type)
|
switch (object_type) {
|
||||||
{
|
|
||||||
case OBJECT_ANALOG_INPUT:
|
case OBJECT_ANALOG_INPUT:
|
||||||
name = Analog_Input_Name(object_instance);
|
name = Analog_Input_Name(object_instance);
|
||||||
break;
|
break;
|
||||||
@@ -450,12 +427,10 @@ char *Device_Valid_Object_Id(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return the length of the apdu encoded or -1 for error
|
// return the length of the apdu encoded or -1 for error
|
||||||
int Device_Encode_Property_APDU(
|
int Device_Encode_Property_APDU(uint8_t * apdu,
|
||||||
uint8_t *apdu,
|
|
||||||
BACNET_PROPERTY_ID property,
|
BACNET_PROPERTY_ID property,
|
||||||
int32_t array_index,
|
int32_t array_index,
|
||||||
BACNET_ERROR_CLASS *error_class,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
|
||||||
BACNET_ERROR_CODE *error_code)
|
|
||||||
{
|
{
|
||||||
int apdu_len = 0; // return value
|
int apdu_len = 0; // return value
|
||||||
int len = 0; // apdu len intermediate value
|
int len = 0; // apdu len intermediate value
|
||||||
@@ -466,8 +441,7 @@ int Device_Encode_Property_APDU(
|
|||||||
uint32_t instance = 0;
|
uint32_t instance = 0;
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
|
|
||||||
switch (property)
|
switch (property) {
|
||||||
{
|
|
||||||
case PROP_OBJECT_IDENTIFIER:
|
case PROP_OBJECT_IDENTIFIER:
|
||||||
apdu_len = encode_tagged_object_id(&apdu[0], OBJECT_DEVICE,
|
apdu_len = encode_tagged_object_id(&apdu[0], OBJECT_DEVICE,
|
||||||
Object_Instance_Number);
|
Object_Instance_Number);
|
||||||
@@ -502,7 +476,8 @@ int Device_Encode_Property_APDU(
|
|||||||
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
||||||
break;
|
break;
|
||||||
case PROP_APPLICATION_SOFTWARE_VERSION:
|
case PROP_APPLICATION_SOFTWARE_VERSION:
|
||||||
characterstring_init_ansi(&char_string, Application_Software_Version);
|
characterstring_init_ansi(&char_string,
|
||||||
|
Application_Software_Version);
|
||||||
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
apdu_len = encode_tagged_character_string(&apdu[0], &char_string);
|
||||||
break;
|
break;
|
||||||
// if you support time
|
// if you support time
|
||||||
@@ -526,7 +501,8 @@ int Device_Encode_Property_APDU(
|
|||||||
// my_tm->tm_mday, ((my_tm->tm_wday == 0) ? 7 : my_tm->tm_wday));
|
// my_tm->tm_mday, ((my_tm->tm_wday == 0) ? 7 : my_tm->tm_wday));
|
||||||
//break;
|
//break;
|
||||||
case PROP_PROTOCOL_VERSION:
|
case PROP_PROTOCOL_VERSION:
|
||||||
apdu_len = encode_tagged_unsigned(&apdu[0], Device_Protocol_Version());
|
apdu_len =
|
||||||
|
encode_tagged_unsigned(&apdu[0], Device_Protocol_Version());
|
||||||
break;
|
break;
|
||||||
// BACnet Legacy Support
|
// BACnet Legacy Support
|
||||||
case PROP_PROTOCOL_CONFORMANCE_CLASS:
|
case PROP_PROTOCOL_CONFORMANCE_CLASS:
|
||||||
@@ -535,10 +511,10 @@ int Device_Encode_Property_APDU(
|
|||||||
case PROP_PROTOCOL_SERVICES_SUPPORTED:
|
case PROP_PROTOCOL_SERVICES_SUPPORTED:
|
||||||
/* Note: list of services that are executed, not initiated. */
|
/* Note: list of services that are executed, not initiated. */
|
||||||
bitstring_init(&bit_string);
|
bitstring_init(&bit_string);
|
||||||
for (i = 0; i < MAX_BACNET_SERVICES_SUPPORTED; i++)
|
for (i = 0; i < MAX_BACNET_SERVICES_SUPPORTED; i++) {
|
||||||
{
|
|
||||||
/* automatic lookup based on handlers set */
|
/* automatic lookup based on handlers set */
|
||||||
bitstring_set_bit(&bit_string, (uint8_t)i, apdu_service_supported(i));
|
bitstring_set_bit(&bit_string, (uint8_t) i,
|
||||||
|
apdu_service_supported(i));
|
||||||
}
|
}
|
||||||
apdu_len = encode_tagged_bitstring(&apdu[0], &bit_string);
|
apdu_len = encode_tagged_bitstring(&apdu[0], &bit_string);
|
||||||
break;
|
break;
|
||||||
@@ -546,8 +522,7 @@ int Device_Encode_Property_APDU(
|
|||||||
/* Note: this is the list of objects that can be in this device,
|
/* Note: this is the list of objects that can be in this device,
|
||||||
not a list of objects that this device can access */
|
not a list of objects that this device can access */
|
||||||
bitstring_init(&bit_string);
|
bitstring_init(&bit_string);
|
||||||
for (i = 0; i < MAX_ASHRAE_OBJECT_TYPE; i++)
|
for (i = 0; i < MAX_ASHRAE_OBJECT_TYPE; i++) {
|
||||||
{
|
|
||||||
// initialize all the object types to not-supported
|
// initialize all the object types to not-supported
|
||||||
bitstring_set_bit(&bit_string, (uint8_t) i, false);
|
bitstring_set_bit(&bit_string, (uint8_t) i, false);
|
||||||
}
|
}
|
||||||
@@ -569,27 +544,23 @@ int Device_Encode_Property_APDU(
|
|||||||
// into one packet. Note that more than likely you will have
|
// into one packet. Note that more than likely you will have
|
||||||
// to return an error if the number of encoded objects exceeds
|
// to return an error if the number of encoded objects exceeds
|
||||||
// your maximum APDU size.
|
// your maximum APDU size.
|
||||||
else if (array_index == BACNET_ARRAY_ALL)
|
else if (array_index == BACNET_ARRAY_ALL) {
|
||||||
{
|
for (i = 1; i <= count; i++) {
|
||||||
for (i = 1; i <= count; i++)
|
if (Device_Object_List_Identifier(i, &object_type,
|
||||||
{
|
&instance)) {
|
||||||
if (Device_Object_List_Identifier(i,&object_type,&instance))
|
len =
|
||||||
{
|
encode_tagged_object_id(&apdu[apdu_len],
|
||||||
len = encode_tagged_object_id(&apdu[apdu_len], object_type,
|
object_type, instance);
|
||||||
instance);
|
|
||||||
apdu_len += len;
|
apdu_len += len;
|
||||||
// assume next one is the same size as this one
|
// assume next one is the same size as this one
|
||||||
// can we all fit into the APDU?
|
// can we all fit into the APDU?
|
||||||
if ((apdu_len + len) >= MAX_APDU)
|
if ((apdu_len + len) >= MAX_APDU) {
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_SERVICES;
|
*error_class = ERROR_CLASS_SERVICES;
|
||||||
*error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
|
*error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT;
|
||||||
apdu_len = -1;
|
apdu_len = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// error: internal error?
|
// error: internal error?
|
||||||
*error_class = ERROR_CLASS_SERVICES;
|
*error_class = ERROR_CLASS_SERVICES;
|
||||||
*error_code = ERROR_CODE_OTHER;
|
*error_code = ERROR_CODE_OTHER;
|
||||||
@@ -597,13 +568,13 @@ int Device_Encode_Property_APDU(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (Device_Object_List_Identifier(array_index, &object_type,
|
||||||
{
|
&instance))
|
||||||
if (Device_Object_List_Identifier(array_index,&object_type,&instance))
|
apdu_len =
|
||||||
apdu_len = encode_tagged_object_id(&apdu[0], object_type, instance);
|
encode_tagged_object_id(&apdu[0], object_type,
|
||||||
else
|
instance);
|
||||||
{
|
else {
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
*error_code = ERROR_CODE_INVALID_ARRAY_INDEX;
|
||||||
apdu_len = -1;
|
apdu_len = -1;
|
||||||
@@ -622,7 +593,8 @@ int Device_Encode_Property_APDU(
|
|||||||
apdu_len = encode_tagged_unsigned(&apdu[0], APDU_Timeout);
|
apdu_len = encode_tagged_unsigned(&apdu[0], APDU_Timeout);
|
||||||
break;
|
break;
|
||||||
case PROP_NUMBER_OF_APDU_RETRIES:
|
case PROP_NUMBER_OF_APDU_RETRIES:
|
||||||
apdu_len = encode_tagged_unsigned(&apdu[0], Number_Of_APDU_Retries);
|
apdu_len =
|
||||||
|
encode_tagged_unsigned(&apdu[0], Number_Of_APDU_Retries);
|
||||||
break;
|
break;
|
||||||
case PROP_DEVICE_ADDRESS_BINDING:
|
case PROP_DEVICE_ADDRESS_BINDING:
|
||||||
/* encode the list here, if it exists */
|
/* encode the list here, if it exists */
|
||||||
@@ -641,125 +613,102 @@ int Device_Encode_Property_APDU(
|
|||||||
extern bool I_Am_Request;
|
extern bool I_Am_Request;
|
||||||
|
|
||||||
// returns true if successful
|
// returns true if successful
|
||||||
bool Device_Write_Property(
|
bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||||
BACNET_WRITE_PROPERTY_DATA *wp_data,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code)
|
||||||
BACNET_ERROR_CLASS *error_class,
|
|
||||||
BACNET_ERROR_CODE *error_code)
|
|
||||||
{
|
{
|
||||||
bool status = false; // return value
|
bool status = false; // return value
|
||||||
|
|
||||||
if (!Device_Valid_Object_Instance_Number(wp_data->object_instance))
|
if (!Device_Valid_Object_Instance_Number(wp_data->object_instance)) {
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_OBJECT;
|
*error_class = ERROR_CLASS_OBJECT;
|
||||||
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
*error_code = ERROR_CODE_UNKNOWN_OBJECT;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode the some of the request
|
// decode the some of the request
|
||||||
switch (wp_data->object_property)
|
switch (wp_data->object_property) {
|
||||||
{
|
|
||||||
case PROP_OBJECT_IDENTIFIER:
|
case PROP_OBJECT_IDENTIFIER:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_OBJECT_ID)
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
|
||||||
{
|
|
||||||
if ((wp_data->value.type.Object_Id.type == OBJECT_DEVICE) &&
|
if ((wp_data->value.type.Object_Id.type == OBJECT_DEVICE) &&
|
||||||
(Device_Set_Object_Instance_Number(
|
(Device_Set_Object_Instance_Number(wp_data->value.type.
|
||||||
wp_data->value.type.Object_Id.instance)))
|
Object_Id.instance))) {
|
||||||
{
|
|
||||||
I_Am_Request = true;
|
I_Am_Request = true;
|
||||||
status = true;
|
status = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
*error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_NUMBER_OF_APDU_RETRIES:
|
case PROP_NUMBER_OF_APDU_RETRIES:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||||
{
|
|
||||||
/* FIXME: bounds check? */
|
/* FIXME: bounds check? */
|
||||||
Device_Set_Number_Of_APDU_Retries((uint8_t)wp_data->value.type.Unsigned_Int);
|
Device_Set_Number_Of_APDU_Retries((uint8_t) wp_data->value.
|
||||||
|
type.Unsigned_Int);
|
||||||
status = true;
|
status = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_APDU_TIMEOUT:
|
case PROP_APDU_TIMEOUT:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||||
{
|
|
||||||
/* FIXME: bounds check? */
|
/* FIXME: bounds check? */
|
||||||
Device_Set_APDU_Timeout((uint16_t)wp_data->value.type.Unsigned_Int);
|
Device_Set_APDU_Timeout((uint16_t) wp_data->value.type.
|
||||||
|
Unsigned_Int);
|
||||||
status = true;
|
status = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_VENDOR_IDENTIFIER:
|
case PROP_VENDOR_IDENTIFIER:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) {
|
||||||
{
|
|
||||||
/* FIXME: bounds check? */
|
/* FIXME: bounds check? */
|
||||||
Device_Set_Vendor_Identifier((uint16_t)wp_data->value.type.Unsigned_Int);
|
Device_Set_Vendor_Identifier((uint16_t) wp_data->value.type.
|
||||||
|
Unsigned_Int);
|
||||||
status = true;
|
status = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_SYSTEM_STATUS:
|
case PROP_SYSTEM_STATUS:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_ENUMERATED)
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
|
||||||
{
|
|
||||||
Device_Set_System_Status(wp_data->value.type.Enumerated);
|
Device_Set_System_Status(wp_data->value.type.Enumerated);
|
||||||
status = true;
|
status = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_OBJECT_NAME:
|
case PROP_OBJECT_NAME:
|
||||||
if (wp_data->value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING)
|
if (wp_data->value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
|
||||||
{
|
|
||||||
uint8_t encoding;
|
uint8_t encoding;
|
||||||
encoding = characterstring_encoding(&wp_data->value.type.Character_String);
|
encoding =
|
||||||
if (encoding == CHARACTER_ANSI_X34)
|
characterstring_encoding(&wp_data->value.type.
|
||||||
{
|
Character_String);
|
||||||
status = Device_Set_Object_Name(
|
if (encoding == CHARACTER_ANSI_X34) {
|
||||||
characterstring_value(&wp_data->value.type.Character_String),
|
status =
|
||||||
characterstring_length(&wp_data->value.type.Character_String));
|
Device_Set_Object_Name(characterstring_value(&wp_data->
|
||||||
if (!status)
|
value.type.Character_String),
|
||||||
{
|
characterstring_length(&wp_data->value.type.
|
||||||
|
Character_String));
|
||||||
|
if (!status) {
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
|
*error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED;
|
*error_code = ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*error_class = ERROR_CLASS_PROPERTY;
|
*error_class = ERROR_CLASS_PROPERTY;
|
||||||
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
|
||||||
}
|
}
|
||||||
@@ -791,10 +740,12 @@ void testDevice(Test * pTest)
|
|||||||
ct_test(pTest, Device_Object_Instance_Number() == BACNET_MAX_INSTANCE);
|
ct_test(pTest, Device_Object_Instance_Number() == BACNET_MAX_INSTANCE);
|
||||||
ct_test(pTest, status == true);
|
ct_test(pTest, status == true);
|
||||||
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2);
|
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2);
|
||||||
ct_test(pTest, Device_Object_Instance_Number() == (BACNET_MAX_INSTANCE/2));
|
ct_test(pTest,
|
||||||
|
Device_Object_Instance_Number() == (BACNET_MAX_INSTANCE / 2));
|
||||||
ct_test(pTest, status == true);
|
ct_test(pTest, status == true);
|
||||||
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1);
|
status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1);
|
||||||
ct_test(pTest, Device_Object_Instance_Number() != (BACNET_MAX_INSTANCE+1));
|
ct_test(pTest,
|
||||||
|
Device_Object_Instance_Number() != (BACNET_MAX_INSTANCE + 1));
|
||||||
ct_test(pTest, status == false);
|
ct_test(pTest, status == false);
|
||||||
|
|
||||||
|
|
||||||
@@ -866,5 +817,3 @@ int main(void)
|
|||||||
}
|
}
|
||||||
#endif /* TEST_DEVICE */
|
#endif /* TEST_DEVICE */
|
||||||
#endif /* TEST */
|
#endif /* TEST */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ bool Device_Set_Object_Instance_Number(uint32_t object_id);
|
|||||||
bool Device_Valid_Object_Instance_Number(uint32_t object_id);
|
bool Device_Valid_Object_Instance_Number(uint32_t object_id);
|
||||||
unsigned Device_Object_List_Count(void);
|
unsigned Device_Object_List_Count(void);
|
||||||
bool Device_Object_List_Identifier(unsigned array_index,
|
bool Device_Object_List_Identifier(unsigned array_index,
|
||||||
int *object_type,
|
int *object_type, uint32_t * instance);
|
||||||
uint32_t *instance);
|
|
||||||
|
|
||||||
BACNET_DEVICE_STATUS Device_System_Status(void);
|
BACNET_DEVICE_STATUS Device_System_Status(void);
|
||||||
void Device_Set_System_Status(BACNET_DEVICE_STATUS status);
|
void Device_Set_System_Status(BACNET_DEVICE_STATUS status);
|
||||||
@@ -68,7 +67,8 @@ const char *Device_Firmware_Revision(void);
|
|||||||
bool Device_Set_Firmware_Revision(const char *name, size_t length);
|
bool Device_Set_Firmware_Revision(const char *name, size_t length);
|
||||||
|
|
||||||
const char *Device_Application_Software_Version(void);
|
const char *Device_Application_Software_Version(void);
|
||||||
bool Device_Set_Application_Software_Version(const char *name, size_t length);
|
bool Device_Set_Application_Software_Version(const char *name,
|
||||||
|
size_t length);
|
||||||
|
|
||||||
const char *Device_Description(void);
|
const char *Device_Description(void);
|
||||||
bool Device_Set_Description(const char *name, size_t length);
|
bool Device_Set_Description(const char *name, size_t length);
|
||||||
@@ -91,29 +91,20 @@ void Device_Set_Number_Of_APDU_Retries(uint8_t retries);
|
|||||||
uint8_t Device_Database_Revision(void);
|
uint8_t Device_Database_Revision(void);
|
||||||
void Device_Set_Database_Revision(uint8_t revision);
|
void Device_Set_Database_Revision(uint8_t revision);
|
||||||
|
|
||||||
bool Device_Valid_Object_Name(
|
bool Device_Valid_Object_Name(const char *object_name,
|
||||||
const char *object_name,
|
int *object_type, uint32_t * object_instance);
|
||||||
int *object_type,
|
char *Device_Valid_Object_Id(int object_type,
|
||||||
uint32_t *object_instance);
|
|
||||||
char *Device_Valid_Object_Id(
|
|
||||||
int object_type,
|
|
||||||
uint32_t object_instance);
|
uint32_t object_instance);
|
||||||
|
|
||||||
int Device_Encode_Property_APDU(
|
int Device_Encode_Property_APDU(uint8_t * apdu,
|
||||||
uint8_t *apdu,
|
|
||||||
BACNET_PROPERTY_ID property,
|
BACNET_PROPERTY_ID property,
|
||||||
int32_t array_index,
|
int32_t array_index,
|
||||||
BACNET_ERROR_CLASS *error_class,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
|
||||||
BACNET_ERROR_CODE *error_code);
|
|
||||||
|
|
||||||
bool Device_Write_Property(
|
bool Device_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data,
|
||||||
BACNET_WRITE_PROPERTY_DATA *wp_data,
|
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CODE * error_code);
|
||||||
BACNET_ERROR_CLASS *error_class,
|
|
||||||
BACNET_ERROR_CODE *error_code);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -60,27 +60,21 @@ static bool End_Of_File_Detected = false;
|
|||||||
static bool Error_Detected = false;
|
static bool Error_Detected = false;
|
||||||
static uint8_t Current_Invoke_ID = 0;
|
static uint8_t Current_Invoke_ID = 0;
|
||||||
|
|
||||||
static void Atomic_Read_File_Error_Handler(
|
static void Atomic_Read_File_Error_Handler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
uint8_t invoke_id,
|
uint8_t invoke_id,
|
||||||
BACNET_ERROR_CLASS error_class,
|
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code)
|
||||||
BACNET_ERROR_CODE error_code)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
(void) invoke_id;
|
(void) invoke_id;
|
||||||
printf("\r\nBACnet Error!\r\n");
|
printf("\r\nBACnet Error!\r\n");
|
||||||
printf("Error Class: %s\r\n",
|
printf("Error Class: %s\r\n", bactext_error_class_name(error_class));
|
||||||
bactext_error_class_name(error_class));
|
printf("Error Code: %s\r\n", bactext_error_code_name(error_code));
|
||||||
printf("Error Code: %s\r\n",
|
|
||||||
bactext_error_code_name(error_code));
|
|
||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAbortHandler(
|
void MyAbortHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t abort_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t abort_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -91,10 +85,8 @@ void MyAbortHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyRejectHandler(
|
void MyRejectHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t reject_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t reject_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -105,11 +97,9 @@ void MyRejectHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t Send_Atomic_Read_File_Stream(
|
static uint8_t Send_Atomic_Read_File_Stream(uint32_t device_id,
|
||||||
uint32_t device_id,
|
|
||||||
uint32_t file_instance,
|
uint32_t file_instance,
|
||||||
int fileStartPosition,
|
int fileStartPosition, unsigned requestedOctetCount)
|
||||||
unsigned requestedOctetCount)
|
|
||||||
{
|
{
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
@@ -125,14 +115,9 @@ static uint8_t Send_Atomic_Read_File_Stream(
|
|||||||
/* is there a tsm available? */
|
/* is there a tsm available? */
|
||||||
if (status)
|
if (status)
|
||||||
status = tsm_transaction_available();
|
status = tsm_transaction_available();
|
||||||
if (status)
|
if (status) {
|
||||||
{
|
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
&my_address,
|
|
||||||
true, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
invoke_id = tsm_next_free_invokeID();
|
invoke_id = tsm_next_free_invokeID();
|
||||||
@@ -142,31 +127,23 @@ static uint8_t Send_Atomic_Read_File_Stream(
|
|||||||
data.access = FILE_STREAM_ACCESS;
|
data.access = FILE_STREAM_ACCESS;
|
||||||
data.type.stream.fileStartPosition = fileStartPosition;
|
data.type.stream.fileStartPosition = fileStartPosition;
|
||||||
data.type.stream.requestedOctetCount = requestedOctetCount;
|
data.type.stream.requestedOctetCount = requestedOctetCount;
|
||||||
pdu_len += arf_encode_apdu(
|
pdu_len += arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
invoke_id, &data);
|
||||||
invoke_id,
|
|
||||||
&data);
|
|
||||||
/* will the APDU fit the target device?
|
/* will the APDU fit the target device?
|
||||||
note: if there is a bottleneck router in between
|
note: if there is a bottleneck router in between
|
||||||
us and the destination, we won't know unless
|
us and the destination, we won't know unless
|
||||||
we have a way to check for that and update the
|
we have a way to check for that and update the
|
||||||
max_apdu in the address binding table. */
|
max_apdu in the address binding table. */
|
||||||
if ((unsigned)pdu_len < max_apdu)
|
if ((unsigned) pdu_len < max_apdu) {
|
||||||
{
|
tsm_set_confirmed_unsegmented_transaction(invoke_id,
|
||||||
tsm_set_confirmed_unsegmented_transaction(
|
&dest, &Handler_Transmit_Buffer[0], pdu_len);
|
||||||
invoke_id,
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest,
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len);
|
|
||||||
bytes_sent = datalink_send_pdu(
|
|
||||||
&dest, // destination address
|
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send AtomicReadFile Request (%s)!\n",
|
fprintf(stderr,
|
||||||
|
"Failed to Send AtomicReadFile Request (%s)!\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
fprintf(stderr, "Failed to Send AtomicReadFile Request "
|
fprintf(stderr, "Failed to Send AtomicReadFile Request "
|
||||||
"(payload exceeds destination maximum APDU)!\n");
|
"(payload exceeds destination maximum APDU)!\n");
|
||||||
}
|
}
|
||||||
@@ -184,32 +161,23 @@ static void Send_WhoIs(uint32_t device_id)
|
|||||||
datalink_get_broadcast_address(&dest);
|
datalink_get_broadcast_address(&dest);
|
||||||
|
|
||||||
/* encode the NPDU portion of the packet */
|
/* encode the NPDU portion of the packet */
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
NULL,
|
|
||||||
false, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
/* encode the APDU portion of the packet */
|
/* encode the APDU portion of the packet */
|
||||||
pdu_len += whois_encode_apdu(
|
pdu_len += whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
device_id, device_id);
|
||||||
device_id,
|
|
||||||
device_id);
|
|
||||||
|
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(&dest, /* destination address */
|
||||||
&dest, /* destination address */
|
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); /* number of bytes of data */
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send Who-Is Request (%s)!\n", strerror(errno));
|
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AtomicReadFileAckHandler(
|
static void AtomicReadFileAckHandler(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
|
||||||
uint16_t service_len,
|
uint16_t service_len,
|
||||||
BACNET_ADDRESS *src,
|
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data)
|
||||||
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
BACNET_ATOMIC_READ_FILE_DATA data;
|
BACNET_ATOMIC_READ_FILE_DATA data;
|
||||||
@@ -217,39 +185,33 @@ static void AtomicReadFileAckHandler(
|
|||||||
size_t octets_written = 0;
|
size_t octets_written = 0;
|
||||||
|
|
||||||
(void) src; /* FIXME: validate the source address matches */
|
(void) src; /* FIXME: validate the source address matches */
|
||||||
len = arf_ack_decode_service_request(
|
len = arf_ack_decode_service_request(service_request,
|
||||||
service_request,
|
service_len, &data);
|
||||||
service_len,
|
if (len > 0) {
|
||||||
&data);
|
|
||||||
if (len > 0)
|
|
||||||
{
|
|
||||||
/* validate the parameters before storing data */
|
/* validate the parameters before storing data */
|
||||||
if ((data.access == FILE_STREAM_ACCESS) &&
|
if ((data.access == FILE_STREAM_ACCESS) &&
|
||||||
(service_data->invoke_id == Current_Invoke_ID))
|
(service_data->invoke_id == Current_Invoke_ID)) {
|
||||||
{
|
|
||||||
if (data.type.stream.fileStartPosition == 0)
|
if (data.type.stream.fileStartPosition == 0)
|
||||||
pFile = fopen(Local_File_Name, "wb");
|
pFile = fopen(Local_File_Name, "wb");
|
||||||
else
|
else
|
||||||
pFile = fopen(Local_File_Name, "rb+");
|
pFile = fopen(Local_File_Name, "rb+");
|
||||||
if (pFile)
|
if (pFile) {
|
||||||
{
|
|
||||||
/* is there anything to do with this? data.stream.requestedOctetCount */
|
/* is there anything to do with this? data.stream.requestedOctetCount */
|
||||||
(void)fseek(pFile, data.type.stream.fileStartPosition, SEEK_SET);
|
(void) fseek(pFile, data.type.stream.fileStartPosition,
|
||||||
octets_written = fwrite(
|
SEEK_SET);
|
||||||
octetstring_value(&data.fileData),
|
octets_written = fwrite(octetstring_value(&data.fileData), 1, /* unit to write in bytes - in our case, an octet is one byte */
|
||||||
1, /* unit to write in bytes - in our case, an octet is one byte */
|
octetstring_length(&data.fileData), pFile);
|
||||||
octetstring_length(&data.fileData),
|
|
||||||
pFile);
|
|
||||||
if (octets_written != octetstring_length(&data.fileData))
|
if (octets_written != octetstring_length(&data.fileData))
|
||||||
fprintf(stderr,"Unable to write data to file \"%s\".\n",
|
fprintf(stderr,
|
||||||
|
"Unable to write data to file \"%s\".\n",
|
||||||
Local_File_Name);
|
Local_File_Name);
|
||||||
else
|
else
|
||||||
printf("\r%u bytes",
|
printf("\r%u bytes",
|
||||||
(data.type.stream.fileStartPosition + octets_written));
|
(data.type.stream.fileStartPosition +
|
||||||
|
octets_written));
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
}
|
}
|
||||||
if (data.endOfFile)
|
if (data.endOfFile) {
|
||||||
{
|
|
||||||
End_Of_File_Detected = true;
|
End_Of_File_Detected = true;
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
}
|
}
|
||||||
@@ -257,10 +219,8 @@ static void AtomicReadFileAckHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LocalIAmHandler(
|
static void LocalIAmHandler(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src)
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
uint32_t device_id = 0;
|
uint32_t device_id = 0;
|
||||||
@@ -270,19 +230,11 @@ static void LocalIAmHandler(
|
|||||||
|
|
||||||
(void) src;
|
(void) src;
|
||||||
(void) service_len;
|
(void) service_len;
|
||||||
len = iam_decode_service_request(
|
len = iam_decode_service_request(service_request,
|
||||||
service_request,
|
&device_id, &max_apdu, &segmentation, &vendor_id);
|
||||||
&device_id,
|
if (len != -1) {
|
||||||
&max_apdu,
|
address_add(device_id, max_apdu, src);
|
||||||
&segmentation,
|
} else
|
||||||
&vendor_id);
|
|
||||||
if (len != -1)
|
|
||||||
{
|
|
||||||
address_add(device_id,
|
|
||||||
max_apdu,
|
|
||||||
src);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fprintf(stderr, "!\n");
|
fprintf(stderr, "!\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -292,33 +244,26 @@ static void Init_Service_Handlers(void)
|
|||||||
{
|
{
|
||||||
/* we need to handle who-is
|
/* we need to handle who-is
|
||||||
to support dynamic device binding to us */
|
to support dynamic device binding to us */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
handler_who_is);
|
handler_who_is);
|
||||||
/* handle i-am to support binding to other devices */
|
/* handle i-am to support binding to other devices */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM,
|
||||||
SERVICE_UNCONFIRMED_I_AM,
|
|
||||||
LocalIAmHandler);
|
LocalIAmHandler);
|
||||||
/* set the handler for all the services we don't implement
|
/* set the handler for all the services we don't implement
|
||||||
It is required to send the proper reject message... */
|
It is required to send the proper reject message... */
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
handler_unrecognized_service);
|
(handler_unrecognized_service);
|
||||||
/* we must implement read property - it's required! */
|
/* we must implement read property - it's required! */
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property);
|
handler_read_property);
|
||||||
/* handle the data coming back from confirmed requests */
|
/* handle the data coming back from confirmed requests */
|
||||||
apdu_set_confirmed_ack_handler(
|
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
||||||
SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
|
||||||
AtomicReadFileAckHandler);
|
AtomicReadFileAckHandler);
|
||||||
/* handle any errors coming back */
|
/* handle any errors coming back */
|
||||||
apdu_set_error_handler(
|
apdu_set_error_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
||||||
SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
|
||||||
Atomic_Read_File_Error_Handler);
|
Atomic_Read_File_Error_Handler);
|
||||||
apdu_set_abort_handler(
|
apdu_set_abort_handler(MyAbortHandler);
|
||||||
MyAbortHandler);
|
apdu_set_reject_handler(MyRejectHandler);
|
||||||
apdu_set_reject_handler(
|
|
||||||
MyRejectHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -337,8 +282,7 @@ int main(int argc, char *argv[])
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
uint16_t my_max_apdu = 0;
|
uint16_t my_max_apdu = 0;
|
||||||
|
|
||||||
if (argc < 4)
|
if (argc < 4) {
|
||||||
{
|
|
||||||
/* FIXME: what about access method - record or stream? */
|
/* FIXME: what about access method - record or stream? */
|
||||||
printf("%s device-instance file-instance local-name\r\n",
|
printf("%s device-instance file-instance local-name\r\n",
|
||||||
filename_remove_path(argv[0]));
|
filename_remove_path(argv[0]));
|
||||||
@@ -348,14 +292,12 @@ int main(int argc, char *argv[])
|
|||||||
Target_Device_Object_Instance = strtol(argv[1], NULL, 0);
|
Target_Device_Object_Instance = strtol(argv[1], NULL, 0);
|
||||||
Target_File_Object_Instance = strtol(argv[2], NULL, 0);
|
Target_File_Object_Instance = strtol(argv[2], NULL, 0);
|
||||||
Local_File_Name = argv[3];
|
Local_File_Name = argv[3];
|
||||||
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE)
|
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
||||||
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_File_Object_Instance >= BACNET_MAX_INSTANCE)
|
if (Target_File_Object_Instance >= BACNET_MAX_INSTANCE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "file-instance=%u - it must be less than %u\r\n",
|
fprintf(stderr, "file-instance=%u - it must be less than %u\r\n",
|
||||||
Target_File_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
Target_File_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -376,45 +318,31 @@ int main(int argc, char *argv[])
|
|||||||
/* try to bind with the device */
|
/* try to bind with the device */
|
||||||
Send_WhoIs(Target_Device_Object_Instance);
|
Send_WhoIs(Target_Device_Object_Instance);
|
||||||
/* loop forever */
|
/* loop forever */
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
current_seconds = time(NULL);
|
current_seconds = time(NULL);
|
||||||
|
|
||||||
/* returns 0 bytes on timeout */
|
/* returns 0 bytes on timeout */
|
||||||
pdu_len = bip_receive(
|
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
|
|
||||||
/* process */
|
/* process */
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
/* at least one second has passed */
|
/* at least one second has passed */
|
||||||
if (current_seconds != last_seconds)
|
if (current_seconds != last_seconds)
|
||||||
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
|
tsm_timer_milliseconds(((current_seconds -
|
||||||
|
last_seconds) * 1000));
|
||||||
if (End_Of_File_Detected || Error_Detected)
|
if (End_Of_File_Detected || Error_Detected)
|
||||||
break;
|
break;
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
iam_send(&Handler_Transmit_Buffer[0]);
|
iam_send(&Handler_Transmit_Buffer[0]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* wait until the device is bound, or timeout and quit */
|
/* wait until the device is bound, or timeout and quit */
|
||||||
found = address_bind_request(
|
found = address_bind_request(Target_Device_Object_Instance,
|
||||||
Target_Device_Object_Instance,
|
&max_apdu, &Target_Address);
|
||||||
&max_apdu,
|
if (found) {
|
||||||
&Target_Address);
|
|
||||||
if (found)
|
|
||||||
{
|
|
||||||
/* calculate the smaller of our APDU size or theirs
|
/* calculate the smaller of our APDU size or theirs
|
||||||
and remove the overhead of the APDU (about 16 octets max).
|
and remove the overhead of the APDU (about 16 octets max).
|
||||||
note: we could fail if there is a bottle neck (router)
|
note: we could fail if there is a bottle neck (router)
|
||||||
@@ -426,22 +354,19 @@ int main(int argc, char *argv[])
|
|||||||
requestedOctetCount = my_max_apdu - 16;
|
requestedOctetCount = my_max_apdu - 16;
|
||||||
/* has the previous invoke id expired or returned?
|
/* has the previous invoke id expired or returned?
|
||||||
note: invoke ID = 0 is invalid, so it will be idle */
|
note: invoke ID = 0 is invalid, so it will be idle */
|
||||||
if ((invoke_id == 0) || tsm_invoke_id_free(invoke_id))
|
if ((invoke_id == 0) || tsm_invoke_id_free(invoke_id)) {
|
||||||
{
|
|
||||||
if (invoke_id != 0)
|
if (invoke_id != 0)
|
||||||
fileStartPosition += requestedOctetCount;
|
fileStartPosition += requestedOctetCount;
|
||||||
/* we'll read the file in chunks
|
/* we'll read the file in chunks
|
||||||
less than max_apdu to keep unsegmented */
|
less than max_apdu to keep unsegmented */
|
||||||
invoke_id = Send_Atomic_Read_File_Stream(
|
invoke_id =
|
||||||
Target_Device_Object_Instance,
|
Send_Atomic_Read_File_Stream
|
||||||
Target_File_Object_Instance,
|
(Target_Device_Object_Instance,
|
||||||
fileStartPosition,
|
Target_File_Object_Instance, fileStartPosition,
|
||||||
requestedOctetCount);
|
requestedOctetCount);
|
||||||
Current_Invoke_ID = invoke_id;
|
Current_Invoke_ID = invoke_id;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
elapsed_seconds += (current_seconds - last_seconds);
|
elapsed_seconds += (current_seconds - last_seconds);
|
||||||
if (elapsed_seconds > timeout_seconds)
|
if (elapsed_seconds > timeout_seconds)
|
||||||
|
|||||||
@@ -62,11 +62,9 @@ static int32_t Target_Object_Index = BACNET_ARRAY_ALL;
|
|||||||
static BACNET_ADDRESS Target_Address;
|
static BACNET_ADDRESS Target_Address;
|
||||||
static bool Error_Detected = false;
|
static bool Error_Detected = false;
|
||||||
|
|
||||||
static void MyErrorHandler(
|
static void MyErrorHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
uint8_t invoke_id,
|
uint8_t invoke_id,
|
||||||
BACNET_ERROR_CLASS error_class,
|
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code)
|
||||||
BACNET_ERROR_CODE error_code)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -77,10 +75,8 @@ static void MyErrorHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAbortHandler(
|
void MyAbortHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t abort_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t abort_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -90,10 +86,8 @@ void MyAbortHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyRejectHandler(
|
void MyRejectHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t reject_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t reject_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -107,33 +101,26 @@ static void Init_Service_Handlers(void)
|
|||||||
{
|
{
|
||||||
/* we need to handle who-is
|
/* we need to handle who-is
|
||||||
to support dynamic device binding to us */
|
to support dynamic device binding to us */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
handler_who_is);
|
handler_who_is);
|
||||||
/* handle i-am to support binding to other devices */
|
/* handle i-am to support binding to other devices */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM,
|
||||||
SERVICE_UNCONFIRMED_I_AM,
|
|
||||||
handler_i_am_bind);
|
handler_i_am_bind);
|
||||||
/* set the handler for all the services we don't implement
|
/* set the handler for all the services we don't implement
|
||||||
It is required to send the proper reject message... */
|
It is required to send the proper reject message... */
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
handler_unrecognized_service);
|
(handler_unrecognized_service);
|
||||||
/* we must implement read property - it's required! */
|
/* we must implement read property - it's required! */
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property);
|
handler_read_property);
|
||||||
/* handle the data coming back from confirmed requests */
|
/* handle the data coming back from confirmed requests */
|
||||||
apdu_set_confirmed_ack_handler(
|
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property_ack);
|
handler_read_property_ack);
|
||||||
/* handle any errors coming back */
|
/* handle any errors coming back */
|
||||||
apdu_set_error_handler(
|
apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
MyErrorHandler);
|
MyErrorHandler);
|
||||||
apdu_set_abort_handler(
|
apdu_set_abort_handler(MyAbortHandler);
|
||||||
MyAbortHandler);
|
apdu_set_reject_handler(MyRejectHandler);
|
||||||
apdu_set_reject_handler(
|
|
||||||
MyRejectHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -149,9 +136,9 @@ int main(int argc, char *argv[])
|
|||||||
uint8_t invoke_id = 0;
|
uint8_t invoke_id = 0;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
if (argc < 5)
|
if (argc < 5) {
|
||||||
{
|
printf
|
||||||
printf("%s device-instance object-type object-instance property [index]\r\n",
|
("%s device-instance object-type object-instance property [index]\r\n",
|
||||||
filename_remove_path(argv[0]));
|
filename_remove_path(argv[0]));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -162,26 +149,22 @@ int main(int argc, char *argv[])
|
|||||||
Target_Object_Property = strtol(argv[4], NULL, 0);
|
Target_Object_Property = strtol(argv[4], NULL, 0);
|
||||||
if (argc > 5)
|
if (argc > 5)
|
||||||
Target_Object_Index = strtol(argv[5], NULL, 0);
|
Target_Object_Index = strtol(argv[5], NULL, 0);
|
||||||
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE)
|
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
||||||
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_Object_Type > MAX_BACNET_OBJECT_TYPE)
|
if (Target_Object_Type > MAX_BACNET_OBJECT_TYPE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
||||||
Target_Object_Type, MAX_BACNET_OBJECT_TYPE + 1);
|
Target_Object_Type, MAX_BACNET_OBJECT_TYPE + 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_Object_Instance > BACNET_MAX_INSTANCE)
|
if (Target_Object_Instance > BACNET_MAX_INSTANCE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "object-instance=%u - it must be less than %u\r\n",
|
fprintf(stderr, "object-instance=%u - it must be less than %u\r\n",
|
||||||
Target_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
Target_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_Object_Property > MAX_BACNET_PROPERTY_ID)
|
if (Target_Object_Property > MAX_BACNET_PROPERTY_ID) {
|
||||||
{
|
|
||||||
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
||||||
Target_Object_Property, MAX_BACNET_PROPERTY_ID + 1);
|
Target_Object_Property, MAX_BACNET_PROPERTY_ID + 1);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -203,61 +186,43 @@ int main(int argc, char *argv[])
|
|||||||
/* no need to spam the world */
|
/* no need to spam the world */
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
/* try to bind with the device */
|
/* try to bind with the device */
|
||||||
Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance);
|
Send_WhoIs(Target_Device_Object_Instance,
|
||||||
|
Target_Device_Object_Instance);
|
||||||
/* loop forever */
|
/* loop forever */
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
current_seconds = time(NULL);
|
current_seconds = time(NULL);
|
||||||
|
|
||||||
/* returns 0 bytes on timeout */
|
/* returns 0 bytes on timeout */
|
||||||
pdu_len = bip_receive(
|
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
|
|
||||||
/* process */
|
/* process */
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
/* at least one second has passed */
|
/* at least one second has passed */
|
||||||
if (current_seconds != last_seconds)
|
if (current_seconds != last_seconds)
|
||||||
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
|
tsm_timer_milliseconds(((current_seconds -
|
||||||
|
last_seconds) * 1000));
|
||||||
if (Error_Detected)
|
if (Error_Detected)
|
||||||
break;
|
break;
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
iam_send(&Handler_Transmit_Buffer[0]);
|
iam_send(&Handler_Transmit_Buffer[0]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* wait until the device is bound, or timeout and quit */
|
/* wait until the device is bound, or timeout and quit */
|
||||||
found = address_bind_request(
|
found = address_bind_request(Target_Device_Object_Instance,
|
||||||
Target_Device_Object_Instance,
|
&max_apdu, &Target_Address);
|
||||||
&max_apdu,
|
if (found) {
|
||||||
&Target_Address);
|
if (invoke_id == 0) {
|
||||||
if (found)
|
invoke_id =
|
||||||
{
|
Send_Read_Property_Request
|
||||||
if (invoke_id == 0)
|
(Target_Device_Object_Instance, Target_Object_Type,
|
||||||
{
|
Target_Object_Instance, Target_Object_Property,
|
||||||
invoke_id = Send_Read_Property_Request(
|
|
||||||
Target_Device_Object_Instance,
|
|
||||||
Target_Object_Type,
|
|
||||||
Target_Object_Instance,
|
|
||||||
Target_Object_Property,
|
|
||||||
Target_Object_Index);
|
Target_Object_Index);
|
||||||
}
|
} else if (tsm_invoke_id_free(invoke_id))
|
||||||
else if (tsm_invoke_id_free(invoke_id))
|
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
elapsed_seconds += (current_seconds - last_seconds);
|
elapsed_seconds += (current_seconds - last_seconds);
|
||||||
if (elapsed_seconds > timeout_seconds)
|
if (elapsed_seconds > timeout_seconds)
|
||||||
|
|||||||
@@ -56,16 +56,15 @@ static uint8_t Rx_Buf[MAX_MPDU] = {0};
|
|||||||
/* global variables used in this file */
|
/* global variables used in this file */
|
||||||
static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE;
|
static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE;
|
||||||
static BACNET_ADDRESS Target_Address;
|
static BACNET_ADDRESS Target_Address;
|
||||||
static BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_COLDSTART;
|
static BACNET_REINITIALIZED_STATE Reinitialize_State =
|
||||||
|
BACNET_REINIT_COLDSTART;
|
||||||
static char *Reinitialize_Password = NULL;
|
static char *Reinitialize_Password = NULL;
|
||||||
|
|
||||||
static bool Error_Detected = false;
|
static bool Error_Detected = false;
|
||||||
|
|
||||||
static void MyErrorHandler(
|
static void MyErrorHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
uint8_t invoke_id,
|
uint8_t invoke_id,
|
||||||
BACNET_ERROR_CLASS error_class,
|
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code)
|
||||||
BACNET_ERROR_CODE error_code)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -76,10 +75,8 @@ static void MyErrorHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAbortHandler(
|
void MyAbortHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t abort_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t abort_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -89,10 +86,8 @@ void MyAbortHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyRejectHandler(
|
void MyRejectHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t reject_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t reject_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -102,8 +97,7 @@ void MyRejectHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyReinitializeDeviceSimpleAckHandler(
|
void MyReinitializeDeviceSimpleAckHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
uint8_t invoke_id)
|
uint8_t invoke_id)
|
||||||
{
|
{
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -115,47 +109,37 @@ static void Init_Service_Handlers(void)
|
|||||||
{
|
{
|
||||||
/* we need to handle who-is
|
/* we need to handle who-is
|
||||||
to support dynamic device binding to us */
|
to support dynamic device binding to us */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
handler_who_is);
|
handler_who_is);
|
||||||
/* handle i-am to support binding to other devices */
|
/* handle i-am to support binding to other devices */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM,
|
||||||
SERVICE_UNCONFIRMED_I_AM,
|
|
||||||
handler_i_am_bind);
|
handler_i_am_bind);
|
||||||
/* set the handler for all the services we don't implement
|
/* set the handler for all the services we don't implement
|
||||||
It is required to send the proper reject message... */
|
It is required to send the proper reject message... */
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
handler_unrecognized_service);
|
(handler_unrecognized_service);
|
||||||
/* we must implement read property - it's required! */
|
/* we must implement read property - it's required! */
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property);
|
handler_read_property);
|
||||||
/* handle the ack coming back */
|
/* handle the ack coming back */
|
||||||
apdu_set_confirmed_simple_ack_handler(
|
apdu_set_confirmed_simple_ack_handler
|
||||||
SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
(SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
||||||
MyReinitializeDeviceSimpleAckHandler);
|
MyReinitializeDeviceSimpleAckHandler);
|
||||||
/* handle any errors coming back */
|
/* handle any errors coming back */
|
||||||
apdu_set_error_handler(
|
apdu_set_error_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
||||||
SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
|
||||||
MyErrorHandler);
|
MyErrorHandler);
|
||||||
apdu_set_abort_handler(
|
apdu_set_abort_handler(MyAbortHandler);
|
||||||
MyAbortHandler);
|
apdu_set_reject_handler(MyRejectHandler);
|
||||||
apdu_set_reject_handler(
|
|
||||||
MyRejectHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BIP_DEBUG
|
#ifdef BIP_DEBUG
|
||||||
static void print_address(
|
static void print_address(char *name, BACNET_ADDRESS * dest) // destination address
|
||||||
char *name,
|
|
||||||
BACNET_ADDRESS *dest) // destination address
|
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
|
|
||||||
if (dest)
|
if (dest) {
|
||||||
{
|
|
||||||
printf("%s: ", name);
|
printf("%s: ", name);
|
||||||
for (i = 0; i < dest->mac_len; i++)
|
for (i = 0; i < dest->mac_len; i++) {
|
||||||
{
|
|
||||||
printf("%02X", dest->mac[i]);
|
printf("%02X", dest->mac[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@@ -179,11 +163,9 @@ int main(int argc, char *argv[])
|
|||||||
BACNET_ADDRESS my_address, broadcast_address;
|
BACNET_ADDRESS my_address, broadcast_address;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3) {
|
||||||
{
|
|
||||||
/* note: priority 16 and 0 should produce the same end results... */
|
/* note: priority 16 and 0 should produce the same end results... */
|
||||||
printf(
|
printf("Usage: %s device-instance state [password]\r\n"
|
||||||
"Usage: %s device-instance state [password]\r\n"
|
|
||||||
"Send BACnet ReinitializeDevice service to device.\r\n"
|
"Send BACnet ReinitializeDevice service to device.\r\n"
|
||||||
"\r\n"
|
"\r\n"
|
||||||
"The device-instance can be 0 to %d.\r\n"
|
"The device-instance can be 0 to %d.\r\n"
|
||||||
@@ -196,8 +178,7 @@ int main(int argc, char *argv[])
|
|||||||
" 5=endrestore\r\n"
|
" 5=endrestore\r\n"
|
||||||
" 6=abortrestore\r\n"
|
" 6=abortrestore\r\n"
|
||||||
"The optional password is a character string of 1 to 20 characters.\r\n",
|
"The optional password is a character string of 1 to 20 characters.\r\n",
|
||||||
filename_remove_path(argv[0]),
|
filename_remove_path(argv[0]), BACNET_MAX_INSTANCE - 1);
|
||||||
BACNET_MAX_INSTANCE-1);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* decode the command line parameters */
|
/* decode the command line parameters */
|
||||||
@@ -207,8 +188,7 @@ int main(int argc, char *argv[])
|
|||||||
if (argc > 3)
|
if (argc > 3)
|
||||||
Reinitialize_Password = argv[3];
|
Reinitialize_Password = argv[3];
|
||||||
|
|
||||||
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE)
|
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
||||||
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -236,59 +216,42 @@ int main(int argc, char *argv[])
|
|||||||
/* don't send an I-Am unless asked */
|
/* don't send an I-Am unless asked */
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
/* try to bind with the device */
|
/* try to bind with the device */
|
||||||
Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance);
|
Send_WhoIs(Target_Device_Object_Instance,
|
||||||
|
Target_Device_Object_Instance);
|
||||||
/* loop forever */
|
/* loop forever */
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
current_seconds = time(NULL);
|
current_seconds = time(NULL);
|
||||||
|
|
||||||
/* returns 0 bytes on timeout */
|
/* returns 0 bytes on timeout */
|
||||||
pdu_len = bip_receive(
|
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
|
|
||||||
/* process */
|
/* process */
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
/* at least one second has passed */
|
/* at least one second has passed */
|
||||||
if (current_seconds != last_seconds)
|
if (current_seconds != last_seconds)
|
||||||
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
|
tsm_timer_milliseconds(((current_seconds -
|
||||||
|
last_seconds) * 1000));
|
||||||
if (Error_Detected)
|
if (Error_Detected)
|
||||||
break;
|
break;
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
iam_send(&Handler_Transmit_Buffer[0]);
|
iam_send(&Handler_Transmit_Buffer[0]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* wait until the device is bound, or timeout and quit */
|
/* wait until the device is bound, or timeout and quit */
|
||||||
found = address_bind_request(
|
found = address_bind_request(Target_Device_Object_Instance,
|
||||||
Target_Device_Object_Instance,
|
&max_apdu, &Target_Address);
|
||||||
&max_apdu,
|
if (found) {
|
||||||
&Target_Address);
|
if (invoke_id == 0) {
|
||||||
if (found)
|
invoke_id =
|
||||||
{
|
Send_Reinitialize_Device_Request
|
||||||
if (invoke_id == 0)
|
(Target_Device_Object_Instance, Reinitialize_State,
|
||||||
{
|
|
||||||
invoke_id = Send_Reinitialize_Device_Request(
|
|
||||||
Target_Device_Object_Instance,
|
|
||||||
Reinitialize_State,
|
|
||||||
Reinitialize_Password);
|
Reinitialize_Password);
|
||||||
}
|
} else if (tsm_invoke_id_free(invoke_id))
|
||||||
else if (tsm_invoke_id_free(invoke_id))
|
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
elapsed_seconds += (current_seconds - last_seconds);
|
elapsed_seconds += (current_seconds - last_seconds);
|
||||||
if (elapsed_seconds > timeout_seconds)
|
if (elapsed_seconds > timeout_seconds)
|
||||||
|
|||||||
@@ -53,33 +53,27 @@ static uint8_t Rx_Buf[MAX_MPDU] = {0};
|
|||||||
static void Init_Service_Handlers(void)
|
static void Init_Service_Handlers(void)
|
||||||
{
|
{
|
||||||
/* we need to handle who-is to support dynamic device binding */
|
/* we need to handle who-is to support dynamic device binding */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
handler_who_is);
|
handler_who_is);
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS,
|
||||||
SERVICE_UNCONFIRMED_WHO_HAS,
|
|
||||||
handler_who_has);
|
handler_who_has);
|
||||||
/* set the handler for all the services we don't implement */
|
/* set the handler for all the services we don't implement */
|
||||||
/* It is required to send the proper reject message... */
|
/* It is required to send the proper reject message... */
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
handler_unrecognized_service);
|
(handler_unrecognized_service);
|
||||||
/* Set the handlers for any confirmed services that we support. */
|
/* Set the handlers for any confirmed services that we support. */
|
||||||
/* We must implement read property - it's required! */
|
/* We must implement read property - it's required! */
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property);
|
handler_read_property);
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
|
||||||
handler_write_property);
|
handler_write_property);
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
||||||
SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
|
||||||
handler_atomic_read_file);
|
handler_atomic_read_file);
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
||||||
SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
|
|
||||||
handler_reinitialize_device);
|
handler_reinitialize_device);
|
||||||
/* handle communication so we can shutup when asked */
|
/* handle communication so we can shutup when asked */
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler
|
||||||
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
|
(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
|
||||||
handler_device_communication_control);
|
handler_device_communication_control);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,17 +82,13 @@ static void cleanup(void)
|
|||||||
datalink_cleanup();
|
datalink_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_address(
|
static void print_address(char *name, BACNET_ADDRESS * dest) // destination address
|
||||||
char *name,
|
|
||||||
BACNET_ADDRESS *dest) // destination address
|
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
|
|
||||||
if (dest)
|
if (dest) {
|
||||||
{
|
|
||||||
printf("%s: ", name);
|
printf("%s: ", name);
|
||||||
for (i = 0; i < dest->mac_len; i++)
|
for (i = 0; i < dest->mac_len; i++) {
|
||||||
{
|
|
||||||
printf("%02X", dest->mac[i]);
|
printf("%02X", dest->mac[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@@ -147,32 +137,22 @@ int main(int argc, char *argv[])
|
|||||||
/* broadcast an I-Am on startup */
|
/* broadcast an I-Am on startup */
|
||||||
I_Am_Request = true;
|
I_Am_Request = true;
|
||||||
// loop forever
|
// loop forever
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
// input
|
// input
|
||||||
current_seconds = time(NULL);
|
current_seconds = time(NULL);
|
||||||
|
|
||||||
// returns 0 bytes on timeout
|
// returns 0 bytes on timeout
|
||||||
pdu_len = datalink_receive(
|
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
|
|
||||||
// process
|
// process
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
/* at least one second has passed */
|
/* at least one second has passed */
|
||||||
if (current_seconds != last_seconds)
|
if (current_seconds != last_seconds)
|
||||||
dcc_timer_seconds(current_seconds - last_seconds);
|
dcc_timer_seconds(current_seconds - last_seconds);
|
||||||
/* send out the I-Am if requested */
|
/* send out the I-Am if requested */
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
iam_send(&Handler_Transmit_Buffer[0]);
|
iam_send(&Handler_Transmit_Buffer[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,10 +59,8 @@ static char *Target_Object_Name = NULL;
|
|||||||
|
|
||||||
static bool Error_Detected = false;
|
static bool Error_Detected = false;
|
||||||
|
|
||||||
void MyAbortHandler(
|
void MyAbortHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t abort_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t abort_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -72,10 +70,8 @@ void MyAbortHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyRejectHandler(
|
void MyRejectHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t reject_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t reject_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -89,40 +85,31 @@ static void Init_Service_Handlers(void)
|
|||||||
{
|
{
|
||||||
/* we need to handle who-is
|
/* we need to handle who-is
|
||||||
to support dynamic device binding to us */
|
to support dynamic device binding to us */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
handler_who_is);
|
handler_who_is);
|
||||||
/* set the handler for all the services we don't implement
|
/* set the handler for all the services we don't implement
|
||||||
It is required to send the proper reject message... */
|
It is required to send the proper reject message... */
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
handler_unrecognized_service);
|
(handler_unrecognized_service);
|
||||||
/* we must implement read property - it's required! */
|
/* we must implement read property - it's required! */
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property);
|
handler_read_property);
|
||||||
/* handle the reply (request) coming back */
|
/* handle the reply (request) coming back */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_HAVE,
|
||||||
SERVICE_UNCONFIRMED_I_HAVE,
|
|
||||||
handler_i_have);
|
handler_i_have);
|
||||||
/* handle any errors coming back */
|
/* handle any errors coming back */
|
||||||
apdu_set_abort_handler(
|
apdu_set_abort_handler(MyAbortHandler);
|
||||||
MyAbortHandler);
|
apdu_set_reject_handler(MyRejectHandler);
|
||||||
apdu_set_reject_handler(
|
|
||||||
MyRejectHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BIP_DEBUG
|
#ifdef BIP_DEBUG
|
||||||
static void print_address(
|
static void print_address(char *name, BACNET_ADDRESS * dest) // destination address
|
||||||
char *name,
|
|
||||||
BACNET_ADDRESS *dest) // destination address
|
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
|
|
||||||
if (dest)
|
if (dest) {
|
||||||
{
|
|
||||||
printf("%s: ", name);
|
printf("%s: ", name);
|
||||||
for (i = 0; i < dest->mac_len; i++)
|
for (i = 0; i < dest->mac_len; i++) {
|
||||||
{
|
|
||||||
printf("%02X", dest->mac[i]);
|
printf("%02X", dest->mac[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@@ -143,11 +130,9 @@ int main(int argc, char *argv[])
|
|||||||
BACNET_ADDRESS my_address, broadcast_address;
|
BACNET_ADDRESS my_address, broadcast_address;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2) {
|
||||||
{
|
|
||||||
/* note: priority 16 and 0 should produce the same end results... */
|
/* note: priority 16 and 0 should produce the same end results... */
|
||||||
printf(
|
printf("Usage: %s <object-type object-instance | object-name>\r\n"
|
||||||
"Usage: %s <object-type object-instance | object-name>\r\n"
|
|
||||||
"Send BACnet WhoHas request to devices, and wait for responses.\r\n"
|
"Send BACnet WhoHas request to devices, and wait for responses.\r\n"
|
||||||
"\r\n"
|
"\r\n"
|
||||||
"Use either:\r\n"
|
"Use either:\r\n"
|
||||||
@@ -156,27 +141,22 @@ int main(int argc, char *argv[])
|
|||||||
"or:\r\n"
|
"or:\r\n"
|
||||||
"The object-name can be any string of characters.\r\n",
|
"The object-name can be any string of characters.\r\n",
|
||||||
filename_remove_path(argv[0]),
|
filename_remove_path(argv[0]),
|
||||||
MAX_BACNET_OBJECT_TYPE-1,
|
MAX_BACNET_OBJECT_TYPE - 1, BACNET_MAX_INSTANCE);
|
||||||
BACNET_MAX_INSTANCE);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* decode the command line parameters */
|
/* decode the command line parameters */
|
||||||
if (argc < 3)
|
if (argc < 3) {
|
||||||
{
|
|
||||||
Target_Object_Name = argv[1];
|
Target_Object_Name = argv[1];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Target_Object_Type = strtol(argv[1], NULL, 0);
|
Target_Object_Type = strtol(argv[1], NULL, 0);
|
||||||
Target_Object_Instance = strtol(argv[2], NULL, 0);
|
Target_Object_Instance = strtol(argv[2], NULL, 0);
|
||||||
if (Target_Object_Instance > BACNET_MAX_INSTANCE)
|
if (Target_Object_Instance > BACNET_MAX_INSTANCE) {
|
||||||
{
|
fprintf(stderr,
|
||||||
fprintf(stderr,"object-instance=%u - it must be less than %u\r\n",
|
"object-instance=%u - it must be less than %u\r\n",
|
||||||
Target_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
Target_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_Object_Type > MAX_BACNET_OBJECT_TYPE)
|
if (Target_Object_Type > MAX_BACNET_OBJECT_TYPE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
||||||
Target_Object_Type, MAX_BACNET_OBJECT_TYPE + 1);
|
Target_Object_Type, MAX_BACNET_OBJECT_TYPE + 1);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -206,36 +186,23 @@ int main(int argc, char *argv[])
|
|||||||
Send_WhoHas_Name(-1, -1, Target_Object_Name);
|
Send_WhoHas_Name(-1, -1, Target_Object_Name);
|
||||||
else
|
else
|
||||||
Send_WhoHas_Object(-1, -1,
|
Send_WhoHas_Object(-1, -1,
|
||||||
Target_Object_Type,
|
Target_Object_Type, Target_Object_Instance);
|
||||||
Target_Object_Instance);
|
|
||||||
/* loop forever */
|
/* loop forever */
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
current_seconds = time(NULL);
|
current_seconds = time(NULL);
|
||||||
/* returns 0 bytes on timeout */
|
/* returns 0 bytes on timeout */
|
||||||
pdu_len = bip_receive(
|
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
/* process */
|
/* process */
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
if (Error_Detected)
|
if (Error_Detected)
|
||||||
break;
|
break;
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
iam_send(&Handler_Transmit_Buffer[0]);
|
iam_send(&Handler_Transmit_Buffer[0]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
elapsed_seconds += (current_seconds - last_seconds);
|
elapsed_seconds += (current_seconds - last_seconds);
|
||||||
if (elapsed_seconds > timeout_seconds)
|
if (elapsed_seconds > timeout_seconds)
|
||||||
|
|||||||
@@ -60,27 +60,21 @@ static bool End_Of_File_Detected = false;
|
|||||||
static bool Error_Detected = false;
|
static bool Error_Detected = false;
|
||||||
static uint8_t Current_Invoke_ID = 0;
|
static uint8_t Current_Invoke_ID = 0;
|
||||||
|
|
||||||
static void Atomic_Read_File_Error_Handler(
|
static void Atomic_Read_File_Error_Handler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
uint8_t invoke_id,
|
uint8_t invoke_id,
|
||||||
BACNET_ERROR_CLASS error_class,
|
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code)
|
||||||
BACNET_ERROR_CODE error_code)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
(void) invoke_id;
|
(void) invoke_id;
|
||||||
printf("\r\nBACnet Error!\r\n");
|
printf("\r\nBACnet Error!\r\n");
|
||||||
printf("Error Class: %s\r\n",
|
printf("Error Class: %s\r\n", bactext_error_class_name(error_class));
|
||||||
bactext_error_class_name(error_class));
|
printf("Error Code: %s\r\n", bactext_error_code_name(error_code));
|
||||||
printf("Error Code: %s\r\n",
|
|
||||||
bactext_error_code_name(error_code));
|
|
||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAbortHandler(
|
void MyAbortHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t abort_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t abort_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -91,10 +85,8 @@ void MyAbortHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyRejectHandler(
|
void MyRejectHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t reject_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t reject_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -105,11 +97,9 @@ void MyRejectHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t Send_Atomic_Write_File_Stream(
|
static uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id,
|
||||||
uint32_t device_id,
|
|
||||||
uint32_t file_instance,
|
uint32_t file_instance,
|
||||||
int fileStartPosition,
|
int fileStartPosition, BACNET_OCTET_STRING * fileData)
|
||||||
BACNET_OCTET_STRING *fileData)
|
|
||||||
{
|
{
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
@@ -125,14 +115,9 @@ static uint8_t Send_Atomic_Write_File_Stream(
|
|||||||
/* is there a tsm available? */
|
/* is there a tsm available? */
|
||||||
if (status)
|
if (status)
|
||||||
status = tsm_transaction_available();
|
status = tsm_transaction_available();
|
||||||
if (status)
|
if (status) {
|
||||||
{
|
|
||||||
datalink_get_my_address(&my_address);
|
datalink_get_my_address(&my_address);
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, &my_address, true, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
&my_address,
|
|
||||||
true, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
invoke_id = tsm_next_free_invokeID();
|
invoke_id = tsm_next_free_invokeID();
|
||||||
@@ -142,40 +127,31 @@ static uint8_t Send_Atomic_Write_File_Stream(
|
|||||||
data.access = FILE_STREAM_ACCESS;
|
data.access = FILE_STREAM_ACCESS;
|
||||||
data.type.stream.fileStartPosition = fileStartPosition;
|
data.type.stream.fileStartPosition = fileStartPosition;
|
||||||
status = octetstring_copy(&data.fileData, fileData);
|
status = octetstring_copy(&data.fileData, fileData);
|
||||||
if (status)
|
if (status) {
|
||||||
{
|
pdu_len += awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
pdu_len += awf_encode_apdu(
|
invoke_id, &data);
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
|
||||||
invoke_id,
|
|
||||||
&data);
|
|
||||||
/* will the APDU fit the target device?
|
/* will the APDU fit the target device?
|
||||||
note: if there is a bottleneck router in between
|
note: if there is a bottleneck router in between
|
||||||
us and the destination, we won't know unless
|
us and the destination, we won't know unless
|
||||||
we have a way to check for that and update the
|
we have a way to check for that and update the
|
||||||
max_apdu in the address binding table. */
|
max_apdu in the address binding table. */
|
||||||
if ((unsigned)pdu_len <= max_apdu)
|
if ((unsigned) pdu_len <= max_apdu) {
|
||||||
{
|
tsm_set_confirmed_unsegmented_transaction(invoke_id,
|
||||||
tsm_set_confirmed_unsegmented_transaction(
|
&dest, &Handler_Transmit_Buffer[0], pdu_len);
|
||||||
invoke_id,
|
bytes_sent = datalink_send_pdu(&dest, // destination address
|
||||||
&dest,
|
&Handler_Transmit_Buffer[0], pdu_len); // number of bytes of data
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len);
|
|
||||||
bytes_sent = datalink_send_pdu(
|
|
||||||
&dest, // destination address
|
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); // number of bytes of data
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send AtomicWriteFile Request (%s)!\n",
|
fprintf(stderr,
|
||||||
|
"Failed to Send AtomicWriteFile Request (%s)!\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
|
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
|
||||||
"(payload [%d] exceeds destination maximum APDU [%u])!\n",
|
"(payload [%d] exceeds destination maximum APDU [%u])!\n",
|
||||||
pdu_len, max_apdu);
|
pdu_len, max_apdu);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
|
fprintf(stderr, "Failed to Send AtomicWriteFile Request "
|
||||||
"(payload [%d] exceeds octet string capacity)!\n",pdu_len);
|
"(payload [%d] exceeds octet string capacity)!\n",
|
||||||
|
pdu_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return invoke_id;
|
return invoke_id;
|
||||||
@@ -191,31 +167,22 @@ static void Send_WhoIs(uint32_t device_id)
|
|||||||
datalink_get_broadcast_address(&dest);
|
datalink_get_broadcast_address(&dest);
|
||||||
|
|
||||||
/* encode the NPDU portion of the packet */
|
/* encode the NPDU portion of the packet */
|
||||||
pdu_len = npdu_encode_apdu(
|
pdu_len = npdu_encode_apdu(&Handler_Transmit_Buffer[0], &dest, NULL, false, // true for confirmed messages
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
&dest,
|
|
||||||
NULL,
|
|
||||||
false, // true for confirmed messages
|
|
||||||
MESSAGE_PRIORITY_NORMAL);
|
MESSAGE_PRIORITY_NORMAL);
|
||||||
|
|
||||||
/* encode the APDU portion of the packet */
|
/* encode the APDU portion of the packet */
|
||||||
pdu_len += whois_encode_apdu(
|
pdu_len += whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||||
&Handler_Transmit_Buffer[pdu_len],
|
device_id, device_id);
|
||||||
device_id,
|
|
||||||
device_id);
|
|
||||||
|
|
||||||
bytes_sent = datalink_send_pdu(
|
bytes_sent = datalink_send_pdu(&dest, /* destination address */
|
||||||
&dest, /* destination address */
|
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
|
||||||
&Handler_Transmit_Buffer[0],
|
|
||||||
pdu_len); /* number of bytes of data */
|
|
||||||
if (bytes_sent <= 0)
|
if (bytes_sent <= 0)
|
||||||
fprintf(stderr,"Failed to Send Who-Is Request (%s)!\n", strerror(errno));
|
fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n",
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LocalIAmHandler(
|
static void LocalIAmHandler(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src)
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
uint32_t device_id = 0;
|
uint32_t device_id = 0;
|
||||||
@@ -225,19 +192,11 @@ static void LocalIAmHandler(
|
|||||||
|
|
||||||
(void) src;
|
(void) src;
|
||||||
(void) service_len;
|
(void) service_len;
|
||||||
len = iam_decode_service_request(
|
len = iam_decode_service_request(service_request,
|
||||||
service_request,
|
&device_id, &max_apdu, &segmentation, &vendor_id);
|
||||||
&device_id,
|
if (len != -1) {
|
||||||
&max_apdu,
|
address_add(device_id, max_apdu, src);
|
||||||
&segmentation,
|
} else
|
||||||
&vendor_id);
|
|
||||||
if (len != -1)
|
|
||||||
{
|
|
||||||
address_add(device_id,
|
|
||||||
max_apdu,
|
|
||||||
src);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fprintf(stderr, "!\n");
|
fprintf(stderr, "!\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -247,29 +206,23 @@ static void Init_Service_Handlers(void)
|
|||||||
{
|
{
|
||||||
/* we need to handle who-is
|
/* we need to handle who-is
|
||||||
to support dynamic device binding to us */
|
to support dynamic device binding to us */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
handler_who_is);
|
handler_who_is);
|
||||||
/* handle i-am to support binding to other devices */
|
/* handle i-am to support binding to other devices */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM,
|
||||||
SERVICE_UNCONFIRMED_I_AM,
|
|
||||||
LocalIAmHandler);
|
LocalIAmHandler);
|
||||||
/* set the handler for all the services we don't implement
|
/* set the handler for all the services we don't implement
|
||||||
It is required to send the proper reject message... */
|
It is required to send the proper reject message... */
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
handler_unrecognized_service);
|
(handler_unrecognized_service);
|
||||||
/* we must implement read property - it's required! */
|
/* we must implement read property - it's required! */
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property);
|
handler_read_property);
|
||||||
/* handle any errors coming back */
|
/* handle any errors coming back */
|
||||||
apdu_set_error_handler(
|
apdu_set_error_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
||||||
SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
|
||||||
Atomic_Read_File_Error_Handler);
|
Atomic_Read_File_Error_Handler);
|
||||||
apdu_set_abort_handler(
|
apdu_set_abort_handler(MyAbortHandler);
|
||||||
MyAbortHandler);
|
apdu_set_reject_handler(MyRejectHandler);
|
||||||
apdu_set_reject_handler(
|
|
||||||
MyRejectHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -291,8 +244,7 @@ int main(int argc, char *argv[])
|
|||||||
static BACNET_OCTET_STRING fileData;
|
static BACNET_OCTET_STRING fileData;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
if (argc < 4)
|
if (argc < 4) {
|
||||||
{
|
|
||||||
/* FIXME: what about access method - record or stream? */
|
/* FIXME: what about access method - record or stream? */
|
||||||
printf("%s device-instance file-instance local-name\r\n",
|
printf("%s device-instance file-instance local-name\r\n",
|
||||||
filename_remove_path(argv[0]));
|
filename_remove_path(argv[0]));
|
||||||
@@ -302,14 +254,12 @@ int main(int argc, char *argv[])
|
|||||||
Target_Device_Object_Instance = strtol(argv[1], NULL, 0);
|
Target_Device_Object_Instance = strtol(argv[1], NULL, 0);
|
||||||
Target_File_Object_Instance = strtol(argv[2], NULL, 0);
|
Target_File_Object_Instance = strtol(argv[2], NULL, 0);
|
||||||
Local_File_Name = argv[3];
|
Local_File_Name = argv[3];
|
||||||
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE)
|
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
||||||
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_File_Object_Instance >= BACNET_MAX_INSTANCE)
|
if (Target_File_Object_Instance >= BACNET_MAX_INSTANCE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "file-instance=%u - it must be less than %u\r\n",
|
fprintf(stderr, "file-instance=%u - it must be less than %u\r\n",
|
||||||
Target_File_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
Target_File_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -330,48 +280,33 @@ int main(int argc, char *argv[])
|
|||||||
/* try to bind with the device */
|
/* try to bind with the device */
|
||||||
Send_WhoIs(Target_Device_Object_Instance);
|
Send_WhoIs(Target_Device_Object_Instance);
|
||||||
/* loop forever */
|
/* loop forever */
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
current_seconds = time(NULL);
|
current_seconds = time(NULL);
|
||||||
|
|
||||||
/* returns 0 bytes on timeout */
|
/* returns 0 bytes on timeout */
|
||||||
pdu_len = bip_receive(
|
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
|
|
||||||
/* process */
|
/* process */
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
/* at least one second has passed */
|
/* at least one second has passed */
|
||||||
if (current_seconds != last_seconds)
|
if (current_seconds != last_seconds)
|
||||||
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
|
tsm_timer_milliseconds(((current_seconds -
|
||||||
if (End_Of_File_Detected || Error_Detected)
|
last_seconds) * 1000));
|
||||||
{
|
if (End_Of_File_Detected || Error_Detected) {
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
iam_send(&Handler_Transmit_Buffer[0]);
|
iam_send(&Handler_Transmit_Buffer[0]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* wait until the device is bound, or timeout and quit */
|
/* wait until the device is bound, or timeout and quit */
|
||||||
found = address_bind_request(
|
found = address_bind_request(Target_Device_Object_Instance,
|
||||||
Target_Device_Object_Instance,
|
&max_apdu, &Target_Address);
|
||||||
&max_apdu,
|
if (found) {
|
||||||
&Target_Address);
|
|
||||||
if (found)
|
|
||||||
{
|
|
||||||
/* calculate the smaller of our APDU size or theirs
|
/* calculate the smaller of our APDU size or theirs
|
||||||
and remove the overhead of the APDU (varies depending on size).
|
and remove the overhead of the APDU (varies depending on size).
|
||||||
note: we could fail if there is a bottle neck (router)
|
note: we could fail if there is a bottle neck (router)
|
||||||
@@ -391,38 +326,32 @@ int main(int argc, char *argv[])
|
|||||||
requestedOctetCount = my_max_apdu / 2;
|
requestedOctetCount = my_max_apdu / 2;
|
||||||
/* has the previous invoke id expired or returned?
|
/* has the previous invoke id expired or returned?
|
||||||
note: invoke ID = 0 is invalid, so it will be idle */
|
note: invoke ID = 0 is invalid, so it will be idle */
|
||||||
if ((invoke_id == 0) || tsm_invoke_id_free(invoke_id))
|
if ((invoke_id == 0) || tsm_invoke_id_free(invoke_id)) {
|
||||||
{
|
|
||||||
if (invoke_id != 0)
|
if (invoke_id != 0)
|
||||||
fileStartPosition += requestedOctetCount;
|
fileStartPosition += requestedOctetCount;
|
||||||
/* we'll read the file in chunks
|
/* we'll read the file in chunks
|
||||||
less than max_apdu to keep unsegmented */
|
less than max_apdu to keep unsegmented */
|
||||||
pFile = fopen(Local_File_Name, "rb");
|
pFile = fopen(Local_File_Name, "rb");
|
||||||
if (pFile)
|
if (pFile) {
|
||||||
{
|
(void) fseek(pFile, fileStartPosition, SEEK_SET);
|
||||||
(void)fseek(pFile,
|
|
||||||
fileStartPosition,
|
|
||||||
SEEK_SET);
|
|
||||||
len = fread(octetstring_value(&fileData), 1,
|
len = fread(octetstring_value(&fileData), 1,
|
||||||
requestedOctetCount, pFile);
|
requestedOctetCount, pFile);
|
||||||
if (len < requestedOctetCount)
|
if (len < requestedOctetCount)
|
||||||
End_Of_File_Detected = true;
|
End_Of_File_Detected = true;
|
||||||
octetstring_truncate(&fileData, len);
|
octetstring_truncate(&fileData, len);
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
End_Of_File_Detected = true;
|
End_Of_File_Detected = true;
|
||||||
printf("\rSending %d bytes",(fileStartPosition+len));
|
printf("\rSending %d bytes",
|
||||||
invoke_id = Send_Atomic_Write_File_Stream(
|
(fileStartPosition + len));
|
||||||
Target_Device_Object_Instance,
|
invoke_id =
|
||||||
Target_File_Object_Instance,
|
Send_Atomic_Write_File_Stream
|
||||||
fileStartPosition,
|
(Target_Device_Object_Instance,
|
||||||
|
Target_File_Object_Instance, fileStartPosition,
|
||||||
&fileData);
|
&fileData);
|
||||||
Current_Invoke_ID = invoke_id;
|
Current_Invoke_ID = invoke_id;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
elapsed_seconds += (current_seconds - last_seconds);
|
elapsed_seconds += (current_seconds - last_seconds);
|
||||||
if (elapsed_seconds > timeout_seconds)
|
if (elapsed_seconds > timeout_seconds)
|
||||||
|
|||||||
@@ -59,35 +59,31 @@ static BACNET_OBJECT_TYPE Target_Object_Type = OBJECT_ANALOG_INPUT;
|
|||||||
static BACNET_PROPERTY_ID Target_Object_Property = PROP_ACKED_TRANSITIONS;
|
static BACNET_PROPERTY_ID Target_Object_Property = PROP_ACKED_TRANSITIONS;
|
||||||
/* array index value or BACNET_ARRAY_ALL */
|
/* array index value or BACNET_ARRAY_ALL */
|
||||||
static int32_t Target_Object_Property_Index = BACNET_ARRAY_ALL;
|
static int32_t Target_Object_Property_Index = BACNET_ARRAY_ALL;
|
||||||
static BACNET_APPLICATION_TAG Target_Object_Property_Tag = BACNET_APPLICATION_TAG_NULL;
|
static BACNET_APPLICATION_TAG Target_Object_Property_Tag =
|
||||||
|
BACNET_APPLICATION_TAG_NULL;
|
||||||
static BACNET_APPLICATION_DATA_VALUE Target_Object_Property_Value = { 0 };
|
static BACNET_APPLICATION_DATA_VALUE Target_Object_Property_Value = { 0 };
|
||||||
|
|
||||||
/* 0 if not set, 1..16 if set */
|
/* 0 if not set, 1..16 if set */
|
||||||
static uint8_t Target_Object_Property_Priority = 0;
|
static uint8_t Target_Object_Property_Priority = 0;
|
||||||
|
|
||||||
static BACNET_ADDRESS Target_Address;
|
static BACNET_ADDRESS Target_Address;
|
||||||
static bool Error_Detected = false;
|
static bool Error_Detected = false;
|
||||||
|
|
||||||
static void MyErrorHandler(
|
static void MyErrorHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
uint8_t invoke_id,
|
uint8_t invoke_id,
|
||||||
BACNET_ERROR_CLASS error_class,
|
BACNET_ERROR_CLASS error_class, BACNET_ERROR_CODE error_code)
|
||||||
BACNET_ERROR_CODE error_code)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
(void) invoke_id;
|
(void) invoke_id;
|
||||||
printf("\r\nBACnet Error!\r\n");
|
printf("\r\nBACnet Error!\r\n");
|
||||||
printf("Error Class: %s\r\n",
|
printf("Error Class: %s\r\n", bactext_error_class_name(error_class));
|
||||||
bactext_error_class_name(error_class));
|
printf("Error Code: %s\r\n", bactext_error_code_name(error_code));
|
||||||
printf("Error Code: %s\r\n",
|
|
||||||
bactext_error_code_name(error_code));
|
|
||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAbortHandler(
|
void MyAbortHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t abort_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t abort_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -98,10 +94,8 @@ void MyAbortHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyRejectHandler(
|
void MyRejectHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
uint8_t invoke_id, uint8_t reject_reason)
|
||||||
uint8_t invoke_id,
|
|
||||||
uint8_t reject_reason)
|
|
||||||
{
|
{
|
||||||
/* FIXME: verify src and invoke id */
|
/* FIXME: verify src and invoke id */
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -112,8 +106,7 @@ void MyRejectHandler(
|
|||||||
Error_Detected = true;
|
Error_Detected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyWritePropertySimpleAckHandler(
|
void MyWritePropertySimpleAckHandler(BACNET_ADDRESS * src,
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
uint8_t invoke_id)
|
uint8_t invoke_id)
|
||||||
{
|
{
|
||||||
(void) src;
|
(void) src;
|
||||||
@@ -125,33 +118,26 @@ static void Init_Service_Handlers(void)
|
|||||||
{
|
{
|
||||||
/* we need to handle who-is
|
/* we need to handle who-is
|
||||||
to support dynamic device binding to us */
|
to support dynamic device binding to us */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
handler_who_is);
|
handler_who_is);
|
||||||
/* handle i-am to support binding to other devices */
|
/* handle i-am to support binding to other devices */
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM,
|
||||||
SERVICE_UNCONFIRMED_I_AM,
|
|
||||||
handler_i_am_bind);
|
handler_i_am_bind);
|
||||||
/* set the handler for all the services we don't implement
|
/* set the handler for all the services we don't implement
|
||||||
It is required to send the proper reject message... */
|
It is required to send the proper reject message... */
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
handler_unrecognized_service);
|
(handler_unrecognized_service);
|
||||||
/* we must implement read property - it's required! */
|
/* we must implement read property - it's required! */
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property);
|
handler_read_property);
|
||||||
/* handle the ack coming back */
|
/* handle the ack coming back */
|
||||||
apdu_set_confirmed_simple_ack_handler(
|
apdu_set_confirmed_simple_ack_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
|
||||||
MyWritePropertySimpleAckHandler);
|
MyWritePropertySimpleAckHandler);
|
||||||
/* handle any errors coming back */
|
/* handle any errors coming back */
|
||||||
apdu_set_error_handler(
|
apdu_set_error_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
|
||||||
MyErrorHandler);
|
MyErrorHandler);
|
||||||
apdu_set_abort_handler(
|
apdu_set_abort_handler(MyAbortHandler);
|
||||||
MyAbortHandler);
|
apdu_set_reject_handler(MyRejectHandler);
|
||||||
apdu_set_reject_handler(
|
|
||||||
MyRejectHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -169,8 +155,7 @@ int main(int argc, char *argv[])
|
|||||||
char *value_string = NULL;
|
char *value_string = NULL;
|
||||||
bool status = false;
|
bool status = false;
|
||||||
|
|
||||||
if (argc < 7)
|
if (argc < 7) {
|
||||||
{
|
|
||||||
/* note: priority 16 and 0 should produce the same end results... */
|
/* note: priority 16 and 0 should produce the same end results... */
|
||||||
printf("Usage: %s device-instance object-type object-instance "
|
printf("Usage: %s device-instance object-type object-instance "
|
||||||
"property tag value [priority] [index]\r\n"
|
"property tag value [priority] [index]\r\n"
|
||||||
@@ -240,8 +225,7 @@ int main(int argc, char *argv[])
|
|||||||
"You could also send a relinquish command:\r\n"
|
"You could also send a relinquish command:\r\n"
|
||||||
"%s 123 1 0 85 0 0\r\n",
|
"%s 123 1 0 85 0 0\r\n",
|
||||||
filename_remove_path(argv[0]),
|
filename_remove_path(argv[0]),
|
||||||
filename_remove_path(argv[0]),
|
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
|
||||||
filename_remove_path(argv[0]));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* decode the command line parameters */
|
/* decode the command line parameters */
|
||||||
@@ -258,42 +242,34 @@ int main(int argc, char *argv[])
|
|||||||
if (argc > 8)
|
if (argc > 8)
|
||||||
Target_Object_Property_Index = strtol(argv[8], NULL, 0);
|
Target_Object_Property_Index = strtol(argv[8], NULL, 0);
|
||||||
|
|
||||||
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE)
|
if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
fprintf(stderr, "device-instance=%u - it must be less than %u\r\n",
|
||||||
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_Object_Type > MAX_BACNET_OBJECT_TYPE)
|
if (Target_Object_Type > MAX_BACNET_OBJECT_TYPE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
||||||
Target_Object_Type, MAX_BACNET_OBJECT_TYPE + 1);
|
Target_Object_Type, MAX_BACNET_OBJECT_TYPE + 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_Object_Instance > BACNET_MAX_INSTANCE)
|
if (Target_Object_Instance > BACNET_MAX_INSTANCE) {
|
||||||
{
|
|
||||||
fprintf(stderr, "object-instance=%u - it must be less than %u\r\n",
|
fprintf(stderr, "object-instance=%u - it must be less than %u\r\n",
|
||||||
Target_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
Target_Object_Instance, BACNET_MAX_INSTANCE + 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_Object_Property > MAX_BACNET_PROPERTY_ID)
|
if (Target_Object_Property > MAX_BACNET_PROPERTY_ID) {
|
||||||
{
|
|
||||||
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
fprintf(stderr, "object-type=%u - it must be less than %u\r\n",
|
||||||
Target_Object_Property, MAX_BACNET_PROPERTY_ID + 1);
|
Target_Object_Property, MAX_BACNET_PROPERTY_ID + 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (Target_Object_Property_Tag >= MAX_BACNET_APPLICATION_TAG)
|
if (Target_Object_Property_Tag >= MAX_BACNET_APPLICATION_TAG) {
|
||||||
{
|
|
||||||
fprintf(stderr, "tag=%u - it must be less than %u\r\n",
|
fprintf(stderr, "tag=%u - it must be less than %u\r\n",
|
||||||
Target_Object_Property_Tag, MAX_BACNET_APPLICATION_TAG);
|
Target_Object_Property_Tag, MAX_BACNET_APPLICATION_TAG);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
status = bacapp_parse_application_data(
|
status = bacapp_parse_application_data(Target_Object_Property_Tag,
|
||||||
Target_Object_Property_Tag,
|
value_string, &Target_Object_Property_Value);
|
||||||
value_string,
|
if (!status) {
|
||||||
&Target_Object_Property_Value);
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
/* FIXME: show the expected entry format for the tag */
|
/* FIXME: show the expected entry format for the tag */
|
||||||
fprintf(stderr, "unable to parse the tag value\r\n");
|
fprintf(stderr, "unable to parse the tag value\r\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -313,63 +289,45 @@ int main(int argc, char *argv[])
|
|||||||
timeout_seconds = (Device_APDU_Timeout() / 1000) *
|
timeout_seconds = (Device_APDU_Timeout() / 1000) *
|
||||||
Device_Number_Of_APDU_Retries();
|
Device_Number_Of_APDU_Retries();
|
||||||
/* try to bind with the device */
|
/* try to bind with the device */
|
||||||
Send_WhoIs(Target_Device_Object_Instance,Target_Device_Object_Instance);
|
Send_WhoIs(Target_Device_Object_Instance,
|
||||||
|
Target_Device_Object_Instance);
|
||||||
/* loop forever */
|
/* loop forever */
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
current_seconds = time(NULL);
|
current_seconds = time(NULL);
|
||||||
|
|
||||||
/* returns 0 bytes on timeout */
|
/* returns 0 bytes on timeout */
|
||||||
pdu_len = bip_receive(
|
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
|
|
||||||
/* process */
|
/* process */
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
/* at least one second has passed */
|
/* at least one second has passed */
|
||||||
if (current_seconds != last_seconds)
|
if (current_seconds != last_seconds)
|
||||||
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
|
tsm_timer_milliseconds(((current_seconds -
|
||||||
|
last_seconds) * 1000));
|
||||||
if (Error_Detected)
|
if (Error_Detected)
|
||||||
break;
|
break;
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
iam_send(&Handler_Transmit_Buffer[0]);
|
iam_send(&Handler_Transmit_Buffer[0]);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* wait until the device is bound, or timeout and quit */
|
/* wait until the device is bound, or timeout and quit */
|
||||||
found = address_bind_request(
|
found = address_bind_request(Target_Device_Object_Instance,
|
||||||
Target_Device_Object_Instance,
|
&max_apdu, &Target_Address);
|
||||||
&max_apdu,
|
if (found) {
|
||||||
&Target_Address);
|
if (invoke_id == 0) {
|
||||||
if (found)
|
invoke_id =
|
||||||
{
|
Send_Write_Property_Request
|
||||||
if (invoke_id == 0)
|
(Target_Device_Object_Instance, Target_Object_Type,
|
||||||
{
|
Target_Object_Instance, Target_Object_Property,
|
||||||
invoke_id = Send_Write_Property_Request(
|
|
||||||
Target_Device_Object_Instance,
|
|
||||||
Target_Object_Type,
|
|
||||||
Target_Object_Instance,
|
|
||||||
Target_Object_Property,
|
|
||||||
&Target_Object_Property_Value,
|
&Target_Object_Property_Value,
|
||||||
Target_Object_Property_Priority,
|
Target_Object_Property_Priority,
|
||||||
Target_Object_Property_Index);
|
Target_Object_Property_Index);
|
||||||
}
|
} else if (tsm_invoke_id_free(invoke_id))
|
||||||
else if (tsm_invoke_id_free(invoke_id))
|
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* increment timer - exit if timed out */
|
/* increment timer - exit if timed out */
|
||||||
elapsed_seconds += (current_seconds - last_seconds);
|
elapsed_seconds += (current_seconds - last_seconds);
|
||||||
if (elapsed_seconds > timeout_seconds)
|
if (elapsed_seconds > timeout_seconds)
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ Don't use C++-style comments (comments beginning with "//" and running
|
|||||||
to the end of the line) for modules that are written in C. The module
|
to the end of the line) for modules that are written in C. The module
|
||||||
may run through C rather than C++ compilers, and not all C compilers
|
may run through C rather than C++ compilers, and not all C compilers
|
||||||
support C++-style comments (GCC does, but IBM's C compiler for AIX, for
|
support C++-style comments (GCC does, but IBM's C compiler for AIX, for
|
||||||
example, doesn't do so by default).
|
example, doesn't do so by default). Note: there is a program
|
||||||
|
called usr/bin/ccmtcnvt in the liwc package that converts the C++
|
||||||
|
comments to C comments.
|
||||||
|
|
||||||
Don't initialize variables in their declaration with non-constant
|
Don't initialize variables in their declaration with non-constant
|
||||||
values. Not all compilers support this. E.g. don't use
|
values. Not all compilers support this. E.g. don't use
|
||||||
|
|||||||
+1
-2
@@ -576,8 +576,7 @@ void MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port)
|
|||||||
// that is not known to this node.
|
// that is not known to this node.
|
||||||
// FIXME: change this if you add a proprietary type
|
// FIXME: change this if you add a proprietary type
|
||||||
else if /*( */ (mstp_port->FrameType >=
|
else if /*( */ (mstp_port->FrameType >=
|
||||||
FRAME_TYPE_PROPRIETARY_MIN)
|
FRAME_TYPE_PROPRIETARY_MIN) { /*&& */
|
||||||
{ /*&& */
|
|
||||||
/*(FrameType <= FRAME_TYPE_PROPRIETARY_MAX)) */
|
/*(FrameType <= FRAME_TYPE_PROPRIETARY_MAX)) */
|
||||||
/* unnecessary if FrameType is uint8_t with max of 255 */
|
/* unnecessary if FrameType is uint8_t with max of 255 */
|
||||||
// an unexpected or unwanted frame was received.
|
// an unexpected or unwanted frame was received.
|
||||||
|
|||||||
@@ -113,24 +113,20 @@ static int arcnet_bind(char *interface_name)
|
|||||||
// modules.conf (or in modutils/alias on Debian with update-modules)
|
// modules.conf (or in modutils/alias on Debian with update-modules)
|
||||||
// alias net-pf-17 af_packet
|
// alias net-pf-17 af_packet
|
||||||
// Then follow it by: # modprobe af_packet
|
// Then follow it by: # modprobe af_packet
|
||||||
if ((sock_fd = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ALL))) < 0)
|
if ((sock_fd = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ALL))) < 0) {
|
||||||
{
|
|
||||||
/* Error occured */
|
/* Error occured */
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"arcnet: Error opening socket: %s\n",
|
"arcnet: Error opening socket: %s\n", strerror(errno));
|
||||||
strerror(errno));
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"You might need to add the following to modules.conf\n"
|
"You might need to add the following to modules.conf\n"
|
||||||
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
||||||
"alias net-pf-17 af_packet\n"
|
"alias net-pf-17 af_packet\n"
|
||||||
"Also, add af_packet to /etc/modules.\n"
|
"Also, add af_packet to /etc/modules.\n"
|
||||||
"Then follow it by:\n"
|
"Then follow it by:\n" "# modprobe af_packet\n");
|
||||||
"# modprobe af_packet\n");
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ARCNET_Sock_FD >= 0)
|
if (ARCNET_Sock_FD >= 0) {
|
||||||
{
|
|
||||||
/* Bind the socket to an interface name so we only get packets from it */
|
/* Bind the socket to an interface name so we only get packets from it */
|
||||||
ARCNET_Socket_Address.sa_family = ARPHRD_ARCNET;
|
ARCNET_Socket_Address.sa_family = ARPHRD_ARCNET;
|
||||||
//ARCNET_Socket_Address.sa_family = PF_INET;
|
//ARCNET_Socket_Address.sa_family = PF_INET;
|
||||||
@@ -140,21 +136,19 @@ static int arcnet_bind(char *interface_name)
|
|||||||
/* Strcpy the interface name into the address */
|
/* Strcpy the interface name into the address */
|
||||||
strncpy(ARCNET_Socket_Address.sa_data, interface_name,
|
strncpy(ARCNET_Socket_Address.sa_data, interface_name,
|
||||||
sizeof(ARCNET_Socket_Address.sa_data) - 1);
|
sizeof(ARCNET_Socket_Address.sa_data) - 1);
|
||||||
fprintf(stderr,"arcnet: binding \"%s\"\n",ARCNET_Socket_Address.sa_data);
|
fprintf(stderr, "arcnet: binding \"%s\"\n",
|
||||||
|
ARCNET_Socket_Address.sa_data);
|
||||||
if (bind(sock_fd, &ARCNET_Socket_Address,
|
if (bind(sock_fd, &ARCNET_Socket_Address,
|
||||||
sizeof(ARCNET_Socket_Address)) != 0)
|
sizeof(ARCNET_Socket_Address)) != 0) {
|
||||||
{
|
|
||||||
/* Bind problem, close socket and return */
|
/* Bind problem, close socket and return */
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"arcnet: Unable to bind socket : %s\n",
|
"arcnet: Unable to bind socket : %s\n", strerror(errno));
|
||||||
strerror(errno));
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"You might need to add the following to modules.conf\n"
|
"You might need to add the following to modules.conf\n"
|
||||||
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
||||||
"alias net-pf-17 af_packet\n"
|
"alias net-pf-17 af_packet\n"
|
||||||
"Also, add af_packet to /etc/modules.\n"
|
"Also, add af_packet to /etc/modules.\n"
|
||||||
"Then follow it by:\n"
|
"Then follow it by:\n" "# modprobe af_packet\n");
|
||||||
"# modprobe af_packet\n");
|
|
||||||
/* Close the socket */
|
/* Close the socket */
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
@@ -174,8 +168,7 @@ static int arcnet_bind(char *interface_name)
|
|||||||
strncpy(ARCNET_Socket_Address.sa_data, interface_name,
|
strncpy(ARCNET_Socket_Address.sa_data, interface_name,
|
||||||
sizeof(ARCNET_Socket_Address.sa_data) - 1);
|
sizeof(ARCNET_Socket_Address.sa_data) - 1);
|
||||||
fprintf(stderr, "arcnet: MAC=%02Xh iface=\"%s\"\n",
|
fprintf(stderr, "arcnet: MAC=%02Xh iface=\"%s\"\n",
|
||||||
ARCNET_MAC_Address,
|
ARCNET_MAC_Address, ARCNET_Socket_Address.sa_data);
|
||||||
ARCNET_Socket_Address.sa_data);
|
|
||||||
|
|
||||||
atexit(arcnet_cleanup);
|
atexit(arcnet_cleanup);
|
||||||
|
|
||||||
@@ -191,8 +184,7 @@ bool arcnet_init(char *interface_name)
|
|||||||
|
|
||||||
/* function to send a packet out the socket */
|
/* function to send a packet out the socket */
|
||||||
/* returns number of bytes sent on success, negative on failure */
|
/* returns number of bytes sent on success, negative on failure */
|
||||||
int arcnet_send(
|
int arcnet_send(BACNET_ADDRESS * dest, // destination address
|
||||||
BACNET_ADDRESS *dest, // destination address
|
|
||||||
BACNET_ADDRESS * src, // source address
|
BACNET_ADDRESS * src, // source address
|
||||||
uint8_t * pdu, // any data to be sent - may be null
|
uint8_t * pdu, // any data to be sent - may be null
|
||||||
unsigned pdu_len) // number of bytes of data
|
unsigned pdu_len) // number of bytes of data
|
||||||
@@ -203,28 +195,24 @@ int arcnet_send(
|
|||||||
struct archdr *pkt = (struct archdr *) mtu;
|
struct archdr *pkt = (struct archdr *) mtu;
|
||||||
|
|
||||||
// don't waste time if the socket is not valid
|
// don't waste time if the socket is not valid
|
||||||
if (ARCNET_Sock_FD < 0)
|
if (ARCNET_Sock_FD < 0) {
|
||||||
{
|
|
||||||
fprintf(stderr, "arcnet: socket is invalid!\n");
|
fprintf(stderr, "arcnet: socket is invalid!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* load destination MAC address */
|
/* load destination MAC address */
|
||||||
if (dest->mac_len == 1)
|
if (dest->mac_len == 1)
|
||||||
pkt->hard.dest = dest->mac[0];
|
pkt->hard.dest = dest->mac[0];
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
fprintf(stderr, "arcnet: invalid destination MAC address!\n");
|
fprintf(stderr, "arcnet: invalid destination MAC address!\n");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (src->mac_len == 1)
|
if (src->mac_len == 1)
|
||||||
pkt->hard.source = src->mac[0];
|
pkt->hard.source = src->mac[0];
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
fprintf(stderr, "arcnet: invalid source MAC address!\n");
|
fprintf(stderr, "arcnet: invalid source MAC address!\n");
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
if ((ARC_HDR_SIZE + pdu_len) > 512)
|
if ((ARC_HDR_SIZE + pdu_len) > 512) {
|
||||||
{
|
|
||||||
fprintf(stderr, "arcnet: PDU is too big to send!\n");
|
fprintf(stderr, "arcnet: PDU is too big to send!\n");
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
@@ -251,8 +239,7 @@ int arcnet_send(
|
|||||||
|
|
||||||
/* function to send a PDU out the socket */
|
/* function to send a PDU out the socket */
|
||||||
/* returns number of bytes sent on success, negative on failure */
|
/* returns number of bytes sent on success, negative on failure */
|
||||||
int arcnet_send_pdu(
|
int arcnet_send_pdu(BACNET_ADDRESS * dest, // destination address
|
||||||
BACNET_ADDRESS *dest, // destination address
|
|
||||||
uint8_t * pdu, // any data to be sent - may be null
|
uint8_t * pdu, // any data to be sent - may be null
|
||||||
unsigned pdu_len) // number of bytes of data
|
unsigned pdu_len) // number of bytes of data
|
||||||
{
|
{
|
||||||
@@ -268,8 +255,7 @@ int arcnet_send_pdu(
|
|||||||
|
|
||||||
// receives an framed packet
|
// receives an framed packet
|
||||||
// returns the number of octets in the PDU, or zero on failure
|
// returns the number of octets in the PDU, or zero on failure
|
||||||
uint16_t arcnet_receive(
|
uint16_t arcnet_receive(BACNET_ADDRESS * src, // source address
|
||||||
BACNET_ADDRESS *src, // source address
|
|
||||||
uint8_t * pdu, // PDU data
|
uint8_t * pdu, // PDU data
|
||||||
uint16_t max_pdu, // amount of space available in the PDU
|
uint16_t max_pdu, // amount of space available in the PDU
|
||||||
unsigned timeout) // milliseconds to wait for a packet
|
unsigned timeout) // milliseconds to wait for a packet
|
||||||
@@ -289,14 +275,11 @@ uint16_t arcnet_receive(
|
|||||||
/* we could just use a non-blocking socket, but that consumes all
|
/* we could just use a non-blocking socket, but that consumes all
|
||||||
the CPU time. We can use a timeout; it is only supported as
|
the CPU time. We can use a timeout; it is only supported as
|
||||||
a select. */
|
a select. */
|
||||||
if (timeout >= 1000)
|
if (timeout >= 1000) {
|
||||||
{
|
|
||||||
select_timeout.tv_sec = timeout / 1000;
|
select_timeout.tv_sec = timeout / 1000;
|
||||||
select_timeout.tv_usec =
|
select_timeout.tv_usec =
|
||||||
1000 * (timeout - select_timeout.tv_sec * 1000);
|
1000 * (timeout - select_timeout.tv_sec * 1000);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
select_timeout.tv_sec = 0;
|
select_timeout.tv_sec = 0;
|
||||||
select_timeout.tv_usec = 1000 * timeout;
|
select_timeout.tv_usec = 1000 * timeout;
|
||||||
}
|
}
|
||||||
@@ -315,7 +298,8 @@ uint16_t arcnet_receive(
|
|||||||
// using O_NONBLOCK and no data
|
// using O_NONBLOCK and no data
|
||||||
// was immediately available for reading.
|
// was immediately available for reading.
|
||||||
if (errno != EAGAIN)
|
if (errno != EAGAIN)
|
||||||
fprintf(stderr,"ethernet: Read error in receiving packet: %s\n",
|
fprintf(stderr,
|
||||||
|
"ethernet: Read error in receiving packet: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -338,22 +322,19 @@ uint16_t arcnet_receive(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((pkt->hard.dest != ARCNET_MAC_Address) &&
|
if ((pkt->hard.dest != ARCNET_MAC_Address) &&
|
||||||
(pkt->hard.dest != ARCNET_BROADCAST))
|
(pkt->hard.dest != ARCNET_BROADCAST)) {
|
||||||
{
|
|
||||||
fprintf(stderr, "arcnet: This packet is not for us.\n");
|
fprintf(stderr, "arcnet: This packet is not for us.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((pkt->soft.raw[1] != 0x82) || /* DSAP */
|
if ((pkt->soft.raw[1] != 0x82) || /* DSAP */
|
||||||
(pkt->soft.raw[2] != 0x82) || /* LSAP */
|
(pkt->soft.raw[2] != 0x82) || /* LSAP */
|
||||||
(pkt->soft.raw[3] != 0x03)) /* LLC Control */
|
(pkt->soft.raw[3] != 0x03)) { /* LLC Control */
|
||||||
{
|
|
||||||
fprintf(stderr, "arcnet: BACnet packet has invalid LLC.\n");
|
fprintf(stderr, "arcnet: BACnet packet has invalid LLC.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* It must be addressed to us or be a Broadcast */
|
/* It must be addressed to us or be a Broadcast */
|
||||||
if ((pkt->hard.dest != ARCNET_MAC_Address) &&
|
if ((pkt->hard.dest != ARCNET_MAC_Address) &&
|
||||||
(pkt->hard.dest != ARCNET_BROADCAST))
|
(pkt->hard.dest != ARCNET_BROADCAST)) {
|
||||||
{
|
|
||||||
fprintf(stderr, "arcnet: This packet is not for us.\n");
|
fprintf(stderr, "arcnet: This packet is not for us.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -381,31 +362,26 @@ void arcnet_get_my_address(BACNET_ADDRESS *my_address)
|
|||||||
my_address->mac[0] = ARCNET_MAC_Address;
|
my_address->mac[0] = ARCNET_MAC_Address;
|
||||||
my_address->net = 0; // local only, no routing
|
my_address->net = 0; // local only, no routing
|
||||||
my_address->len = 0;
|
my_address->len = 0;
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
my_address->adr[i] = 0;
|
my_address->adr[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void arcnet_get_broadcast_address(
|
void arcnet_get_broadcast_address(BACNET_ADDRESS * dest) // destination address
|
||||||
BACNET_ADDRESS *dest) // destination address
|
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
|
|
||||||
if (dest)
|
if (dest) {
|
||||||
{
|
|
||||||
dest->mac[0] = ARCNET_BROADCAST;
|
dest->mac[0] = ARCNET_BROADCAST;
|
||||||
dest->mac_len = 1;
|
dest->mac_len = 1;
|
||||||
dest->net = BACNET_BROADCAST_NETWORK;
|
dest->net = BACNET_BROADCAST_NETWORK;
|
||||||
dest->len = 0; // len=0 denotes broadcast address
|
dest->len = 0; // len=0 denotes broadcast address
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
dest->adr[i] = 0;
|
dest->adr[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,8 @@
|
|||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
|
|
||||||
static int get_local_ifr_ioctl(char *ifname, struct ifreq *ifr, int request)
|
static int get_local_ifr_ioctl(char *ifname, struct ifreq *ifr,
|
||||||
|
int request)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int rv; // return value
|
int rv; // return value
|
||||||
@@ -54,10 +55,8 @@ static int get_local_ifr_ioctl(char *ifname, struct ifreq *ifr, int request)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_local_address_ioctl(
|
static int get_local_address_ioctl(char *ifname,
|
||||||
char *ifname,
|
struct in_addr *addr, int request)
|
||||||
struct in_addr *addr,
|
|
||||||
int request)
|
|
||||||
{
|
{
|
||||||
struct ifreq ifr = { {{0}} };
|
struct ifreq ifr = { {{0}} };
|
||||||
struct sockaddr_in *tcpip_address;
|
struct sockaddr_in *tcpip_address;
|
||||||
@@ -87,7 +86,8 @@ void bip_set_interface(char *ifname)
|
|||||||
get_local_address_ioctl(ifname, &broadcast_address, SIOCGIFBRDADDR);
|
get_local_address_ioctl(ifname, &broadcast_address, SIOCGIFBRDADDR);
|
||||||
bip_set_broadcast_addr(broadcast_address.s_addr);
|
bip_set_broadcast_addr(broadcast_address.s_addr);
|
||||||
#ifdef BIP_DEBUG
|
#ifdef BIP_DEBUG
|
||||||
fprintf(stderr,"Broadcast Address: %s\n",inet_ntoa(broadcast_address));
|
fprintf(stderr, "Broadcast Address: %s\n",
|
||||||
|
inet_ntoa(broadcast_address));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,8 +108,7 @@ bool bip_init(void)
|
|||||||
sockopt = 1;
|
sockopt = 1;
|
||||||
status = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
|
status = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
|
||||||
&sockopt, sizeof(sockopt));
|
&sockopt, sizeof(sockopt));
|
||||||
if (status < 0)
|
if (status < 0) {
|
||||||
{
|
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
bip_set_socket(-1);
|
bip_set_socket(-1);
|
||||||
return status;
|
return status;
|
||||||
@@ -117,13 +116,11 @@ bool bip_init(void)
|
|||||||
// allow us to send a broadcast
|
// allow us to send a broadcast
|
||||||
status = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
|
status = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
|
||||||
&sockopt, sizeof(sockopt));
|
&sockopt, sizeof(sockopt));
|
||||||
if (status < 0)
|
if (status < 0) {
|
||||||
{
|
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
bip_set_socket(-1);
|
bip_set_socket(-1);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind the socket to the local port number and IP address
|
// bind the socket to the local port number and IP address
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
@@ -131,8 +128,7 @@ bool bip_init(void)
|
|||||||
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
|
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
|
||||||
status = bind(sock_fd,
|
status = bind(sock_fd,
|
||||||
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
|
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
|
||||||
if (status < 0)
|
if (status < 0) {
|
||||||
{
|
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
bip_set_socket(-1);
|
bip_set_socket(-1);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
|
|||||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
// commonly used empty address for ethernet quick compare
|
// commonly used empty address for ethernet quick compare
|
||||||
uint8_t Ethernet_Empty_MAC[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
|
uint8_t Ethernet_Empty_MAC[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
// my local device data - MAC address
|
// my local device data - MAC address
|
||||||
uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = { 0 };
|
uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = { 0 };
|
||||||
|
|
||||||
@@ -104,19 +105,16 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
|
|||||||
// Then follow it by: # modprobe af_packet
|
// Then follow it by: # modprobe af_packet
|
||||||
|
|
||||||
/* Attempt to open the socket for 802.2 ethernet frames */
|
/* Attempt to open the socket for 802.2 ethernet frames */
|
||||||
if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0)
|
if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0) {
|
||||||
{
|
|
||||||
/* Error occured */
|
/* Error occured */
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ethernet: Error opening socket: %s\n",
|
"ethernet: Error opening socket: %s\n", strerror(errno));
|
||||||
strerror(errno));
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"You might need to add the following to modules.conf\n"
|
"You might need to add the following to modules.conf\n"
|
||||||
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
||||||
"alias net-pf-17 af_packet\n"
|
"alias net-pf-17 af_packet\n"
|
||||||
"Also, add af_packet to /etc/modules.\n"
|
"Also, add af_packet to /etc/modules.\n"
|
||||||
"Then follow it by:\n"
|
"Then follow it by:\n" "# modprobe af_packet\n");
|
||||||
"# modprobe af_packet\n");
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
/* Bind the socket to an address */
|
/* Bind the socket to an address */
|
||||||
@@ -124,11 +122,11 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
|
|||||||
/* Clear the memory before copying */
|
/* Clear the memory before copying */
|
||||||
memset(eth_addr->sa_data, '\0', sizeof(eth_addr->sa_data));
|
memset(eth_addr->sa_data, '\0', sizeof(eth_addr->sa_data));
|
||||||
/* Strcpy the interface name into the address */
|
/* Strcpy the interface name into the address */
|
||||||
strncpy(eth_addr->sa_data, interface_name, sizeof(eth_addr->sa_data)-1);
|
strncpy(eth_addr->sa_data, interface_name,
|
||||||
|
sizeof(eth_addr->sa_data) - 1);
|
||||||
fprintf(stderr, "ethernet: binding \"%s\"\n", eth_addr->sa_data);
|
fprintf(stderr, "ethernet: binding \"%s\"\n", eth_addr->sa_data);
|
||||||
/* Attempt to bind the socket to the interface */
|
/* Attempt to bind the socket to the interface */
|
||||||
if (bind(sock_fd, eth_addr, sizeof(struct sockaddr)) != 0)
|
if (bind(sock_fd, eth_addr, sizeof(struct sockaddr)) != 0) {
|
||||||
{
|
|
||||||
/* Bind problem, close socket and return */
|
/* Bind problem, close socket and return */
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ethernet: Unable to bind 802.2 socket : %s\n",
|
"ethernet: Unable to bind 802.2 socket : %s\n",
|
||||||
@@ -138,8 +136,7 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
|
|||||||
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
"(or in /etc/modutils/alias on Debian with update-modules):\n"
|
||||||
"alias net-pf-17 af_packet\n"
|
"alias net-pf-17 af_packet\n"
|
||||||
"Also, add af_packet to /etc/modules.\n"
|
"Also, add af_packet to /etc/modules.\n"
|
||||||
"Then follow it by:\n"
|
"Then follow it by:\n" "# modprobe af_packet\n");
|
||||||
"# modprobe af_packet\n");
|
|
||||||
/* Close the socket */
|
/* Close the socket */
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
@@ -174,16 +171,14 @@ static int get_local_hwaddr(const char *ifname, unsigned char *mac)
|
|||||||
bool ethernet_init(char *interface_name)
|
bool ethernet_init(char *interface_name)
|
||||||
{
|
{
|
||||||
get_local_hwaddr(interface_name, Ethernet_MAC_Address);
|
get_local_hwaddr(interface_name, Ethernet_MAC_Address);
|
||||||
eth802_sockfd =
|
eth802_sockfd = ethernet_bind(ð_addr, interface_name);
|
||||||
ethernet_bind(ð_addr, interface_name);
|
|
||||||
|
|
||||||
return ethernet_valid();
|
return ethernet_valid();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* function to send a packet out the 802.2 socket */
|
/* function to send a packet out the 802.2 socket */
|
||||||
/* returns bytes sent success, negative on failure */
|
/* returns bytes sent success, negative on failure */
|
||||||
int ethernet_send(
|
int ethernet_send(BACNET_ADDRESS * dest, // destination address
|
||||||
BACNET_ADDRESS *dest, // destination address
|
|
||||||
BACNET_ADDRESS * src, // source address
|
BACNET_ADDRESS * src, // source address
|
||||||
uint8_t * pdu, // any data to be sent - may be null
|
uint8_t * pdu, // any data to be sent - may be null
|
||||||
unsigned pdu_len) // number of bytes of data
|
unsigned pdu_len) // number of bytes of data
|
||||||
@@ -194,42 +189,32 @@ int ethernet_send(
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// don't waste time if the socket is not valid
|
// don't waste time if the socket is not valid
|
||||||
if (eth802_sockfd < 0)
|
if (eth802_sockfd < 0) {
|
||||||
{
|
|
||||||
fprintf(stderr, "ethernet: 802.2 socket is invalid!\n");
|
fprintf(stderr, "ethernet: 802.2 socket is invalid!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* load destination ethernet MAC address */
|
/* load destination ethernet MAC address */
|
||||||
if (dest->mac_len == 6)
|
if (dest->mac_len == 6) {
|
||||||
{
|
for (i = 0; i < 6; i++) {
|
||||||
for (i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
mtu[mtu_len] = dest->mac[i];
|
mtu[mtu_len] = dest->mac[i];
|
||||||
mtu_len++;
|
mtu_len++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ethernet: invalid destination MAC address!\n");
|
fprintf(stderr, "ethernet: invalid destination MAC address!\n");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load source ethernet MAC address */
|
/* load source ethernet MAC address */
|
||||||
if (src->mac_len == 6)
|
if (src->mac_len == 6) {
|
||||||
{
|
for (i = 0; i < 6; i++) {
|
||||||
for (i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
mtu[mtu_len] = src->mac[i];
|
mtu[mtu_len] = src->mac[i];
|
||||||
mtu_len++;
|
mtu_len++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ethernet: invalid source MAC address!\n");
|
fprintf(stderr, "ethernet: invalid source MAC address!\n");
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
if ((14 + 3 + pdu_len) > MAX_MPDU)
|
if ((14 + 3 + pdu_len) > MAX_MPDU) {
|
||||||
{
|
|
||||||
fprintf(stderr, "ethernet: PDU is too big to send!\n");
|
fprintf(stderr, "ethernet: PDU is too big to send!\n");
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
@@ -257,16 +242,14 @@ int ethernet_send(
|
|||||||
|
|
||||||
/* function to send a packet out the 802.2 socket */
|
/* function to send a packet out the 802.2 socket */
|
||||||
/* returns number of bytes sent on success, negative on failure */
|
/* returns number of bytes sent on success, negative on failure */
|
||||||
int ethernet_send_pdu(
|
int ethernet_send_pdu(BACNET_ADDRESS * dest, // destination address
|
||||||
BACNET_ADDRESS *dest, // destination address
|
|
||||||
uint8_t * pdu, // any data to be sent - may be null
|
uint8_t * pdu, // any data to be sent - may be null
|
||||||
unsigned pdu_len) // number of bytes of data
|
unsigned pdu_len) // number of bytes of data
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
BACNET_ADDRESS src = { 0 }; // source address
|
BACNET_ADDRESS src = { 0 }; // source address
|
||||||
|
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++) {
|
||||||
{
|
|
||||||
src.mac[i] = Ethernet_MAC_Address[i];
|
src.mac[i] = Ethernet_MAC_Address[i];
|
||||||
src.mac_len++;
|
src.mac_len++;
|
||||||
}
|
}
|
||||||
@@ -280,8 +263,7 @@ int ethernet_send_pdu(
|
|||||||
|
|
||||||
// receives an 802.2 framed packet
|
// receives an 802.2 framed packet
|
||||||
// returns the number of octets in the PDU, or zero on failure
|
// returns the number of octets in the PDU, or zero on failure
|
||||||
uint16_t ethernet_receive(
|
uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address
|
||||||
BACNET_ADDRESS *src, // source address
|
|
||||||
uint8_t * pdu, // PDU data
|
uint8_t * pdu, // PDU data
|
||||||
uint16_t max_pdu, // amount of space available in the PDU
|
uint16_t max_pdu, // amount of space available in the PDU
|
||||||
unsigned timeout) // number of milliseconds to wait for a packet
|
unsigned timeout) // number of milliseconds to wait for a packet
|
||||||
@@ -300,14 +282,11 @@ uint16_t ethernet_receive(
|
|||||||
/* we could just use a non-blocking socket, but that consumes all
|
/* we could just use a non-blocking socket, but that consumes all
|
||||||
the CPU time. We can use a timeout; it is only supported as
|
the CPU time. We can use a timeout; it is only supported as
|
||||||
a select. */
|
a select. */
|
||||||
if (timeout >= 1000)
|
if (timeout >= 1000) {
|
||||||
{
|
|
||||||
select_timeout.tv_sec = timeout / 1000;
|
select_timeout.tv_sec = timeout / 1000;
|
||||||
select_timeout.tv_usec =
|
select_timeout.tv_usec =
|
||||||
1000 * (timeout - select_timeout.tv_sec * 1000);
|
1000 * (timeout - select_timeout.tv_sec * 1000);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
select_timeout.tv_sec = 0;
|
select_timeout.tv_sec = 0;
|
||||||
select_timeout.tv_usec = 1000 * timeout;
|
select_timeout.tv_usec = 1000 * timeout;
|
||||||
}
|
}
|
||||||
@@ -326,7 +305,8 @@ uint16_t ethernet_receive(
|
|||||||
// using O_NONBLOCK and no data
|
// using O_NONBLOCK and no data
|
||||||
// was immediately available for reading.
|
// was immediately available for reading.
|
||||||
if (errno != EAGAIN)
|
if (errno != EAGAIN)
|
||||||
fprintf(stderr,"ethernet: Read error in receiving packet: %s\n",
|
fprintf(stderr,
|
||||||
|
"ethernet: Read error in receiving packet: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -346,8 +326,7 @@ uint16_t ethernet_receive(
|
|||||||
// check destination address for when
|
// check destination address for when
|
||||||
// the Ethernet card is in promiscious mode
|
// the Ethernet card is in promiscious mode
|
||||||
if ((memcmp(&buf[0], Ethernet_MAC_Address, 6) != 0)
|
if ((memcmp(&buf[0], Ethernet_MAC_Address, 6) != 0)
|
||||||
&& (memcmp(&buf[0], Ethernet_Broadcast, 6) != 0))
|
&& (memcmp(&buf[0], Ethernet_Broadcast, 6) != 0)) {
|
||||||
{
|
|
||||||
//fprintf(stderr, "ethernet: This packet isn't for us\n");
|
//fprintf(stderr, "ethernet: This packet isn't for us\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -369,8 +348,7 @@ void ethernet_set_my_address(BACNET_ADDRESS *my_address)
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++) {
|
||||||
{
|
|
||||||
Ethernet_MAC_Address[i] = my_address->mac[i];
|
Ethernet_MAC_Address[i] = my_address->mac[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,37 +360,31 @@ void ethernet_get_my_address(BACNET_ADDRESS *my_address)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
my_address->mac_len = 0;
|
my_address->mac_len = 0;
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++) {
|
||||||
{
|
|
||||||
my_address->mac[i] = Ethernet_MAC_Address[i];
|
my_address->mac[i] = Ethernet_MAC_Address[i];
|
||||||
my_address->mac_len++;
|
my_address->mac_len++;
|
||||||
}
|
}
|
||||||
my_address->net = 0; // local only, no routing
|
my_address->net = 0; // local only, no routing
|
||||||
my_address->len = 0;
|
my_address->len = 0;
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
my_address->adr[i] = 0;
|
my_address->adr[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ethernet_get_broadcast_address(
|
void ethernet_get_broadcast_address(BACNET_ADDRESS * dest) // destination address
|
||||||
BACNET_ADDRESS *dest) // destination address
|
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
|
|
||||||
if (dest)
|
if (dest) {
|
||||||
{
|
for (i = 0; i < 6; i++) {
|
||||||
for (i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
dest->mac[i] = Ethernet_Broadcast[i];
|
dest->mac[i] = Ethernet_Broadcast[i];
|
||||||
}
|
}
|
||||||
dest->mac_len = 6;
|
dest->mac_len = 6;
|
||||||
dest->net = BACNET_BROADCAST_NETWORK;
|
dest->net = BACNET_BROADCAST_NETWORK;
|
||||||
dest->len = 0; // denotes broadcast address
|
dest->len = 0; // denotes broadcast address
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
dest->adr[i] = 0;
|
dest->adr[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -420,29 +392,24 @@ void ethernet_get_broadcast_address(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ethernet_debug_address(
|
void ethernet_debug_address(const char *info, BACNET_ADDRESS * dest)
|
||||||
const char *info,
|
|
||||||
BACNET_ADDRESS *dest)
|
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
|
|
||||||
if (info)
|
if (info)
|
||||||
fprintf(stderr, "%s", info);
|
fprintf(stderr, "%s", info);
|
||||||
if (dest)
|
if (dest) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Address:\n");
|
fprintf(stderr, "Address:\n");
|
||||||
fprintf(stderr, " MAC Length=%d\n", dest->mac_len);
|
fprintf(stderr, " MAC Length=%d\n", dest->mac_len);
|
||||||
fprintf(stderr, " MAC Address=");
|
fprintf(stderr, " MAC Address=");
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
fprintf(stderr, "%02X ", (unsigned) dest->mac[i]);
|
fprintf(stderr, "%02X ", (unsigned) dest->mac[i]);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, " Net=%hu\n", dest->net);
|
fprintf(stderr, " Net=%hu\n", dest->net);
|
||||||
fprintf(stderr, " Len=%d\n", dest->len);
|
fprintf(stderr, " Len=%d\n", dest->len);
|
||||||
fprintf(stderr, " Adr=");
|
fprintf(stderr, " Adr=");
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
fprintf(stderr, "%02X ", (unsigned) dest->adr[i]);
|
fprintf(stderr, "%02X ", (unsigned) dest->adr[i]);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
@@ -450,4 +417,3 @@ void ethernet_debug_address(
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,10 +50,8 @@ bool Who_Is_Request = true;
|
|||||||
// buffers used for receiving
|
// buffers used for receiving
|
||||||
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
||||||
|
|
||||||
static void LocalIAmHandler(
|
static void LocalIAmHandler(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src)
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
uint32_t device_id = 0;
|
uint32_t device_id = 0;
|
||||||
@@ -63,21 +61,13 @@ static void LocalIAmHandler(
|
|||||||
|
|
||||||
(void) src;
|
(void) src;
|
||||||
(void) service_len;
|
(void) service_len;
|
||||||
len = iam_decode_service_request(
|
len = iam_decode_service_request(service_request,
|
||||||
service_request,
|
&device_id, &max_apdu, &segmentation, &vendor_id);
|
||||||
&device_id,
|
|
||||||
&max_apdu,
|
|
||||||
&segmentation,
|
|
||||||
&vendor_id);
|
|
||||||
fprintf(stderr, "Received I-Am Request");
|
fprintf(stderr, "Received I-Am Request");
|
||||||
if (len != -1)
|
if (len != -1) {
|
||||||
{
|
|
||||||
fprintf(stderr, " from %u!\n", device_id);
|
fprintf(stderr, " from %u!\n", device_id);
|
||||||
address_add(device_id,
|
address_add(device_id, max_apdu, src);
|
||||||
max_apdu,
|
} else
|
||||||
src);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fprintf(stderr, "!\n");
|
fprintf(stderr, "!\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -96,8 +86,7 @@ static void Read_Properties(void)
|
|||||||
properties in the Device Object. Note that this demo
|
properties in the Device Object. Note that this demo
|
||||||
tests for error messages so that the device doesn't have
|
tests for error messages so that the device doesn't have
|
||||||
to have all the properties listed here. */
|
to have all the properties listed here. */
|
||||||
const int object_props[] =
|
const int object_props[] = {
|
||||||
{
|
|
||||||
PROP_OBJECT_IDENTIFIER,
|
PROP_OBJECT_IDENTIFIER,
|
||||||
PROP_OBJECT_NAME,
|
PROP_OBJECT_NAME,
|
||||||
PROP_OBJECT_TYPE,
|
PROP_OBJECT_TYPE,
|
||||||
@@ -136,32 +125,24 @@ static void Read_Properties(void)
|
|||||||
-1
|
-1
|
||||||
};
|
};
|
||||||
|
|
||||||
if (address_count())
|
if (address_count()) {
|
||||||
{
|
if (address_get_by_index(index, &device_id, &max_apdu, &src)) {
|
||||||
if (address_get_by_index(index, &device_id, &max_apdu, &src))
|
|
||||||
{
|
|
||||||
if (object_props[property] < 0)
|
if (object_props[property] < 0)
|
||||||
next_device = true;
|
next_device = true;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* note: if we wanted to do this synchronously, we would get the
|
/* note: if we wanted to do this synchronously, we would get the
|
||||||
invoke ID from the sending of the request, and wait until we
|
invoke ID from the sending of the request, and wait until we
|
||||||
got the reply with matching invoke ID or the TSM of the
|
got the reply with matching invoke ID or the TSM of the
|
||||||
invoke ID expired. This demo is doing things asynchronously. */
|
invoke ID expired. This demo is doing things asynchronously. */
|
||||||
status = Send_Read_Property_Request(
|
status = Send_Read_Property_Request(device_id, // destination device
|
||||||
device_id, // destination device
|
|
||||||
OBJECT_DEVICE,
|
OBJECT_DEVICE,
|
||||||
device_id,
|
device_id, object_props[property], BACNET_ARRAY_ALL);
|
||||||
object_props[property],
|
|
||||||
BACNET_ARRAY_ALL);
|
|
||||||
if (status)
|
if (status)
|
||||||
property++;
|
property++;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
next_device = true;
|
next_device = true;
|
||||||
if (next_device)
|
if (next_device) {
|
||||||
{
|
|
||||||
next_device = false;
|
next_device = false;
|
||||||
index++;
|
index++;
|
||||||
if (index >= MAX_ADDRESS_CACHE)
|
if (index >= MAX_ADDRESS_CACHE)
|
||||||
@@ -176,34 +157,27 @@ static void Read_Properties(void)
|
|||||||
static void Init_Service_Handlers(void)
|
static void Init_Service_Handlers(void)
|
||||||
{
|
{
|
||||||
// we need to handle who-is to support dynamic device binding
|
// we need to handle who-is to support dynamic device binding
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
handler_who_is);
|
handler_who_is);
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM,
|
||||||
SERVICE_UNCONFIRMED_I_AM,
|
|
||||||
LocalIAmHandler);
|
LocalIAmHandler);
|
||||||
|
|
||||||
// set the handler for all the services we don't implement
|
// set the handler for all the services we don't implement
|
||||||
// It is required to send the proper reject message...
|
// It is required to send the proper reject message...
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
handler_unrecognized_service);
|
(handler_unrecognized_service);
|
||||||
// Set the handlers for any confirmed services that we support.
|
// Set the handlers for any confirmed services that we support.
|
||||||
// We must implement read property - it's required!
|
// We must implement read property - it's required!
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property);
|
handler_read_property);
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
|
||||||
handler_write_property);
|
handler_write_property);
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
||||||
SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
|
||||||
handler_atomic_read_file);
|
handler_atomic_read_file);
|
||||||
// handle the data coming back from confirmed requests
|
// handle the data coming back from confirmed requests
|
||||||
apdu_set_confirmed_ack_handler(
|
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property_ack);
|
handler_read_property_ack);
|
||||||
apdu_set_confirmed_ack_handler(
|
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
||||||
SERVICE_CONFIRMED_ATOMIC_READ_FILE,
|
|
||||||
handler_atomic_read_file_ack);
|
handler_atomic_read_file_ack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,13 +189,10 @@ static void print_address_cache(void)
|
|||||||
unsigned max_apdu = 0;
|
unsigned max_apdu = 0;
|
||||||
|
|
||||||
fprintf(stderr, "Device\tMAC\tMaxAPDU\tNet\n");
|
fprintf(stderr, "Device\tMAC\tMaxAPDU\tNet\n");
|
||||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++)
|
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||||
{
|
if (address_get_by_index(i, &device_id, &max_apdu, &address)) {
|
||||||
if (address_get_by_index(i,&device_id, &max_apdu, &address))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%u\t", device_id);
|
fprintf(stderr, "%u\t", device_id);
|
||||||
for (j = 0; j < address.mac_len; j++)
|
for (j = 0; j < address.mac_len; j++) {
|
||||||
{
|
|
||||||
fprintf(stderr, "%02X", address.mac[j]);
|
fprintf(stderr, "%02X", address.mac[j]);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\t");
|
fprintf(stderr, "\t");
|
||||||
@@ -284,44 +255,31 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// loop forever
|
// loop forever
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
// input
|
// input
|
||||||
new_time = time(NULL);
|
new_time = time(NULL);
|
||||||
// returns 0 bytes on timeout
|
// returns 0 bytes on timeout
|
||||||
pdu_len = datalink_receive(
|
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
|
|
||||||
// process
|
// process
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
if (new_time > start_time)
|
if (new_time > start_time) {
|
||||||
{
|
|
||||||
tsm_timer_milliseconds(new_time - start_time * 1000);
|
tsm_timer_milliseconds(new_time - start_time * 1000);
|
||||||
start_time = new_time;
|
start_time = new_time;
|
||||||
}
|
}
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
iam_send(&Handler_Transmit_Buffer[0]);
|
iam_send(&Handler_Transmit_Buffer[0]);
|
||||||
} else if (Who_Is_Request)
|
} else if (Who_Is_Request) {
|
||||||
{
|
|
||||||
Who_Is_Request = false;
|
Who_Is_Request = false;
|
||||||
Send_WhoIs(-1, -1);
|
Send_WhoIs(-1, -1);
|
||||||
}
|
}
|
||||||
// output
|
// output
|
||||||
// some round robin task switching
|
// some round robin task switching
|
||||||
count++;
|
count++;
|
||||||
switch (count)
|
switch (count) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
// used for testing, but kind of noisy on the network
|
// used for testing, but kind of noisy on the network
|
||||||
//Read_Properties();
|
//Read_Properties();
|
||||||
|
|||||||
@@ -44,22 +44,19 @@
|
|||||||
#include "mstp.h"
|
#include "mstp.h"
|
||||||
|
|
||||||
// Transmits a Frame on the wire
|
// Transmits a Frame on the wire
|
||||||
void RS485_Send_Frame(
|
void RS485_Send_Frame(struct mstp_port_struct_t *mstp_port, // port specific data
|
||||||
struct mstp_port_struct_t *mstp_port, // port specific data
|
|
||||||
uint8_t * buffer, // frame to send (up to 501 bytes of data)
|
uint8_t * buffer, // frame to send (up to 501 bytes of data)
|
||||||
uint16_t nbytes) // number of bytes of data (up to 501)
|
uint16_t nbytes) // number of bytes of data (up to 501)
|
||||||
{
|
{
|
||||||
|
|
||||||
// in order to avoid line contention
|
// in order to avoid line contention
|
||||||
while (mstp_port->Turn_Around_Waiting)
|
while (mstp_port->Turn_Around_Waiting) {
|
||||||
{
|
|
||||||
// wait, yield, or whatever
|
// wait, yield, or whatever
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable the receiver, and enable the transmit line driver.
|
// Disable the receiver, and enable the transmit line driver.
|
||||||
|
|
||||||
while (nbytes)
|
while (nbytes) {
|
||||||
{
|
|
||||||
putc(*buffer, stderr);
|
putc(*buffer, stderr);
|
||||||
buffer++;
|
buffer++;
|
||||||
nbytes--;
|
nbytes--;
|
||||||
@@ -76,13 +73,11 @@ void RS485_Send_Frame(
|
|||||||
// called by timer, interrupt(?) or other thread
|
// called by timer, interrupt(?) or other thread
|
||||||
void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port)
|
void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port)
|
||||||
{
|
{
|
||||||
if (mstp_port->ReceiveError == true)
|
if (mstp_port->ReceiveError == true) {
|
||||||
{
|
|
||||||
// wait for state machine to clear this
|
// wait for state machine to clear this
|
||||||
}
|
}
|
||||||
// wait for state machine to read from the DataRegister
|
// wait for state machine to read from the DataRegister
|
||||||
else if (mstp_port->DataAvailable == false)
|
else if (mstp_port->DataAvailable == false) {
|
||||||
{
|
|
||||||
// check for data
|
// check for data
|
||||||
|
|
||||||
// if error,
|
// if error,
|
||||||
@@ -96,4 +91,3 @@ void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port)
|
|||||||
// return;
|
// return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ static void Error(const char * Msg)
|
|||||||
/*-----------------------------------*/
|
/*-----------------------------------*/
|
||||||
void InterfaceCleanup(void)
|
void InterfaceCleanup(void)
|
||||||
{
|
{
|
||||||
if (interface != SOCKET_ERROR)
|
if (interface != SOCKET_ERROR) {
|
||||||
{
|
|
||||||
xn_interface_close(interface);
|
xn_interface_close(interface);
|
||||||
interface = SOCKET_ERROR;
|
interface = SOCKET_ERROR;
|
||||||
#if DEVICE_ID == PRISM_PCMCIA_DEVICE
|
#if DEVICE_ID == PRISM_PCMCIA_DEVICE
|
||||||
@@ -100,7 +99,6 @@ static void NetInitialize(void)
|
|||||||
#ifdef DHCP
|
#ifdef DHCP
|
||||||
XN_REGISTER_DHCP_CLI() // and optionally the DHCP client
|
XN_REGISTER_DHCP_CLI() // and optionally the DHCP client
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Result = xn_rtip_init(); // Initialize the RTIP stack
|
Result = xn_rtip_init(); // Initialize the RTIP stack
|
||||||
if (Result != 0)
|
if (Result != 0)
|
||||||
Error("xn_rtip_init failed");
|
Error("xn_rtip_init failed");
|
||||||
@@ -119,23 +117,25 @@ static void NetInitialize(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Open the interface
|
// Open the interface
|
||||||
interface = xn_interface_open_config(DEVICE_ID, MINOR_0, ED_IO_ADD, ED_IRQ, ED_MEM_ADD);
|
interface =
|
||||||
|
xn_interface_open_config(DEVICE_ID, MINOR_0, ED_IO_ADD, ED_IRQ,
|
||||||
|
ED_MEM_ADD);
|
||||||
if (interface == SOCKET_ERROR)
|
if (interface == SOCKET_ERROR)
|
||||||
Error("xn_interface_open_config failed");
|
Error("xn_interface_open_config failed");
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
struct _iface_info ii;
|
struct _iface_info ii;
|
||||||
#ifdef BACDL_ETHERNET
|
#ifdef BACDL_ETHERNET
|
||||||
BACNET_ADDRESS my_address;
|
BACNET_ADDRESS my_address;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
#endif
|
#endif
|
||||||
xn_interface_info(interface, &ii);
|
xn_interface_info(interface, &ii);
|
||||||
printf("Interface opened, MAC address: %02x-%02x-%02x-%02x-%02x-%02x\n",
|
printf
|
||||||
ii.my_ethernet_address[0], ii.my_ethernet_address[1], ii.my_ethernet_address[2],
|
("Interface opened, MAC address: %02x-%02x-%02x-%02x-%02x-%02x\n",
|
||||||
ii.my_ethernet_address[3], ii.my_ethernet_address[4], ii.my_ethernet_address[5]);
|
ii.my_ethernet_address[0], ii.my_ethernet_address[1],
|
||||||
|
ii.my_ethernet_address[2], ii.my_ethernet_address[3],
|
||||||
|
ii.my_ethernet_address[4], ii.my_ethernet_address[5]);
|
||||||
#ifdef BACDL_ETHERNET
|
#ifdef BACDL_ETHERNET
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++) {
|
||||||
{
|
|
||||||
my_address.mac[i] = ii.my_ethernet_address[i];
|
my_address.mac[i] = ii.my_ethernet_address[i];
|
||||||
}
|
}
|
||||||
ethernet_set_my_address(&my_address);
|
ethernet_set_my_address(&my_address);
|
||||||
@@ -157,16 +157,20 @@ static void NetInitialize(void)
|
|||||||
Result = xn_autoip(interface, MinIP, MaxIP, NetMask, TargetIP);
|
Result = xn_autoip(interface, MinIP, MaxIP, NetMask, TargetIP);
|
||||||
if (Result == SOCKET_ERROR)
|
if (Result == SOCKET_ERROR)
|
||||||
Error("xn_autoip failed");
|
Error("xn_autoip failed");
|
||||||
else
|
else {
|
||||||
{
|
printf("Auto-assigned IP address %i.%i.%i.%i\n", TargetIP[0],
|
||||||
printf("Auto-assigned IP address %i.%i.%i.%i\n", TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]);
|
TargetIP[1], TargetIP[2], TargetIP[3]);
|
||||||
// define default gateway and DNS server
|
// define default gateway and DNS server
|
||||||
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface, RT_INF);
|
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface,
|
||||||
|
RT_INF);
|
||||||
xn_set_server_list((DWORD *) DNSServer, 1);
|
xn_set_server_list((DWORD *) DNSServer, 1);
|
||||||
}
|
}
|
||||||
#elif defined(DHCP) // use DHCP
|
#elif defined(DHCP) // use DHCP
|
||||||
{
|
{
|
||||||
DHCP_param param[] = {{SUBNET_MASK, 1}, {DNS_OP, 1}, {ROUTER_OPTION, 1}};
|
DHCP_param param[] = { {SUBNET_MASK, 1}
|
||||||
|
, {DNS_OP, 1}
|
||||||
|
, {ROUTER_OPTION, 1}
|
||||||
|
};
|
||||||
DHCP_session DS;
|
DHCP_session DS;
|
||||||
DHCP_conf DC;
|
DHCP_conf DC;
|
||||||
|
|
||||||
@@ -178,11 +182,13 @@ static void NetInitialize(void)
|
|||||||
if (Result == SOCKET_ERROR)
|
if (Result == SOCKET_ERROR)
|
||||||
Error("xn_dhcp failed");
|
Error("xn_dhcp failed");
|
||||||
memcpy(TargetIP, DS.client_ip, 4);
|
memcpy(TargetIP, DS.client_ip, 4);
|
||||||
printf("My IP address is: %i.%i.%i.%i\n", TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]);
|
printf("My IP address is: %i.%i.%i.%i\n", TargetIP[0], TargetIP[1],
|
||||||
|
TargetIP[2], TargetIP[3]);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Set the IP address and interface
|
// Set the IP address and interface
|
||||||
printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]);
|
printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0],
|
||||||
|
TargetIP[1], TargetIP[2], TargetIP[3]);
|
||||||
Result = xn_set_ip(interface, TargetIP, NetMask);
|
Result = xn_set_ip(interface, TargetIP, NetMask);
|
||||||
// define default gateway and DNS server
|
// define default gateway and DNS server
|
||||||
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface, RT_INF);
|
xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface, RT_INF);
|
||||||
@@ -239,8 +245,7 @@ bool bip_init(void)
|
|||||||
memset(&(sin.sin_zero), '\0', 8);
|
memset(&(sin.sin_zero), '\0', 8);
|
||||||
rv = bind(sock_fd,
|
rv = bind(sock_fd,
|
||||||
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
|
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
|
||||||
if (rv < 0)
|
if (rv < 0) {
|
||||||
{
|
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
bip_set_socket(-1);
|
bip_set_socket(-1);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
|
|||||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
// commonly used empty address for ethernet quick compare
|
// commonly used empty address for ethernet quick compare
|
||||||
uint8_t Ethernet_Empty_MAC[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
|
uint8_t Ethernet_Empty_MAC[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
// my local device data - MAC address
|
// my local device data - MAC address
|
||||||
uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
|
uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = { 0, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
@@ -83,8 +84,7 @@ bool ethernet_init(char *interface_name)
|
|||||||
|
|
||||||
/* function to send a packet out the 802.2 socket */
|
/* function to send a packet out the 802.2 socket */
|
||||||
/* returns bytes sent on success, negative number on failure */
|
/* returns bytes sent on success, negative number on failure */
|
||||||
int ethernet_send(
|
int ethernet_send(BACNET_ADDRESS * dest, // destination address
|
||||||
BACNET_ADDRESS *dest, // destination address
|
|
||||||
BACNET_ADDRESS * src, // source address
|
BACNET_ADDRESS * src, // source address
|
||||||
uint8_t * pdu, // any data to be sent - may be null
|
uint8_t * pdu, // any data to be sent - may be null
|
||||||
unsigned pdu_len) // number of bytes of data
|
unsigned pdu_len) // number of bytes of data
|
||||||
@@ -95,42 +95,32 @@ int ethernet_send(
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// don't waste time if the socket is not valid
|
// don't waste time if the socket is not valid
|
||||||
if (Ethernet_Socket < 0)
|
if (Ethernet_Socket < 0) {
|
||||||
{
|
|
||||||
fprintf(stderr, "ethernet: 802.2 socket is invalid!\n");
|
fprintf(stderr, "ethernet: 802.2 socket is invalid!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* load destination ethernet MAC address */
|
/* load destination ethernet MAC address */
|
||||||
if (dest->mac_len == 6)
|
if (dest->mac_len == 6) {
|
||||||
{
|
for (i = 0; i < 6; i++) {
|
||||||
for (i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
mtu[mtu_len] = dest->mac[i];
|
mtu[mtu_len] = dest->mac[i];
|
||||||
mtu_len++;
|
mtu_len++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ethernet: invalid destination MAC address!\n");
|
fprintf(stderr, "ethernet: invalid destination MAC address!\n");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load source ethernet MAC address */
|
/* load source ethernet MAC address */
|
||||||
if (src->mac_len == 6)
|
if (src->mac_len == 6) {
|
||||||
{
|
for (i = 0; i < 6; i++) {
|
||||||
for (i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
mtu[mtu_len] = src->mac[i];
|
mtu[mtu_len] = src->mac[i];
|
||||||
mtu_len++;
|
mtu_len++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ethernet: invalid source MAC address!\n");
|
fprintf(stderr, "ethernet: invalid source MAC address!\n");
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
if ((14 + 3 + pdu_len) > MAX_MPDU)
|
if ((14 + 3 + pdu_len) > MAX_MPDU) {
|
||||||
{
|
|
||||||
fprintf(stderr, "ethernet: PDU is too big to send!\n");
|
fprintf(stderr, "ethernet: PDU is too big to send!\n");
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
@@ -145,8 +135,7 @@ int ethernet_send(
|
|||||||
mtu_len += pdu_len;
|
mtu_len += pdu_len;
|
||||||
|
|
||||||
/* Send the packet */
|
/* Send the packet */
|
||||||
bytes =
|
bytes = send(Ethernet_Socket, (const char *) &mtu, mtu_len, 0);
|
||||||
send(Ethernet_Socket, (const char *)&mtu, mtu_len, 0);
|
|
||||||
/* did it get sent? */
|
/* did it get sent? */
|
||||||
if (bytes < 0)
|
if (bytes < 0)
|
||||||
fprintf(stderr, "ethernet: Error sending packet: %s\n",
|
fprintf(stderr, "ethernet: Error sending packet: %s\n",
|
||||||
@@ -157,16 +146,14 @@ int ethernet_send(
|
|||||||
|
|
||||||
/* function to send a packet out the 802.2 socket */
|
/* function to send a packet out the 802.2 socket */
|
||||||
/* returns bytes sent on success, negative number on failure */
|
/* returns bytes sent on success, negative number on failure */
|
||||||
int ethernet_send_pdu(
|
int ethernet_send_pdu(BACNET_ADDRESS * dest, // destination address
|
||||||
BACNET_ADDRESS *dest, // destination address
|
|
||||||
uint8_t * pdu, // any data to be sent - may be null
|
uint8_t * pdu, // any data to be sent - may be null
|
||||||
unsigned pdu_len) // number of bytes of data
|
unsigned pdu_len) // number of bytes of data
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
BACNET_ADDRESS src = { 0 }; // source address
|
BACNET_ADDRESS src = { 0 }; // source address
|
||||||
|
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++) {
|
||||||
{
|
|
||||||
src.mac[i] = Ethernet_MAC_Address[i];
|
src.mac[i] = Ethernet_MAC_Address[i];
|
||||||
src.mac_len++;
|
src.mac_len++;
|
||||||
}
|
}
|
||||||
@@ -180,8 +167,7 @@ int ethernet_send_pdu(
|
|||||||
|
|
||||||
// receives an 802.2 framed packet
|
// receives an 802.2 framed packet
|
||||||
// returns the number of octets in the PDU, or zero on failure
|
// returns the number of octets in the PDU, or zero on failure
|
||||||
uint16_t ethernet_receive(
|
uint16_t ethernet_receive(BACNET_ADDRESS * src, // source address
|
||||||
BACNET_ADDRESS *src, // source address
|
|
||||||
uint8_t * pdu, // PDU data
|
uint8_t * pdu, // PDU data
|
||||||
uint16_t max_pdu, // amount of space available in the PDU
|
uint16_t max_pdu, // amount of space available in the PDU
|
||||||
unsigned timeout) // number of milliseconds to wait for a packet
|
unsigned timeout) // number of milliseconds to wait for a packet
|
||||||
@@ -200,14 +186,11 @@ uint16_t ethernet_receive(
|
|||||||
/* we could just use a non-blocking socket, but that consumes all
|
/* we could just use a non-blocking socket, but that consumes all
|
||||||
the CPU time. We can use a timeout; it is only supported as
|
the CPU time. We can use a timeout; it is only supported as
|
||||||
a select. */
|
a select. */
|
||||||
if (timeout >= 1000)
|
if (timeout >= 1000) {
|
||||||
{
|
|
||||||
select_timeout.tv_sec = timeout / 1000;
|
select_timeout.tv_sec = timeout / 1000;
|
||||||
select_timeout.tv_usec =
|
select_timeout.tv_usec =
|
||||||
1000 * (timeout - select_timeout.tv_sec * 1000);
|
1000 * (timeout - select_timeout.tv_sec * 1000);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
select_timeout.tv_sec = 0;
|
select_timeout.tv_sec = 0;
|
||||||
select_timeout.tv_usec = 1000 * timeout;
|
select_timeout.tv_usec = 1000 * timeout;
|
||||||
}
|
}
|
||||||
@@ -216,7 +199,8 @@ uint16_t ethernet_receive(
|
|||||||
max = Ethernet_Socket;
|
max = Ethernet_Socket;
|
||||||
|
|
||||||
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0)
|
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0)
|
||||||
received_bytes = recv(Ethernet_Socket, (char *)&buf[0], MAX_MPDU, 0);
|
received_bytes =
|
||||||
|
recv(Ethernet_Socket, (char *) &buf[0], MAX_MPDU, 0);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -226,7 +210,8 @@ uint16_t ethernet_receive(
|
|||||||
// using O_NONBLOCK and no data
|
// using O_NONBLOCK and no data
|
||||||
// was immediately available for reading.
|
// was immediately available for reading.
|
||||||
if (errno != EAGAIN)
|
if (errno != EAGAIN)
|
||||||
fprintf(stderr,"ethernet: Read error in receiving packet: %s\n",
|
fprintf(stderr,
|
||||||
|
"ethernet: Read error in receiving packet: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -246,8 +231,7 @@ uint16_t ethernet_receive(
|
|||||||
// check destination address for when
|
// check destination address for when
|
||||||
// the Ethernet card is in promiscious mode
|
// the Ethernet card is in promiscious mode
|
||||||
if ((memcmp(&buf[0], Ethernet_MAC_Address, 6) != 0)
|
if ((memcmp(&buf[0], Ethernet_MAC_Address, 6) != 0)
|
||||||
&& (memcmp(&buf[0], Ethernet_Broadcast, 6) != 0))
|
&& (memcmp(&buf[0], Ethernet_Broadcast, 6) != 0)) {
|
||||||
{
|
|
||||||
//fprintf(stderr, "ethernet: This packet isn't for us\n");
|
//fprintf(stderr, "ethernet: This packet isn't for us\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -270,15 +254,13 @@ void ethernet_get_my_address(BACNET_ADDRESS *my_address)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
my_address->mac_len = 0;
|
my_address->mac_len = 0;
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++) {
|
||||||
{
|
|
||||||
my_address->mac[i] = Ethernet_MAC_Address[i];
|
my_address->mac[i] = Ethernet_MAC_Address[i];
|
||||||
my_address->mac_len++;
|
my_address->mac_len++;
|
||||||
}
|
}
|
||||||
my_address->net = 0; // local only, no routing
|
my_address->net = 0; // local only, no routing
|
||||||
my_address->len = 0;
|
my_address->len = 0;
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
my_address->adr[i] = 0;
|
my_address->adr[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,30 +271,25 @@ void ethernet_set_my_address(BACNET_ADDRESS *my_address)
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++) {
|
||||||
{
|
|
||||||
Ethernet_MAC_Address[i] = my_address->mac[i];
|
Ethernet_MAC_Address[i] = my_address->mac[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ethernet_get_broadcast_address(
|
void ethernet_get_broadcast_address(BACNET_ADDRESS * dest) // destination address
|
||||||
BACNET_ADDRESS *dest) // destination address
|
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
|
|
||||||
if (dest)
|
if (dest) {
|
||||||
{
|
for (i = 0; i < 6; i++) {
|
||||||
for (i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
dest->mac[i] = Ethernet_Broadcast[i];
|
dest->mac[i] = Ethernet_Broadcast[i];
|
||||||
}
|
}
|
||||||
dest->mac_len = 6;
|
dest->mac_len = 6;
|
||||||
dest->net = BACNET_BROADCAST_NETWORK;
|
dest->net = BACNET_BROADCAST_NETWORK;
|
||||||
dest->len = 0; // denotes broadcast address
|
dest->len = 0; // denotes broadcast address
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
dest->adr[i] = 0;
|
dest->adr[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,29 +297,24 @@ void ethernet_get_broadcast_address(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ethernet_debug_address(
|
void ethernet_debug_address(const char *info, BACNET_ADDRESS * dest)
|
||||||
const char *info,
|
|
||||||
BACNET_ADDRESS *dest)
|
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
|
|
||||||
if (info)
|
if (info)
|
||||||
fprintf(stderr, "%s", info);
|
fprintf(stderr, "%s", info);
|
||||||
if (dest)
|
if (dest) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Address:\n");
|
fprintf(stderr, "Address:\n");
|
||||||
fprintf(stderr, " MAC Length=%d\n", dest->mac_len);
|
fprintf(stderr, " MAC Length=%d\n", dest->mac_len);
|
||||||
fprintf(stderr, " MAC Address=");
|
fprintf(stderr, " MAC Address=");
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
fprintf(stderr, "%02X ", (unsigned) dest->mac[i]);
|
fprintf(stderr, "%02X ", (unsigned) dest->mac[i]);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr, " Net=%hu\n", dest->net);
|
fprintf(stderr, " Net=%hu\n", dest->net);
|
||||||
fprintf(stderr, " Len=%d\n", dest->len);
|
fprintf(stderr, " Len=%d\n", dest->len);
|
||||||
fprintf(stderr, " Adr=");
|
fprintf(stderr, " Adr=");
|
||||||
for (i = 0; i < MAX_MAC_LEN; i++)
|
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||||
{
|
|
||||||
fprintf(stderr, "%02X ", (unsigned) dest->adr[i]);
|
fprintf(stderr, "%02X ", (unsigned) dest->adr[i]);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ extern void RTEmuInit(void);
|
|||||||
static RTFDrvDOCData DOCDriveData = { 0 };
|
static RTFDrvDOCData DOCDriveData = { 0 };
|
||||||
static RTFDrvIDEData IDEDriveData = { 0 };
|
static RTFDrvIDEData IDEDriveData = { 0 };
|
||||||
|
|
||||||
RTFDevice RTFDeviceList[] =
|
RTFDevice RTFDeviceList[] = {
|
||||||
{
|
|
||||||
/* type,number,flags,driver,driverdata */
|
/* type,number,flags,driver,driverdata */
|
||||||
{RTF_DEVICE_FLOPPY, 0, 0, &RTFDrvFloppy, &FLPYDriveAData},
|
{RTF_DEVICE_FLOPPY, 0, 0, &RTFDrvFloppy, &FLPYDriveAData},
|
||||||
{RTF_DEVICE_FDISK, 0, 0, &RTFDrvDOC, &DOCDriveData},
|
{RTF_DEVICE_FDISK, 0, 0, &RTFDrvDOC, &DOCDriveData},
|
||||||
@@ -85,11 +84,9 @@ int RTTypeCount = MAXTYPES;
|
|||||||
that here, as well as the LPT, console, and FAT.
|
that here, as well as the LPT, console, and FAT.
|
||||||
From RTFiles-32 manual, ch. 7, "Using RTFiles-32 with
|
From RTFiles-32 manual, ch. 7, "Using RTFiles-32 with
|
||||||
RTTarget-32" */
|
RTTarget-32" */
|
||||||
RTFileSystem Console =
|
RTFileSystem Console = { RT_FS_CONSOLE, 0, 0, &RTConsoleFileSystem };
|
||||||
{ RT_FS_CONSOLE, 0, 0, &RTConsoleFileSystem };
|
|
||||||
|
|
||||||
RTFileSystem LPTFiles =
|
RTFileSystem LPTFiles = { RT_FS_LPT_DEVICE, 0, 0, &RTLPTFileSystem };
|
||||||
{ RT_FS_LPT_DEVICE, 0, 0, &RTLPTFileSystem };
|
|
||||||
|
|
||||||
/* logical drive Z: can be used to access the RAM drive */
|
/* logical drive Z: can be used to access the RAM drive */
|
||||||
RTFileSystem RAMFiles =
|
RTFileSystem RAMFiles =
|
||||||
@@ -99,8 +96,7 @@ RTFileSystem RAMFiles =
|
|||||||
RTFileSystem FATFiles =
|
RTFileSystem FATFiles =
|
||||||
{ RT_FS_FILE | RT_FS_IS_DEFAULT, 0x0F, 0x03, &RTFilesFileSystem };
|
{ RT_FS_FILE | RT_FS_IS_DEFAULT, 0x0F, 0x03, &RTFilesFileSystem };
|
||||||
|
|
||||||
RTFileSystem *RTFileSystemList[] =
|
RTFileSystem *RTFileSystemList[] = {
|
||||||
{
|
|
||||||
&Console,
|
&Console,
|
||||||
&LPTFiles,
|
&LPTFiles,
|
||||||
&RAMFiles,
|
&RAMFiles,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
// buffers used for transmit and receive
|
// buffers used for transmit and receive
|
||||||
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
||||||
|
|
||||||
#ifdef BACDL_MSTP
|
#ifdef BACDL_MSTP
|
||||||
volatile struct mstp_port_struct_t MSTP_Port; // port data
|
volatile struct mstp_port_struct_t MSTP_Port; // port data
|
||||||
static uint8_t MSTP_MAC_Address = 0x05; // local MAC address
|
static uint8_t MSTP_MAC_Address = 0x05; // local MAC address
|
||||||
@@ -46,19 +47,15 @@ static uint8_t MSTP_MAC_Address = 0x05; // local MAC address
|
|||||||
static void Init_Service_Handlers(void)
|
static void Init_Service_Handlers(void)
|
||||||
{
|
{
|
||||||
// we need to handle who-is to support dynamic device binding
|
// we need to handle who-is to support dynamic device binding
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, WhoIsHandler);
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
WhoIsHandler);
|
|
||||||
// set the handler for all the services we don't implement
|
// set the handler for all the services we don't implement
|
||||||
// It is required to send the proper reject message...
|
// It is required to send the proper reject message...
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
UnrecognizedServiceHandler);
|
(UnrecognizedServiceHandler);
|
||||||
// we must implement read property - it's required!
|
// we must implement read property - it's required!
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
ReadPropertyHandler);
|
ReadPropertyHandler);
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
|
||||||
WritePropertyHandler);
|
WritePropertyHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +85,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
|
|
||||||
// loop forever
|
// loop forever
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
// input
|
// input
|
||||||
#ifdef BACDL_MSTP
|
#ifdef BACDL_MSTP
|
||||||
MSTP_Millisecond_Timer(&MSTP_Port);
|
MSTP_Millisecond_Timer(&MSTP_Port);
|
||||||
@@ -100,24 +96,15 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
#if (defined(BACDL_ETHERNET) || defined(BACDL_BIP))
|
#if (defined(BACDL_ETHERNET) || defined(BACDL_BIP))
|
||||||
// returns 0 bytes on timeout
|
// returns 0 bytes on timeout
|
||||||
pdu_len = bacdl_receive(
|
pdu_len = bacdl_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// process
|
// process
|
||||||
|
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
Send_IAm();
|
Send_IAm();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ static long RS485_Base = 0;
|
|||||||
/* hardware IRQ number */
|
/* hardware IRQ number */
|
||||||
static long RS485_IRQ_Number = 0;
|
static long RS485_IRQ_Number = 0;
|
||||||
|
|
||||||
static void RS485_Standard_Port_Settings(long port, long *pIRQ, long *pBase)
|
static void RS485_Standard_Port_Settings(long port, long *pIRQ,
|
||||||
{
|
long *pBase)
|
||||||
switch (port)
|
|
||||||
{
|
{
|
||||||
|
switch (port) {
|
||||||
case COM1:
|
case COM1:
|
||||||
*pBase = (long) 0x3F8;
|
*pBase = (long) 0x3F8;
|
||||||
*pIRQ = 4L;
|
*pIRQ = 4L;
|
||||||
@@ -69,12 +69,11 @@ static void RS485_Standard_Port_Settings(long port, long *pIRQ, long *pBase)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static RS485_Open_Port(
|
static RS485_Open_Port(int port, /* COM port number - COM1 = 0 */
|
||||||
int port, /* COM port number - COM1 = 0 */
|
|
||||||
long baud, /* baud rate */
|
long baud, /* baud rate */
|
||||||
unsigned base, /* io base address */
|
unsigned base, /* io base address */
|
||||||
int irq) /* hardware IRQ number */
|
int irq)
|
||||||
{
|
{ /* hardware IRQ number */
|
||||||
/* setup the COM IO */
|
/* setup the COM IO */
|
||||||
SetIOBase(port, base);
|
SetIOBase(port, base);
|
||||||
SetIRQ(port, irq);
|
SetIRQ(port, irq);
|
||||||
@@ -97,12 +96,12 @@ static RS485_Open_Port(
|
|||||||
|
|
||||||
void RS485_Initialize(void)
|
void RS485_Initialize(void)
|
||||||
{
|
{
|
||||||
RS485_Standard_Port_Settings(RS485_Port, &RS485_IRQ_Number, &RS485_Base);
|
RS485_Standard_Port_Settings(RS485_Port, &RS485_IRQ_Number,
|
||||||
|
&RS485_Base);
|
||||||
RS485_Open_Port(RS485_Port, RS485_Baud, RS485_Base, RS485_IRQ_Number);
|
RS485_Open_Port(RS485_Port, RS485_Baud, RS485_Base, RS485_IRQ_Number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RS485_Send_Frame(
|
void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, // port specific data
|
||||||
volatile struct mstp_port_struct_t *mstp_port, // port specific data
|
|
||||||
uint8_t * buffer, // frame to send (up to 501 bytes of data)
|
uint8_t * buffer, // frame to send (up to 501 bytes of data)
|
||||||
uint16_t nbytes) // number of bytes of data (up to 501)
|
uint16_t nbytes) // number of bytes of data (up to 501)
|
||||||
{
|
{
|
||||||
@@ -120,33 +119,28 @@ void RS485_Send_Frame(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RS485_Check_UART_Data(
|
void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) // port specific data
|
||||||
volatile struct mstp_port_struct_t *mstp_port) // port specific data
|
|
||||||
{
|
{
|
||||||
COMData com_data = 0; /* byte from COM driver */
|
COMData com_data = 0; /* byte from COM driver */
|
||||||
unsigned timeout = 10; // milliseconds to wait for a character
|
unsigned timeout = 10; // milliseconds to wait for a character
|
||||||
Duration ticks; /* duration to wait for data */
|
Duration ticks; /* duration to wait for data */
|
||||||
|
|
||||||
if (mstp_port->ReceiveError)
|
if (mstp_port->ReceiveError) {
|
||||||
{
|
|
||||||
// wait for state machine to clear this
|
// wait for state machine to clear this
|
||||||
}
|
}
|
||||||
// wait for state machine to read from the DataRegister
|
// wait for state machine to read from the DataRegister
|
||||||
else if (!mstp_port->DataAvailable)
|
else if (!mstp_port->DataAvailable) {
|
||||||
{
|
|
||||||
// check for data
|
// check for data
|
||||||
ticks = MilliSecsToTicks(timeout);
|
ticks = MilliSecsToTicks(timeout);
|
||||||
if (!ticks)
|
if (!ticks)
|
||||||
ticks = 1;
|
ticks = 1;
|
||||||
if (RTKGetTimed(ReceiveBuffer[RS485_Port],&com_data,ticks))
|
if (RTKGetTimed(ReceiveBuffer[RS485_Port], &com_data, ticks)) {
|
||||||
{
|
|
||||||
// if error,
|
// if error,
|
||||||
if (com_data & (COM_OVERRUN << 8))
|
if (com_data & (COM_OVERRUN << 8))
|
||||||
mstp_port->ReceiveError = true;
|
mstp_port->ReceiveError = true;
|
||||||
else if (com_data & (COM_FRAME << 8))
|
else if (com_data & (COM_FRAME << 8))
|
||||||
mstp_port->ReceiveError = true;
|
mstp_port->ReceiveError = true;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
mstp_port->DataRegister = com_data & 0x00FF;
|
mstp_port->DataRegister = com_data & 0x00FF;
|
||||||
mstp_port->DataAvailable = true;
|
mstp_port->DataAvailable = true;
|
||||||
}
|
}
|
||||||
@@ -158,4 +152,3 @@ void RS485_Process_Tx_Message(void)
|
|||||||
{
|
{
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,13 +72,17 @@ static void set_broadcast_address(uint32_t net_address)
|
|||||||
bip_set_broadcast_addr(INADDR_BROADCAST);
|
bip_set_broadcast_addr(INADDR_BROADCAST);
|
||||||
#else
|
#else
|
||||||
if (IN_CLASSA(ntohl(net_address)))
|
if (IN_CLASSA(ntohl(net_address)))
|
||||||
broadcast_address = (ntohl(net_address) & ~IN_CLASSA_HOST) | IN_CLASSA_HOST;
|
broadcast_address =
|
||||||
|
(ntohl(net_address) & ~IN_CLASSA_HOST) | IN_CLASSA_HOST;
|
||||||
else if (IN_CLASSB(ntohl(net_address)))
|
else if (IN_CLASSB(ntohl(net_address)))
|
||||||
broadcast_address = (ntohl(net_address) & ~IN_CLASSB_HOST) | IN_CLASSB_HOST;
|
broadcast_address =
|
||||||
|
(ntohl(net_address) & ~IN_CLASSB_HOST) | IN_CLASSB_HOST;
|
||||||
else if (IN_CLASSC(ntohl(net_address)))
|
else if (IN_CLASSC(ntohl(net_address)))
|
||||||
broadcast_address = (ntohl(net_address) & ~IN_CLASSC_HOST) | IN_CLASSC_HOST;
|
broadcast_address =
|
||||||
|
(ntohl(net_address) & ~IN_CLASSC_HOST) | IN_CLASSC_HOST;
|
||||||
else if (IN_CLASSD(ntohl(net_address)))
|
else if (IN_CLASSD(ntohl(net_address)))
|
||||||
broadcast_address = (ntohl(net_address) & ~IN_CLASSD_HOST) | IN_CLASSD_HOST;
|
broadcast_address =
|
||||||
|
(ntohl(net_address) & ~IN_CLASSD_HOST) | IN_CLASSD_HOST;
|
||||||
else
|
else
|
||||||
broadcast_address = INADDR_BROADCAST;
|
broadcast_address = INADDR_BROADCAST;
|
||||||
bip_set_broadcast_addr(htonl(broadcast_address));
|
bip_set_broadcast_addr(htonl(broadcast_address));
|
||||||
@@ -109,8 +113,7 @@ bool bip_init(void)
|
|||||||
|
|
||||||
Result = WSAStartup((1 << 8) | 1, &wd);
|
Result = WSAStartup((1 << 8) | 1, &wd);
|
||||||
//Result = WSAStartup(MAKEWORD(2,2), &wd);
|
//Result = WSAStartup(MAKEWORD(2,2), &wd);
|
||||||
if (Result != 0)
|
if (Result != 0) {
|
||||||
{
|
|
||||||
Code = WSAGetLastError();
|
Code = WSAGetLastError();
|
||||||
printf("TCP/IP stack initialization failed, error code: %i\n",
|
printf("TCP/IP stack initialization failed, error code: %i\n",
|
||||||
Code);
|
Code);
|
||||||
@@ -119,11 +122,9 @@ bool bip_init(void)
|
|||||||
atexit(cleanup);
|
atexit(cleanup);
|
||||||
|
|
||||||
address.s_addr = gethostaddr();
|
address.s_addr = gethostaddr();
|
||||||
if (address.s_addr == (unsigned)-1)
|
if (address.s_addr == (unsigned) -1) {
|
||||||
{
|
|
||||||
Code = WSAGetLastError();
|
Code = WSAGetLastError();
|
||||||
printf("Get host address failed, error code: %i\n",
|
printf("Get host address failed, error code: %i\n", Code);
|
||||||
Code);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#ifdef BIP_DEBUG
|
#ifdef BIP_DEBUG
|
||||||
@@ -135,18 +136,15 @@ bool bip_init(void)
|
|||||||
/* assumes that the driver has already been initialized */
|
/* assumes that the driver has already been initialized */
|
||||||
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
bip_set_socket(sock_fd);
|
bip_set_socket(sock_fd);
|
||||||
if (sock_fd < 0)
|
if (sock_fd < 0) {
|
||||||
{
|
|
||||||
fprintf(stderr, "bip: failed to allocate a socket.\n");
|
fprintf(stderr, "bip: failed to allocate a socket.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow us to use the same socket for sending and receiving
|
// Allow us to use the same socket for sending and receiving
|
||||||
// This makes sure that the src port is correct when sending
|
// This makes sure that the src port is correct when sending
|
||||||
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
|
rv = setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR,
|
||||||
(char *) &value, sizeof(value));
|
(char *) &value, sizeof(value));
|
||||||
if (rv < 0)
|
if (rv < 0) {
|
||||||
{
|
|
||||||
fprintf(stderr, "bip: failed to set REUSEADDR socket option.\n");
|
fprintf(stderr, "bip: failed to set REUSEADDR socket option.\n");
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
bip_set_socket(-1);
|
bip_set_socket(-1);
|
||||||
@@ -155,14 +153,12 @@ bool bip_init(void)
|
|||||||
// allow us to send a broadcast
|
// allow us to send a broadcast
|
||||||
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
|
rv = setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST,
|
||||||
(char *) &value, sizeof(value));
|
(char *) &value, sizeof(value));
|
||||||
if (rv < 0)
|
if (rv < 0) {
|
||||||
{
|
|
||||||
fprintf(stderr, "bip: failed to set BROADCAST socket option.\n");
|
fprintf(stderr, "bip: failed to set BROADCAST socket option.\n");
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
bip_set_socket(-1);
|
bip_set_socket(-1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind the socket to the local port number and IP address
|
// bind the socket to the local port number and IP address
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
#if USE_INADDR
|
#if USE_INADDR
|
||||||
@@ -191,11 +187,9 @@ bool bip_init(void)
|
|||||||
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
|
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
|
||||||
rv = bind(sock_fd,
|
rv = bind(sock_fd,
|
||||||
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
|
(const struct sockaddr *) &sin, sizeof(struct sockaddr));
|
||||||
if (rv < 0)
|
if (rv < 0) {
|
||||||
{
|
|
||||||
fprintf(stderr, "bip: failed to bind to %s port %hd\n",
|
fprintf(stderr, "bip: failed to bind to %s port %hd\n",
|
||||||
inet_ntoa(sin.sin_addr),
|
inet_ntoa(sin.sin_addr), bip_get_port());
|
||||||
bip_get_port());
|
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
bip_set_socket(-1);
|
bip_set_socket(-1);
|
||||||
return false;
|
return false;
|
||||||
@@ -203,4 +197,3 @@ bool bip_init(void)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
// buffer used for receive
|
// buffer used for receive
|
||||||
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
||||||
|
|
||||||
/* send a whois to see who is on the network */
|
/* send a whois to see who is on the network */
|
||||||
static bool Who_Is_Request = true;
|
static bool Who_Is_Request = true;
|
||||||
|
|
||||||
@@ -60,8 +61,7 @@ static void Read_Properties(void)
|
|||||||
Device Object
|
Device Object
|
||||||
note: you could just loop through
|
note: you could just loop through
|
||||||
all the properties in all the objects. */
|
all the properties in all the objects. */
|
||||||
const int object_props[] =
|
const int object_props[] = {
|
||||||
{
|
|
||||||
PROP_OBJECT_IDENTIFIER,
|
PROP_OBJECT_IDENTIFIER,
|
||||||
PROP_OBJECT_NAME,
|
PROP_OBJECT_NAME,
|
||||||
PROP_OBJECT_TYPE,
|
PROP_OBJECT_TYPE,
|
||||||
@@ -97,28 +97,20 @@ static void Read_Properties(void)
|
|||||||
-1
|
-1
|
||||||
};
|
};
|
||||||
|
|
||||||
if (address_count())
|
if (address_count()) {
|
||||||
{
|
if (address_get_by_index(index, &device_id, &max_apdu, &src)) {
|
||||||
if (address_get_by_index(index, &device_id, &max_apdu, &src))
|
|
||||||
{
|
|
||||||
if (object_props[property] < 0)
|
if (object_props[property] < 0)
|
||||||
next_device = true;
|
next_device = true;
|
||||||
else
|
else {
|
||||||
{
|
status = Send_Read_Property_Request(device_id, // destination device
|
||||||
status = Send_Read_Property_Request(
|
|
||||||
device_id, // destination device
|
|
||||||
OBJECT_DEVICE,
|
OBJECT_DEVICE,
|
||||||
device_id,
|
device_id, object_props[property], BACNET_ARRAY_ALL);
|
||||||
object_props[property],
|
|
||||||
BACNET_ARRAY_ALL);
|
|
||||||
if (status)
|
if (status)
|
||||||
property++;
|
property++;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
next_device = true;
|
next_device = true;
|
||||||
if (next_device)
|
if (next_device) {
|
||||||
{
|
|
||||||
next_device = false;
|
next_device = false;
|
||||||
index++;
|
index++;
|
||||||
if (index >= MAX_ADDRESS_CACHE)
|
if (index >= MAX_ADDRESS_CACHE)
|
||||||
@@ -130,10 +122,8 @@ static void Read_Properties(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LocalIAmHandler(
|
static void LocalIAmHandler(uint8_t * service_request,
|
||||||
uint8_t *service_request,
|
uint16_t service_len, BACNET_ADDRESS * src)
|
||||||
uint16_t service_len,
|
|
||||||
BACNET_ADDRESS *src)
|
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
uint32_t device_id = 0;
|
uint32_t device_id = 0;
|
||||||
@@ -143,21 +133,13 @@ static void LocalIAmHandler(
|
|||||||
|
|
||||||
(void) src;
|
(void) src;
|
||||||
(void) service_len;
|
(void) service_len;
|
||||||
len = iam_decode_service_request(
|
len = iam_decode_service_request(service_request,
|
||||||
service_request,
|
&device_id, &max_apdu, &segmentation, &vendor_id);
|
||||||
&device_id,
|
|
||||||
&max_apdu,
|
|
||||||
&segmentation,
|
|
||||||
&vendor_id);
|
|
||||||
fprintf(stderr, "Received I-Am Request");
|
fprintf(stderr, "Received I-Am Request");
|
||||||
if (len != -1)
|
if (len != -1) {
|
||||||
{
|
|
||||||
fprintf(stderr, " from %u!\n", device_id);
|
fprintf(stderr, " from %u!\n", device_id);
|
||||||
address_add(device_id,
|
address_add(device_id, max_apdu, src);
|
||||||
max_apdu,
|
} else
|
||||||
src);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fprintf(stderr, "!\n");
|
fprintf(stderr, "!\n");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -166,41 +148,32 @@ static void LocalIAmHandler(
|
|||||||
static void Init_Service_Handlers(void)
|
static void Init_Service_Handlers(void)
|
||||||
{
|
{
|
||||||
// we need to handle who-is to support dynamic device binding
|
// we need to handle who-is to support dynamic device binding
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||||
SERVICE_UNCONFIRMED_WHO_IS,
|
|
||||||
handler_who_is);
|
handler_who_is);
|
||||||
apdu_set_unconfirmed_handler(
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM,
|
||||||
SERVICE_UNCONFIRMED_I_AM,
|
|
||||||
LocalIAmHandler);
|
LocalIAmHandler);
|
||||||
|
|
||||||
// set the handler for all the services we don't implement
|
// set the handler for all the services we don't implement
|
||||||
// It is required to send the proper reject message...
|
// It is required to send the proper reject message...
|
||||||
apdu_set_unrecognized_service_handler_handler(
|
apdu_set_unrecognized_service_handler_handler
|
||||||
handler_unrecognized_service);
|
(handler_unrecognized_service);
|
||||||
// we must implement read property - it's required!
|
// we must implement read property - it's required!
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property);
|
handler_read_property);
|
||||||
apdu_set_confirmed_handler(
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
SERVICE_CONFIRMED_WRITE_PROPERTY,
|
|
||||||
handler_write_property);
|
handler_write_property);
|
||||||
// handle the data coming back from confirmed requests
|
// handle the data coming back from confirmed requests
|
||||||
apdu_set_confirmed_ack_handler(
|
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
SERVICE_CONFIRMED_READ_PROPERTY,
|
|
||||||
handler_read_property_ack);
|
handler_read_property_ack);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_address(
|
static void print_address(char *name, BACNET_ADDRESS * dest) // destination address
|
||||||
char *name,
|
|
||||||
BACNET_ADDRESS *dest) // destination address
|
|
||||||
{
|
{
|
||||||
int i = 0; // counter
|
int i = 0; // counter
|
||||||
|
|
||||||
if (dest)
|
if (dest) {
|
||||||
{
|
|
||||||
printf("%s: ", name);
|
printf("%s: ", name);
|
||||||
for (i = 0; i < dest->mac_len; i++)
|
for (i = 0; i < dest->mac_len; i++) {
|
||||||
{
|
|
||||||
printf("%02X", dest->mac[i]);
|
printf("%02X", dest->mac[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@@ -215,13 +188,10 @@ static void print_address_cache(void)
|
|||||||
unsigned max_apdu = 0;
|
unsigned max_apdu = 0;
|
||||||
|
|
||||||
fprintf(stderr, "Device\tMAC\tMaxAPDU\tNet\n");
|
fprintf(stderr, "Device\tMAC\tMaxAPDU\tNet\n");
|
||||||
for (i = 0; i < MAX_ADDRESS_CACHE; i++)
|
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
|
||||||
{
|
if (address_get_by_index(i, &device_id, &max_apdu, &address)) {
|
||||||
if (address_get_by_index(i,&device_id, &max_apdu, &address))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%u\t", device_id);
|
fprintf(stderr, "%u\t", device_id);
|
||||||
for (j = 0; j < address.mac_len; j++)
|
for (j = 0; j < address.mac_len; j++) {
|
||||||
{
|
|
||||||
fprintf(stderr, "%02X", address.mac[j]);
|
fprintf(stderr, "%02X", address.mac[j]);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\t");
|
fprintf(stderr, "\t");
|
||||||
@@ -255,37 +225,24 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
printf("BACnet stack running...\n");
|
printf("BACnet stack running...\n");
|
||||||
// loop forever
|
// loop forever
|
||||||
for (;;)
|
for (;;) {
|
||||||
{
|
|
||||||
// input
|
// input
|
||||||
|
|
||||||
// returns 0 bytes on timeout
|
// returns 0 bytes on timeout
|
||||||
pdu_len = bip_receive(
|
pdu_len = bip_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
MAX_MPDU,
|
|
||||||
timeout);
|
|
||||||
|
|
||||||
// process
|
// process
|
||||||
|
|
||||||
if (pdu_len)
|
if (pdu_len) {
|
||||||
{
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
npdu_handler(
|
|
||||||
&src,
|
|
||||||
&Rx_Buf[0],
|
|
||||||
pdu_len);
|
|
||||||
}
|
}
|
||||||
if (I_Am_Request)
|
if (I_Am_Request) {
|
||||||
{
|
|
||||||
I_Am_Request = false;
|
I_Am_Request = false;
|
||||||
iam_send(&Handler_Transmit_Buffer[0]);
|
iam_send(&Handler_Transmit_Buffer[0]);
|
||||||
} else if (Who_Is_Request)
|
} else if (Who_Is_Request) {
|
||||||
{
|
|
||||||
Who_Is_Request = false;
|
Who_Is_Request = false;
|
||||||
Send_WhoIs(-1, -1);
|
Send_WhoIs(-1, -1);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Read_Properties();
|
Read_Properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user