Modified to compile correctly using MicroChip C18 compiler (mcc18), although I had to turn on all optimizations to fit it into the 18F252 32k code space (88% full).

This commit is contained in:
skarg
2005-04-13 20:52:18 +00:00
parent 70e4f220d4
commit fe5b2f86e7
13 changed files with 47 additions and 52 deletions
-1
View File
@@ -34,7 +34,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <assert.h>
#include "bits.h"
#include "apdu.h"
#include "bacdef.h"
-1
View File
@@ -36,7 +36,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include "bacdef.h"
#include "bacenum.h"
+5 -5
View File
@@ -33,7 +33,6 @@
####COPYRIGHTEND####*/
#include <string.h>
#include <assert.h>
#include "bacdef.h"
#include "bacdcode.h"
@@ -98,8 +97,7 @@ uint8_t encode_max_segs_max_apdu(int max_segs, int max_apdu)
octet = 0x70;
// max_apdu must be 50 octets minimum
assert(max_apdu >= 50);
if (max_apdu == 50)
if (max_apdu <= 50)
octet |= 0x00;
else if (max_apdu <= 128)
octet |= 0x01;
@@ -676,8 +674,10 @@ int encode_tagged_character_string(uint8_t * apdu, const char *char_string)
string_len = encode_bacnet_character_string(&apdu[1], char_string);
len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING,
false, string_len);
assert((len + string_len) < MAX_APDU);
len += encode_bacnet_character_string(&apdu[len], char_string);
if ((len + string_len) < MAX_APDU)
len += encode_bacnet_character_string(&apdu[len], char_string);
else
len = 0;
return len;
}
+24 -24
View File
@@ -202,7 +202,7 @@ typedef enum
PROP_ZONE_MEMBERS = 165,
PROP_LIFE_SAFETY_ALARM_VALUES = 166,
PROP_MAX_SEGMENTS_ACCEPTED = 167,
PROP_PROFILE_NAME = 168,
PROP_PROFILE_NAME = 168
// The special property identifiers all, optional, and required
// are reserved for use in the ReadPropertyConditional and
// ReadPropertyMultiple services or services not defined in this standard.
@@ -215,13 +215,13 @@ typedef enum
typedef enum
{
ACTION_DIRECT = 0,
ACTION_REVERSE = 1,
ACTION_REVERSE = 1
} BACNET_ACTION;
typedef enum
{
BINARY_INACTIVE = 0,
BINARY_ACTIVE = 1,
BINARY_ACTIVE = 1
} BACNET_BINARY_PV;
typedef enum
@@ -237,7 +237,7 @@ typedef enum
EVENT_STATE_FAULT = 1,
EVENT_STATE_OFFNORMAL = 2,
EVENT_STATE_HIGH_LIMIT = 3,
EVENT_STATE_LOW_LIMIT = 4,
EVENT_STATE_LOW_LIMIT = 4
} BACNET_EVENT_STATE;
typedef enum
@@ -246,7 +246,7 @@ typedef enum
STATUS_OPERATIONAL_READ_ONLY = 1,
STATUS_DOWNLOAD_REQUIRED = 2,
STATUS_DOWNLOAD_IN_PROGRESS = 3,
STATUS_NON_OPERATIONAL = 4,
STATUS_NON_OPERATIONAL = 4
} BACNET_DEVICE_STATUS;
typedef enum
@@ -373,13 +373,13 @@ typedef enum
UNITS_PER_SECOND = 101,
UNITS_PSI_PER_DEGREE_FAHRENHEIT = 102,
UNITS_RADIANS = 103,
UNITS_REVOLUTIONS_PER_MINUTE = 104,
UNITS_REVOLUTIONS_PER_MINUTE = 104
} BACNET_ENGINEERING_UNITS;
typedef enum
{
POLARITY_NORMAL = 0,
POLARITY_REVERSE = 1,
POLARITY_REVERSE = 1
} BACNET_POLARITY;
typedef enum
@@ -389,7 +389,7 @@ typedef enum
PROGRAM_REQUEST_RUN = 2,
PROGRAM_REQUEST_HALT = 3,
PROGRAM_REQUEST_RESTART = 4,
PROGRAM_REQUEST_UNLOAD = 5,
PROGRAM_REQUEST_UNLOAD = 5
} BACNET_PROGRAM_REQUEST;
typedef enum
@@ -399,7 +399,7 @@ typedef enum
PROGRAM_STATE_RUNNING = 2,
PROGRAM_STATE_WAITING = 3,
PROGRAM_STATE_HALTED = 4,
PROGRAM_STATE_UNLOADING = 5,
PROGRAM_STATE_UNLOADING = 5
} BACNET_PROGRAM_STATE;
typedef enum
@@ -408,7 +408,7 @@ typedef enum
PROGRAM_ERROR_LOAD_FAILED = 1,
PROGRAM_ERROR_INTERNAL = 2,
PROGRAM_ERROR_PROGRAM = 3,
PROGRAM_ERROR_OTHER = 4,
PROGRAM_ERROR_OTHER = 4
// Enumerated values 0-63 are reserved for definition by ASHRAE.
// Enumerated values 64-65535 may be used by others subject to
// the procedures and constraints described in Clause 23.
@@ -425,7 +425,7 @@ typedef enum
RELIABILITY_NO_OUTPUT = 6,
RELIABILITY_UNRELIABLE_OTHER = 7,
RELIABILITY_PROCESS_ERROR = 8,
RELIABILITY_MULTI_STATE_FAULT = 9,
RELIABILITY_MULTI_STATE_FAULT = 9
// Enumerated values 0-63 are reserved for definition by ASHRAE.
// Enumerated values 64-65535 may be used by others subject to
// the procedures and constraints described in Clause 23.
@@ -441,7 +441,7 @@ typedef enum
EVENT_OUT_OF_RANGE = 5,
// complex-event-type (6), -- see comment below
EVENT_BUFFER_READY =7,
CHANGE_OF_LIFE_SAFETY = 8,
CHANGE_OF_LIFE_SAFETY = 8
// Enumerated values 0-63 are reserved for definition by ASHRAE.
// Enumerated values 64-65535 may be used by others subject to
// the procedures and constraints described in Clause 23.
@@ -455,7 +455,7 @@ typedef enum
{
FILE_RECORD_ACCESS = 0,
FILE_STREAM_ACCESS = 1,
FILE_RECORD_AND_STREAM_ACCESS = 2,
FILE_RECORD_AND_STREAM_ACCESS = 2
} BACNET_FILE_ACCESS_METHOD;
typedef enum
@@ -474,7 +474,7 @@ typedef enum
LIFE_SAFETY_MODE_ENABLED = 11,
LIFE_SAFETY_MODE_DISABLED = 12,
LIFE_SAFETY_MODE_AUTOMATIC_RELEASE_DISABLED = 13,
LIFE_SAFETY_MODE_DEFAULT = 14,
LIFE_SAFETY_MODE_DEFAULT = 14
// Enumerated values 0-255 are reserved for definition by ASHRAE.
// Enumerated values 256-65535 may be used by others subject to
// procedures and constraints described in Clause 23.
@@ -488,7 +488,7 @@ typedef enum
LIFE_SAFETY_OPERATION_SILENCE_VISUAL = 3,
LIFE_SAFETY_OPERATION_RESET = 4,
LIFE_SAFETY_OPERATION_RESET_ALARM = 5,
LIFE_SAFETY_OPERATION_RESET_FAULT = 6,
LIFE_SAFETY_OPERATION_RESET_FAULT = 6
// Enumerated values 0-63 are reserved for definition by ASHRAE.
// Enumerated values 64-65535 may be used by others subject to
// procedures and constraints described in Clause 23.
@@ -519,7 +519,7 @@ typedef enum
LIFE_SAFETY_STATE_LOCAL_ALARM = 20,
LIFE_SAFETY_STATE_GENERAL_ALARM = 21,
LIFE_SAFETY_STATE_SUPERVISORY = 22,
LIFE_SAFETY_STATE_TEST_SUPERVISORY = 23,
LIFE_SAFETY_STATE_TEST_SUPERVISORY = 23
// Enumerated values 0-255 are reserved for definition by ASHRAE.
// Enumerated values 256-65535 may be used by others subject to
// procedures and constraints described in Clause 23.
@@ -530,7 +530,7 @@ typedef enum
MAINTENANCE_NONE = 0,
MAINTENANCE_PERIODIC_TEST = 1,
AINTENANCE_NEED_SERVICE_OPERATIONAL = 2,
MAINTENANCE_NEED_SERVICE_INOPERATIVE = 3,
MAINTENANCE_NEED_SERVICE_INOPERATIVE = 3
// Enumerated values 0-255 are reserved for definition by ASHRAE.
// Enumerated values 256-65535 may be used by others subject to
// procedures and constraints described in Clause 23.
@@ -540,7 +540,7 @@ typedef enum
{
NOTIFY_ALARM = 0,
NOTIFY_EVENT = 1,
NOTIFY_ACK_NOTIFICATION = 2,
NOTIFY_ACK_NOTIFICATION = 2
} BACNET_NOTIFY_TYPE;
typedef enum
@@ -567,7 +567,7 @@ typedef enum
OBJECT_MULTI_STATE_VALUE = 19,
OBJECT_TRENDLOG = 20,
OBJECT_LIFE_SAFETY_POINT = 21,
OBJECT_LIFE_SAFETY_ZONE = 22,
OBJECT_LIFE_SAFETY_ZONE = 22
// Enumerated values 0-127 are reserved for definition by ASHRAE.
// Enumerated values 128-1023 may be used by others subject to
// the procedures and constraints described in Clause 23.
@@ -579,7 +579,7 @@ typedef enum
SEGMENTATION_TRANSMIT = 1,
SEGMENTATION_RECEIVE = 2,
SEGMENTATION_NONE = 3,
MAX_BACNET_SEGMENTATION = 4,
MAX_BACNET_SEGMENTATION = 4
} BACNET_SEGMENTATION;
typedef enum
@@ -590,7 +590,7 @@ typedef enum
VT_CLASS_DEC_VT100 = 3,
VT_CLASS_DEC_VT220 = 4,
VT_CLASS_HP_700_94 = 5, /* real name is HP 700/94 */
VT_CLASS_IBM_3130 = 6,
VT_CLASS_IBM_3130 = 6
// Enumerated values 0-63 are reserved for definition by ASHRAE.
// Enumerated values 64-65535 may be used by others subject to
// the procedures and constraints described in Clause 23.
@@ -603,7 +603,7 @@ typedef enum
CHARACTER_JISC_6226 = 2,
CHARACTER_UCS4 = 3,
CHARACTER_UCS2 = 4,
CHARACTER_ISO8859 = 5,
CHARACTER_ISO8859 = 5
} BACNET_CHARACTER_STRING;
typedef enum {
@@ -622,7 +622,7 @@ typedef enum {
BACNET_APPLICATION_TAG_OBJECT_ID = 12,
BACNET_APPLICATION_TAG_RESERVED1 = 13,
BACNET_APPLICATION_TAG_RESERVED2 = 14,
BACNET_APPLICATION_TAG_RESERVED3 = 15,
BACNET_APPLICATION_TAG_RESERVED3 = 15
} BACNET_APPLICATION_TAG;
// note: these are not the real values,
@@ -758,7 +758,7 @@ typedef enum {
NETWORK_MESSAGE_INITIALIZE_ROUTING_TABLE = 6,
NETWORK_MESSAGE_INITIALIZE_ROUTING_TABLE_ACK = 7,
NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK = 8,
NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK = 9,
NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK = 9
// X'0A' to X'7F': Reserved for use by ASHRAE,
// X'80' to X'FF': Available for vendor proprietary messages
} BACNET_NETWORK_MESSAGE_TYPE;
-1
View File
@@ -34,7 +34,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
-1
View File
@@ -36,7 +36,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include "bacdef.h"
#include "bacenum.h"
+4 -3
View File
@@ -86,6 +86,7 @@ int iam_decode_apdu(
uint8_t tag_number = 0;
uint32_t len_value = 0;
unsigned int decoded_value = 0;
int decoded_integer = 0;
// valid data?
if (!apdu)
@@ -121,12 +122,12 @@ int iam_decode_apdu(
apdu_len += len;
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED)
return -1;
len = decode_enumerated(&apdu[apdu_len],len_value, &decoded_value);
len = decode_enumerated(&apdu[apdu_len],len_value, &decoded_integer);
apdu_len += len;
if (decoded_value >= MAX_BACNET_SEGMENTATION)
if (decoded_integer >= MAX_BACNET_SEGMENTATION)
return -1;
if (pSegmentation)
*pSegmentation = decoded_value;
*pSegmentation = decoded_integer;
// Vendor ID - unsigned16
len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value);
apdu_len += len;
+2 -2
View File
@@ -194,7 +194,7 @@ void MSTP_Create_And_Send_Frame(
uint8_t *data, // any data to be sent - may be null
unsigned data_len) // number of bytes of data (up to 501)
{
uint8_t buffer[INPUT_BUFFER_SIZE] = {0};
uint8_t buffer[MAX_MPDU] = {0};
uint16_t len = 0; // number of bytes to send
len = (uint16_t)MSTP_Create_Frame(
@@ -446,7 +446,7 @@ void MSTP_Receive_Frame_FSM(struct mstp_port_struct_t *mstp_port)
(mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS))
{
// FrameTooLong
if (mstp_port->DataLength > INPUT_BUFFER_SIZE)
if (mstp_port->DataLength > MAX_MPDU)
{
// indicate that a frame with an illegal or
// unacceptable data length has been received
+3 -8
View File
@@ -45,10 +45,6 @@
#define MAX_HEADER (2+1+1+1+2+1+2+1)
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
// The number of elements in the array InputBuffer[].
// Note: minimum APDU is 50 bytes, so buffer may vary
#define INPUT_BUFFER_SIZE (501)
// The value 255 is used to denote broadcast when used as a
// destination address but is not allowed as a value for a station.
#define MSTP_BROADCAST_ADDRESS 255
@@ -80,7 +76,7 @@ typedef enum
MSTP_RECEIVE_STATE_HEADER,
MSTP_RECEIVE_STATE_HEADER_CRC,
MSTP_RECEIVE_STATE_DATA,
MSTP_RECEIVE_STATE_DATA_CRC,
MSTP_RECEIVE_STATE_DATA_CRC
} MSTP_RECEIVE_STATE;
// master node FSM states
@@ -94,7 +90,7 @@ typedef enum
MSTP_MASTER_STATE_PASS_TOKEN,
MSTP_MASTER_STATE_NO_TOKEN,
MSTP_MASTER_STATE_POLL_FOR_MASTER,
MSTP_MASTER_STATE_ANSWER_DATA_REQUEST,
MSTP_MASTER_STATE_ANSWER_DATA_REQUEST
} MSTP_MASTER_STATE;
// data for a given MS/TP port
@@ -143,8 +139,7 @@ struct mstp_port_struct_t
// An array of octets, used to store octets as they are received.
// InputBuffer is indexed from 0 to InputBufferSize-1.
// The maximum size of a frame is 501 octets.
// A smaller value for InputBufferSize may be used by some implementations.
uint8_t InputBuffer[INPUT_BUFFER_SIZE];
uint8_t InputBuffer[MAX_MPDU];
// "Next Station," the MAC address of the node to which This Station passes
// the token. If the Next_Station is unknown, Next_Station shall be equal to
-1
View File
@@ -33,7 +33,6 @@
####COPYRIGHTEND####*/
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include "bacdef.h"
#include "bacdcode.h"
#include "bacenum.h"
-1
View File
@@ -36,7 +36,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <assert.h>
#include "bacdef.h"
#include "bacenum.h"
+6 -2
View File
@@ -89,6 +89,7 @@ int rp_decode_service_request(
uint32_t len_value_type = 0;
int type = 0; // for decoding
int property = 0; // for decoding
unsigned array_value = 0; // for decoding
// check for value pointers
if (apdu_len && object_type && object_instance &&
@@ -114,7 +115,8 @@ int rp_decode_service_request(
if (tag_number == 2)
{
len += decode_unsigned(&apdu[len], len_value_type,
array_index);
&array_value);
*array_index = array_value;
}
else
*array_index = BACNET_ARRAY_ALL;
@@ -210,6 +212,7 @@ int rp_ack_decode_service_request(
int tag_len = 0; // length of tag decode
int len = 0; // total length of decodes
int object = 0, property = 0; // for decoding
unsigned array_value = 0; // for decoding
// FIXME: check apdu_len against the len during decode
// Tag 0: Object ID
@@ -235,7 +238,8 @@ int rp_ack_decode_service_request(
{
len += tag_len;
len += decode_unsigned(&apdu[len],
len_value_type, &data->array_index);
len_value_type, &array_value);
data->array_index = array_value;
}
else
data->array_index = BACNET_ARRAY_ALL;
+3 -2
View File
@@ -90,7 +90,7 @@ int wp_decode_service_request(
uint32_t len_value_type = 0;
int type = 0; // for decoding
int property = 0; // for decoding
uint32_t unsigned_value = 0;
unsigned unsigned_value = 0;
// check for value pointers
if (apdu_len && data)
@@ -115,7 +115,8 @@ int wp_decode_service_request(
{
len += tag_len;
len += decode_unsigned(&apdu[len], len_value_type,
&data->array_index);
&unsigned_value);
data->array_index = unsigned_value;
}
else
data->array_index = BACNET_ARRAY_ALL;