diff --git a/bacnet-stack/ports/pic18f6720/BACnet-Server.mcp b/bacnet-stack/ports/pic18f6720/BACnet-Server.mcp index 34a6d3ee..33546dc4 100644 --- a/bacnet-stack/ports/pic18f6720/BACnet-Server.mcp +++ b/bacnet-stack/ports/pic18f6720/BACnet-Server.mcp @@ -79,6 +79,9 @@ file_059=no file_060=no file_061=no file_062=no +file_063=no +file_064=no +file_065=no [FILE_INFO] file_000=C:\code\bacnet-stack\abort.c file_001=C:\code\bacnet-stack\apdu.c @@ -105,44 +108,47 @@ file_021=C:\code\bacnet-stack\datetime.c file_022=C:\code\bacnet-stack\demo\handler\txbuf.c file_023=C:\code\bacnet-stack\demo\handler\h_whois.c file_024=mstp.c -file_025=C:\code\bacnet-stack\demo\handler\h_rp_tiny.c -file_026=bv.c -file_027=ai.c -file_028=bi.c -file_029=C:\code\bacnet-stack\wp.h -file_030=C:\code\bacnet-stack\abort.h -file_031=C:\code\bacnet-stack\apdu.h -file_032=C:\code\bacnet-stack\bacapp.h -file_033=C:\code\bacnet-stack\bacdcode.h -file_034=C:\code\bacnet-stack\bacdef.h -file_035=C:\code\bacnet-stack\bacenum.h -file_036=C:\code\bacnet-stack\bacerror.h -file_037=C:\code\bacnet-stack\bacstr.h -file_038=C:\code\bacnet-stack\config.h -file_039=C:\code\bacnet-stack\crc.h -file_040=C:\code\bacnet-stack\dcc.h -file_041=C:\code\bacnet-stack\dlmstp.h -file_042=C:\code\bacnet-stack\iam.h -file_043=C:\code\bacnet-stack\npdu.h -file_044=C:\code\bacnet-stack\rd.h -file_045=C:\code\bacnet-stack\reject.h -file_046=C:\code\bacnet-stack\rp.h -file_047=C:\code\bacnet-stack\whois.h -file_048=C:\code\bacnet-stack\demo\handler\client.h -file_049=C:\code\bacnet-stack\demo\handler\handlers.h -file_050=C:\code\bacnet-stack\demo\object\ai.h -file_051=C:\code\bacnet-stack\demo\object\ao.h -file_052=C:\code\bacnet-stack\demo\object\device.h -file_053=stdbool.h -file_054=stdint.h -file_055=hardware.h -file_056=rs485.h -file_057=C:\code\bacnet-stack\datetime.h -file_058=C:\code\bacnet-stack\demo\handler\txbuf.h -file_059=mstp.h -file_060=C:\code\bacnet-stack\datalink.h -file_061=C:\mcc18\h\p18f6720.h -file_062=18F6720.lkr +file_025=bv.c +file_026=ai.c +file_027=bi.c +file_028=av.c +file_029=h_rp.c +file_030=h_wp.c +file_031=C:\code\bacnet-stack\wp.c +file_032=C:\code\bacnet-stack\wp.h +file_033=C:\code\bacnet-stack\abort.h +file_034=C:\code\bacnet-stack\apdu.h +file_035=C:\code\bacnet-stack\bacapp.h +file_036=C:\code\bacnet-stack\bacdcode.h +file_037=C:\code\bacnet-stack\bacdef.h +file_038=C:\code\bacnet-stack\bacenum.h +file_039=C:\code\bacnet-stack\bacerror.h +file_040=C:\code\bacnet-stack\bacstr.h +file_041=C:\code\bacnet-stack\config.h +file_042=C:\code\bacnet-stack\crc.h +file_043=C:\code\bacnet-stack\dcc.h +file_044=C:\code\bacnet-stack\dlmstp.h +file_045=C:\code\bacnet-stack\iam.h +file_046=C:\code\bacnet-stack\npdu.h +file_047=C:\code\bacnet-stack\rd.h +file_048=C:\code\bacnet-stack\reject.h +file_049=C:\code\bacnet-stack\rp.h +file_050=C:\code\bacnet-stack\whois.h +file_051=C:\code\bacnet-stack\demo\handler\client.h +file_052=C:\code\bacnet-stack\demo\handler\handlers.h +file_053=C:\code\bacnet-stack\demo\object\ai.h +file_054=C:\code\bacnet-stack\demo\object\ao.h +file_055=C:\code\bacnet-stack\demo\object\device.h +file_056=stdbool.h +file_057=stdint.h +file_058=hardware.h +file_059=rs485.h +file_060=C:\code\bacnet-stack\datetime.h +file_061=C:\code\bacnet-stack\demo\handler\txbuf.h +file_062=mstp.h +file_063=C:\code\bacnet-stack\datalink.h +file_064=C:\mcc18\h\p18f6720.h +file_065=18F6720.lkr [SUITE_INFO] suite_guid={5B7D72DD-9861-47BD-9F60-2BE967BF8416} suite_state= diff --git a/bacnet-stack/ports/pic18f6720/BACnet-Server.mcw b/bacnet-stack/ports/pic18f6720/BACnet-Server.mcw index 3e467055..63b379e6 100644 Binary files a/bacnet-stack/ports/pic18f6720/BACnet-Server.mcw and b/bacnet-stack/ports/pic18f6720/BACnet-Server.mcw differ diff --git a/bacnet-stack/ports/pic18f6720/av.c b/bacnet-stack/ports/pic18f6720/av.c index 022ce72c..36ff384f 100644 --- a/bacnet-stack/ports/pic18f6720/av.c +++ b/bacnet-stack/ports/pic18f6720/av.c @@ -44,29 +44,24 @@ /* When all the priorities are level null, the present value returns */ /* the Relinquish Default value */ #define ANALOG_RELINQUISH_DEFAULT 0 -/* Here is our Priority Array. They are supposed to be Real, but */ +/* Here is our Present_Value. They are supposed to be Real, but */ /* 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. */ -static uint8_t Analog_Value_Level[MAX_ANALOG_VALUES][BACNET_MAX_PRIORITY]; -/* Writable out-of-service allows others to play with our Present Value */ -/* without changing the physical output */ -static bool Analog_Value_Out_Of_Service[MAX_ANALOG_VALUES]; +static uint8_t Present_Value[MAX_ANALOG_VALUES]; /* we need to have our arrays initialized before answering any calls */ static bool Analog_Value_Initialized = false; void Analog_Value_Init(void) { - unsigned i, j; + unsigned i; if (!Analog_Value_Initialized) { Analog_Value_Initialized = true; /* initialize all the analog output priority arrays to NULL */ for (i = 0; i < MAX_ANALOG_VALUES; i++) { - for (j = 0; j < BACNET_MAX_PRIORITY; j++) { - Analog_Value_Level[i][j] = ANALOG_LEVEL_NULL; - } + Present_Value[i] = ANALOG_LEVEL_NULL; } } @@ -125,12 +120,7 @@ static float Analog_Value_Present_Value(uint32_t object_instance) Analog_Value_Init(); index = Analog_Value_Instance_To_Index(object_instance); if (index < MAX_ANALOG_VALUES) { - for (i = 0; i < BACNET_MAX_PRIORITY; i++) { - if (Analog_Value_Level[index][i] != ANALOG_LEVEL_NULL) { - value = Analog_Value_Level[index][i]; - break; - } - } + value = Present_Value[index]; } return value; @@ -142,7 +132,7 @@ char *Analog_Value_Name(uint32_t object_instance) static char text_string[32] = ""; /* okay for single thread */ if (object_instance < MAX_ANALOG_VALUES) { - sprintf(text_string, "ANALOG VALUE %u", object_instance); + sprintf(text_string, "AV-%lu", object_instance); return text_string; } @@ -196,13 +186,16 @@ int Analog_Value_Encode_Property_APDU(uint8_t * apdu, apdu_len = encode_tagged_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: +#if 0 object_index = Analog_Value_Instance_To_Index(object_instance); - state = Analog_Value_Out_Of_Service[object_index]; - apdu_len = encode_tagged_boolean(&apdu[0], state); + state = Analog_Value_Out_Of_Service[object_index]; +#endif + apdu_len = encode_tagged_boolean(&apdu[0], false); break; case PROP_UNITS: apdu_len = encode_tagged_enumerated(&apdu[0], UNITS_PERCENT); break; +#if 0 case PROP_PRIORITY_ARRAY: /* Array element zero is the number of elements in the array */ if (array_index == 0) @@ -214,11 +207,11 @@ int Analog_Value_Encode_Property_APDU(uint8_t * apdu, object_index = Analog_Value_Instance_To_Index(object_instance); for (i = 0; i < BACNET_MAX_PRIORITY; i++) { /* FIXME: check if we have room before adding it to APDU */ - if (Analog_Value_Level[object_index][i] == + if (Present_Value[object_index][i] == ANALOG_LEVEL_NULL) len = encode_tagged_null(&apdu[apdu_len]); else { - real_value = Analog_Value_Level[object_index][i]; + real_value = Present_Value[object_index][i]; len = encode_tagged_real(&apdu[apdu_len], real_value); } /* add it if we have room */ @@ -234,12 +227,12 @@ int Analog_Value_Encode_Property_APDU(uint8_t * apdu, } else { object_index = Analog_Value_Instance_To_Index(object_instance); if (array_index <= BACNET_MAX_PRIORITY) { - if (Analog_Value_Level[object_index][array_index - 1] == + if (Present_Value[object_index][array_index - 1] == ANALOG_LEVEL_NULL) apdu_len = encode_tagged_null(&apdu[0]); else { real_value = - Analog_Value_Level[object_index][array_index - 1]; + Present_Value[object_index][array_index - 1]; apdu_len = encode_tagged_real(&apdu[0], real_value); } } else { @@ -254,6 +247,7 @@ int Analog_Value_Encode_Property_APDU(uint8_t * apdu, real_value = ANALOG_RELINQUISH_DEFAULT; apdu_len = encode_tagged_real(&apdu[0], real_value); break; +#endif default: *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_UNKNOWN_PROPERTY; @@ -301,7 +295,7 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, Analog_Value_Instance_To_Index(wp_data-> object_instance); priority--; - Analog_Value_Level[object_index][priority] = level; + Present_Value[object_index] = level; /* Note: you could set the physical output here if we are the highest priority. However, if Out of Service is TRUE, then don't set the @@ -318,14 +312,15 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } - } else if (value.tag == BACNET_APPLICATION_TAG_NULL) { +#if 0 + } else if (value.tag == BACNET_APPLICATION_TAG_NULL) { level = ANALOG_LEVEL_NULL; object_index = Analog_Value_Instance_To_Index(wp_data->object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; - Analog_Value_Level[object_index][priority] = level; + Present_Value[object_index][priority] = level; /* Note: you could set the physical output here to the next highest priority, or to the relinquish default if no priorities are set. @@ -337,11 +332,13 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; } - } else { +#endif + } else { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_INVALID_DATA_TYPE; } break; +#if 0 case PROP_OUT_OF_SERVICE: if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) { object_index = @@ -353,6 +350,7 @@ bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data, *error_code = ERROR_CODE_INVALID_DATA_TYPE; } break; +#endif default: *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_WRITE_ACCESS_DENIED; diff --git a/bacnet-stack/ports/pic18f6720/device.c b/bacnet-stack/ports/pic18f6720/device.c index 1dfacb41..248527a2 100644 --- a/bacnet-stack/ports/pic18f6720/device.c +++ b/bacnet-stack/ports/pic18f6720/device.c @@ -36,6 +36,7 @@ #include "dlmstp.h" #include "rs485.h" #include "ai.h" +#include "av.h" #include "bi.h" #include "bv.h" #include "wp.h" @@ -182,13 +183,16 @@ bool Device_Object_List_Identifier(unsigned array_index, *instance = Object_Instance_Number; status = true; } + /* normalize the index since + we know it is not the previous objects */ + /* array index starts at 1 */ + object_index = array_index - 1; + /* 1 for the device object */ + object_count = 1; /* FIXME: add objects as needed */ - /* binary input objects */ + /* binary value objects */ if (!status) { - /* normalize the index since - we know it is not the previous objects */ - /* array index starts at 1, and 1 for the device object */ - object_index = array_index - 2; + object_index -= object_count; object_count = Binary_Value_Count(); /* is it a valid index for this object? */ if (object_index < object_count) { @@ -198,6 +202,17 @@ bool Device_Object_List_Identifier(unsigned array_index, } } /* analog input objects */ + if (!status) { + /* array index starts at 1, and 1 for the device object */ + object_index -= object_count; + object_count = Analog_Value_Count(); + if (object_index < object_count) { + *object_type = OBJECT_ANALOG_VALUE; + *instance = Analog_Value_Index_To_Instance(object_index); + status = true; + } + } + /* analog input objects */ if (!status) { /* array index starts at 1, and 1 for the device object */ object_index -= object_count; @@ -329,6 +344,7 @@ int Device_Encode_Property_APDU(uint8_t * apdu, } /* FIXME: indicate the objects that YOU support */ bitstring_set_bit(&bit_string, OBJECT_DEVICE, true); + bitstring_set_bit(&bit_string, OBJECT_ANALOG_VALUE, true); bitstring_set_bit(&bit_string, OBJECT_BINARY_VALUE, true); bitstring_set_bit(&bit_string, OBJECT_ANALOG_INPUT, true); bitstring_set_bit(&bit_string, OBJECT_BINARY_INPUT, true); diff --git a/bacnet-stack/ports/pic18f6720/h_wp.c b/bacnet-stack/ports/pic18f6720/h_wp.c index 2be77f93..4ecc82b5 100644 --- a/bacnet-stack/ports/pic18f6720/h_wp.c +++ b/bacnet-stack/ports/pic18f6720/h_wp.c @@ -38,23 +38,17 @@ /* demo objects */ #include "device.h" #include "ai.h" -#include "ao.h" #include "av.h" #include "bi.h" -#include "bo.h" #include "bv.h" -#include "lc.h" -#include "lsp.h" -#include "mso.h" -#if BACFILE -#include "bacfile.h" -#endif + +/* too big to reside on stack frame for PIC */ +static BACNET_WRITE_PROPERTY_DATA wp_data; void handler_write_property(uint8_t * service_request, uint16_t service_len, BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data) { - BACNET_WRITE_PROPERTY_DATA wp_data; int len = 0; int pdu_len = 0; BACNET_NPDU_DATA npdu_data; @@ -131,28 +125,6 @@ void handler_write_property(uint8_t * service_request, fprintf(stderr, "Sending Write Access Error!\n"); #endif break; - case OBJECT_BINARY_OUTPUT: - if (Binary_Output_Write_Property(&wp_data, &error_class, - &error_code)) { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY); -#if PRINT_ENABLED - fprintf(stderr, - "Sending Write Property Simple Ack for BO!\n"); -#endif - } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, - error_code); -#if PRINT_ENABLED - fprintf(stderr, "Sending Write Access Error for BO!\n"); -#endif - } - break; case OBJECT_BINARY_VALUE: if (Binary_Value_Write_Property(&wp_data, &error_class, &error_code)) { @@ -172,28 +144,6 @@ void handler_write_property(uint8_t * service_request, error_code); #if PRINT_ENABLED fprintf(stderr, "Sending Write Access Error for BV!\n"); -#endif - } - break; - case OBJECT_ANALOG_OUTPUT: - if (Analog_Output_Write_Property(&wp_data, &error_class, - &error_code)) { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY); -#if PRINT_ENABLED - fprintf(stderr, - "Sending Write Property Simple Ack for AO!\n"); -#endif - } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, - error_code); -#if PRINT_ENABLED - fprintf(stderr, "Sending Write Access Error for AO!\n"); #endif } break; @@ -219,97 +169,6 @@ void handler_write_property(uint8_t * service_request, #endif } break; - case OBJECT_LIFE_SAFETY_POINT: - if (Life_Safety_Point_Write_Property(&wp_data, &error_class, - &error_code)) { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY); -#if PRINT_ENABLED - fprintf(stderr, - "Sending Write Property Simple Ack for LSP!\n"); -#endif - } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, - error_code); -#if PRINT_ENABLED - fprintf(stderr, "Sending Write Access Error for LSP!\n"); -#endif - } - break; - case OBJECT_LOAD_CONTROL: - if (Load_Control_Write_Property(&wp_data, &error_class, - &error_code)) { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY); -#if PRINT_ENABLED - fprintf(stderr, - "Sending Write Property Simple Ack for Load Control!\n"); -#endif - } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, - error_code); -#if PRINT_ENABLED - fprintf(stderr, - "Sending Write Access Error for Load Control!\n"); -#endif - } - break; - case OBJECT_MULTI_STATE_OUTPUT: - if (Multistate_Output_Write_Property(&wp_data, &error_class, - &error_code)) { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY); -#if PRINT_ENABLED - fprintf(stderr, - "Sending Write Property Simple Ack for MSO!\n"); -#endif - } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, - error_code); -#if PRINT_ENABLED - fprintf(stderr, "Sending Write Access Error for MSO!\n"); -#endif - } - break; -#if BACFILE - case OBJECT_FILE: - if (bacfile_write_property(&wp_data, &error_class, - &error_code)) { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY); -#if PRINT_ENABLED - fprintf(stderr, - "Sending Write Property Simple Ack for File!\n"); -#endif - } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_WRITE_PROPERTY, error_class, - error_code); -#if PRINT_ENABLED - fprintf(stderr, "Sending Write Access Error for File!\n"); -#endif - } - break; -#endif /* BACFILE */ default: len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], diff --git a/bacnet-stack/ports/pic18f6720/main.c b/bacnet-stack/ports/pic18f6720/main.c index 3523a850..abaeb5be 100644 --- a/bacnet-stack/ports/pic18f6720/main.c +++ b/bacnet-stack/ports/pic18f6720/main.c @@ -103,9 +103,9 @@ static void BACnet_Service_Handlers_Init(void) handler_read_property); apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, handler_reinitialize_device); -#if 0 apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, handler_write_property); +#if 0 apdu_set_unconfirmed_handler (SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, handler_timesync_utc);