adding TSM support
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
|
// declare a single physical layer
|
||||||
|
//#include "ethernet.h"
|
||||||
|
//#include "arcnet.h"
|
||||||
|
//#include "mstp.h"
|
||||||
|
|
||||||
// Max number of bytes in an APDU.
|
// Max number of bytes in an APDU.
|
||||||
// Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets
|
// Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets
|
||||||
// This is used in constructing messages and to tell others our limits
|
// This is used in constructing messages and to tell others our limits
|
||||||
|
|||||||
+17
-7
@@ -40,13 +40,13 @@
|
|||||||
#include "config.h" // the custom stuff
|
#include "config.h" // the custom stuff
|
||||||
|
|
||||||
static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL;
|
static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL;
|
||||||
static char *Vendor_Name = "ASHRAE";
|
static const char *Vendor_Name = "ASHRAE";
|
||||||
static uint16_t Vendor_Identifier = 0;
|
static uint16_t Vendor_Identifier = 0;
|
||||||
static char *Model_Name = "GNU";
|
static const char *Model_Name = "GNU";
|
||||||
static char *Firmware_Revision = "1.0";
|
static const char *Firmware_Revision = "1.0";
|
||||||
static char *Application_Software_Version = "1.0";
|
static const char *Application_Software_Version = "1.0";
|
||||||
//static char *Location = "USA";
|
//static char *Location = "USA";
|
||||||
static char *Description = "server";
|
static const char *Description = "server";
|
||||||
//static uint8_t Protocol_Version = 1; - constant, not settable
|
//static uint8_t Protocol_Version = 1; - constant, not settable
|
||||||
//static uint8_t Protocol_Revision = 4; - constant, not settable
|
//static uint8_t Protocol_Revision = 4; - constant, not settable
|
||||||
//Protocol_Services_Supported
|
//Protocol_Services_Supported
|
||||||
@@ -138,7 +138,7 @@ const char *Device_Application_Software_Version(void)
|
|||||||
return Application_Software_Version;
|
return Application_Software_Version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device_Application_Software_Version(const char *name)
|
void Device_Set_Application_Software_Version(const char *name)
|
||||||
{
|
{
|
||||||
Application_Software_Version = name;
|
Application_Software_Version = name;
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ const char *Device_Description(void)
|
|||||||
return Description;
|
return Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device_Description(const char *name)
|
void Device_Set_Description(const char *name)
|
||||||
{
|
{
|
||||||
Description = name;
|
Description = name;
|
||||||
}
|
}
|
||||||
@@ -201,3 +201,13 @@ void Device_Set_Number_Of_APDU_Retries(uint8_t retries)
|
|||||||
Number_Of_APDU_Retries = retries;
|
Number_Of_APDU_Retries = retries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t Device_Database_Revision(void)
|
||||||
|
{
|
||||||
|
return Database_Revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device_Set_Database_Revision(uint8_t revision)
|
||||||
|
{
|
||||||
|
Database_Revision = revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,16 +56,16 @@ const char *Device_Firmware_Revision(void);
|
|||||||
void Device_Set_Firmware_Revision(const char *name);
|
void Device_Set_Firmware_Revision(const char *name);
|
||||||
|
|
||||||
const char *Device_Application_Software_Version(void);
|
const char *Device_Application_Software_Version(void);
|
||||||
void Device_Application_Software_Version(const char *name);
|
void Device_Set_Application_Software_Version(const char *name);
|
||||||
|
|
||||||
const char *Device_Description(void);
|
const char *Device_Description(void);
|
||||||
void Device_Description(const char *name);
|
void Device_Set_Description(const char *name);
|
||||||
|
|
||||||
uint8_t Device_Protocol_Version(void);
|
uint8_t Device_Protocol_Version(void);
|
||||||
uint8_t Device_Protocol_Revision(void);
|
uint8_t Device_Set_Protocol_Revision(void);
|
||||||
|
|
||||||
uint16_t Device_Max_APDU_Length_Accepted(void);
|
uint16_t Device_Max_APDU_Length_Accepted(void);
|
||||||
BACNET_SEGMENTATION Device_Segmentation_Supported(void);
|
BACNET_SEGMENTATION Device_Set_Segmentation_Supported(void);
|
||||||
|
|
||||||
uint16_t Device_APDU_Timeout(void);
|
uint16_t Device_APDU_Timeout(void);
|
||||||
void Device_Set_APDU_Timeout(uint16_t timeout);
|
void Device_Set_APDU_Timeout(uint16_t timeout);
|
||||||
@@ -73,5 +73,8 @@ void Device_Set_APDU_Timeout(uint16_t timeout);
|
|||||||
uint8_t Device_Number_Of_APDU_Retries(void);
|
uint8_t Device_Number_Of_APDU_Retries(void);
|
||||||
void Device_Set_Number_Of_APDU_Retries(uint8_t retries);
|
void Device_Set_Number_Of_APDU_Retries(uint8_t retries);
|
||||||
|
|
||||||
|
uint8_t Device_Database_Revision(void);
|
||||||
|
void Device_Set_Database_Revision(uint8_t revision);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,9 @@
|
|||||||
#ifndef ETHERNET_H
|
#ifndef ETHERNET_H
|
||||||
#define ETHERNET_H
|
#define ETHERNET_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include "bacdef.h"
|
#include "bacdef.h"
|
||||||
|
|
||||||
// specific defines for Ethernet
|
// specific defines for Ethernet
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "config.h"
|
||||||
#include "bacdef.h"
|
#include "bacdef.h"
|
||||||
#include "npdu.h"
|
#include "npdu.h"
|
||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
@@ -92,6 +93,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// custom handlers
|
// custom handlers
|
||||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,WhoIsHandler);
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,WhoIsHandler);
|
||||||
|
// init the physical layer
|
||||||
if (!ethernet_init("eth0"))
|
if (!ethernet_init("eth0"))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|||||||
+18
-3
@@ -34,6 +34,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <string.h> // memmove()
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
@@ -52,7 +53,8 @@
|
|||||||
|
|
||||||
// FIXME: not coded for segmentation
|
// FIXME: not coded for segmentation
|
||||||
|
|
||||||
static BACNET_TSM_DATA TSM_List[MAX_TSM_TRANSACTIONS] = {0};
|
// declare space for the TSM transactions, and set it up in the init.
|
||||||
|
static BACNET_TSM_DATA TSM_List[MAX_TSM_TRANSACTIONS] = {{0}};
|
||||||
|
|
||||||
// returns MAX_TSM_TRANSACTIONS if not found
|
// returns MAX_TSM_TRANSACTIONS if not found
|
||||||
uint8_t tsm_find_invokeID_index(uint8_t invokeID)
|
uint8_t tsm_find_invokeID_index(uint8_t invokeID)
|
||||||
@@ -134,10 +136,9 @@ uint8_t tsm_next_free_invokeID(void)
|
|||||||
|
|
||||||
// returns 0 if there are no free transactions
|
// returns 0 if there are no free transactions
|
||||||
uint8_t tsm_request_confirmed_unsegmented_transaction(
|
uint8_t tsm_request_confirmed_unsegmented_transaction(
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
BACNET_ADDRESS *dest,
|
BACNET_ADDRESS *dest,
|
||||||
uint8_t *pdu,
|
uint8_t *pdu,
|
||||||
uint16_t pdu_len);
|
uint16_t pdu_len)
|
||||||
{
|
{
|
||||||
uint8_t invokeID = 0;
|
uint8_t invokeID = 0;
|
||||||
unsigned i = 0, j = 0;
|
unsigned i = 0, j = 0;
|
||||||
@@ -161,6 +162,7 @@ uint8_t tsm_request_confirmed_unsegmented_transaction(
|
|||||||
{
|
{
|
||||||
TSM_List[i].pdu[j] = pdu[j];
|
TSM_List[i].pdu[j] = pdu[j];
|
||||||
}
|
}
|
||||||
|
memmove(&TSM_List[i].dest,dest,sizeof(TSM_List[i].dest));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -176,9 +178,22 @@ uint8_t tsm_request_confirmed_unsegmented_transaction(
|
|||||||
|
|
||||||
void testTSM(Test * pTest)
|
void testTSM(Test * pTest)
|
||||||
{
|
{
|
||||||
|
//unsigned i;
|
||||||
|
uint8_t invokeID = 0;
|
||||||
|
BACNET_ADDRESS dest = {0};
|
||||||
|
uint8_t pdu[MAX_PDU] = {0};
|
||||||
|
uint16_t pdu_len = 0;
|
||||||
|
|
||||||
|
memset(pdu,0xa5,sizeof(pdu));
|
||||||
|
pdu_len = sizeof(pdu);
|
||||||
|
|
||||||
|
invokeID = tsm_request_confirmed_unsegmented_transaction(
|
||||||
|
&dest,
|
||||||
|
&pdu[0],
|
||||||
|
pdu_len);
|
||||||
|
ct_test(pTest, invokeID != 0);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST_TSM
|
#ifdef TEST_TSM
|
||||||
|
|||||||
+4
-4
@@ -37,6 +37,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include "bacdef.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@@ -75,21 +76,20 @@ typedef struct BACnet_TSM_Data
|
|||||||
uint8_t InvokeID;
|
uint8_t InvokeID;
|
||||||
// state that the TSM is in
|
// state that the TSM is in
|
||||||
BACNET_TSM_STATE state;
|
BACNET_TSM_STATE state;
|
||||||
// the address it was sent from
|
|
||||||
BACNET_ADDRESS src;
|
|
||||||
// the address we sent it to
|
// the address we sent it to
|
||||||
BACNET_ADDRESS dest;
|
BACNET_ADDRESS dest;
|
||||||
// copy of the PDU, should we need to send it again
|
// copy of the PDU, should we need to send it again
|
||||||
uint8_t pdu[MAX_MPDU];
|
uint8_t pdu[MAX_PDU];
|
||||||
} BACNET_TSM_DATA;
|
} BACNET_TSM_DATA;
|
||||||
|
|
||||||
bool tsm_transaction_available(void);
|
bool tsm_transaction_available(void);
|
||||||
uint8_t tsm_transaction_idle_count(void);
|
uint8_t tsm_transaction_idle_count(void);
|
||||||
uint8_t tsm_request_confirmed_unsegmented_transaction(
|
uint8_t tsm_request_confirmed_unsegmented_transaction(
|
||||||
BACNET_ADDRESS *src,
|
|
||||||
BACNET_ADDRESS *dest,
|
BACNET_ADDRESS *dest,
|
||||||
uint8_t *pdu,
|
uint8_t *pdu,
|
||||||
uint16_t pdu_len);
|
uint16_t pdu_len);
|
||||||
|
void tsm_init_list(BACNET_TSM_DATA *list);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -94,7 +94,8 @@ int whois_decode_service_request(
|
|||||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||||
return -1;
|
return -1;
|
||||||
len += decode_unsigned(&apdu[len], len_value, &decoded_value);
|
len += decode_unsigned(&apdu[len],
|
||||||
|
len_value, &decoded_value);
|
||||||
if ((decoded_value >= 0) && (decoded_value <= BACNET_MAX_INSTANCE))
|
if ((decoded_value >= 0) && (decoded_value <= BACNET_MAX_INSTANCE))
|
||||||
{
|
{
|
||||||
if (pHigh_limit)
|
if (pHigh_limit)
|
||||||
|
|||||||
Reference in New Issue
Block a user