Skip to content

Commit

Permalink
move from pico_rec package to a separate repo spp-picoadc
Browse files Browse the repository at this point in the history
  • Loading branch information
slazav committed Jan 25, 2024
1 parent bfbcb84 commit f9a481a
Show file tree
Hide file tree
Showing 44 changed files with 3,229 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gear/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tar: .
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
srcdir = spp-picoadc

all:
make -C ${srcdir}


DESTDIR ?=
prefix ?= $(DESTDIR)/usr
bindir ?= $(prefix)/bin

install: all
install -D -m755 ${srcdir}/pico_adc -t ${bindir}
10 changes: 8 additions & 2 deletions spp-picoadc/Readme.md → Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# pico_adc program -- SPP interface for Pico ADC24 device.
## pico_adc program -- SPP interface to Pico ADC devices

This is a simple C++ program which implements SPP interface
to Pico ADC devices for using with device2 server
(https://github.com/slazav/device2)

libpicohrdl library is needed.

### Command line options:

Expand Down Expand Up @@ -70,4 +76,4 @@ to mix `get_val` measurements with the block read measuremens.
* `get` -- collect and return a single data block.
Returns one value for each enabled channel.
`chan_set` and `set_t` should be done before.
In case of overflow +/-Inf is returned;
In case of overflow +/-Inf is returned;
5 changes: 5 additions & 0 deletions modules/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.deps
*.o
*.a
*.test
*.test.passed
6 changes: 6 additions & 0 deletions modules/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all:
sh -e -c 'for i in */Makefile; do make -C $${i%/Makefile}; done'

clean:
sh -e -c 'for i in */Makefile; do make -C $${i%/Makefile} clean; done'

149 changes: 149 additions & 0 deletions modules/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# module subdirs.
#
# Module name equals to the subdir name. Module h-file should
# have the same name (with .h extension)
#
# Before using define following variables:
# MODDIR -- directory where all modiles are located
# MOD_HEADERS -- list of module headers (*.h)
# MOD_SOURCES -- list of module sources (*.cpp)
# PROGRAMS -- programs to be build
# SHARED_LIB -- shared library to build (collect all MOD_SOURCES + dependencies)
# SIMPLE_TESTS -- Programs returning 0/1.
# For each <name> should be a source <name>.test.cpp.
# SCRIPT_TESTS -- Programs with testing scripts.
# For each <name> should be a source <name>.test.cpp and
# a script <name>.test.script
# OTHER_TESTS -- Any programs or scripts which should be run after building
# PKG_CONFIG -- external libraries used in this module, controlled by pkg-config
# PROG_DEPS -- External programs needed for building the module.
# LDLIBS, LDFLAGS, CXXFLAGS, etc. -- standard Makefile variables
# MOD_LOCAL -- do not find dependencies, use only local information,
# do not expand PKG_CONFIG options (used in get_deps)
######################################################

######################################################
# Main building rules
all: make_deps make_nodeps
clean:
rm -f *.o *.a *.so *.test *.passed Makefile.deps $(PROGRAMS)


MODDIR ?= ..

MOD_NAME :=
MOD_STATIC :=
MOD_OBJECTS :=

ifdef MOD_HEADERS
MOD_NAME := $(notdir $(shell pwd))
MOD_STATIC := $(MOD_NAME).a
endif
ifdef MOD_SOURCES
MOD_OBJECTS := $(patsubst %.cpp, %.o, $(MOD_SOURCES))
MOD_OBJECTS := $(patsubst %.c, %.o, $(MOD_OBJECTS))
endif

SHARED_LIB_SO := $(patsubst %, %.so, $(SHARED_LIB))


######################################################
# Build and include dependency file (using get_deps script).

# .SHELLSTATUS variable appears in make 4.2. We set it to 0 for earlier
# versions of make and skip error detection in the get_deps script:

ifndef MOD_LOCAL

$(shell true)
ifneq (${.SHELLSTATUS},0)
.SHELLSTATUS := 0
endif

$(shell $(MODDIR)/get_deps $(MODDIR) . > Makefile.deps)
ifneq (${.SHELLSTATUS},0)
$(error "get_deps failed: ${.SHELLSTATUS}")
endif
-include Makefile.deps

######################################################
# Building flags
# user-defined flags are added _after_ this

override CFLAGS_ = $(shell [ "$(PKG_CONFIG)" = "" ] ||\
pkg-config --cflags '$(PKG_CONFIG)')
override LDLIBS_ = $(shell [ "$(PKG_CONFIG)" = "" ] ||\
pkg-config --libs '$(PKG_CONFIG)')

override CFLAGS_ += -Werror=return-type -O2 -fPIC -g -I$(MODDIR)

override CFLAGS := $(CFLAGS_) $(CFLAGS)
override CXXFLAGS := -std=gnu++11 $(CFLAGS_) $(CXXFLAGS)
override LDLIBS := $(LDLIBS_) $(LDLIBS)

endif # MOD_LOCAL

######################################################
# make_deps/make_nodeps building rules:
make_deps:
@echo "## Building dependencies: [$(MDEPS)]"
@sh -e -c 'for i in $(MDEPS); do $(MAKE) -C $(MODDIR)/$$i make_nodeps; done'
@echo "## Finish building dependencies"

make_nodeps: $(MOD_STATIC) $(PROGRAMS) $(SHARED_LIB_SO) make_tests

######################################################
# Building rules for tests
SIMPLE_TEST_PROGS := $(patsubst %, %.test, $(SIMPLE_TESTS))
SCRIPT_TEST_PROGS := $(patsubst %, %.test, $(SCRIPT_TESTS))
SIMPLE_TEST_RES := $(patsubst %, %.test.passed, $(SIMPLE_TESTS))
SCRIPT_TEST_RES := $(patsubst %, %.test.passed, $(SCRIPT_TESTS))

$(SIMPLE_TEST_RES): TEST_DEP := ''
$(SCRIPT_TEST_RES): TEST_DEP := %.test.script
$(SIMPLE_TEST_RES): TEST_CMD = ./$< && > $<.passed
$(SCRIPT_TEST_RES): TEST_CMD = ./$<.script && > $<.passed

TEST_OBJECTS := $(patsubst %,%.test.o, $(SIMPLE_TESTS) $(SCRIPT_TESTS))
$(SIMPLE_TEST_PROGS) $(SCRIPT_TEST_PROGS): CC:=$(CXX)
$(SIMPLE_TEST_PROGS) $(SCRIPT_TEST_PROGS): %: %.o $(MOD_OBJECTS) $(ADEPS)
$(TEST_OBJECTS): %.o: %.cpp

%.test.passed: %.test $(TEST_DEP)
@echo "## Running test: $<"
@$(TEST_CMD)

make_tests: $(SIMPLE_TEST_RES) $(SCRIPT_TEST_RES)
@sh -e -c 'for i in $(OTHER_TESTS); do echo "## Running test: $$i"; ./$$i; done'

######################################################
# building rules for programs and shared lib
PROG_OBJECTS := $(patsubst %,%.o, $(PROGRAMS))
$(PROGRAMS): CC:=$(CXX)
$(PROGRAMS): %: %.o $(MOD_OBJECTS) $(ADEPS)
$(PROG_OBJECTS): %.o: %.cpp

$(SHARED_LIB_SO): %.so: $(MOD_OBJECTS) $(ADEPS)
$(CXX) -shared $(LDFLAGS) $+ $(LDLIBS) -o $@
######################################################
# Building rules for module static library

$(MOD_STATIC): $(MOD_OBJECTS)
ar crs $@ $+

######################################################
info:
@echo "MOD_NAME: $(MOD_NAME)"
@echo "MOD_STATIC: $(MOD_STATIC)"
@echo "MOD_SOURCES: $(MOD_SOURCES)"
@echo "MOD_HEADERS: $(MOD_HEADERS)"
@echo "PKG_CONFIG: $(PKG_CONFIG)"
@echo "PROG_DEPS: $(PROG_DEPS)"
@echo "MDEPS: $(MDEPS)"
@echo "ADEPS: $(ADEPS)"
@echo "LDEPS: $(LDEPS)"
@echo "SIMPLE_TESTS: $(SIMPLE_TESTS)"
@echo "SCRIPT_TESTS: $(SCRIPT_TESTS)"
@echo "PROGRAMS: $(PROGRAMS)"
@echo "LDLIBS: $(LDLIBS)"
@echo "CXXFLAGS: $(CXXFLAGS)"
7 changes: 7 additions & 0 deletions modules/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This folder contains some modules from mapsoft2-libs source code library:
https://github.com/slazav/mapsoft2-libs

Modules are copied locally by update_moddir script.
Update time: 2024-01-25 15:05:33
Commit: 36262eb25595b3306b37d45ef9cf73b9e7bf6626

4 changes: 4 additions & 0 deletions modules/err/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MOD_HEADERS := err.h assert_err.h
SIMPLE_TESTS := err assert_err

include ../Makefile.inc
45 changes: 45 additions & 0 deletions modules/err/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Err class

Human-readable text exceptions (with optional error codes)

- Throwing an error:
```c
throw Err() << "some message";
```

- Catching and printing error:
```c
catch (Err E){ cerr << "Error: " << E.str() << "\n"; }
```
- Integer error code can be set as an optional constructor parameter
and extracted by `code` method: `E.code()`. Default code is -1.
```c
try {throw Err(1); } catch (Err E) {int code=E.code();}
```

## assert_err macro

```
#include "err/assert_err.h"
assert_err(<code>, <expected error>)
```


------------------
## Changelog:
2020.09.18 V.Zavjalov 1.3:
- Add Err::operator=

2020.08.13 V.Zavjalov 1.2.5:
- err: add std::exception interface

2019.10.10 V.Zavjalov 1.2:
- Add assert_eq, assert_deq, and assert_feq macro
- Print more information in assert_*

2019.08.16 V.Zavjalov 1.1:
- Add assert_err macro

2019.05.02 V.Zavjalov 1.0:
- First version (used widely in many of my projects)
64 changes: 64 additions & 0 deletions modules/err/assert_err.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef ASSERT_ERR_H
#define ASSERT_ERR_H

///\addtogroup libmapsoft
///@{

#include <cmath> // fabs
#include "err.h"

// assert_err macro

#define assert_err(cmd,ret)\
{try{\
cmd;\
throw Err(-9999)\
<< "assert_err: " << __FILE__ << ":" << __LINE__ << ": error is not thrown:\n"\
<< "command: " << #cmd << "\n"\
<< "expected error: " << (ret)<< "\n";\
} catch (Err & e) {\
if (e.code()==-9999) throw;\
if (e.str()!=(ret)){\
throw Err()\
<< "assert_err: " << __FILE__ << ":" << __LINE__ << ": wrong error message:\n"\
<< "command: " << #cmd << "\n"\
<< "expected error: " << (ret) << "\n"\
<< "actual error: " << e.str()<< "\n";\
}\
}}

// catch an error and check it
#define assert_eq(v1,v2)\
{if ((v1) != (v2)){\
throw Err()\
<< "assert_eq: " << __FILE__ << ":" << __LINE__ << ": arguments are not equal:\n"\
<< "v1: " << #v1 << "\n"\
<< " " << (v1) << "\n"\
<< "v2: " << #v2 << "\n"\
<< " " << (v2) << "\n";\
}}

// compare two double values and check that difference is less then e
#define assert_feq(v1,v2,e)\
{if (fabs((v1) - (v2)) > e){\
throw Err()\
<< "assert_feq: " << __FILE__ << ":" << __LINE__ << ": arguments are not equal:\n"\
<< "v1: " << #v1 << "\n"\
<< " " << (v1) << "\n"\
<< "v2: " << #v2 << "\n"\
<< " " << (v2) << "\n";\
}}

// compare two objects with a dist(a,b) function, check thet the result is less then e
#define assert_deq(v1,v2,e)\
{if (dist((v1),(v2)) > e){\
throw Err()\
<< "assert_feq: " << __FILE__ << ":" << __LINE__ << ": arguments are not equal:\n"\
<< "v1: " << #v1 << "\n"\
<< " " << (v1) << "\n"\
<< "v2: " << #v2 << "\n"\
<< " " << (v2) << "\n";\
}}

///@}
#endif
53 changes: 53 additions & 0 deletions modules/err/assert_err.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
///\cond HIDDEN (do not show this in Doxyden)

#include <cassert>
#include "assert_err.h"

void errorfunc(){
throw Err() << "some error";
}

void nonerrorfunc(){}

double dist(double v1, double v2){return fabs(v1-v2);}

int
main(){
try{
assert_err(errorfunc(), "some error");

// assert_err(errorfunc(), "some error1");
// assert_err(nonerrorfunc(), "some error");

assert_err(throw Err() << "eee", "eee");

assert_eq(10, 10);
assert_eq(20-10, 10);
assert_eq(10, 20-10);

assert_feq(10.0, 10.0, 1e-6);
assert_feq(10.1, 10.2, 0.2);
assert_feq(10.2, 10.1, 0.2);

assert_feq(1, 2-1, 1e-6);
assert_feq(2-1, 1, 1e-6);

// using dist() function
assert_deq(10.0, 10.0, 1e-6);
assert_deq(10.1, 10.2, 0.2);
assert_deq(10.2, 10.1, 0.2);

assert_deq(1, 2-1, 1e-6);
assert_deq(2-1, 1, 1e-6);



}
catch (Err & e) {
std::cerr << "Error: " << e.str() << "\n";
return 1;
}
return 0;
}

///\endcond
Loading

0 comments on commit f9a481a

Please sign in to comment.