From f9f7a55eba320825d86d953cfb6ca337b6276ef4 Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Tue, 20 Aug 2024 22:11:44 +0300 Subject: [PATCH] Starting AS3935 --- LightningSensor/Makefile | 57 ++++++++ LightningSensor/as3935.c | 178 ++++++++++++++++++++++++ LightningSensor/as3935.h | 123 +++++++++++++++++ LightningSensor/i2c.c | 78 +++++++++++ LightningSensor/i2c.h | 33 +++++ LightningSensor/lightning.cflags | 1 + LightningSensor/lightning.config | 2 + LightningSensor/lightning.creator | 1 + LightningSensor/lightning.creator.user | 184 +++++++++++++++++++++++++ LightningSensor/lightning.cxxflags | 1 + LightningSensor/lightning.files | 6 + LightningSensor/lightning.includes | 0 LightningSensor/main.c | 61 ++++++++ schlagbaum/Makefile | 8 +- 14 files changed, 729 insertions(+), 4 deletions(-) create mode 100644 LightningSensor/Makefile create mode 100644 LightningSensor/as3935.c create mode 100644 LightningSensor/as3935.h create mode 100644 LightningSensor/i2c.c create mode 100644 LightningSensor/i2c.h create mode 100644 LightningSensor/lightning.cflags create mode 100644 LightningSensor/lightning.config create mode 100644 LightningSensor/lightning.creator create mode 100644 LightningSensor/lightning.creator.user create mode 100644 LightningSensor/lightning.cxxflags create mode 100644 LightningSensor/lightning.files create mode 100644 LightningSensor/lightning.includes create mode 100644 LightningSensor/main.c diff --git a/LightningSensor/Makefile b/LightningSensor/Makefile new file mode 100644 index 0000000..bf7f58d --- /dev/null +++ b/LightningSensor/Makefile @@ -0,0 +1,57 @@ +# run `make DEF=...` to add extra defines +PROGRAM := lightning +LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all +LDFLAGS += -lusefull_macros +SRCS := $(wildcard *.c) +DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 +OBJDIR := mk +CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99 +OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) +DEPS := $(OBJS:.o=.d) +TARGFILE := $(OBJDIR)/TARGET +CC = gcc +#TARGET := RELEASE + +ifeq ($(shell test -e $(TARGFILE) && echo -n yes),yes) + TARGET := $(file < $(TARGFILE)) +else + TARGET := RELEASE +endif + +ifeq ($(TARGET), DEBUG) + .DEFAULT_GOAL := debug +endif + +release: $(PROGRAM) + +debug: CFLAGS += -DEBUG -Werror +debug: TARGET := DEBUG +debug: $(PROGRAM) + +$(TARGFILE): $(OBJDIR) + @echo -e "\t\tTARGET: $(TARGET)" + @echo "$(TARGET)" > $(TARGFILE) + +$(PROGRAM) : $(TARGFILE) $(OBJS) + @echo -e "\t\tLD $(PROGRAM)" + $(CC) $(OBJS) $(LDFLAGS) -o $(PROGRAM) + +$(OBJDIR): + @mkdir $(OBJDIR) + +ifneq ($(MAKECMDGOALS),clean) +-include $(DEPS) +endif + +$(OBJDIR)/%.o: %.c + @echo -e "\t\tCC $<" + $(CC) $< -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ + +clean: + @echo -e "\t\tCLEAN" + @rm -rf $(OBJDIR) 2>/dev/null || true + +xclean: clean + @rm -f $(PROGRAM) + +.PHONY: clean xclean diff --git a/LightningSensor/as3935.c b/LightningSensor/as3935.c new file mode 100644 index 0000000..497aa68 --- /dev/null +++ b/LightningSensor/as3935.c @@ -0,0 +1,178 @@ +/* + * This file is part of the lightning project. + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "as3935.h" +#include "i2c.h" + +static int dev_fd = -1; + +// open device and set slave address +int as3935_open(const char *path, uint8_t id){ + dev_fd = i2c_open(path); + if(dev_fd < 0) return FALSE; + if(!i2c_set_slave_address(dev_fd, id)){ + WARNX("Can't set slave address 0x%02x", G.slaveaddr); + return FALSE; + } + return as3935_wakeup(); +} + +// common getter +int as3935_getter(uint8_t reg, uint8_t *data){ + return i2c_read_reg(dev_fd, reg, data); +} + +// and common setter +int as3935_setter(uint8_t reg, uint8_t data){ + return i2c_write_reg(dev_fd, reg, data); +} + + +// starting calibration +int as3935_calib_rco(){ + t_tun_disp t; + if(!i2c_read_reg(dev_fd, TUN_DISP, &t)) return FALSE; + if(!i2c_write_reg(dev_fd, CALIB_RCO, DIRECT_COMMAND)) return FALSE; + t.DISP_SRCO = 1; + if(!i2c_write_reg(dev_fd, TUN_DISP, &t)) return FALSE; + double t0 = dtime(); + while(dtime() - t0 < 0.002); + t.DISP_SRCO = 0; + if(!i2c_write_reg(dev_fd, TUN_DISP, &t)) return FALSE; + t_calib srco, trco; + if(!i2c_read_reg(dev_fd, CALIB_TRCO, &trco)) return FALSE; + if(!i2c_read_reg(dev_fd, CALIB_SRCO, &srco)) return FALSE; + if(!srco.CALIB_DONE || !trco.CALIB_DONE) return FALSE; + return TRUE; +} + +// wakeup - call this function after first run +int as3935_wakeup(){ + t_afe_gain g; + if(!i2c_read_reg(dev_fd, AFE_GAIN, &g)) return FALSE; + g.PWD = 0; + if(!i2c_write_reg(dev_fd, AFE_GAIN, g)) return FALSE; + return as3935_calib_rco; +} + +// set amplifier gain +int as3935_set_gain(uint8_t g){ + if(g > 0x1f) return FALSE; + t_afe_gain a = {0}; + a.AFE_GB = g; + return i2c_write_reg(dev_fd, AFE_GAIN, a); +} + +// watchdog threshold +int as3935_wdthres(uint8_t t){ + if(t > 0x0f) return FALSE; + t_threshold thres; + if(!i2c_read_reg(dev_fd, THRESHOLD, &thres)) return FALSE; + thres.WDTH = t; + return i2c_write_reg(dev_fd, THRESHOLD, thres); +} + +// noice floor level +int as3935_nflev(uint8_t l){ + if(l > 7) return FALSE; + t_threshold thres; + if(!i2c_read_reg(dev_fd, THRESHOLD, &thres)) return FALSE; + thres.NF_LEV = l; + return i2c_write_reg(dev_fd, THRESHOLD, thres); +} + +// spike rejection +int as3935_srej(uint8_t s){ + if(s > 0xf) return FALSE; + t_lightning_reg lr; + if(!i2c_read_reg(dev_fd, LIGHTNING_REG, &lr)) return FALSE; + lr.SREJ = s; + return i2c_write_reg(dev_fd, LIGHTNING_REG, lr); +} + +// minimal lighting number +int as3935_minnumlig(uint8_t n){ + if(n > 3) return FALSE; + t_lightning_reg lr; + if(!i2c_read_reg(dev_fd, LIGHTNING_REG, &lr)) return FALSE; + lr.MIN_NUM_LIG = n; + return i2c_write_reg(dev_fd, LIGHTNING_REG, lr); +} + +// clear amount of lightnings for last 15 min +int as3935_clearstat(){ + if(n > 3) return FALSE; + t_lightning_reg lr; + if(!i2c_read_reg(dev_fd, LIGHTNING_REG, &lr)) return FALSE; + lr.CL_STAT = 1; + return i2c_write_reg(dev_fd, LIGHTNING_REG, lr); +} + +// get interrupt code +int as3935_intcode(uint8_t *code){ + if(!code) return FALSE; + t_int_mask_ant i; + if(!i2c_read_reg(dev_fd, INT_MASK_ANT, &i)) return FALSE; + *code = i.INT; + return TRUE; +} + +// should interrupt react on disturbers? +int as3935_mask_disturber(uint8_t m){ + if(m > 1) return FALSE; + t_int_mask_ant i; + if(!i2c_read_reg(dev_fd, INT_MASK_ANT, &i)) return FALSE; + i.MASK_DIST = m; + return i2c_write_reg(dev_fd, INT_MASK_ANT, i); +} + +// set Fdiv of antenna LCO +int as3935_lco_fdiv(uint8_t d){ + if(d > 3) return FALSE; + t_int_mask_ant i; + if(!i2c_read_reg(dev_fd, INT_MASK_ANT, &i)) return FALSE; + i.LCO_FDIV = d; + return i2c_write_reg(dev_fd, INT_MASK_ANT, i); +} + +// calculate last lightning energy +int as3935_energy(uint32_t *E){ + if(!E) return FALSE; + uint8_t u8; uint32_t energy; + t_s_lig_mm mm; + if(!i2c_read_reg(dev_fd, S_LIG_MM, &mm)) return FALSE; + energy = mm.S_LIG_MM << 8; + if(!i2c_read_reg(dev_fd, S_LIG_M, &u8)) return FALSE; + energy |= u8; + energy <<= 8; + if(!i2c_read_reg(dev_fd, S_LIG_L, &u8)) return FALSE; + energy |= u8; + *E = energy; + return TRUE; +} + +int as3935_distance(uint8_t *d){ + if(!d) return FALSE; + t_distance dist; + if(!i2c_read_reg(dev_fd, DISTANCE, &dist)) return FALSE; + *d = dist.DISTANCE; + return TRUE; +} + diff --git a/LightningSensor/as3935.h b/LightningSensor/as3935.h new file mode 100644 index 0000000..b063610 --- /dev/null +++ b/LightningSensor/as3935.h @@ -0,0 +1,123 @@ +/* + * This file is part of the lightning project. + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +enum AS3935_REGISTERS{ + AFE_GAIN = 0x00, + THRESHOLD, + LIGHTNING_REG, + INT_MASK_ANT, + S_LIG_L, + S_LIG_M, + S_LIG_MM, + DISTANCE, + TUN_DISP, + CALIB_TRCO = 0x3A, + CALIB_SRCO = 0x3B, + PRESET_DEFAULT = 0x3C, + CALIB_RCO = 0x3D +}; + +// REGISTERS + +typedef struct{ + uint8_t PWD : 1; + uint8_t AFE_GB : 5; + uint8_t RESERVED : 2; +} t_afe_gain; + +typedef struct{ + uint8_t WDTH : 4; + uint8_t NF_LEV : 3; + uint8_t RESERVED : 1; +} t_threshold; + +typedef struct{ + uint8_t SREJ : 4; +// minimal number of lightnings +#define NUM_LIG_1 (0) +#define NUM_LIG_5 (1) +#define NUM_LIG_9 (2) +#define NUM_LIG_16 (3) + uint8_t MIN_NUM_LIG : 2; + uint8_t CL_STAT : 1; + uint8_t RESERVED : 1; +} t_lightning_reg; + +typedef struct{ +// interrupt flags +// noice level too high +#define INT_NH (1) +// disturber detected +#define INT_D (4) +// lightning interrupt +#define INT_L (8) + uint8_t INT : 4; + uint8_t RESERVED : 1; + uint8_t MASK_DIST : 1; + uint8_t LCO_FDIV : 2; +} t_int_mask_ant; + +typedef struct{ + uint8_t S_LIG_MM : 5; + uint8_t RESERVED : 3; +} t_s_lig_mm; + +typedef struct{ + uint8_t DISTANCE : 6; + uint8_t RESERVED : 2; +} t_distance; + +typedef struct{ + uint8_t TUN_CAP : 4; + uint8_t RESERVED : 1; + uint8_t DISP_TRCO : 1; + uint8_t DISP_SRCO : 1; + uint8_t DISP_LCO : 1; +} t_tun_disp; + +typedef struct{ + uint8_t RESERVED : 6; + uint8_t CALIB_NOK : 1; + uint8_t CALIB_DONE : 1; +} t_calib; + +// direct command send to PRESET_DEFAULT and CALIB_RCO +#define DIRECT_COMMAND (0x96) +// distance out of range +#define DIST_OUT_OF_RANGE (0x3f) + +int as3935_open(const char *path, uint8_t id); +int as3935_getter(uint8_t reg, uint8_t *data); +int as3935_setter(uint8_t reg, uint8_t data); +int as3935_wakeup(); +int as3935_calib_rco(); +int as3935_set_gain(uint8_t g); +int as3935_wdthres(uint8_t t); +int as3935_nflev(uint8_t l); +int as3935_srej(uint8_t s); +int as3935_minnumlig(uint8_t n); +int as3935_clearstat(); +int as3935_intcode(uint8_t *code); +int as3935_mask_disturber(uint8_t m); +int as3935_lco_fdiv(uint8_t d); +int as3935_energy(uint32_t *E); +int as3935_distance(uint8_t *d); diff --git a/LightningSensor/i2c.c b/LightningSensor/i2c.c new file mode 100644 index 0000000..8962c3a --- /dev/null +++ b/LightningSensor/i2c.c @@ -0,0 +1,78 @@ +/* + * This file is part of the lightning project. + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +uint8_t slaveaddr = 0; + +int i2c_read_reg(int fd, uint8_t regaddr, uint8_t *data){ + struct i2c_smbus_ioctl_data args; + union i2c_smbus_data sd; + args.read_write = I2C_SMBUS_READ; + args.command = regaddr; + args.size = I2C_SMBUS_BYTE_DATA; + args.data = &sd; + if(ioctl(fd, I2C_SMBUS, &args) < 0){ + WARNX("Can't read reg %d", regaddr); + LOGWARN("Can't read reg %d", regaddr); + return FALSE; + } + *data = sd.byte; + return TRUE; +} + +int i2c_write_reg(int fd, uint8_t regaddr, uint8_t data){ + struct i2c_smbus_ioctl_data args; + union i2c_smbus_data sd; + sd.byte = data; + args.read_write = I2C_SMBUS_WRITE; + args.command = regaddr; + args.size = I2C_SMBUS_BYTE_DATA; + args.data = &sd; + if(ioctl(fd, I2C_SMBUS, &args) < 0){ + WARNX("Can't write reg %d", regaddr); + LOGWARN("Can't write reg %d", regaddr); + return FALSE; + } + return TRUE; +} + +int i2c_set_slave_address(int fd, uint8_t addr){ + if(addr == slaveaddr) return TRUE; + if(ioctl (fd, I2C_SLAVE, addr) < 0){ + WARNX("Can't set slave address %d", addr); + LOGWARN("Can't set slave address %d", addr); + return FALSE; + } + slaveaddr = addr; + return TRUE; +} + +int i2c_open(const char *path){ + return open(path, O_RDWR); +} diff --git a/LightningSensor/i2c.h b/LightningSensor/i2c.h new file mode 100644 index 0000000..81a2257 --- /dev/null +++ b/LightningSensor/i2c.h @@ -0,0 +1,33 @@ +/* + * This file is part of the lightning project. + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif + +int i2c_read_reg(int fd, uint8_t regaddr, uint8_t *data); +int i2c_write_reg(int fd, uint8_t regaddr, uint8_t data); +int i2c_set_slave_address(int fd, uint8_t addr); +int i2c_open(const char *path); diff --git a/LightningSensor/lightning.cflags b/LightningSensor/lightning.cflags new file mode 100644 index 0000000..68d5165 --- /dev/null +++ b/LightningSensor/lightning.cflags @@ -0,0 +1 @@ +-std=c17 \ No newline at end of file diff --git a/LightningSensor/lightning.config b/LightningSensor/lightning.config new file mode 100644 index 0000000..e0284f4 --- /dev/null +++ b/LightningSensor/lightning.config @@ -0,0 +1,2 @@ +// Add predefined macros for your project here. For example: +// #define THE_ANSWER 42 diff --git a/LightningSensor/lightning.creator b/LightningSensor/lightning.creator new file mode 100644 index 0000000..e94cbbd --- /dev/null +++ b/LightningSensor/lightning.creator @@ -0,0 +1 @@ +[General] diff --git a/LightningSensor/lightning.creator.user b/LightningSensor/lightning.creator.user new file mode 100644 index 0000000..d898ea0 --- /dev/null +++ b/LightningSensor/lightning.creator.user @@ -0,0 +1,184 @@ + + + + + + EnvironmentId + {7bd84e39-ca37-46d3-be9d-99ebea85bc0d} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + KOI8-R + false + 4 + false + 80 + true + true + 1 + 0 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + false + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + false + + + 0 + true + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 2 + false + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Desktop + {65a14f9e-e008-4c1b-89df-4eaa4774b6e3} + 0 + 0 + 0 + + /tmp/1/home/eddy/I2C + + + + all + + true + GenericProjectManager.GenericMakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + GenericProjectManager.GenericMakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + По умолчанию + GenericProjectManager.GenericBuildConfiguration + + 1 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/LightningSensor/lightning.cxxflags b/LightningSensor/lightning.cxxflags new file mode 100644 index 0000000..6435dfc --- /dev/null +++ b/LightningSensor/lightning.cxxflags @@ -0,0 +1 @@ +-std=c++17 \ No newline at end of file diff --git a/LightningSensor/lightning.files b/LightningSensor/lightning.files new file mode 100644 index 0000000..4d0661c --- /dev/null +++ b/LightningSensor/lightning.files @@ -0,0 +1,6 @@ +i2c.c +i2c.h + +as3935.c +as3935.h +main.c diff --git a/LightningSensor/lightning.includes b/LightningSensor/lightning.includes new file mode 100644 index 0000000..e69de29 diff --git a/LightningSensor/main.c b/LightningSensor/main.c new file mode 100644 index 0000000..eaeb96c --- /dev/null +++ b/LightningSensor/main.c @@ -0,0 +1,61 @@ +/* + * This file is part of the lightning project. + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "as3935.h" +#include "i2c.h" +#include +#include + +typedef struct{ + char *device; + int slaveaddr; + int verbose; + int help; + char *logfile; +} glob_pars; + +static glob_pars G = {.device = "/dev/i2c-3", .slaveaddr = 0}; + +static myoption cmdlnopts[] = { + {"device", NEED_ARG, NULL, 'd', arg_string, APTR(&G.device), "I2C device path"}, + {"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"}, + {"slave", NEED_ARG, NULL, 'a', arg_int, APTR(&G.slaveaddr), "I2C slave address"}, + {"verbose", NO_ARGS, NULL, 'v', arg_none, APTR(&G.verbose), "Verbose (each -v increase)"}, + {"logfile", NEED_ARG, NULL, 'l', arg_string, APTR(&G.logfile), "file for logging"}, + end_option +}; + +int main(int argc, char **argv){ + initial_setup(); + parseargs(&argc, &argv, cmdlnopts); + if(G.help) showhelp(-1, cmdlnopts); + if(G.slaveaddr < 0 || G.slaveaddr > 0x7f) ERRX("I2C address should be 7-bit"); + if(!as3935_open(G.device, G.slaveaddr)) ERR("Can't open %s", G.device); + if(G.logfile){ + sl_loglevel l = LOGLEVEL_ERR; + for(int i = 0; i < G.verbose; ++i){ + if(++l == LOGLEVEL_ANY) break; + } + OPENLOG(G.logfile, l, 1); + if(!globlog) ERRX("Can't open logfile %s", G.logfile); + } + LOGMSG("Connected to slave 0x%02x\n", G.slaveaddr); + ; + return 0; +} + diff --git a/schlagbaum/Makefile b/schlagbaum/Makefile index ec54d83..d2d12e9 100644 --- a/schlagbaum/Makefile +++ b/schlagbaum/Makefile @@ -2,12 +2,12 @@ CLIENT := sslclient SERVER := sslserver LDFLAGS += -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all -LDFLAGS += -lusefull_macros -lssl -lcrypto +LDFLAGS += -lusefull_macros -lssl -lcrypto -lm DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 SOBJDIR := mkserver COBJDIR := mkclient CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -pthread -COMMSRCS := sslsock.c daemon.c cmdlnopts.c main.c +COMMSRCS := sslsock.c daemon.c cmdlnopts.c main.c gpio.c SSRC := server.c $(COMMSRCS) CSRC := client.c $(COMMSRCS) SOBJS := $(addprefix $(SOBJDIR)/, $(SSRC:%.c=%.o)) @@ -43,13 +43,13 @@ $(TARGFILE): $(CLIENT) : DEFINES += -DCLIENT $(CLIENT) : $(COBJDIR) $(COBJS) @echo -e "\tLD $(CLIENT)" - $(CC) $(LDFLAGS) $(COBJS) -o $(CLIENT) + $(CC) $(COBJS) $(LDFLAGS) -o $(CLIENT) $(SERVER) : DEFINES += -DSERVER $(SERVER) : $(SOBJDIR) $(SOBJS) @echo -e "\tLD $(SERVER)" - $(CC) $(LDFLAGS) $(SOBJS) -o $(SERVER) + $(CC) $(SOBJS) $(LDFLAGS) -o $(SERVER) $(SOBJDIR): @mkdir $(SOBJDIR)