Created handler for AtomicWriteFile service. Added it to the demo/server example.
This commit is contained in:
@@ -374,3 +374,30 @@ bool bacfile_read_data(BACNET_ATOMIC_READ_FILE_DATA * data)
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
bool bacfile_write_stream_data(BACNET_ATOMIC_WRITE_FILE_DATA * data)
|
||||
{
|
||||
char *pFilename = NULL;
|
||||
bool found = false;
|
||||
FILE *pFile = NULL;
|
||||
|
||||
pFilename = bacfile_name(data->object_instance);
|
||||
if (pFilename) {
|
||||
found = true;
|
||||
/* open the file as a clean slate when starting at 0 */
|
||||
if (data->type.stream.fileStartPosition == 0)
|
||||
pFile = fopen(pFilename, "wb");
|
||||
else
|
||||
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) {
|
||||
|
||||
}
|
||||
fclose(pFile);
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "bacenum.h"
|
||||
#include "apdu.h"
|
||||
#include "arf.h"
|
||||
#include "awf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -51,16 +52,17 @@ extern "C" {
|
||||
uint32_t bacfile_index_to_instance(unsigned find_index);
|
||||
uint32_t bacfile_instance(char *filename);
|
||||
#if TSM_ENABLED
|
||||
/* this is one way to match up the invoke ID with */
|
||||
/* the file ID from the AtomicReadFile request. */
|
||||
/* Another way would be to store the */
|
||||
/* invokeID and file instance in a list or table */
|
||||
/* when the request was sent */
|
||||
/* this is one way to match up the invoke ID with */
|
||||
/* the file ID from the AtomicReadFile request. */
|
||||
/* Another way would be to store the */
|
||||
/* invokeID and file instance in a list or table */
|
||||
/* when the request was sent */
|
||||
uint32_t bacfile_instance_from_tsm(uint8_t invokeID);
|
||||
#endif
|
||||
|
||||
/* AtomicReadFile ACK helper */
|
||||
/* handler ACK helper */
|
||||
bool bacfile_read_data(BACNET_ATOMIC_READ_FILE_DATA * data);
|
||||
bool bacfile_write_stream_data(BACNET_ATOMIC_WRITE_FILE_DATA * data);
|
||||
|
||||
/* handling for read property service */
|
||||
int bacfile_encode_property_apdu(uint8_t * apdu,
|
||||
|
||||
Reference in New Issue
Block a user