Moved send I-Am to a send module and out of iam.c.

This commit is contained in:
skarg
2008-11-12 15:38:43 +00:00
parent 2284a70bc2
commit c7a5c05ac7
27 changed files with 171 additions and 94 deletions
+2 -2
View File
@@ -51,7 +51,7 @@ void handler_who_is(
whois_decode_service_request(service_request, service_len, &low_limit,
&high_limit);
if (len == 0)
iam_send(&Handler_Transmit_Buffer[0]);
Send_I_Am(&Handler_Transmit_Buffer[0]);
else if (len != -1) {
/* is my device id within the limits? */
if (((Device_Object_Instance_Number() >= (uint32_t) low_limit) &&
@@ -60,7 +60,7 @@ void handler_who_is(
/* BACnet wildcard is the max instance number - everyone responds */
((BACNET_MAX_INSTANCE >= (uint32_t) low_limit) &&
(BACNET_MAX_INSTANCE <= (uint32_t) high_limit)))
iam_send(&Handler_Transmit_Buffer[0]);
Send_I_Am(&Handler_Transmit_Buffer[0]);
}
return;
+73
View File
@@ -0,0 +1,73 @@
/**************************************************************************
*
* Copyright (C) 2008 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include "config.h"
#include "config.h"
#include "txbuf.h"
#include "bacdef.h"
#include "bacdcode.h"
#include "address.h"
#include "tsm.h"
#include "npdu.h"
#include "apdu.h"
#include "device.h"
#include "datalink.h"
#include "iam.h"
/* some demo stuff needed */
#include "handlers.h"
#include "txbuf.h"
void Send_I_Am(
uint8_t * buffer)
{
int len = 0;
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
/* I-Am is a global broadcast */
datalink_get_broadcast_address(&dest);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&buffer[0], &dest, NULL, &npdu_data);
/* encode the APDU portion of the packet */
len =
iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
pdu_len += len;
/* send data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n",
strerror(errno));
#endif
return;
}
+1 -1
View File
@@ -206,7 +206,7 @@ int main(int argc, char *argv[]) {
/* configure the timeout values */
last_seconds = time(NULL);
/* broadcast an I-Am on startup */
iam_send(&Handler_Transmit_Buffer[0]);
Send_I_Am(&Handler_Transmit_Buffer[0]);
/* loop forever */
for (;;) {
/* input */
+7
View File
@@ -6,5 +6,12 @@ Q1: GNU GCC Compiler, undefined reference to closesocket
A1: Under Project->Build Options->Linker settings,
add "ws2_32" to Link Libraries.
Q2: GNU GCC Compiler, creating a DLL
A2: Under Project->Build Options->Linker settings,
add "user32" to Link Libraries.
Q3: GNU GCC Compiler, undefined reference to _GetAdaptersInfo
A3: Under Project->Build Options->Linker settings,
add "iphlpapi" to Link Libraries.
+3
View File
@@ -39,6 +39,9 @@ extern "C" {
#endif /* __cplusplus */
/* unconfirmed requests */
void Send_I_Am(
uint8_t * buffer);
void Send_WhoIs(
int32_t low_limit,
int32_t high_limit);
+2 -1
View File
@@ -77,6 +77,7 @@
defined(BACAPP_UNSIGNED) || \
defined(BACAPP_SIGNED) || \
defined(BACAPP_REAL) || \
defined(BACAPP_DOUBLE) || \
defined(BACAPP_OCTET_STRING) || \
defined(BACAPP_CHARACTER_STRING) || \
defined(BACAPP_BIT_STRING) || \
@@ -93,7 +94,7 @@
#define BACAPP_UNSIGNED
#define BACAPP_SIGNED
#define BACAPP_REAL
/* FIXME: not implemented #define BACAPP_DOUBLE */
#define BACAPP_DOUBLE
#define BACAPP_OCTET_STRING
#define BACAPP_CHARACTER_STRING
#define BACAPP_BIT_STRING
-8
View File
@@ -58,14 +58,6 @@ extern "C" {
int *pSegmentation,
uint16_t * pVendor_id);
int iam_encode_pdu(
uint8_t * buffer,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data);
int iam_send(
uint8_t * buffer);
#ifdef TEST
#include "ctest.h"
int iam_decode_apdu(
+1
View File
@@ -90,6 +90,7 @@ HANDLER_SRC = \
$(BACNET_HANDLER)/s_awfs.c \
$(BACNET_HANDLER)/s_dcc.c \
$(BACNET_HANDLER)/s_ihave.c \
$(BACNET_HANDLER)/s_iam.c \
$(BACNET_HANDLER)/s_rd.c \
$(BACNET_HANDLER)/s_rp.c \
$(BACNET_HANDLER)/s_ts.c \
+7 -1
View File
@@ -97,6 +97,9 @@
<Unit filename="..\demo\handler\noserv.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\handler\s_iam.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\handler\s_arfs.c">
<Option compilerVar="CC" />
</Unit>
@@ -106,9 +109,12 @@
<Unit filename="..\demo\handler\s_dcc.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\handler\s_ihave.c">
<Unit filename="..\demo\handler\s_iam.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\handler\s_ihave.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\handler\s_rd.c">
<Option compilerVar="CC" />
</Unit>
+1 -33
View File
@@ -46,40 +46,8 @@
<Linker>
<Add library="user32" />
<Add library="ws2_32" />
<Add library="iphlpapi" />
</Linker>
<Unit filename="..\demo\object\ai.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\ao.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\av.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\bacfile.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\bi.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\bo.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\bv.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\device.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\lc.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\lsp.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\demo\object\mso.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="..\include\abort.h" />
<Unit filename="..\include\address.h" />
<Unit filename="..\include\ai.h" />
+31
View File
@@ -0,0 +1,31 @@
#include "main.h"
// a sample exported function
void SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
#endif // __MAIN_H__
+1
View File
@@ -92,6 +92,7 @@ HANDLER_SRC = $(BACNET_HANDLER)\txbuf.c \
$(BACNET_HANDLER)\s_awfs.c \
$(BACNET_HANDLER)\s_dcc.c \
$(BACNET_HANDLER)\s_ihave.c \
$(BACNET_HANDLER)\s_iam.c \
$(BACNET_HANDLER)\s_rd.c \
$(BACNET_HANDLER)\s_rp.c \
$(BACNET_HANDLER)\s_ts.c \
+1 -1
View File
@@ -180,7 +180,7 @@ int main(
enableIRQ();
enableFIQ();
/* broadcast an I-Am on startup */
iam_send(&Handler_Transmit_Buffer[0]);
Send_I_Am(&Handler_Transmit_Buffer[0]);
/* endless blink loop */
while (1) {
millisecond_timer();
+2 -1
View File
@@ -62,7 +62,8 @@ DEMOSRC = ai.c \
$(BACNET_DEMO)/handler/h_npdu.c \
$(BACNET_DEMO)/handler/h_whois.c \
$(BACNET_DEMO)/handler/h_rd.c \
$(BACNET_DEMO)/handler/h_dcc.c
$(BACNET_DEMO)/handler/h_dcc.c \
$(BACNET_DEMO)/handler/s_iam.c
CORESRC = $(BACNET_CORE)/npdu.c \
$(BACNET_CORE)/apdu.c \
+1
View File
@@ -35,6 +35,7 @@ CSRC = main.c \
# common demo files needed
DEMOSRC = $(BACNET_DEMO)/handler/txbuf.c \
$(BACNET_DEMO)/handler/h_npdu.c \
$(BACNET_DEMO)/handler/s_iam.c \
$(BACNET_DEMO)/handler/noserv.c
# core BACnet stack files
+6
View File
@@ -2008,6 +2008,12 @@
<file>
<name>$PROJ_DIR$\..\..\demo\handler\noserv.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\demo\handler\s_iam.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\demo\handler\h_npdu.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\..\src\npdu.c</name>
</file>
+1 -1
View File
@@ -94,7 +94,7 @@ int main(
Timer_Init();
bacnet_init();
/* broadcast an I-Am on startup */
iam_send(&Handler_Transmit_Buffer[0]);
Send_I_Am(&Handler_Transmit_Buffer[0]);
for (;;) {
millisecond_timer();
if (!DCC_Timer) {
+1 -1
View File
@@ -279,7 +279,7 @@ int main(
}
if (I_Am_Request) {
I_Am_Request = false;
iam_send(&Handler_Transmit_Buffer[0]);
Send_I_Am(&Handler_Transmit_Buffer[0]);
} else if (Who_Is_Request) {
Who_Is_Request = false;
Send_WhoIs(-1, -1);
@@ -149,6 +149,8 @@ file_062=mstp.h
file_063=C:\code\bacnet-stack\datalink.h
file_064=C:\mcc18\h\p18f6720.h
file_065=18F6720.lkr
file_066=C:\code\bacnet-stack\demo\handler\h_npdu.c
file_067=C:\code\bacnet-stack\demo\handler\s_iam.c
[SUITE_INFO]
suite_guid={5B7D72DD-9861-47BD-9F60-2BE967BF8416}
suite_state=
+1 -1
View File
@@ -286,7 +286,7 @@ void main(
Initialize_Variables();
/* Handle anything that needs to be done on powerup */
/* Greet the BACnet world! */
iam_send(&Handler_Transmit_Buffer[0]);
Send_I_Am(&Handler_Transmit_Buffer[0]);
/* Main loop */
while (TRUE) {
RESTART_WDT();
+1 -1
View File
@@ -148,7 +148,7 @@ int main(
dlmstp_set_my_address(0x05);
#endif
datalink_init(NULL);
iam_send(&Handler_Transmit_Buffer[0]);
Send_I_Am(&Handler_Transmit_Buffer[0]);
/* loop forever */
for (;;) {
/* input */
+1
View File
@@ -43,6 +43,7 @@ SRCS = main.c \
..\..\demo\handler\h_rp.c \
..\..\demo\handler\noserv.c \
..\..\demo\handler\txbuf.c \
..\..\demo\handler\s_iam.c \
..\..\demo\handler\s_rp.c \
..\..\demo\handler\s_whois.c \
..\..\bacdcode.c \
@@ -285,6 +285,10 @@ SOURCE=..\..\..\demo\handler\noserv.c
# End Source File
# Begin Source File
SOURCE=..\..\..\demo\handler\s_iam.c
# End Source File
# Begin Source File
SOURCE=..\..\..\src\npdu.c
# End Source File
# Begin Source File
+1 -1
View File
@@ -325,7 +325,7 @@ int main(
}
if (I_Am_Request) {
I_Am_Request = false;
iam_send(&Handler_Transmit_Buffer[0]);
Send_I_Am(&Handler_Transmit_Buffer[0]);
} else if (Who_Is_Request) {
Who_Is_Request = false;
Send_WhoIs(-1, -1);
+2
View File
@@ -40,6 +40,8 @@ DEMOSRC = ai.c \
../../demo/object/device.c \
../../demo/handler/txbuf.c \
../../demo/handler/h_whois.c \
../../demo/handler/noserv.c \
../../demo/handler/s_iam.c \
../../demo/handler/h_rd.c \
../../demo/handler/h_dcc.c
-41
View File
@@ -137,47 +137,6 @@ int iam_decode_service_request(
return apdu_len;
}
int iam_encode_pdu(
uint8_t * buffer,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data)
{
int len = 0;
int pdu_len = 0;
/* I-Am is a global broadcast */
datalink_get_broadcast_address(dest);
/* encode the NPDU portion of the packet */
npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&buffer[0], dest, NULL, npdu_data);
/* encode the APDU portion of the packet */
len =
iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
pdu_len += len;
return pdu_len;
}
int iam_send(
uint8_t * buffer)
{
int pdu_len = 0;
BACNET_ADDRESS dest;
int bytes_sent = 0;
BACNET_NPDU_DATA npdu_data;
/* are we are forbidden to send? */
if (!dcc_communication_enabled())
return 0;
/* encode the data */
pdu_len = iam_encode_pdu(buffer, &dest, &npdu_data);
/* send data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len);
return bytes_sent;
}
#ifdef TEST
#include <assert.h>
#include <string.h>