ARDUINO_DIR?=external/ArduinoCore-avr NANOPB_DIR?=external/nanopb CC=avr-gcc CXX=avr-g++ OBJCOPY=avr-objcopy OBJDUMP=avr-objdump BINSIZE=avr-size OUT=./bin/ NAME=collar CFLAGS?=-Datmega328p\ -Dmega328p\ -mmcu=atmega328p\ -Wl,--gc-sections\ -DF_CPU=16000000L\ -DARDUINO=200\ -DARDUINO_AVR_NANO\ -DARDUINO_ARCH_AVR\ -Os\ -ffunction-sections\ -fdata-sections\ -MMD\ -flto\ -std=c++11\ -fno-fat-lto-objects\ -fuse-linker-plugin\ -Wall CXXFLAGS?=-Datmega328p\ -std=c++11\ -Dmega328p\ -mmcu=atmega328p\ -Wl,--gc-sections\ -DF_CPU=16000000L\ -DARDUINO=200\ -DARDUINO_AVR_NANO\ -DARDUINO_ARCH_AVR\ -Os\ -ffunction-sections\ -fdata-sections\ -MMD\ -flto\ -fno-fat-lto-objects\ -fuse-linker-plugin\ -Wall INC_DIRS?=-I./$(ARDUINO_DIR)/libraries/SPI/src\ -I./$(ARDUINO_DIR)/cores/arduino\ -I./$(ARDUINO_DIR)/variants/eightanaloginputs\ -I./libraries/TinyGPSPlus/src\ -I./libraries/arduino-base64\ -I./$(NANOPB_DIR)\ -I./protobuf\ -I./$(ARDUINO_DIR)/libraries/SoftwareSerial/src/\ -I./libraries/arduino-lmic/src/\ -I./libraries/arduino-lmic/src/hal/\ -I./libraries/arduino-lmic/src/lmic/\ -I./libraries/arduino-lmic/src/aes/ SRC_FILES?=./$(ARDUINO_DIR)/cores/arduino/main.cpp\ ./$(ARDUINO_DIR)/cores/arduino/wiring_digital.c\ ./$(ARDUINO_DIR)/cores/arduino/wiring_analog.c\ ./$(ARDUINO_DIR)/cores/arduino/WInterrupts.c\ ./$(ARDUINO_DIR)/cores/arduino/hooks.c\ ./$(ARDUINO_DIR)/cores/arduino/wiring.c\ ./$(NANOPB_DIR)/pb_encode.c\ ./$(NANOPB_DIR)/pb_decode.c\ ./$(NANOPB_DIR)/pb_common.c\ ./protobuf/gateway/message.pb.c\ ./$(ARDUINO_DIR)/cores/arduino/HardwareSerial.cpp\ ./$(ARDUINO_DIR)/cores/arduino/HardwareSerial0.cpp\ ./$(ARDUINO_DIR)/cores/arduino/HardwareSerial1.cpp\ ./$(ARDUINO_DIR)/cores/arduino/HardwareSerial2.cpp\ ./$(ARDUINO_DIR)/cores/arduino/HardwareSerial3.cpp\ ./$(ARDUINO_DIR)/cores/arduino/WString.cpp\ ./$(ARDUINO_DIR)/cores/arduino/Print.cpp\ ./$(ARDUINO_DIR)/cores/arduino/Stream.cpp\ ./$(ARDUINO_DIR)/cores/arduino/new.cpp\ ./$(ARDUINO_DIR)/cores/arduino/abi.cpp\ ./$(ARDUINO_DIR)/libraries/SoftwareSerial/src/SoftwareSerial.cpp\ ./$(ARDUINO_DIR)/libraries/SPI/src/SPI.cpp\ ./libraries/TinyGPSPlus/src/TinyGPS++.cpp\ ./libraries/arduino-lmic/src/hal/hal.cpp\ ./libraries/arduino-lmic/src/hal/getpinmap_thisboard.cpp\ ./libraries/arduino-lmic/src/aes/ideetron/AES-128_V10.cpp\ ./libraries/arduino-lmic/src/lmic/lmic.c\ ./libraries/arduino-lmic/src/lmic/lmic_eu_like.c\ ./libraries/arduino-lmic/src/lmic/lmic_compliance.c\ ./libraries/arduino-lmic/src/lmic/lmic_us_like.c\ ./libraries/arduino-lmic/src/lmic/lmic_util.c\ ./libraries/arduino-lmic/src/lmic/lmic_as923.c\ ./libraries/arduino-lmic/src/lmic/lmic_au915.c\ ./libraries/arduino-lmic/src/lmic/oslmic.c\ ./libraries/arduino-lmic/src/lmic/lmic_eu868.c\ ./libraries/arduino-lmic/src/lmic/lmic_us915.c\ ./libraries/arduino-lmic/src/lmic/lmic_kr920.c\ ./libraries/arduino-lmic/src/lmic/radio.c\ ./libraries/arduino-lmic/src/lmic/lmic_in866.c\ ./libraries/arduino-lmic/src/aes/lmic.c\ ./libraries/arduino-lmic/src/aes/other.c SRC_FILES_COMMON?=\ ./$(NANOPB_DIR)/pb_encode.c\ ./$(NANOPB_DIR)/pb_decode.c\ ./$(NANOPB_DIR)/pb_common.c\ ./protobuf/gateway/message.pb.c\ # Make targets for each source file OBJS := $(SRC_FILES:%=./bin/%.o) OBJDIRS := $(SRC_FILES:%=./bin/%) build: $(OUT)$(NAME) $(OBJDIRS): @mkdir -p $(shell dirname $@) $(OUT)%.cpp.o: %.cpp $(CXX) $(CXXFLAGS) -c $(INC_DIRS) -o $@ $< $(OUT)%.c.o: %.c $(CC) $(CFLAGS) -c $(INC_DIRS) -o $@ $< $(OUT)$(NAME): $(OUT)$(NAME).elf $(OBJCOPY) -R .eeprom -O ihex $(OUT)$(NAME).elf $(OUT)$(NAME).hex $(OUT)eep.hex: $(OUT)$(NAME).elf $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $(OUT)$(NAME).elf $(OUT)eep.hex $(OUT)$(NAME).elf: protobufg bin $(OBJDIRS) $(OBJS) $(CC) $(CFLAGS) -o $(OUT)$(NAME).elf collar.cpp $(INC_DIRS) $(OBJS) test: g++ -o $(OUT)test prototest.cpp $(INC_DIRS) $(SRC_FILES_COMMON) $(OUT)test protobufg: @mkdir -p protobuf/gateway python3 external/nanopb/generator/nanopb_generator.py gateway/message.proto -D protobuf bin: @mkdir bin flash: $(OUT)$(NAME) avrdude -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:$(OUT)$(NAME).hex:i run: flash screen /dev/ttyUSB0 start: flash systemctl start lora-gateway-bridge loraserver stop: avrdude -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:nothing.hex:i systemctl stop lora-gateway-bridge loraserver clean: rm -r protobuf rm -r bin