Refactored the example BACnet File object and file handler. Corrected bacfile_name compiler error.

This commit is contained in:
skarg
2011-04-07 17:21:09 +00:00
parent bd2eda9a74
commit 7bb2149ea0
3 changed files with 35 additions and 20 deletions
+1 -19
View File
@@ -56,8 +56,6 @@ void handler_atomic_read_file_ack(
{ {
int len = 0; int len = 0;
BACNET_ATOMIC_READ_FILE_DATA data; BACNET_ATOMIC_READ_FILE_DATA data;
FILE *pFile = NULL;
char *pFilename = NULL;
uint32_t instance = 0; uint32_t instance = 0;
(void) src; (void) src;
@@ -70,23 +68,7 @@ void handler_atomic_read_file_ack(
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); bacfile_read_ack_stream_data(instance, &data);
if (pFilename) {
pFile = fopen(pFilename, "rb");
if (pFile) {
(void) fseek(pFile, data.type.stream.fileStartPosition,
SEEK_SET);
if (fwrite(octetstring_value(&data.fileData),
octetstring_length(&data.fileData), 1,
pFile) != 1) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to write to %s (%lu)!\n",
pFilename, (unsigned long) instance);
#endif
}
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 */
} }
+30
View File
@@ -478,6 +478,36 @@ bool bacfile_write_stream_data(
return found; return found;
} }
bool bacfile_read_ack_stream_data(
uint32_t instance,
BACNET_ATOMIC_READ_FILE_DATA * data)
{
bool found = false;
FILE *pFile = NULL;
char *pFilename = NULL;
pFilename = bacfile_name(instance);
if (pFilename) {
found = true;
pFile = fopen(pFilename, "rb");
if (pFile) {
(void) fseek(pFile, data->type.stream.fileStartPosition,
SEEK_SET);
if (fwrite(octetstring_value(&data->fileData),
octetstring_length(&data->fileData), 1,
pFile) != 1) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to write to %s (%lu)!\n",
pFilename, (unsigned long) instance);
#endif
}
fclose(pFile);
}
}
return found;
}
void bacfile_init( void bacfile_init(
void) void)
{ {
+4 -1
View File
@@ -76,6 +76,9 @@ extern "C" {
/* handler ACK helper */ /* handler ACK helper */
bool bacfile_read_data( bool bacfile_read_data(
BACNET_ATOMIC_READ_FILE_DATA * data); BACNET_ATOMIC_READ_FILE_DATA * data);
bool bacfile_read_ack_stream_data(
uint32_t instance,
BACNET_ATOMIC_READ_FILE_DATA * data);
bool bacfile_write_stream_data( bool bacfile_write_stream_data(
BACNET_ATOMIC_WRITE_FILE_DATA * data); BACNET_ATOMIC_WRITE_FILE_DATA * data);
@@ -97,6 +100,6 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#define FILE_OBJ_FUNCTIONS \ #define FILE_OBJ_FUNCTIONS \
OBJECT_FILE, bacfile_init, bacfile_count, bacfile_index_to_instance, \ OBJECT_FILE, bacfile_init, bacfile_count, bacfile_index_to_instance, \
bacfile_valid_instance, bacfile_name, bacfile_read_property, \ bacfile_valid_instance, bacfile_object_name, bacfile_read_property, \
bacfile_write_property, BACfile_Property_Lists, NULL bacfile_write_property, BACfile_Property_Lists, NULL
#endif #endif