simple bacnet server with 1 AV
Brought to you by:
skarg
Hi,
Is it possible for learning purposes to create a real simple-server
? Can I get a tip on how to fix the linker errors when I compile with make simple-server
from the root dir? I created a main.c
and Makefile
like the other example apps.
BACNET_SRC_DIR = $(realpath ../../src)
BACNET_LIB_DIR = $(realpath ../../lib)
CC = gcc
#CFLAGS = -I$(BACNET_SRC_DIR) -std=gnu99
CFLAGS = -I$(BACNET_SRC_DIR) -std=gnu99 -Wall -Wextra
LFLAGS = -L$(BACNET_LIB_DIR) -lbacnet
TARGET = simple_server
# Include all necessary C source files
SRC = main.c \
$(BACNET_SRC_DIR)/bacnet/basic/object/av.c \
$(BACNET_SRC_DIR)/bacnet/basic/sys/mstimer.c \
$(BACNET_SRC_DIR)/bacnet/datalink/bip.c \
$(BACNET_SRC_DIR)/bacnet/basic/object/device.c \
$(BACNET_SRC_DIR)/bacnet/basic/sys/sfilename.c \
$(BACNET_SRC_DIR)/bacnet/basic/sys/sbuf.c
OBJS = $(SRC:.c=.o)
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(OBJS) $(LFLAGS) -o $@
.c.o:
$(CC) -c $(CFLAGS) $< -o $@
clean:
rm -f $(OBJS) $(TARGET)
.PHONY: all clean
This is my fake temp sensor main.c
:
#include "bacnet/basic/sys/mstimer.h"
#include "bacnet/datalink/bip.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/object/av.h"
#include "bacnet/datalink/bip.h"
static struct mstimer Update_Timer;
static float space_temperature = 24.5;
void Analog_Value_Init(void) {
static bool initialized = false;
if (!initialized) {
initialized = true;
Analog_Value_Create(0); // Instance 0
Analog_Value_Units_Set(0, UNITS_DEGREES_CELSIUS);
Analog_Value_Present_Value_Set(0, space_temperature, 10);
}
}
void Update_Analog_Value(void) {
mstimer_reset(&Update_Timer);
space_temperature += 0.1; // Update the temperature for simulation
Analog_Value_Present_Value_Set(0, space_temperature, 10);
}
int main(void) {
BACNET_ADDRESS src = {0}; // source address
Device_Set_Object_Instance_Number(12345); // Set device instance number
bip_init(NULL); // BACnet/IP initialization
Analog_Value_Init(); // Initialize the Analog Value object
mstimer_set(&Update_Timer, 1000); // 1 second timer
while (1) {
bip_network_layer_task(); // BACnet tasks
if (mstimer_expired(&Update_Timer)) {
Update_Analog_Value();
}
}
return 0;
}
Traceback:
ben@benspi:~/bacnet-stack $ make simple-server
make -s -C apps/simple-server all
main.c: In function 'main':
main.c:38:9: warning: implicit declaration of function 'bip_network_layer_task' [-Wimplicit-function-declaration]
38 | bip_network_layer_task(); // BACnet tasks
| ^~~~~~~~~~~~~~~~~~~~~~
main.c:29:20: warning: unused variable 'src' [-Wunused-variable]
29 | BACNET_ADDRESS src = {0}; // source address
| ^~~
make[1]: *** No rule to make target '/home/ben/bacnet-stack/src/bacnet/datalink/bip.o', needed by 'simple_server'. Stop.
make: *** [Makefile:437: simple-server] Error 2
Anonymous