├── .gitignore ├── 11a.c ├── B-trees.c ├── B-trees.h ├── Binary_search ├── errors.c └── errors.h ├── Bresenham_circle.c ├── C-functions_overload.c ├── FITS ├── Makefile ├── README ├── fits.c ├── fits.h ├── main.c ├── usefull_macros.c └── usefull_macros.h ├── GLUT_window ├── LICENSE ├── Makefile ├── Readme ├── Readme.md ├── aux.c ├── aux.h ├── cmdlnopts.c ├── cmdlnopts.h ├── events.c ├── events.h ├── image_functions.c ├── image_functions.h ├── imageview.c ├── imageview.h ├── opengl.c ├── opengl.cflags ├── opengl.config ├── opengl.creator ├── opengl.creator.user ├── opengl.creator.user.7bd84e3 ├── opengl.cxxflags ├── opengl.files └── opengl.includes ├── GPS ├── Makefile ├── README ├── cmdlnopts.c ├── cmdlnopts.h ├── daemon.c ├── daemon.h ├── main.c ├── parceargs.c ├── parceargs.h ├── usefull_macros.c └── usefull_macros.h ├── HSFW_management ├── 99-edmund_hsfw.rules ├── CMakeLists.txt ├── LICENSE ├── Readme.md ├── cmdlnopts.c ├── cmdlnopts.h ├── hidmanage.c ├── hidmanage.h ├── hsfw.c ├── hsfw.h ├── locale │ └── ru │ │ ├── LC_MESSAGES │ │ └── HSFW_manage.mo │ │ ├── messages.po │ │ └── ru.po ├── main.c ├── parseargs.c ├── parseargs.h ├── usefull_macros.c └── usefull_macros.h ├── Makefile ├── NES_webiface ├── .gitignore ├── CMakeLists.txt ├── HOWTO.cert ├── README.md ├── auth.c ├── auth.h ├── cert.key ├── cert.pem ├── cmdlnopts.c ├── cmdlnopts.h ├── main.c ├── static │ ├── admin.html │ ├── auth.js │ ├── index.html │ ├── pass.html │ ├── pass.js │ └── requests.js ├── websockets.c └── websockets.h ├── Ncurses ├── Makefile ├── acs.c ├── menu.c ├── mouse_menu.c ├── ncurses.cflags ├── ncurses.config ├── ncurses.creator ├── ncurses.cxxflags ├── ncurses.files ├── ncurses.includes ├── ncurses_and_readline.c ├── rolling.c ├── scroll.c └── scrollfile.c ├── README ├── Raspberry └── MPU-6050-log │ ├── MPU6050.h │ ├── Makefile │ ├── README │ └── main.c ├── SMSD-1.5 ├── Makefile ├── README └── client.c ├── SSL_Socket_snippet ├── Makefile ├── Readme ├── ca │ └── gen.sh ├── ca_cert.pem ├── client.c ├── client.h ├── client_cert.pem ├── client_key.pem ├── cmdlnopts.c ├── cmdlnopts.h ├── daemon.c ├── daemon.h ├── main.c ├── server.c ├── server.h ├── server_cert.pem ├── server_key.pem ├── sslsock.c ├── sslsock.h ├── sslsosk.cflags ├── sslsosk.config ├── sslsosk.creator ├── sslsosk.cxxflags ├── sslsosk.files └── sslsosk.includes ├── Socket_CAN ├── 99-socketcan.rules ├── HOWTO.cert ├── Makefile ├── Makefile.bk ├── README_ports ├── Readme.md ├── SocketCAN.cflags ├── SocketCAN.config ├── SocketCAN.creator ├── SocketCAN.creator.user ├── SocketCAN.cxxflags ├── SocketCAN.files ├── SocketCAN.includes ├── ca │ ├── ca │ │ ├── ca_cert.pem │ │ ├── ca_cert.srl │ │ └── private │ │ │ └── ca_key.pem │ ├── client │ │ ├── client.csr │ │ ├── client_cert.pem │ │ └── private │ │ │ └── client_key.pem │ ├── gen.sh │ └── server │ │ ├── private │ │ └── server_key.pem │ │ ├── server.csr │ │ └── server_cert.pem ├── can4linux.h ├── can_io.c ├── can_io.h ├── canbus.h ├── cansock.c ├── cert.key ├── cert.pem ├── client.c ├── client.h ├── cmdlnopts.c ├── cmdlnopts.h ├── daemon.c ├── daemon.h ├── diff │ ├── clientscript │ └── serverscript ├── log.log ├── server.c ├── server.h ├── socketcan0 ├── sslsock.c └── sslsock.h ├── Socket_snippet ├── Makefile ├── Readme.md ├── client.c ├── client.h ├── cmdlnopts.c ├── cmdlnopts.h ├── main.c ├── server.c ├── server.h ├── socket.c ├── socket.h ├── socksnippet.cflags ├── socksnippet.config ├── socksnippet.creator ├── socksnippet.creator.user ├── socksnippet.cxxflags ├── socksnippet.files ├── socksnippet.includes └── testcommands ├── TeAmanagement ├── Makefile ├── Readme ├── TeAman.cflags ├── TeAman.config ├── TeAman.creator ├── TeAman.creator.user ├── TeAman.cxxflags ├── TeAman.files ├── TeAman.includes ├── cmdlnopts.c ├── cmdlnopts.h ├── log.log ├── main.c ├── out.fits ├── sersock.c ├── sersock.h ├── teacmd.c └── teacmd.h ├── Tetris ├── Makefile ├── disp.c ├── disp.h ├── displaybuf.c ├── displaybuf.h ├── main.c ├── tetris.cflags ├── tetris.config ├── tetris.creator ├── tetris.cxxflags ├── tetris.files └── tetris.includes ├── Trinamic ├── SHA_client │ ├── Makefile │ └── client.c ├── SHA_client_cmdline │ ├── Makefile │ ├── client.c │ ├── cmdlnopts.c │ ├── cmdlnopts.h │ ├── parceargs.c │ └── parceargs.h ├── client │ ├── Makefile │ └── client.c └── websock_simple │ ├── Makefile │ ├── test.c │ └── test.html ├── USB_reset.c ├── USBrelay ├── 1.c ├── 99-hidrelay.rules └── Makefile ├── Zernike ├── Makefile ├── README ├── Z-BTA_test.c ├── simple_list.c ├── simple_list.h ├── spots.c ├── spots.h ├── test.c ├── zern_private.h ├── zernike.c ├── zernike.h ├── zernikeR.c └── zernike_annular.c ├── astrosib ├── CMakeLists.txt ├── Readme.md ├── astrosib.cpp └── astrosib.h ├── avx ├── Makefile ├── SIMD_SSE_AVX ├── add.c └── dotproduct.c ├── bidirectional_list.c ├── bidirectional_list.h ├── calcAP ├── Makefile ├── Readme ├── slalib_and_sofa.c └── slalib_sofa_nova.c ├── clr.c ├── cmakelists_ ├── CMakeLists.txt ├── CMakeLists_regular_01.txt ├── CMakeLists_regular_02.txt ├── CMakeLists_regular_03.txt ├── CMakeLists_regular_04.txt ├── Makefile ├── Makefile_dbg_rls └── get_proc_count ├── comments_before.c ├── count_bits.c ├── cryptpass.c ├── erosion-dilation ├── Makefile ├── README ├── binmorph.c ├── binmorph.h ├── cclabling.h ├── cclabling_1.h ├── dilation.h ├── fc_filter.h ├── fs_filter.h └── main.c ├── factor.c ├── fifo_lifo.c ├── fifo_lifo.h ├── fixed_sort_example.c ├── get_avail_mem.c ├── getopt ├── README ├── cmdlnopts │ ├── Makefile │ ├── cmdlnopts.c │ ├── cmdlnopts.h │ ├── main.c │ ├── parseargs.c │ ├── parseargs.h │ ├── usefull_macros.c │ └── usefull_macros.h ├── cmdlnopts_deprecated │ ├── cmdlnopts.c │ ├── cmdlnopts.h │ ├── parceargs.c │ └── parceargs.h └── getopt │ ├── getopt.c │ └── getopt.h ├── guard.c ├── image_view_module ├── CMakeLists.txt ├── README ├── events.c ├── events.h ├── imageview.c ├── imageview.h ├── list.c ├── list.h ├── locale │ └── ru │ │ ├── LC_MESSAGES │ │ └── image_view_module.mo │ │ ├── messages.po │ │ └── ru.po ├── macros.c ├── macros.h ├── main.c └── main.h ├── inotify.c ├── json ├── json.c └── json.h ├── kicad-copy ├── Makefile ├── cmdlnopts.c ├── cmdlnopts.h ├── copy_pcb.c ├── copy_pcb.h ├── parceargs.c ├── parceargs.h ├── usefull_macros.c └── usefull_macros.h ├── med.c ├── modbus_relay ├── Makefile ├── cmdlnopts.c ├── cmdlnopts.h ├── main.c ├── modbus_relay.cflags ├── modbus_relay.config ├── modbus_relay.creator ├── modbus_relay.creator.user ├── modbus_relay.cxxflags ├── modbus_relay.files ├── modbus_relay.includes └── web_management │ ├── index.html │ └── relay_daemon │ ├── Makefile │ ├── cmdlnopts.c │ ├── cmdlnopts.h │ ├── main.c │ ├── modbus_relay │ ├── modbus_relay.cflags │ ├── modbus_relay.config │ ├── modbus_relay.creator │ ├── modbus_relay.creator.user │ ├── modbus_relay.cxxflags │ ├── modbus_relay.files │ ├── modbus_relay.includes │ ├── server.c │ └── server.h ├── mydiff.c ├── netdaemon ├── Makefile ├── Readme.md ├── cmdlnopts.c ├── cmdlnopts.h ├── main.c ├── netdaemon.c.tags ├── parseargs.c ├── parseargs.h ├── socket.c ├── socket.h ├── term.c ├── term.h ├── usefull_macros.c └── usefull_macros.h ├── opengl.c ├── pipe_and_buffering_read.c ├── powerof2.c ├── pwd.c ├── randline.c ├── randomstring.c ├── sendfile.c ├── serialsock ├── Makefile ├── Readme ├── canserver.cflags ├── canserver.config ├── canserver.creator ├── canserver.creator.user ├── canserver.cxxflags ├── canserver.files ├── canserver.includes ├── cmdlnopts.c ├── cmdlnopts.h ├── main.c ├── sersock.c └── sersock.h ├── serialsockCANmanage ├── Makefile ├── Readme ├── SEWmanage.cflags ├── SEWmanage.config ├── SEWmanage.creator ├── SEWmanage.creator.user ├── SEWmanage.cxxflags ├── SEWmanage.files ├── SEWmanage.includes ├── cmdlnopts.c ├── cmdlnopts.h ├── main.c ├── sersock.c ├── sersock.h └── www │ ├── bin │ ├── acc │ └── runSpeedCtrl │ ├── fans.html │ └── favicon.ico ├── sharedlib_template ├── CMake.readme ├── CMakeLists.txt ├── examples │ ├── CMakeLists.txt │ └── helloworld.c ├── locale │ └── ru │ │ ├── LC_MESSAGES │ │ └── usefull_macros.mo │ │ └── ru.po ├── usefull_macros.c ├── usefull_macros.h └── usefull_macros.pc.in ├── sigtest.c ├── simple_Eratosfen_sieve.c ├── simple_gettext ├── 1.c ├── Makefile └── test_ru.po ├── simple_list.c ├── simple_list.h ├── simple_websockets ├── Makefile ├── Readme.md ├── dbg.h ├── main.c ├── que.c ├── que.h └── www │ ├── fastermd5.js │ ├── getpass.js │ ├── localstore.js │ ├── md5.js │ └── test.html ├── sockmsgs.c ├── stellarium_emul ├── Makefile ├── Readme ├── cmdlnopts.c ├── cmdlnopts.h ├── daemon.c ├── emulation.c ├── emulation.h ├── main.c ├── main.h ├── parseargs.c ├── parseargs.h ├── telescope.c ├── telescope.h ├── usefull_macros.c └── usefull_macros.h ├── stringHash4MCU_ ├── En_words ├── Readme ├── hashgen.c ├── hashtest.c ├── run ├── strfunc.c ├── strfunc.h ├── test.c └── testdic ├── table_sincos ├── Makefile ├── README ├── calcsin.c ├── gentab.c └── sqrt.c ├── thread_array_management ├── Makefile ├── Readme └── test.c ├── tmout.c ├── usb_reset └── reset.c ├── usefull_macros.c ├── usefull_macros.h ├── websockets ├── Makefile ├── leaf.jpg ├── leaf1.jpg ├── test.c ├── test.html └── testlog2.c └── xor.c /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.bak 3 | *.bck 4 | *.o 5 | .hg* 6 | .dropbox.attr 7 | -------------------------------------------------------------------------------- /B-trees.h: -------------------------------------------------------------------------------- 1 | /* 2 | * B-trees.h 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __B_TREES_H__ 24 | #define __B_TREES_H__ 25 | 26 | typedef struct btree_node{ 27 | int data; 28 | struct btree_node *left, *right; 29 | } BTree; 30 | 31 | BTree *bt_get(BTree *root, int v); 32 | BTree *bt_search(BTree *root, int v, BTree **prev); 33 | BTree *bt_create_leaf(int v); 34 | BTree *bt_insert(BTree **root, int v); 35 | BTree *max_leaf(BTree *root, BTree **prev); 36 | BTree *min_leaf(BTree *root, BTree **prev); 37 | void bt_remove(BTree **root, int v); 38 | 39 | void print_tree(BTree *leaf); 40 | 41 | #endif // __B_TREES_H__ 42 | -------------------------------------------------------------------------------- /Binary_search/errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Edward V. Emelianov . 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | #pragma once 18 | #ifndef ERRORS_H__ 19 | #define ERRORS_H__ 20 | 21 | #include 22 | 23 | typedef struct{ 24 | uint32_t code; 25 | char *errmsg; 26 | } abortcodes; 27 | 28 | #endif // ERRORS_H__ 29 | -------------------------------------------------------------------------------- /Bresenham_circle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | char *drawCircle(int R, int geom){ 6 | if(R > 200 || R < 1) return NULL; 7 | int S, i, Y = 2 * R + 2; 8 | if(geom) 9 | S = Y * (R + 1); 10 | else 11 | S = Y * (Y - 1); 12 | char *buf = malloc(S+1); 13 | if(!buf) return NULL; 14 | memset(buf, ' ', S); 15 | buf[S] = 0; 16 | for(i = Y-1; i < S; i+=Y) buf[i] = '\n'; 17 | inline void DrawPixel(int x, int y){ 18 | if(geom){ 19 | if(y%2==0) buf[Y * y/2 + x] = '*'; 20 | }else{ 21 | buf[Y * y + x] = '*'; 22 | } 23 | } 24 | // Bresenham's circle algorithm 25 | int x = R; 26 | int y = 0; 27 | int radiusError = 1-x; 28 | while(x >= y){ 29 | DrawPixel(x + R, y + R); 30 | DrawPixel(y + R, x + R); 31 | DrawPixel(-x + R, y + R); 32 | DrawPixel(-y + R, x + R); 33 | DrawPixel(-x + R, -y + R); 34 | DrawPixel(-y + R, -x + R); 35 | DrawPixel(x + R, -y + R); 36 | DrawPixel(y + R, -x + R); 37 | y++; 38 | if (radiusError < 0){ 39 | radiusError += 2 * y + 1; 40 | }else{ 41 | x--; 42 | radiusError += 2 * (y - x) + 1; 43 | } 44 | } 45 | return buf; 46 | } 47 | 48 | int main(int argc, char **argv){ 49 | int i, R; 50 | char *buf; 51 | for(i = 1; i < argc; i++){ 52 | if(!(buf = drawCircle(R = atoi(argv[i]), 1))){ 53 | printf("Wrong parameter %s\n", argv[i]); 54 | continue; 55 | } 56 | printf("\nCircle with R = %d:\n%s\n", R, buf); 57 | free(buf); buf = NULL; 58 | } 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /C-functions_overload.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define FUNC(arg) _Generic(arg, uint16_t: funcu, int32_t: funci)(arg) 5 | 6 | void funcu(uint16_t arg){ 7 | printf("uint16_t: %u\n", arg); 8 | } 9 | 10 | void funci(int32_t arg){ 11 | printf("int32_t: %d\n", arg); 12 | } 13 | 14 | int main(){ 15 | uint16_t u = 32; 16 | int32_t i = -50333; 17 | FUNC(u); 18 | FUNC(i); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /FITS/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = fitsread 2 | LDFLAGS = -lcfitsio 3 | SRCS = $(wildcard *.c) 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=1111 -DEBUG 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror -Wextra $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /FITS/README: -------------------------------------------------------------------------------- 1 | Simple routines for FITS reading/writing 2 | -------------------------------------------------------------------------------- /FITS/fits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fits.h 3 | * 4 | * Copyright 2015 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #pragma once 22 | #ifndef __FITS_H__ 23 | #define __FITS_H__ 24 | 25 | #include 26 | #include 27 | 28 | 29 | typedef struct{ 30 | int width; // width 31 | int height; // height 32 | int dtype; // data type 33 | double *data; // picture data 34 | char **keylist; // list of options for each key 35 | size_t keynum; // full number of keys (size of *keylist) 36 | } IMAGE; 37 | 38 | void imfree(IMAGE **ima); 39 | bool readFITS(char *filename, IMAGE **fits); 40 | bool writeFITS(char *filename, IMAGE *fits); 41 | 42 | #endif // __FITS_H__ 43 | -------------------------------------------------------------------------------- /FITS/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * main.c 3 | * 4 | * Copyright 2015 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #include 23 | #include "usefull_macros.h" 24 | #include "fits.h" 25 | 26 | void signals(int signo){ 27 | exit(signo); 28 | } 29 | 30 | int main(int argc, char **argv){ 31 | IMAGE *fits; 32 | //size_t i, s; 33 | initial_setup(); 34 | if(argc != 3) ERRX("Usage: %s infile outfile", argv[0]); 35 | readFITS(argv[1], &fits); 36 | DBG("ima: %dx%d", fits->width, fits->height); 37 | //s = fits->width * fits->height; 38 | //double *img = fits->data; 39 | //for(i = 0; i < s; ++i) *img++ /= 2.; 40 | unlink(argv[2]); 41 | writeFITS(argv[2], fits); 42 | imfree(&fits); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /GLUT_window/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := opengl 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lusefull_macros -lflycapture-c -lflycapture -L/usr/local/lib 5 | LDFLAGS += -lm -pthread -lglut -lGL -lX11 -lGLEW 6 | SRCS := $(wildcard *.c) 7 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 8 | OBJDIR := mk 9 | CFLAGS += -O2 -Wno-trampolines -std=gnu99 10 | CFLAGS += -I/usr/local/include/flycapture 11 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 12 | DEPS := $(OBJS:.o=.d) 13 | CC = gcc 14 | #CXX = g++ 15 | 16 | 17 | all : $(OBJDIR) $(PROGRAM) 18 | 19 | debug: CFLAGS += -DEBUG -Werror -Wall -Wextra 20 | debug: all 21 | 22 | $(PROGRAM) : $(OBJS) 23 | @echo -e "\t\tLD $(PROGRAM)" 24 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 25 | 26 | $(OBJDIR): 27 | mkdir $(OBJDIR) 28 | 29 | ifneq ($(MAKECMDGOALS),clean) 30 | -include $(DEPS) 31 | endif 32 | 33 | $(OBJDIR)/%.o: %.c 34 | @echo -e "\t\tCC $<" 35 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 36 | 37 | clean: 38 | @echo -e "\t\tCLEAN" 39 | @rm -f $(OBJS) $(DEPS) 40 | @rmdir $(OBJDIR) 2>/dev/null || true 41 | 42 | xclean: clean 43 | @rm -f $(PROGRAM) 44 | 45 | .PHONY: clean xclean 46 | -------------------------------------------------------------------------------- /GLUT_window/Readme: -------------------------------------------------------------------------------- 1 | imagewiew with GLUT 2 | -------------------------------------------------------------------------------- /GLUT_window/Readme.md: -------------------------------------------------------------------------------- 1 | Simplest tool for Grasshopper3 control 2 | ====================================== 3 | 4 | (pre-pre-alpha version) 5 | -------------------------------------------------------------------------------- /GLUT_window/aux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the opengl project. 3 | * Copyright 2020 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include // PATH_MAX 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "aux.h" 27 | #include "cmdlnopts.h" 28 | 29 | // print messages for given verbose_level 30 | int verbose(verblevel levl, const char *fmt, ...){ 31 | if((unsigned)verbose_level < levl) return 0; 32 | va_list ar; int i; 33 | va_start(ar, fmt); 34 | i = vprintf(fmt, ar); 35 | va_end(ar); 36 | printf("\n"); 37 | fflush(stdout); 38 | return i; 39 | } 40 | 41 | /** 42 | * @brief check_filename - find file name "outfile_xxxx.suff" NOT THREAD-SAFE! 43 | * @param outfile - file name prefix 44 | * @param suff - file name suffix 45 | * @return NULL or next free file name like "outfile_0010.suff" (don't free() it!) 46 | */ 47 | char *check_filename(char *outfile, char *suff){ 48 | static char buff[PATH_MAX]; 49 | struct stat filestat; 50 | int num; 51 | for(num = 1; num < 10000; num++){ 52 | if(snprintf(buff, PATH_MAX, "%s_%04d.%s", outfile, num, suff) < 1) 53 | return NULL; 54 | if(stat(buff, &filestat)) // OK, file not exists 55 | return buff; 56 | } 57 | return NULL; 58 | } 59 | -------------------------------------------------------------------------------- /GLUT_window/aux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the opengl project. 3 | * Copyright 2020 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef AUX_H__ 21 | #define AUX_H__ 22 | 23 | typedef enum{ 24 | VERB_NONE, 25 | VERB_MESG, 26 | VERB_DEBUG 27 | } verblevel; 28 | 29 | int verbose(verblevel levl, const char *fmt, ...); 30 | char *check_filename(char *outfile, char *suff); 31 | 32 | #define VMESG(...) do{verbose(VERB_MESG, __VA_ARGS__);}while(0) 33 | #define VDBG(...) do{verbose(VERB_DEBUG, __VA_ARGS__);}while(0) 34 | 35 | #endif // AUX_H__ 36 | -------------------------------------------------------------------------------- /GLUT_window/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the opengl project. 3 | * Copyright 2020 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #pragma once 21 | #ifndef CMDLNOPTS_H__ 22 | #define CMDLNOPTS_H__ 23 | 24 | /* 25 | * here are some typedef's for global data 26 | */ 27 | typedef struct{ 28 | char *device; // camera device name 29 | char *pidfile; // name of PID file 30 | int camno; // number of camera to work with 31 | float exptime; // exposition time 32 | float gain; // gain value 33 | int showimage; // display last captured image in OpenGL screen 34 | int nimages; // number of images to capture 35 | int save_png; // save png file 36 | int rest_pars_num; // number of rest parameters 37 | char** rest_pars; // the rest parameters: array of char* 38 | } glob_pars; 39 | 40 | 41 | glob_pars *parse_args(int argc, char **argv); 42 | extern glob_pars G; 43 | extern int verbose_level; 44 | 45 | #endif // CMDLNOPTS_H__ 46 | -------------------------------------------------------------------------------- /GLUT_window/events.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/GLUT_window/events.h -------------------------------------------------------------------------------- /GLUT_window/image_functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the opengl project. 3 | * Copyright 2020 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef IMAGE_FUNCTIONS__ 21 | #define IMAGE_FUNCTIONS__ 22 | 23 | #include 24 | #include "imageview.h" 25 | 26 | // functions for converting grayscale value into colour 27 | typedef enum{ 28 | COLORFN_LINEAR, // linear 29 | COLORFN_LOG, // ln 30 | COLORFN_SQRT, // sqrt 31 | COLORFN_MAX // end of list 32 | } colorfn_type; 33 | 34 | typedef struct{ 35 | uint16_t *data; 36 | int w; 37 | int h; 38 | } IMG; 39 | 40 | void change_displayed_image(windowData *win, IMG *convertedImage); 41 | 42 | void gray2rgb(double gray, GLubyte *rgb); 43 | colorfn_type get_colorfun(); 44 | void change_colorfun(colorfn_type f); 45 | void roll_colorfun(); 46 | 47 | #endif // IMAGE_FUNCTIONS__ 48 | -------------------------------------------------------------------------------- /GLUT_window/opengl.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /GLUT_window/opengl.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | -------------------------------------------------------------------------------- /GLUT_window/opengl.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /GLUT_window/opengl.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /GLUT_window/opengl.files: -------------------------------------------------------------------------------- 1 | aux.c 2 | aux.h 3 | camera_functions.h 4 | cmdlnopts.c 5 | cmdlnopts.h 6 | events.c 7 | events.h 8 | opengl.c 9 | image_functions.c 10 | image_functions.h 11 | imageview.c 12 | imageview.h 13 | -------------------------------------------------------------------------------- /GLUT_window/opengl.includes: -------------------------------------------------------------------------------- 1 | . 2 | /usr/local/include/flycapture 3 | -------------------------------------------------------------------------------- /GPS/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = gpstest 2 | LDFLAGS = -lm 3 | SRCS = $(wildcard *.c) 4 | OBJDIR = mk 5 | CC = gcc 6 | DEFINES = -D_XOPEN_SOURCE=1001 7 | CFLAGS = -DEBUG -Wall -Werror -Wextra $(DEFINES) 8 | OBJS = $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 9 | 10 | all : $(OBJDIR) $(OBJS) $(PROGRAM) 11 | 12 | $(PROGRAM) : $(OBJDIR) $(OBJS) 13 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 14 | 15 | $(OBJDIR): 16 | mkdir $(OBJDIR) 17 | 18 | $(OBJDIR)/%.o: %.c 19 | @printf " CC $<\n" 20 | $(CC) $(LDFLAGS) $(CFLAGS) -o $@ -c $< 21 | 22 | # some addition dependencies 23 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 24 | # @touch $@ 25 | 26 | clean: 27 | /bin/rm -rf $(OBJDIR) 28 | depend: 29 | $(CXX) -MM $(CXX.SRCS) 30 | -------------------------------------------------------------------------------- /GPS/README: -------------------------------------------------------------------------------- 1 | Small utility for working with GPS module NEO-6M 2 | -------------------------------------------------------------------------------- /GPS/cmdlnopts.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/GPS/cmdlnopts.c -------------------------------------------------------------------------------- /GPS/daemon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * daemon.h 3 | * 4 | * Copyright 2015 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #ifndef PROC_BASE 22 | #define PROC_BASE "/proc" 23 | #endif 24 | 25 | #include // pid_t 26 | 27 | void iffound_default(pid_t pid); 28 | void check4running(char **argv, char *pidfilename, void (*iffound)(pid_t pid)); 29 | -------------------------------------------------------------------------------- /HSFW_management/99-edmund_hsfw.rules: -------------------------------------------------------------------------------- 1 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="82cd", MODE:="0666" 2 | -------------------------------------------------------------------------------- /HSFW_management/cmdlnopts.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/HSFW_management/cmdlnopts.c -------------------------------------------------------------------------------- /HSFW_management/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cmdlnopts.h - comand line options for parseargs 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __CMDLNOPTS_H__ 24 | #define __CMDLNOPTS_H__ 25 | 26 | #include "parseargs.h" 27 | 28 | /* 29 | * here are some typedef's for global data 30 | */ 31 | typedef struct{ 32 | char *wheelID; // ID of wheel to work with 33 | char *wheelName; // and/or its name 34 | char *serial; // turret's serial (string description) 35 | int filterPos; // position of filter 36 | char *filterName; // and/or its name 37 | char *filterId; // or full ID like "A2" 38 | } glob_pars; 39 | 40 | // ids for "list all", "list present", "list short" 41 | typedef enum{ 42 | LIST_NONE = 0, 43 | LIST_ALL, 44 | LIST_PRES, 45 | LIST_SHORT 46 | } listopts; 47 | 48 | // default & global parameters 49 | extern glob_pars const Gdefault; 50 | extern int listNms, gohome, reName, showpos, setdef; 51 | 52 | extern glob_pars G; 53 | 54 | glob_pars *parse_args(int argc, char **argv); 55 | 56 | #endif // __CMDLNOPTS_H__ 57 | -------------------------------------------------------------------------------- /HSFW_management/hidmanage.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/HSFW_management/hidmanage.c -------------------------------------------------------------------------------- /HSFW_management/hidmanage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hidmanage.h - manage HID devices 3 | * 4 | * Copyright 2016 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #pragma once 22 | #ifndef __HIDMANAGE_H__ 23 | #define __HIDMANAGE_H__ 24 | 25 | #define W_VID "10c4" 26 | #define W_PID "82cd" 27 | 28 | typedef struct{ 29 | int fd; 30 | char *serial; 31 | char ID; 32 | char name[9]; 33 | int maxpos; 34 | } wheel_descr; 35 | 36 | int find_wheels(wheel_descr **wheels); 37 | 38 | #endif // __HIDMANAGE_H__ 39 | -------------------------------------------------------------------------------- /HSFW_management/hsfw.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/HSFW_management/hsfw.c -------------------------------------------------------------------------------- /HSFW_management/hsfw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hsfw.h - functions for work with wheels 3 | * 4 | * Copyright 2016 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #pragma once 22 | #ifndef __HSFW_H__ 23 | #define __HSFW_H__ 24 | 25 | #define REG_CLERR (0x02) 26 | #define REG_CLERR_LEN (2) 27 | #define REG_STATUS (0x0a) 28 | #define REG_STATUS_LEN (6) 29 | #define REG_INFO (0x0b) 30 | #define REG_INFO_LEN (7) 31 | #define REG_GOTO (0x14) 32 | #define REG_GOTO_LEN (3) 33 | #define REG_HOME (0x15) 34 | #define REG_HOME_LEN (3) 35 | #define REG_NAME (0x16) 36 | #define REG_NAME_LEN (14) 37 | 38 | // absolute max position (5 for wheels 'A'..'E' & 8 for wheels 'F'..'G') 39 | #define ABS_MAX_POS_A (5) 40 | #define ABS_MAX_POS_B (8) 41 | // end of 5-position wheel descriptor range 42 | #define POS_A_END ('E') 43 | // end of 8-pos range 44 | #define POS_B_END ('H') 45 | 46 | enum name_cmd{ 47 | RESTORE_DEFVALS = 1, 48 | RENAME_FILTER, 49 | FILTER_NAME, 50 | RENAME_WHEEL, 51 | WHEEL_NAME 52 | }; 53 | 54 | void check_args(); 55 | int process_args(); 56 | int get_max_pos(char filter_id); 57 | #endif // __HSFW_H__ 58 | -------------------------------------------------------------------------------- /HSFW_management/locale/ru/LC_MESSAGES/HSFW_manage.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/HSFW_management/locale/ru/LC_MESSAGES/HSFW_manage.mo -------------------------------------------------------------------------------- /HSFW_management/locale/ru/messages.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/HSFW_management/locale/ru/messages.po -------------------------------------------------------------------------------- /HSFW_management/locale/ru/ru.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/HSFW_management/locale/ru/ru.po -------------------------------------------------------------------------------- /HSFW_management/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * main.c 3 | * 4 | * Copyright 2016 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #include 22 | #include "usefull_macros.h" 23 | #include "cmdlnopts.h" 24 | #include "hsfw.h" 25 | 26 | void signals(int signo){ 27 | exit(signo); 28 | } 29 | 30 | 31 | int main(int argc, char **argv){ 32 | initial_setup(); 33 | parse_args(argc, argv); 34 | check_args(); 35 | return process_args(); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /HSFW_management/parseargs.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/HSFW_management/parseargs.c -------------------------------------------------------------------------------- /HSFW_management/usefull_macros.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/HSFW_management/usefull_macros.c -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | LDFLAGS = 3 | DEFINES = -DSTANDALONE -DEBUG 4 | CFLAGS = -Wall -Werror 5 | 6 | all : fifo_lifo bidirectional_list B-trees simple_list 7 | 8 | %: %.c 9 | $(CC) $(LDFLAGS) $(CFLAGS) $(DEFINES) $< -o $@ 10 | -------------------------------------------------------------------------------- /NES_webiface/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | 7 | # Libraries 8 | *.lib 9 | *.a 10 | *.la 11 | *.lo 12 | 13 | # Shared objects (inc. Windows DLLs) 14 | *.so 15 | *.so.* 16 | 17 | # qt-creator 18 | *.config 19 | *.cflags 20 | *.cxxflags 21 | *.creator* 22 | *.files 23 | *.includes 24 | -------------------------------------------------------------------------------- /NES_webiface/HOWTO.cert: -------------------------------------------------------------------------------- 1 | create: 2 | openssl req -newkey rsa:2048 -nodes -keyout cert.key -x509 -days 365 -out cert.pem 3 | 4 | review: 5 | openssl x509 -text -noout -in cert.pem 6 | -------------------------------------------------------------------------------- /NES_webiface/README.md: -------------------------------------------------------------------------------- 1 | # NES_web 2 | 3 | Web-interface for NES (Nesmith Echelle Spectrograph) management. Based on pusirobot and liboninon. -------------------------------------------------------------------------------- /NES_webiface/cert.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC68f94gnFpcepC 3 | +kpD4bxY7sQAXYbyp5ahAWun4scbLJPjJe56/CE47yvTpdU8KrVfHLYmP8KcF4pM 4 | w0ZUNMCEenkQkb+eWjIviw3wzgesqLSssM+GZzlg92V2xkYlS/hEolUh0Z+Gl1Se 5 | zl9f1S/EhL6RTfQx5ZuGlppHknqtbP0g4QNkxPXGj/qXqmaWLOxb8fX30eNf/6SF 6 | vl1o45xwFE1SSGQnyh8KKZUWAPH2aZWpwwgB8gv4XwaVWo7DirbqOlUhhkylhhl0 7 | cA7dHFgODTLluRstYr9M5u3WdoJzTGZTvg2ZV1vmfpQMVbat49TVJYZI3iLKoBHQ 8 | IzeSU/lvAgMBAAECggEAUlc40RmTXoBgUHPxtgh9byZrikWnpMWQIQaBJodKb3uo 9 | /8m7Ssw2zd76jNRkIYYmMOhyilJXI21y6vCvz3MUwMU5AcVQgyzzIeG7mC8HTlNY 10 | kR+nqGla6ozNUg1u5AqcJY7itGyiOSP6j6ASfiFmUsatMU8GmduqLxOyjIfGJRA1 11 | hnNAqYsVv2LbhbUQJTBozYMz2XYfiq/GbzL2NC1tv/xWoSL4zELjDuiGyZcT8oyV 12 | u+dOf0x/VXOLvHqDrA8HuFbUrBjK5z0QW9iYReti/oxuhGrlp2rJLuzivKr4l+v8 13 | qA0momNxhFFgyyx2Mb5zxp9TwA2x7q5Cg3vOCje3MQKBgQDe6MTywxuO4MVpwDSl 14 | yot8vzUlI7Bv8BtdW18JUc5y1SIyGHlW1cuaQnZW6hbor6UxAoWi7oIjaFX+JQVD 15 | 3NLEnjuUF64/Y+k8wtvK0fFeZ2nvx2UNHF50JV0tQZtHo8znwKI/L8ZBSGJcBwh2 16 | BGXtJtK9AY6C5xv5U03xRukw/QKBgQDWsn0qd6mV6iGqLth6sjDOJt/RFrvcikXb 17 | lMhkCyGPuR2lQsUDbgWMcb/td3CqR5iZAksDbXrPqQBZVm9LO7DfDsL9GxtfgMrt 18 | 0dWk0Baod/n4NQBn8A6qGpbheFZwOhNGayYI17IqtRJmfLJuR7gRvm/IfGKso24X 19 | TTA3kpSl2wKBgEBv52cJ8bB213p/fniiuXnhSDqpO3rQXQi6vhlSlaxqYk069/Cb 20 | MxUvu0faua6f/8/QG9OCwQn9QkaKayA3+JGv8CcaRVu7xRO0fJb/45dXq68N4+9L 21 | UR6gInRPr9SgzD3+WKiNZfE/PHe/7Lk5AkHw5CCRD6JVrqd/ZlumFQj9AoGBAKae 22 | fM7xcRYcTyYRFwYZthC3UKmnOAJO+SoRTHd/v/sXUe+IYvdncjztpmK3eCNeTwoo 23 | Imk1lMMGSHQMxXCgkYJ6pU7is5qpjFOGroQqzfrOqZs8HuWLAwZ2fjPbPVH5cC4N 24 | R8ZDB01nmzEYgy1c0XhLz9rK1ZVffDfvOoVWZ7BTAoGAdQUkTWTTHU+Xwc9HshJy 25 | qDFAFu5SvvO2dn3OvbGVUVc+I3M1P+HMeKS3HnomFLtRRDUGEbqZtPfrxBRnduW9 26 | cEtgO+smyq86vs1p/ohmUESB2ablkvOgwXTXus+NsmUt3uVDq+0lFTfog/DX49+O 27 | EiTvSXB1U92Opv/kh8ZhQak= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /NES_webiface/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDazCCAlOgAwIBAgIUU3mUrQDJVG5A00d+WvVFfqScrqIwDQYJKoZIhvcNAQEL 3 | BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM 4 | GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMDA3MTMxNjE0MTlaFw0yMTA3 5 | MTMxNjE0MTlaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw 6 | HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB 7 | AQUAA4IBDwAwggEKAoIBAQC68f94gnFpcepC+kpD4bxY7sQAXYbyp5ahAWun4scb 8 | LJPjJe56/CE47yvTpdU8KrVfHLYmP8KcF4pMw0ZUNMCEenkQkb+eWjIviw3wzges 9 | qLSssM+GZzlg92V2xkYlS/hEolUh0Z+Gl1Sezl9f1S/EhL6RTfQx5ZuGlppHknqt 10 | bP0g4QNkxPXGj/qXqmaWLOxb8fX30eNf/6SFvl1o45xwFE1SSGQnyh8KKZUWAPH2 11 | aZWpwwgB8gv4XwaVWo7DirbqOlUhhkylhhl0cA7dHFgODTLluRstYr9M5u3WdoJz 12 | TGZTvg2ZV1vmfpQMVbat49TVJYZI3iLKoBHQIzeSU/lvAgMBAAGjUzBRMB0GA1Ud 13 | DgQWBBQiHARml0EswF90cHiLYLKxpgj3DjAfBgNVHSMEGDAWgBQiHARml0EswF90 14 | cHiLYLKxpgj3DjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQB4 15 | mMeSGGA4GAfJnxIwRJWGhj2KoweOh9UOVUtvrEJm3LoURbElo1pV3Q3vzt79wLn5 16 | JPdXyN/MexYhtq7cwKQps3E4FElmIGUbR4peO/M1z3wJLaXSbaZqeo7ogSW6vzZL 17 | xIHuxLtchNOi4rkSmOhzJqJ23cLULIF7Z94nwxXRxqKaIW8hXB7mlV9cDztpn2sz 18 | K58M9VYmlfZetoHDzmsymM2DTmmoqR28Ykz+wK+G4U6W1+s7sY3Q+mG91lwvpzTf 19 | yvz6dEtqi8ktBdu86E0yHfX04oDyKtl40d0LDzQT5JWhKQFiC25W5tE2p8QLbtHz 20 | D5vg23HjTgRHZ80+3e4J 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /NES_webiface/static/admin.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/NES_webiface/static/admin.html -------------------------------------------------------------------------------- /NES_webiface/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Index 4 | 5 | 6 | 7 | 8 |

Text 9 |

More text 10 |

11 |

12 |
13 |

14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /NES_webiface/static/pass.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/NES_webiface/static/pass.html -------------------------------------------------------------------------------- /NES_webiface/static/pass.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/NES_webiface/static/pass.js -------------------------------------------------------------------------------- /NES_webiface/static/requests.js: -------------------------------------------------------------------------------- 1 | const Debug = true; 2 | 3 | var elementsCache = {}; 4 | function $(id) { 5 | if (elementsCache[id] === undefined) 6 | elementsCache[id] = document.getElementById(id); 7 | return elementsCache[id]; 8 | } 9 | 10 | function dbg(text){ 11 | if(Debug) console.log("Debug message: " + text); 12 | } 13 | 14 | function sendrequest(req_STR, onOK, postdata){ 15 | var request = new XMLHttpRequest(), timeout_id; 16 | dbg("send request " + req_STR); 17 | var method = postdata ? "POST" : "GET"; 18 | request.open(method, req_STR, true); 19 | //request.setRequestHeader("Accept-Charset", "koi8-r"); 20 | //request.overrideMimeType("multipart/form-data; charset=koi8-r"); 21 | request.onreadystatechange=function(){ 22 | if(request.readyState == 4){ 23 | if(request.status == 200){ 24 | clearTimeout(timeout_id); 25 | if(onOK) onOK(request); 26 | } 27 | else{ 28 | clearTimeout(timeout_id); 29 | parseErr("request sending error"); 30 | } 31 | } 32 | } 33 | request.send(postdata); 34 | timeout_id = setTimeout(function(){request.onreadystatechange=null; request.abort(); parseErr("request timeout");}, 5000); 35 | } 36 | 37 | function parseErr(txt){ 38 | console.log("Error: " + txt); 39 | var msgDiv = $('errmsg'); 40 | if(!msgDiv) return; 41 | msgDiv.innerHTML = "Error: " + txt; 42 | setTimeout(function(){msgDiv.innerHTML = "";}, 3500); 43 | } 44 | -------------------------------------------------------------------------------- /NES_webiface/websockets.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the NES_web project. 3 | * Copyright 2020 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #pragma once 19 | #ifndef WEBSOCKETS_H__ 20 | #define WEBSOCKETS_H__ 21 | #include 22 | #include 23 | 24 | onion_connection_status websocket_run(void *data, onion_request *req, onion_response *res); 25 | 26 | #endif // WEBSOCKETS_H__ 27 | -------------------------------------------------------------------------------- /Ncurses/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS= -Wall -Werror -Wextra -O3 `pkg-config --libs --cflags ncurses` 3 | 4 | all: menu mouse_menu acs rolling readf ncurses_and_readline 5 | 6 | ncurses_and_readline: ncurses_and_readline.c 7 | @echo -e "\t\tCC $<" 8 | $(CC) $(CFLAGS) -lreadline -o $@ $< 9 | 10 | %: %.c 11 | @echo -e "\t\tCC $<" 12 | $(CC) $(CFLAGS) -o $@ $< 13 | 14 | -------------------------------------------------------------------------------- /Ncurses/ncurses.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /Ncurses/ncurses.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | -------------------------------------------------------------------------------- /Ncurses/ncurses.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /Ncurses/ncurses.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /Ncurses/ncurses.files: -------------------------------------------------------------------------------- 1 | acs.c 2 | menu.c 3 | mouse_menu.c 4 | ncurses_and_readline.c 5 | rolling.c 6 | scroll.c 7 | scrollfile.c 8 | -------------------------------------------------------------------------------- /Ncurses/ncurses.includes: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /Ncurses/rolling.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static int maxx, maxy; 5 | 6 | 7 | void initscreen(){ 8 | initscr(); 9 | getmaxyx(stdscr, maxy, maxx); // getyx - get current coords 10 | cbreak(); 11 | keypad(stdscr, TRUE); // We get F1, F2 etc.. 12 | noecho(); 13 | nodelay(stdscr, TRUE); // getch() returns ERR if no keys pressed 14 | start_color(); 15 | init_pair(1, COLOR_RED, COLOR_BLACK); 16 | init_pair(2, COLOR_GREEN, COLOR_BLACK); 17 | init_pair(3, COLOR_YELLOW, COLOR_BLACK); 18 | init_pair(4, COLOR_BLUE, COLOR_BLACK); 19 | init_pair(5, COLOR_MAGENTA, COLOR_BLACK); 20 | init_pair(6, COLOR_CYAN, COLOR_BLACK); 21 | init_pair(7, COLOR_WHITE, COLOR_BLACK); 22 | clear(); 23 | } 24 | 25 | int main(){ 26 | initscreen(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is a set of small usefull utilites & macros 2 | 3 | 4 | bidirectional_list - simple list with operation of searching, inserting, deleting 5 | 6 | B-trees - simple but slowly binary search trees with all main operations 7 | 8 | fifo_lifo - simple stack-like queues 9 | 10 | netdaemon - snippet for network management of serial devices 11 | 12 | serialsock - socket server for serial devices 13 | 14 | simple_list - 1-directional list with functions: add element; delete list 15 | 16 | stellarium_emul - snippet for stellarium telescope remote control 17 | 18 | tmout - theads-based timeout to check something 19 | 20 | usefull_macros - a lot of different macros & functions 21 | 22 | * safe memory allocation & freeing 23 | * coloured output on tty & monochromeous on non-tty 24 | * error/warning/debug macros 25 | * MMAP files into memory 26 | 27 | USBrelay - simplest tool to manage USB-HID chinese relays 28 | 29 | 30 | translate c into asm: gcc -S -fverbose-asm file.c 31 | 32 | -------------------------------------------------------------------------------- /Raspberry/MPU-6050-log/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM = hyrolog 3 | LDFLAGS = -lwiringPi -lm 4 | SRCS = $(wildcard *.c) 5 | CC = gcc 6 | DEFINES = $(DEF) -D_XOPEN_SOURCE=1111 -D_GNU_SOURCE=11 7 | CFLAGS = -Wall -Werror -Wextra $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | # 19 | #%.h: ; 20 | 21 | clean: 22 | /bin/rm -f *.o *~ 23 | depend: 24 | $(CC) -MM $(SRCS) 25 | -------------------------------------------------------------------------------- /Raspberry/MPU-6050-log/README: -------------------------------------------------------------------------------- 1 | Simple data logger for 6-axis gyroscope/accelerometer MPU6050 -------------------------------------------------------------------------------- /SMSD-1.5/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = client 2 | LDFLAGS = 3 | SRCS = client.c 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=501 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) clean 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /SMSD-1.5/README: -------------------------------------------------------------------------------- 1 | Simple CLI interface for motorized linear translator Standa 8MT175-150 moving by SMSD-1.5 driver 2 | 3 | Run ./client & press h for help. -------------------------------------------------------------------------------- /SMSD-1.5/client.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/SMSD-1.5/client.c -------------------------------------------------------------------------------- /SSL_Socket_snippet/Readme: -------------------------------------------------------------------------------- 1 | Client/server snippet using SSL-protected TCP-socket connection between client and server (check certs from both sides) 2 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/ca/gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # https://gist.github.com/zapstar/4b51d7cfa74c7e709fcdaace19233443 4 | mkdir -p ca/private 5 | chmod 700 ca/private 6 | # NOTE: I'm using -nodes, this means that once anybody gets 7 | # their hands on this particular key, they can become this CA. 8 | openssl req \ 9 | -x509 \ 10 | -nodes \ 11 | -days 36524 \ 12 | -newkey rsa:4096 \ 13 | -keyout ca/private/ca_key.pem \ 14 | -out ca/ca_cert.pem \ 15 | -subj "/C=RU/ST=KChR/L=Bukovo/O=SAO RAS/CN=sao.ru" 16 | 17 | # Create server private key and certificate request 18 | mkdir -p server/private 19 | chmod 700 ca/private 20 | openssl genrsa -out server/private/server_key.pem 4096 21 | openssl req -new \ 22 | -key server/private/server_key.pem \ 23 | -out server/server.csr \ 24 | -subj "/C=RU/ST=KChR/L=Bukovo/O=SAO RAS" 25 | 26 | # Create client private key and certificate request 27 | mkdir -p client/private 28 | chmod 700 client/private 29 | openssl genrsa -out client/private/client_key.pem 4096 30 | openssl req -new \ 31 | -key client/private/client_key.pem \ 32 | -out client/client.csr \ 33 | -subj "/C=RU/ST=KChR/L=Bukovo/O=SAO RAS" 34 | 35 | # Generate certificates 36 | openssl x509 -req -days 36524 -in server/server.csr \ 37 | -CA ca/ca_cert.pem -CAkey ca/private/ca_key.pem \ 38 | -CAcreateserial -out server/server_cert.pem 39 | openssl x509 -req -days 36524 -in client/client.csr \ 40 | -CA ca/ca_cert.pem -CAkey ca/private/ca_key.pem \ 41 | -CAcreateserial -out client/client_cert.pem 42 | 43 | # Now test both the server and the client 44 | # On one shell, run the following 45 | # openssl s_server -CAfile ca/ca_cert.pem -cert server/server_cert.pem -key server/private/server_key.pem -Verify 1 46 | # On another shell, run the following 47 | # openssl s_client -CAfile ca/ca_cert.pem -cert client/client_cert.pem -key client/private/client_key.pem 48 | # Once the negotiation is complete, any line you type is sent over to the other side. 49 | # By line, I mean some text followed by a keyboard return press. 50 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/ca_cert.pem: -------------------------------------------------------------------------------- 1 | ca/ca/ca_cert.pem -------------------------------------------------------------------------------- /SSL_Socket_snippet/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the sslsosk project. 3 | * Copyright 2023 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "sslsock.h" 22 | 23 | void clientproc(SSL_CTX *ctx, int fd); 24 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/client_cert.pem: -------------------------------------------------------------------------------- 1 | ca/client/client_cert.pem -------------------------------------------------------------------------------- /SSL_Socket_snippet/client_key.pem: -------------------------------------------------------------------------------- 1 | ca/client/private/client_key.pem -------------------------------------------------------------------------------- /SSL_Socket_snippet/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the sslsosk project. 3 | * Copyright 2023 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | // default PID filename: 22 | #ifndef DEFAULT_PIDFILE 23 | #define DEFAULT_PIDFILE "/tmp/sslsock.pid" 24 | #endif 25 | #ifndef DEFAULT_PORT 26 | #define DEFAULT_PORT "4444" 27 | #endif 28 | 29 | /* 30 | * here are some typedef's for global data 31 | */ 32 | typedef struct{ 33 | char *pidfile; // name of PID file 34 | char *logfile; // logging to this file 35 | char *cert; // sertificate 36 | char *key; // key 37 | char *port; // port number 38 | int verbose; // logfile verbose level 39 | char *ca; // ca 40 | #ifdef CLIENT 41 | char *serverhost; // server IP address 42 | #endif 43 | } glob_pars; 44 | 45 | extern glob_pars G; 46 | 47 | void parse_args(int argc, char **argv); 48 | 49 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/daemon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the sslsosk project. 3 | * Copyright 2023 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | int start_daemon(char *self); 22 | 23 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the sslsosk project. 3 | * Copyright 2023 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include "daemon.h" 23 | #include "cmdlnopts.h" 24 | 25 | int main(int argc, char **argv){ 26 | char *self = argv[0]; 27 | initial_setup(); 28 | parse_args(argc, argv); 29 | return start_daemon(self); 30 | } 31 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the sslsosk project. 3 | * Copyright 2023 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "sslsock.h" 22 | 23 | // timeout of SSL_accept (seconds) 24 | #define ACCEPT_TIMEOUT (0.1) 25 | 26 | 27 | void serverproc(SSL_CTX *ctx, int fd); 28 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/server_cert.pem: -------------------------------------------------------------------------------- 1 | ca/server/server_cert.pem -------------------------------------------------------------------------------- /SSL_Socket_snippet/server_key.pem: -------------------------------------------------------------------------------- 1 | ca/server/private/server_key.pem -------------------------------------------------------------------------------- /SSL_Socket_snippet/sslsock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the sslsosk project. 3 | * Copyright 2023 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | #include // inet_ntop 22 | #include 23 | #include // addrinfo 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #if ! defined CLIENT && ! defined SERVER 32 | #error "Define CLIENT or SERVER before including this file" 33 | #endif 34 | #if defined CLIENT && defined SERVER 35 | #error "Both CLIENT and SERVER defined" 36 | #endif 37 | 38 | #define BACKLOG 10 39 | 40 | int open_socket(); 41 | int read_string(SSL *ssl, char *buf, int l); 42 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/sslsosk.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /SSL_Socket_snippet/sslsosk.config: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #define _XOPEN_SOURCE 1111 3 | #define CLIENT 4 | #define EBUG 5 | 6 | //#define SERVER 7 | 8 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/sslsosk.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/sslsosk.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /SSL_Socket_snippet/sslsosk.files: -------------------------------------------------------------------------------- 1 | client.c 2 | client.h 3 | cmdlnopts.c 4 | cmdlnopts.h 5 | daemon.c 6 | daemon.h 7 | main.c 8 | server.c 9 | server.h 10 | sslsock.c 11 | sslsock.h 12 | -------------------------------------------------------------------------------- /SSL_Socket_snippet/sslsosk.includes: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /Socket_CAN/99-socketcan.rules: -------------------------------------------------------------------------------- 1 | SUBSYSTEMS=="net", ACTION=="add", ENV{INTERFACE}=="can0", RUN+="/etc/udev/rules.d/socketcan0" 2 | -------------------------------------------------------------------------------- /Socket_CAN/HOWTO.cert: -------------------------------------------------------------------------------- 1 | create: 2 | openssl req -newkey rsa:2048 -nodes -keyout cert.key -x509 -days 10100 -out cert.pem 3 | 4 | review: 5 | openssl x509 -text -noout -in cert.pem 6 | -------------------------------------------------------------------------------- /Socket_CAN/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | CLIENT := soccanclient 3 | SERVER := soccanserver 4 | LDFLAGS += -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 5 | LDFLAGS += -lusefull_macros -lssl -lcrypto 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | SOBJDIR := mkserver 8 | COBJDIR := mkclient 9 | CFLAGS += -O2 -Wno-trampolines -std=gnu99 -pthread 10 | COMMSRCS := sslsock.c daemon.c cmdlnopts.c 11 | SSRC := server.c can_io.c $(COMMSRCS) 12 | CSRC := client.c $(COMMSRCS) 13 | SOBJS := $(addprefix $(SOBJDIR)/, $(SSRC:%.c=%.o)) 14 | COBJS := $(addprefix $(COBJDIR)/, $(CSRC:%.c=%.o)) 15 | SDEPS := $(SOBJS:.o=.d) 16 | CDEPS := $(COBJS:.o=.d) 17 | CC = gcc 18 | #CXX = g++ 19 | 20 | 21 | all : $(SOBJDIR) $(COBJDIR) $(CLIENT) $(SERVER) 22 | 23 | debug: DEFINES += -DEBUG -Werror -Wall -Wextra 24 | debug: all 25 | 26 | $(CLIENT) : DEFINES += -DCLIENT 27 | $(CLIENT) : $(COBJS) 28 | @echo -e "\t\tLD $(CLIENT)" 29 | $(CC) $(LDFLAGS) $(COBJS) -o $(CLIENT) 30 | 31 | 32 | $(SERVER) : DEFINES += -DSERVER 33 | $(SERVER) : $(SOBJS) 34 | @echo -e "\t\tLD $(SERVER)" 35 | $(CC) $(LDFLAGS) $(SOBJS) -o $(SERVER) 36 | 37 | $(SOBJDIR): 38 | mkdir $(SOBJDIR) 39 | 40 | $(COBJDIR): 41 | mkdir $(COBJDIR) 42 | 43 | ifneq ($(MAKECMDGOALS),clean) 44 | -include $(SDEPS) $(CDEPS) 45 | endif 46 | 47 | $(SOBJDIR)/%.o: %.c 48 | @echo -e "\t\tCC $<" 49 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 50 | 51 | $(COBJDIR)/%.o: %.c 52 | @echo -e "\t\tCC $<" 53 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 54 | 55 | clean: 56 | @echo -e "\t\tCLEAN" 57 | @rm -f $(SOBJS) $(SDEPS) $(COBJS) $(CDEPS) 2>/dev/null || true 58 | @rmdir $(SOBJDIR) $(COBJDIR) 2>/dev/null || true 59 | 60 | xclean: clean 61 | @rm -f $(PROGRAM) 62 | 63 | .PHONY: clean xclean 64 | -------------------------------------------------------------------------------- /Socket_CAN/Makefile.bk: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | CLIENT := soccanclient 3 | SERVER := soccanserver 4 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 5 | LDFLAGS += -lusefull_macros 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | OBJDIR := mk 8 | CFLAGS += -O2 -Wno-trampolines -std=gnu99 9 | SSRC := server.c 10 | CSRC := client.c 11 | COMMSRCS := sslsock.c daemon.c cmdlnopts.c 12 | SOBJS := $(addprefix $(OBJDIR)/, $(SSRC:%.c=%.o)) 13 | COBJS := $(addprefix $(OBJDIR)/, $(CSRC:%.c=%.o)) 14 | COMMOBJS := $(addprefix $(OBJDIR)/, $(COMMSRCS:%.c=%.o)) 15 | OBJS := $(SOBJS) $(COBJS) $(COMMOBJS) 16 | DEPS := $(OBJS:.o=.d) 17 | CC = gcc 18 | #CXX = g++ 19 | 20 | 21 | all : $(OBJDIR) $(CLIENT) $(SERVER) 22 | 23 | debug: DEFINES += -DEBUG -Werror -Wall -Wextra 24 | debug: all 25 | 26 | $(CLIENT) : DEFINES += -DCLIENT 27 | $(CLIENT) : $(COBJS) 28 | @rm $(COMMOBJS) 2>/dev/null || true 29 | @make DEF="$(DEFINES)" $(COMMOBJS) 30 | @echo -e "\t\tLD $(CLIENT)" 31 | $(CC) $(LDFLAGS) $(COBJS) $(COMMOBJS) -o $(CLIENT) 32 | 33 | 34 | $(SERVER) : DEFINES += -DSERVER 35 | $(SERVER) : $(SOBJS) 36 | @rm $(COMMOBJS) 2>/dev/null || true 37 | @make DEF="$(DEFINES)" $(COMMOBJS) 38 | @echo -e "\t\tLD $(SERVER)" 39 | $(CC) $(LDFLAGS) $(SOBJS) $(COMMOBJS) -o $(SERVER) 40 | @rm $(COMMOBJS) 41 | 42 | 43 | $(OBJDIR): 44 | mkdir $(OBJDIR) 45 | 46 | ifneq ($(MAKECMDGOALS),clean) 47 | -include $(DEPS) 48 | endif 49 | 50 | $(OBJDIR)/%.o: %.c 51 | @echo -e "\t\tCC $<" 52 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 53 | 54 | clean: 55 | @echo -e "\t\tCLEAN" 56 | @rm -f $(OBJS) $(DEPS) 57 | @rmdir $(OBJDIR) 2>/dev/null || true 58 | 59 | xclean: clean 60 | @rm -f $(PROGRAM) 61 | 62 | .PHONY: clean xclean 63 | -------------------------------------------------------------------------------- /Socket_CAN/README_ports: -------------------------------------------------------------------------------- 1 | server: 2 | socat pty,link=/tmp/ttyX0,waitslave tcp:127.0.0.1:2002 & 3 | ssh -L 2002:robotel1:2000 -N -f robotel1 & 4 | 5 | client: 6 | 7 | socat TCP-LISTEN:2000 PTY,link=/tmp/ttyX0,raw,crnl & 8 | -------------------------------------------------------------------------------- /Socket_CAN/Readme.md: -------------------------------------------------------------------------------- 1 | CANbus messages retranslation from BTA bus into Dome bus 2 | 3 | RUN server: 4 | 5 | ./soccanserver -i localhost -l log.log -a ca/ca/ca_cert.pem -c ca/server/server_cert.pem -k ca/server/private/server_key.pem 6 | 7 | 8 | RUN client: 9 | 10 | ./soccanclient -i localhost -a ca/ca/ca_cert.pem -c ca/client/client_cert.pem -k ca/client/private/client_key.pem 11 | 12 | 13 | 14 | Compile i686: 15 | export LDFLAGS=-m32 16 | -------------------------------------------------------------------------------- /Socket_CAN/SocketCAN.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /Socket_CAN/SocketCAN.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | #define EBUG 4 | #define SERVER 5 | #define CLIENT 6 | #define _GNU_SOURCE 7 | -------------------------------------------------------------------------------- /Socket_CAN/SocketCAN.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /Socket_CAN/SocketCAN.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /Socket_CAN/SocketCAN.files: -------------------------------------------------------------------------------- 1 | Makefile 2 | can4linux.h 3 | can_io.c 4 | can_io.h 5 | canbus.h 6 | cansock.c 7 | client.c 8 | client.h 9 | cmdlnopts.c 10 | cmdlnopts.h 11 | daemon.c 12 | daemon.h 13 | server.c 14 | server.h 15 | sslsock.c 16 | sslsock.h 17 | -------------------------------------------------------------------------------- /Socket_CAN/SocketCAN.includes: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /Socket_CAN/ca/ca/ca_cert.srl: -------------------------------------------------------------------------------- 1 | 1D339878EE448B717AB9855CC9DFBBC66C06FF8D 2 | -------------------------------------------------------------------------------- /Socket_CAN/ca/client/client.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIEhDCCAmwCAQAwPzELMAkGA1UEBhMCUlUxDTALBgNVBAgMBEtDaFIxDzANBgNV 3 | BAcMBkJ1a292bzEQMA4GA1UECgwHU0FPIFJBUzCCAiIwDQYJKoZIhvcNAQEBBQAD 4 | ggIPADCCAgoCggIBALwxkEemASoXwJu8qEIFhnOqrn50Gj6xI8O4/2RyyB35nisR 5 | 3VB24a5cdBvXzCq7PfuVzCtHCnKbLxPJhA5HJAB4MHOyXH97NKp0Ihpp/8A3FWJq 6 | /oNF0QpnBlSKVlQ/5Omh7kWzzqNlQHIIJpgyZZJlePi1RBjCK0h+HZMg+/1jutvt 7 | FRGXOcbRLke8Vm5NSmdPBAYLCzaoByCCqefhxmdiSnUC6TgPqiGgSxQ7SSMB/sdb 8 | ADd9e8pEZRGWMyU2z6X8GtuyRkIKC4txdPYdAxBNSe32nHDOx4RE0GsjSzqCQ2di 9 | +mzh4mbeQGJLQprqNRLbR1moppumBM9qatL9bDr+NIOJVj9y2RqmEbuXLzV8f0vM 10 | v61k89ZlQJro5y+4AffwpKXDrHqXaALhUvD80xZDvTRRZrBTC5cLvCC/Qx5Lq8hI 11 | /Yp/N8E4ZLIJGL0PJ0gKiuUQabLGNydqLxLuDp4nwPvRQdsB/MVErlw1ojA9L0wN 12 | WvxTJl5tCflcIH9imCceuIhGP9+TGuJdknZPk1pl97wfQjWGunbkHWzw20bQXL1f 13 | sqZOYHIaRjX/TRsIo8A6xOo9tM+J8tlkr6Vbf177xv+yxblMOhMnbi77efSKDImj 14 | mqrAm7EzxzOximrAxRjJEANtgfoFCY205cwM8uepnJYoTg4ZY4YLuHX9lInvAgMB 15 | AAGgADANBgkqhkiG9w0BAQsFAAOCAgEAsiA2FfbdcQCFlYhgD2vZZMqOvJD3IfT+ 16 | 2Jt1QTfLBiPtqCIa20A6lHCaRQ8FxQ3IbpJpSlpJ9Abj1UqOkNFHKCHIfIbkITr9 17 | uG/UlWu3dQ0FnmxpM5i6Vm4yEgZymGbNDObmCP50Ai1mtGpFjb3lYIv8sgX/e9+B 18 | d/evTvzH+QjSWGzABLe7uMv94wkjWm+LFSVT9XIQ8FzkoIz17QQTcg8q5ku5qveW 19 | SYmOS3rOxWzh+kYJG8+qkLw9ga6T+/lydzqb6gr7iW2pEUSFCWpwb9v7yFk8uZ6L 20 | NZe3YW6e601uqzPpvH0/aQSIbnh//vVTHxFitA+lCENYgIaz8/TAT3/VQhCiM3OZ 21 | cTEZWIPRtlV84c9kIvxfYTthmS3vnFPSMvI5STUmFA1MSvuxOx1c5BUtdlMv/58x 22 | WL8btQB1oRqt6KuMKnwsUA8nv84MRzkH0tCatmcuAIy2/NXrsbo/F794jwCFJFWp 23 | nEoKFnCIhpFvAYTV70BV0jkAQ3iLV4RpU6LdqdVtzDQbjbFd/bWIjT/A7/xEoMI7 24 | jaJfPE/1JaDnzFD20WTSXU1SrOcFlDRURrfYRrWMxaqCHBQbp+OwTaa3ut928tZk 25 | Gs/m+Ov6hMNt54tbBmc2Yc42rbBStBbUKjO4YpwMbFm/dyjFZ4dGx/K54XMve7R6 26 | dFl5goynSwo= 27 | -----END CERTIFICATE REQUEST----- 28 | -------------------------------------------------------------------------------- /Socket_CAN/ca/client/client_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFGDCCAwACFB0zmHjuRItxermFXMnfu8ZsBv+NMA0GCSqGSIb3DQEBCwUAMFAx 3 | CzAJBgNVBAYTAlJVMQ0wCwYDVQQIDARLQ2hSMQ8wDQYDVQQHDAZCdWtvdm8xEDAO 4 | BgNVBAoMB1NBTyBSQVMxDzANBgNVBAMMBnNhby5ydTAgFw0yMTEyMjAwODE3NDBa 5 | GA8yMTIxMTIyMDA4MTc0MFowPzELMAkGA1UEBhMCUlUxDTALBgNVBAgMBEtDaFIx 6 | DzANBgNVBAcMBkJ1a292bzEQMA4GA1UECgwHU0FPIFJBUzCCAiIwDQYJKoZIhvcN 7 | AQEBBQADggIPADCCAgoCggIBALwxkEemASoXwJu8qEIFhnOqrn50Gj6xI8O4/2Ry 8 | yB35nisR3VB24a5cdBvXzCq7PfuVzCtHCnKbLxPJhA5HJAB4MHOyXH97NKp0Ihpp 9 | /8A3FWJq/oNF0QpnBlSKVlQ/5Omh7kWzzqNlQHIIJpgyZZJlePi1RBjCK0h+HZMg 10 | +/1jutvtFRGXOcbRLke8Vm5NSmdPBAYLCzaoByCCqefhxmdiSnUC6TgPqiGgSxQ7 11 | SSMB/sdbADd9e8pEZRGWMyU2z6X8GtuyRkIKC4txdPYdAxBNSe32nHDOx4RE0Gsj 12 | SzqCQ2di+mzh4mbeQGJLQprqNRLbR1moppumBM9qatL9bDr+NIOJVj9y2RqmEbuX 13 | LzV8f0vMv61k89ZlQJro5y+4AffwpKXDrHqXaALhUvD80xZDvTRRZrBTC5cLvCC/ 14 | Qx5Lq8hI/Yp/N8E4ZLIJGL0PJ0gKiuUQabLGNydqLxLuDp4nwPvRQdsB/MVErlw1 15 | ojA9L0wNWvxTJl5tCflcIH9imCceuIhGP9+TGuJdknZPk1pl97wfQjWGunbkHWzw 16 | 20bQXL1fsqZOYHIaRjX/TRsIo8A6xOo9tM+J8tlkr6Vbf177xv+yxblMOhMnbi77 17 | efSKDImjmqrAm7EzxzOximrAxRjJEANtgfoFCY205cwM8uepnJYoTg4ZY4YLuHX9 18 | lInvAgMBAAEwDQYJKoZIhvcNAQELBQADggIBALG6oAI97WWjGKVkfZZMDCztpkJw 19 | GQOPArtPqz+rmVPC2YsqAK891TbiJ+vfniQ4u17+oJp+UeeTfBkRsLyHpdIWjqpZ 20 | OG5Q3+fIMvlWKv1Vds76gY6fbnGPdI3rFZASl4qhN85K3a8T7AsB4pkBjJg0W/sO 21 | sgDU3s+8XUsuSQtIhgXS4Rl2upEjrJ1/9/3HOwcsHX7Qe2VgInN8r2vLXz0Tn86A 22 | yB0ZqmhqjTaA6aObd3ncx2m4UD9IU2h1IoDRpmJP9Rfeyovdp1IGS5FQEsrJkxXS 23 | gYCgzsWq1X6u3NF9Rtu4b8tY7BGK11lvds2J8QCJZomW6A+WSNK20ksR044SlSy6 24 | RvNioaDIkL0mKhMu87DJnB2phDTmF/6SFVQtNt9MWtOuAUujrn9FiNVeBxqnkzP7 25 | Fq4zMgmZVjKydA5BiR1cXCH/0C+jOPmaGUSvxVLX9B3U81Tj2jBBLh5C4QHy/D8f 26 | DPFN5WOrpbrfH9HOstC0Kk4bLHq4xsFtwEz7N/8aL9ahutejVlaKaviaBA3sJ+uv 27 | oz0cEa8Bn4owDDnGwRPeimxNHd+C8dulUoZQ/ukT8ah6cuo35ykYdOiOgqewTsPT 28 | 2J3hJa1DqD9zkH2BzLatHEdZkXpNtgF8RRpDH3m1ZsS4a4ykd03oYEoh3XOFVbwi 29 | myCZgwzp8pk0xfV1 30 | -----END CERTIFICATE----- 31 | -------------------------------------------------------------------------------- /Socket_CAN/ca/gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # https://gist.github.com/zapstar/4b51d7cfa74c7e709fcdaace19233443 4 | mkdir -p ca/private 5 | chmod 700 ca/private 6 | # NOTE: I'm using -nodes, this means that once anybody gets 7 | # their hands on this particular key, they can become this CA. 8 | openssl req \ 9 | -x509 \ 10 | -nodes \ 11 | -days 36524 \ 12 | -newkey rsa:4096 \ 13 | -keyout ca/private/ca_key.pem \ 14 | -out ca/ca_cert.pem \ 15 | -subj "/C=RU/ST=KChR/L=Bukovo/O=SAO RAS/CN=sao.ru" 16 | 17 | # Create server private key and certificate request 18 | mkdir -p server/private 19 | chmod 700 ca/private 20 | openssl genrsa -out server/private/server_key.pem 4096 21 | openssl req -new \ 22 | -key server/private/server_key.pem \ 23 | -out server/server.csr \ 24 | -subj "/C=RU/ST=KChR/L=Bukovo/O=SAO RAS" 25 | 26 | # Create client private key and certificate request 27 | mkdir -p client/private 28 | chmod 700 client/private 29 | openssl genrsa -out client/private/client_key.pem 4096 30 | openssl req -new \ 31 | -key client/private/client_key.pem \ 32 | -out client/client.csr \ 33 | -subj "/C=RU/ST=KChR/L=Bukovo/O=SAO RAS" 34 | 35 | # Generate certificates 36 | openssl x509 -req -days 36524 -in server/server.csr \ 37 | -CA ca/ca_cert.pem -CAkey ca/private/ca_key.pem \ 38 | -CAcreateserial -out server/server_cert.pem 39 | openssl x509 -req -days 36524 -in client/client.csr \ 40 | -CA ca/ca_cert.pem -CAkey ca/private/ca_key.pem \ 41 | -CAcreateserial -out client/client_cert.pem 42 | 43 | # Now test both the server and the client 44 | # On one shell, run the following 45 | # openssl s_server -CAfile ca/ca_cert.pem -cert server/server_cert.pem -key server/private/server_key.pem -Verify 1 46 | # On another shell, run the following 47 | # openssl s_client -CAfile ca/ca_cert.pem -cert client/client_cert.pem -key client/private/client_key.pem 48 | # Once the negotiation is complete, any line you type is sent over to the other side. 49 | # By line, I mean some text followed by a keyboard return press. 50 | -------------------------------------------------------------------------------- /Socket_CAN/ca/server/server.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIEhDCCAmwCAQAwPzELMAkGA1UEBhMCUlUxDTALBgNVBAgMBEtDaFIxDzANBgNV 3 | BAcMBkJ1a292bzEQMA4GA1UECgwHU0FPIFJBUzCCAiIwDQYJKoZIhvcNAQEBBQAD 4 | ggIPADCCAgoCggIBAM/Iqcldh+6UfwTJySrY7WpzFlUTq2c0nwTyvRDDP1+R9Ryt 5 | zyOwnkKMRvU4Bs40iftpacwlU4JfQGGeQn1g7507rRlalIxt11D2kB+hHh7V8pS1 6 | 3Y5Y1yOTZlhExdKrs1A3EpaEl4wurF2Rxk6fQMfGoi18Tx/jvjy5diT2LTWv+KOb 7 | xFIJv7o0ikLdvdLFdqobWn4xaYNjP6M7+3IlWCU8N0ickAprKBHOf9jFgE3ABjNu 8 | MYUY1gX9dJbkEbhjrvIcbjC5MmknMoR1HHbG8MHLgEbcbu0ZFgj7pu01QfiByEbL 9 | gDT1xl4pZ8S+6d4q7lPmkwmJzwGJr5ZmCqyT7A4i01AqVRHbezZvR0oV4QusErhK 10 | xvGh7123H/OrSvfwIxEIbWEAIzvWaxV14ctLKOiOw+mENltQxFWziaiGNHXM38SH 11 | QNSmTHJUWC08IUqslR5r1Ys4h15vdJ+ZMVpw1ijNIW0C9zgdJu/ERkaCnVSW5rl3 12 | gicou4NobomKscHfnyYTiPUWZ+GccnNR35xlSbGSmjzPwYtvvX0UOn8wSp2oCeW6 13 | PQuWJDpVOlTFgQwJNVT6T9J2XW/wtlNWyZGjM3tATqAlpXTrrapJzTlLuEGpkebK 14 | IMTLnDa/DXemy1A7ehjyKMXfXC4pzwEsR12oPfZ1qyO+lQJPYV0Ur+onSNlZAgMB 15 | AAGgADANBgkqhkiG9w0BAQsFAAOCAgEAAD2CuiczzQnU0+W2lYGuxueCbIkD6ZW0 16 | li48K4iu5kp2Axv4H/d9o61nHn8E+fqkZLNB10eIut/45yRXUA6cWjBTtMZR1Gcz 17 | BFXnaau1agCnFEqqanU7uBJpflQD+soieICjtQGyrqCTSJlaZy9V/iv5lYCvCn8T 18 | mP9yiUkoAKOnAf/XHLkyBrt7IW2ovT5raMcBj0z/5GNNKouhu2kdWEk/BH9zMvYY 19 | uccf2+YMbtdHDUG+0qlSVAYOyDONbJgHAFfROVdlfN2mVDMkUSnSg9/IE4aevP9s 20 | LuHBzCJzodRqpMuIgV+GtTETzWcZvnaXKLmOvKCnLQtxP2OZYrF4EwxK2SdDPCW+ 21 | YQYu51YF/tBumZbCWrGThg5YYGJfghTaINr8x51j1lQNBTGh1gi3I5633eGtIlpW 22 | HUaY49KSQ+yBefmHMWesC6dbSbHfqvfbugidVAk8eFNS3weo26AJsv3dPNKani/+ 23 | c0bOeEJ4tfIQUEpTRlPC5MWqEk0/wz9XC1hPAYHV4YZExQ+kBQ2xyEa0w/9yLuWG 24 | 5sZjd/k/XBnz/V6rrx+jPeqikaaScCGR8YpCwglWEmn6K1Mp6ciSNAFqGTeVnhwD 25 | U0E3INACyi984vDzL886zWt7J1zT0t6IpIaDnxDpmoqvJDK5+xVaw4059HeXwaYb 26 | 5zpySGMozeg= 27 | -----END CERTIFICATE REQUEST----- 28 | -------------------------------------------------------------------------------- /Socket_CAN/ca/server/server_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFGDCCAwACFB0zmHjuRItxermFXMnfu8ZsBv+MMA0GCSqGSIb3DQEBCwUAMFAx 3 | CzAJBgNVBAYTAlJVMQ0wCwYDVQQIDARLQ2hSMQ8wDQYDVQQHDAZCdWtvdm8xEDAO 4 | BgNVBAoMB1NBTyBSQVMxDzANBgNVBAMMBnNhby5ydTAgFw0yMTEyMjAwODE3NDBa 5 | GA8yMTIxMTIyMDA4MTc0MFowPzELMAkGA1UEBhMCUlUxDTALBgNVBAgMBEtDaFIx 6 | DzANBgNVBAcMBkJ1a292bzEQMA4GA1UECgwHU0FPIFJBUzCCAiIwDQYJKoZIhvcN 7 | AQEBBQADggIPADCCAgoCggIBAM/Iqcldh+6UfwTJySrY7WpzFlUTq2c0nwTyvRDD 8 | P1+R9RytzyOwnkKMRvU4Bs40iftpacwlU4JfQGGeQn1g7507rRlalIxt11D2kB+h 9 | Hh7V8pS13Y5Y1yOTZlhExdKrs1A3EpaEl4wurF2Rxk6fQMfGoi18Tx/jvjy5diT2 10 | LTWv+KObxFIJv7o0ikLdvdLFdqobWn4xaYNjP6M7+3IlWCU8N0ickAprKBHOf9jF 11 | gE3ABjNuMYUY1gX9dJbkEbhjrvIcbjC5MmknMoR1HHbG8MHLgEbcbu0ZFgj7pu01 12 | QfiByEbLgDT1xl4pZ8S+6d4q7lPmkwmJzwGJr5ZmCqyT7A4i01AqVRHbezZvR0oV 13 | 4QusErhKxvGh7123H/OrSvfwIxEIbWEAIzvWaxV14ctLKOiOw+mENltQxFWziaiG 14 | NHXM38SHQNSmTHJUWC08IUqslR5r1Ys4h15vdJ+ZMVpw1ijNIW0C9zgdJu/ERkaC 15 | nVSW5rl3gicou4NobomKscHfnyYTiPUWZ+GccnNR35xlSbGSmjzPwYtvvX0UOn8w 16 | Sp2oCeW6PQuWJDpVOlTFgQwJNVT6T9J2XW/wtlNWyZGjM3tATqAlpXTrrapJzTlL 17 | uEGpkebKIMTLnDa/DXemy1A7ehjyKMXfXC4pzwEsR12oPfZ1qyO+lQJPYV0Ur+on 18 | SNlZAgMBAAEwDQYJKoZIhvcNAQELBQADggIBAJH7lEF/tpLN0uOz7pnUdTT2A3IF 19 | 0cehqlhv2E8pXLQ7lydAwMuSh582/jCPx9f/aAz11MKfcUwdSBJvdinLvOpM0qCN 20 | 0i2aCxHGXnC9kVRsukCkKbF2/+hqoM/Cfmi995f1eEgrk/QkR34HC/2745mh//3S 21 | i69jzwbEGDM7YuGisY25OYSyT37SHR56dU/j1SRw9JgfIEC4DPzS38oqWQfEJjEk 22 | VCg2XrPwUmRk6eLqC80pBL4tmItT1RTERN/0vBNVivHZrseEGWrtMsq52mDEPuVf 23 | mijF6ImVkonKi7ouIrTE/4no3TpNjjUTlMNYumedO38q30/4A0+wjHvsP42b9e5V 24 | bahjejgwlhhbFaEkUpKk9ApcM6Pqq8kURoWgzcmjrUYuXryWAPKWTwE5Y939CgsV 25 | DJXbSkITl61jZQWyAzl5kEUPVguBwJjOyL2zsxbLcHuvIx51RDEa0xl9sKp4kCJR 26 | FoLyexymVyMw8yPenPL0jF7LvY1ua6+60avE7tNnJ0DdWt0DIjEUtqmuQEfBUP0M 27 | n0q/fO9+ZOqfOhuNLPKlw2UFKCw2xd6SU6qm0BFebLiIBkvU4GQ3IWwNGZWw+66J 28 | UzDRHzWiVNED+IBrdGE43+1TdROkKz0HCiIrAnE7gjWeaq2ShGmjaabyYOFE0FoJ 29 | Qx01GFwRqiRjVnId 30 | -----END CERTIFICATE----- 31 | -------------------------------------------------------------------------------- /Socket_CAN/can4linux.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/Socket_CAN/can4linux.h -------------------------------------------------------------------------------- /Socket_CAN/can_io.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/Socket_CAN/can_io.c -------------------------------------------------------------------------------- /Socket_CAN/can_io.h: -------------------------------------------------------------------------------- 1 | #define CAN_CTLR_SIZE 300 /* size of client process shared area */ 2 | #define CAN_RX_SIZE 1000 /* max. # frames in Rx-buffer */ 3 | 4 | int can_wait(int fd, double tout); 5 | #define can_delay(Tout) can_wait(0, Tout) 6 | void set_server_mode(int mode); 7 | int can_server(); 8 | int can_card(); 9 | int can_gate(); 10 | double can_gate_time_offset(); 11 | unsigned long get_acckey(); 12 | void *init_can_io(); 13 | void *start_can_io(); 14 | void can_put_buff_frame(double rtime, int id, int length, unsigned char data[]); 15 | int can_io_ok(); 16 | int can_io_shm_ok(); 17 | int can_ok(); 18 | void can_clean_recv(int *pbuf, double *rtime); 19 | int can_get_buff_frame(int *pbuf, double *rtime, 20 | int *id, int *length, unsigned char data[]); 21 | int can_recv_frame(int *pbuf, double *rtime, 22 | int *id, int *length, unsigned char data[]); 23 | int can_send_frame(int id, int length, unsigned char data[]); 24 | void can_exit(int sig); 25 | char *time2asc(double t); 26 | double can_dsleep(double dt); 27 | double can_dtime(); 28 | char *can_atime(); 29 | void can_prtime(FILE *fd); 30 | -------------------------------------------------------------------------------- /Socket_CAN/canbus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SocketCAN project. 3 | * Copyright 2021 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef CANBUS_H__ 21 | #define CANBUS_H__ 22 | 23 | #include 24 | 25 | // CAN packet MAGICK 26 | #define CANMAGICK (0xdeadbeef) 27 | // BTA SEW mask 28 | #define ID_MASK (0xD80) 29 | // BTA SEW-dome frames 30 | #define ID_DOME (0x580) 31 | 32 | typedef struct{ 33 | uint32_t magick; 34 | uint16_t ID; 35 | uint8_t len; 36 | uint8_t data[8]; 37 | } can_packet; 38 | 39 | #endif // CANBUS_H__ 40 | -------------------------------------------------------------------------------- /Socket_CAN/cert.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCocrggX/uMcOfG 3 | bVqeVZpqzX/RPl0YZf9R5ym0YhCeZPj4Ribl59vLsjFShR0PtwV3pCffZUazQJHs 4 | yA/UxrIG3JN9sk5B3+SdBUdmFDXcjI/vTYAFjqa6cqQ7GqQENNSKnvIW2PWe+TS8 5 | KepPQKEqdXLb2k7MTTLx7sFeS3RyNHnQ9V1Ef7ZTjmYGrGe6QQA1irf3QgZ8c47Q 6 | oIUQBEIj1JFyXhChU15BRwVEcAGDrcp8QCYjSba8ac+eBDmn/c8Ojrw3MIsgB38q 7 | I18xXIfuf4jSN+hZjMktFr/IZwePOUFqQjSNkMlUsZvUdkFWfEoEamP3b5Pft1IC 8 | okeg4+rDAgMBAAECggEAYHRoOKmdadrQ7Q97H0UXSeboNNHIDwuAus5qVA7/QyPA 9 | aLIK3gT5F9euZHkynegIKm0GI+ZjKItlw7b/UbCBCmrNzeEG7LOevcbjDnGuMd8P 10 | IFE5aHU5xXOV1P45QutZdRL0vt53LxO1/bTmpYD1iFF+dqO4EUZ3UI+NjEgaorW5 11 | x9kZwV6PE4Cnfcx8kdDNvBrQDs/AXJz3zNNsIU7cEFAVLvtkDnw5+aa0O52lLa+D 12 | 2vtpctxCyPrKtV5Z7Cgd+KkvXKDYbSgrld/Pb6Bhwj+cD39s5Jd/JRBnhpprHq5Y 13 | X8nCs0rZP901rTbGPRcOAu1qUrgdtEyFyiAMnCBGWQKBgQDWQGD87w2E7cbNxZAp 14 | nYBc4LizChtvFRu5hDmbblhvRt93XWh4H5wrJuKbFBM/O38KHy/9GCEVv8XwCkgd 15 | DKhNlAPwMkszxYkVw4cmc3FwKEQhfX4KpzwfrWFbPFTGlCtt3EAP5g6wvXYJeWZZ 16 | T+KXCOzWG5b+v38LLZzxctPp7QKBgQDJRYHKK4txrbXIfqSILk1k9C3+8H6lPFfk 17 | S0gemPP7TuE2jHH/OsK36qtgH+i6pWrqZVKL9QmpFugiSvI/SP0DWk7t17iFnJ6s 18 | bltn8gftASRnx8yFVZBYUO9TbmriS0ZRJG8Yz7f79jj2TGDunBVgeu560X6Syjyk 19 | WpzEjEPRbwKBgFL2MNggNOrxK5cIVi9XFppgRgTF+COGV+r5IVlnXAUSu3s8BzTk 20 | gJNRBlQobN+CSUoBE5L8YetLC/lL8eqVuSH5G6FJyEbuyYtM4CtqblWQsfkJ3+F+ 21 | KlDV0SoD7YvLWhm7PG8rlSqo4mj+wjv5K/Nx+Etb+ZcBTc9lRS1VWmttAoGBAMSC 22 | GnA7B5Bb26n/C8DyBBpW1TmdsOi++8knPyiwiTWKFBTgFsTsqARNGDlnrh/dNX/Y 23 | oTmIaoAun0IsDkx/hJfrajiJb9zzx2/u50ubYOWjQdoZlrNvkNjJXIEGw1Bh0iuS 24 | +O0ukSFtirveYp1UwwJJw+Eh/QRwc7i7x2eW0vf9AoGAVPIZuGkwafu4yfsKBKqx 25 | Qvmgm7+iCywBz6jj70Zk1uS2+l/Kvc1sFD3vF9QS6LzxWgotMqqTR+JTLqMhw/SW 26 | nTSoickIlkchWWnOF0tg1Gx9qHj9iTXufSwAqtYa18Srf/lQKB/HM24BSugGAxK/ 27 | W+UrzBJIZnVyR/HkDSk5VWY= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /Socket_CAN/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDXzCCAkegAwIBAgIUBo309dQtnbIqVJIYQ0929yXmRB0wDQYJKoZIhvcNAQEL 3 | BQAwPzELMAkGA1UEBhMCUlUxDTALBgNVBAgMBEtDaFIxDzANBgNVBAcMBkJ1a292 4 | bzEQMA4GA1UECgwHU0FPIFJBUzAeFw0yMTEyMTYwODA3NDNaFw00OTA4MTEwODA3 5 | NDNaMD8xCzAJBgNVBAYTAlJVMQ0wCwYDVQQIDARLQ2hSMQ8wDQYDVQQHDAZCdWtv 6 | dm8xEDAOBgNVBAoMB1NBTyBSQVMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK 7 | AoIBAQCocrggX/uMcOfGbVqeVZpqzX/RPl0YZf9R5ym0YhCeZPj4Ribl59vLsjFS 8 | hR0PtwV3pCffZUazQJHsyA/UxrIG3JN9sk5B3+SdBUdmFDXcjI/vTYAFjqa6cqQ7 9 | GqQENNSKnvIW2PWe+TS8KepPQKEqdXLb2k7MTTLx7sFeS3RyNHnQ9V1Ef7ZTjmYG 10 | rGe6QQA1irf3QgZ8c47QoIUQBEIj1JFyXhChU15BRwVEcAGDrcp8QCYjSba8ac+e 11 | BDmn/c8Ojrw3MIsgB38qI18xXIfuf4jSN+hZjMktFr/IZwePOUFqQjSNkMlUsZvU 12 | dkFWfEoEamP3b5Pft1ICokeg4+rDAgMBAAGjUzBRMB0GA1UdDgQWBBRqwlIH5zOT 13 | 171ywLEMmP1WfJ3ZdjAfBgNVHSMEGDAWgBRqwlIH5zOT171ywLEMmP1WfJ3ZdjAP 14 | BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAwgUv4mlGxwqmyQsTg 15 | LHVppuLl4TA1EMrUuvJfSBClfStnWiCDJmNMn7OMAuNVmpLZHz2gPbAz5fHRnm0N 16 | Ey3nQNS0X18/jq4NCjaONoSjcRxHDbw0V0E2Kap+t9YZbzw83FWKcJM3WKMAL51p 17 | xiUWQ9bP5E7CFY+j+kcty3HfSgoGcEqanTK94QQqlKxczI1kKkR/Bdow3jTk6PG7 18 | fMPU6c8FL3NkRacKGoc5VNq8A7HI5Hll4gu1fYxXVYnkKc45NrLsipdhInFNJOmx 19 | O16CWm+S/YEJFVio6Eke9FhLehaHagY0oMhadaV4sxtTDXGosfoI/XorGsYE79sU 20 | uqgK 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /Socket_CAN/client.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SocketCAN project. 3 | * Copyright 2021 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "cmdlnopts.h" 29 | #include "daemon.h" 30 | #include "sslsock.h" 31 | 32 | 33 | int main(int argc, char **argv){ 34 | char *self = argv[0]; 35 | initial_setup(); 36 | parse_args(argc, argv); 37 | // check args 38 | if(!G.serverhost) ERR("Point server IP address"); 39 | #ifdef EBUG 40 | printf("Server: %s\n", G.serverhost); 41 | #endif 42 | return start_daemon(self); 43 | } 44 | -------------------------------------------------------------------------------- /Socket_CAN/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SocketCAN project. 3 | * Copyright 2021 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #pragma once 19 | #ifndef CLIENT_H__ 20 | #define CLIENT_H__ 21 | 22 | #include "canbus.h" 23 | 24 | #endif // CLIENT_H__ 25 | -------------------------------------------------------------------------------- /Socket_CAN/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SocketCAN project. 3 | * Copyright 2021 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef CMDLNOPTS_H__ 21 | #define CMDLNOPTS_H__ 22 | 23 | // default PID filename: 24 | #ifndef DEFAULT_PIDFILE 25 | #define DEFAULT_PIDFILE "/tmp/soccan.pid" 26 | #endif 27 | #ifndef DEFAULT_PORT 28 | #define DEFAULT_PORT "4444" 29 | #endif 30 | 31 | /* 32 | * here are some typedef's for global data 33 | */ 34 | typedef struct{ 35 | char *pidfile; // name of PID file 36 | char *logfile; // logging to this file 37 | char *cert; // sertificate 38 | char *key; // key 39 | char *ca; // ca 40 | char *port; // port number 41 | int verbose; // logfile verbose level 42 | #ifdef SERVER 43 | #endif 44 | #ifdef CLIENT 45 | char *serverhost; // server IP address 46 | int speed; // connection speed 47 | #endif 48 | } glob_pars; 49 | 50 | extern glob_pars G; 51 | 52 | void parse_args(int argc, char **argv); 53 | 54 | #endif // CMDLNOPTS_H__ 55 | -------------------------------------------------------------------------------- /Socket_CAN/daemon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SocketCAN project. 3 | * Copyright 2021 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef DAEMON_H__ 21 | #define DAEMON_H__ 22 | 23 | int start_daemon(char *self); 24 | 25 | #endif // DAEMON_H__ 26 | -------------------------------------------------------------------------------- /Socket_CAN/diff/clientscript: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for ((x=0; x<10; ++x)); do 4 | socat TCP-LISTEN:2000 PTY,link=/tmp/ttyX0,raw,crnl 5 | done -------------------------------------------------------------------------------- /Socket_CAN/diff/serverscript: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #for ((x=0; x<10; ++x)); do 4 | socat pty,link=/tmp/ttyX0,waitslave tcp:127.0.0.1:2002 & 5 | ssh -L 2002:robotel1:2000 -N -f robotel1 6 | #done -------------------------------------------------------------------------------- /Socket_CAN/server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SocketCAN project. 3 | * Copyright 2021 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #pragma once 19 | #ifndef SERVER_H__ 20 | #define SERVER_H__ 21 | 22 | #include "canbus.h" 23 | 24 | can_packet *readBTAcan(can_packet *pk); 25 | 26 | extern int can_inited; 27 | 28 | 29 | #endif // SERVER_H__ 30 | -------------------------------------------------------------------------------- /Socket_CAN/socketcan0: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ip link set can0 type can bitrate 100000 triple-sampling on 4 | ifconfig can0 up 5 | -------------------------------------------------------------------------------- /Socket_CAN/sslsock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SocketCAN project. 3 | * Copyright 2021 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef SSLSOCK_H__ 21 | #define SSLSOCK_H__ 22 | 23 | #if ! defined CLIENT && ! defined SERVER 24 | #error "Define CLIENT or SERVER before including this file" 25 | #endif 26 | #if defined CLIENT && defined SERVER 27 | #error "Both CLIENT and SERVER defined" 28 | #endif 29 | 30 | #define BACKLOG 10 31 | 32 | int open_socket(); 33 | 34 | 35 | #endif // SSLSOCK_H__ 36 | -------------------------------------------------------------------------------- /Socket_snippet/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := socket 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lusefull_macros -lm -L/usr/local/lib/ 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | OBJDIR := mk 8 | CFLAGS += -O3 -Wno-trampolines -std=gnu99 9 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 10 | DEPS := $(OBJS:.o=.d) 11 | CC = gcc 12 | #CXX = g++ 13 | 14 | 15 | all : $(PROGRAM) 16 | 17 | debug: CFLAGS += -DEBUG -Werror -Wall -Wextra 18 | debug: all 19 | 20 | $(OBJS): $(OBJDIR) 21 | 22 | $(PROGRAM) : $(OBJS) 23 | @echo -e "\t\tLD $(PROGRAM)" 24 | $(CC) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 25 | 26 | $(OBJDIR): 27 | mkdir $(OBJDIR) 28 | 29 | ifneq ($(MAKECMDGOALS),clean) 30 | -include $(DEPS) 31 | endif 32 | 33 | $(OBJDIR)/%.o: %.c 34 | @echo -e "\t\tCC $<" 35 | $(CC) $< -MD -c $(CFLAGS) $(DEFINES) -o $@ 36 | 37 | clean: 38 | @echo -e "\t\tCLEAN" 39 | @rm -f $(OBJS) $(DEPS) 40 | @rmdir $(OBJDIR) 2>/dev/null || true 41 | 42 | xclean: clean 43 | @rm -f $(PROGRAM) 44 | 45 | .PHONY: clean xclean 46 | -------------------------------------------------------------------------------- /Socket_snippet/Readme.md: -------------------------------------------------------------------------------- 1 | Socket server and client snippet 2 | ================================ 3 | 4 | This snippet allows to create some utilities than can be run both in client or server mode. 5 | The sockets are **local** TCP or UNIX sockets. Server-side polling use `poll()`. 6 | 7 | The pieces of user code may be in comments marked `USERCODE` -------------------------------------------------------------------------------- /Socket_snippet/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the socksnippet project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef CLIENT_H__ 21 | #define CLIENT_H__ 22 | 23 | // client-side functions 24 | void client(int fd); 25 | 26 | #endif // CLIENT_H__ 27 | -------------------------------------------------------------------------------- /Socket_snippet/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the socksnippet project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef CMDLNOPTS_H__ 21 | #define CMDLNOPTS_H__ 22 | 23 | /* 24 | * here are some typedef's for global data 25 | */ 26 | typedef struct{ 27 | char *pidfile; // name of PID file 28 | char *logfile; // logging to this file 29 | char *path; // path to UNIX-socket file 30 | char *port; // local TCP socket port 31 | int verbose; // verbose level: for messages & logging 32 | int client; // ==1 if application runs in client mode 33 | } glob_pars; 34 | 35 | extern glob_pars *GP; 36 | 37 | void parse_args(int argc, char **argv); 38 | void verbose(int levl, const char *fmt, ...); 39 | 40 | #endif // CMDLNOPTS_H__ 41 | -------------------------------------------------------------------------------- /Socket_snippet/server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the socksnippet project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef SERVER_H__ 21 | #define SERVER_H__ 22 | 23 | // server-side functions 24 | void server(int fd); 25 | 26 | #endif // SERVER_H__ 27 | -------------------------------------------------------------------------------- /Socket_snippet/socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the socksnippet project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef SERSOCK_H__ 21 | #define SERSOCK_H__ 22 | 23 | // max & min TCP socket port number 24 | #define PORTN_MAX (65535) 25 | #define PORTN_MIN (1024) 26 | 27 | #define BUFLEN (1024) 28 | // Max amount of connections 29 | #define MAXCLIENTS (30) 30 | 31 | typedef enum{ 32 | RESULT_OK, // all OK 33 | RESULT_FAIL, // failed running command 34 | RESULT_BADVAL, // bad key's value 35 | RESULT_BADKEY, // bad key 36 | RESULT_SILENCE, // send nothing to client 37 | RESULT_NUM 38 | } hresult; 39 | 40 | const char *hresult2str(hresult r); 41 | 42 | // fd - socket fd to send private messages, key, val - key and its value 43 | typedef hresult (*mesghandler)(int fd, const char *key, const char *val); 44 | 45 | typedef struct{ 46 | mesghandler handler; 47 | const char *key; 48 | } handleritem; 49 | 50 | int start_socket(int server, char *path, int isnet); 51 | void sendmessage(int fd, const char *msg, int l); 52 | void sendstrmessage(int fd, const char *msg); 53 | 54 | int processData(int fd, handleritem *handlers, char *buf, int buflen); 55 | 56 | #endif // SERSOCK_H__ 57 | -------------------------------------------------------------------------------- /Socket_snippet/socksnippet.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /Socket_snippet/socksnippet.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | #define EBUG 4 | #define _GNU_SOURCE 5 | #define _XOPEN_SOURCE=1111 6 | 7 | -------------------------------------------------------------------------------- /Socket_snippet/socksnippet.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /Socket_snippet/socksnippet.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /Socket_snippet/socksnippet.files: -------------------------------------------------------------------------------- 1 | client.c 2 | client.h 3 | cmdlnopts.c 4 | cmdlnopts.h 5 | main.c 6 | server.c 7 | server.h 8 | socket.c 9 | socket.h 10 | -------------------------------------------------------------------------------- /Socket_snippet/socksnippet.includes: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /Socket_snippet/testcommands: -------------------------------------------------------------------------------- 1 | time 2 | getval1 3 | setval1 = 56 4 | getval2 5 | setval2 = 189 6 | getval1 = asdf 7 | getval2 = 000000asdffd fdassdf fda 8 | time 9 | a 10 | getval1 11 | getval2 12 | -------------------------------------------------------------------------------- /TeAmanagement/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := teacmd 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lusefull_macros 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | OBJDIR := mk 8 | CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99 9 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 10 | DEPS := $(OBJS:.o=.d) 11 | TARGFILE := $(OBJDIR)/TARGET 12 | CC = gcc 13 | 14 | ifeq ($(shell test -e $(TARGFILE) && echo -n yes),yes) 15 | TARGET := $(file < $(TARGFILE)) 16 | else 17 | TARGET := RELEASE 18 | endif 19 | 20 | ifeq ($(TARGET), DEBUG) 21 | .DEFAULT_GOAL := debug 22 | endif 23 | 24 | release: $(PROGRAM) 25 | 26 | debug: CFLAGS += -DEBUG -Werror 27 | debug: TARGET := DEBUG 28 | debug: $(PROGRAM) 29 | 30 | $(TARGFILE): $(OBJDIR) 31 | @echo -e "\t\tTARGET: $(TARGET)" 32 | @echo "$(TARGET)" > $(TARGFILE) 33 | 34 | $(PROGRAM) : $(TARGFILE) $(OBJS) 35 | @echo -e "\t\tLD $(PROGRAM)" 36 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 37 | 38 | $(OBJDIR): 39 | @mkdir $(OBJDIR) 40 | 41 | ifneq ($(MAKECMDGOALS),clean) 42 | -include $(DEPS) 43 | endif 44 | 45 | $(OBJDIR)/%.o: %.c 46 | @echo -e "\t\tCC $<" 47 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 48 | 49 | clean: 50 | @echo -e "\t\tCLEAN" 51 | @rm -rf $(OBJDIR) 2>/dev/null || true 52 | 53 | xclean: clean 54 | @rm -f $(PROGRAM) 55 | 56 | .PHONY: clean xclean 57 | -------------------------------------------------------------------------------- /TeAmanagement/Readme: -------------------------------------------------------------------------------- 1 | Client/server 2 | 3 | 4 | -------------------------------------------------------------------------------- /TeAmanagement/TeAman.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /TeAmanagement/TeAman.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | #define EBUG 4 | #define _GNU_SOURCE 5 | #define _XOPEN_SOURCE=1111 6 | 7 | -------------------------------------------------------------------------------- /TeAmanagement/TeAman.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /TeAmanagement/TeAman.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /TeAmanagement/TeAman.files: -------------------------------------------------------------------------------- 1 | cmdlnopts.c 2 | cmdlnopts.h 3 | main.c 4 | sersock.c 5 | sersock.h 6 | teacmd.c 7 | teacmd.h 8 | -------------------------------------------------------------------------------- /TeAmanagement/TeAman.includes: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /TeAmanagement/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the TeAman project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef CMDLNOPTS_H__ 21 | #define CMDLNOPTS_H__ 22 | 23 | /* 24 | * here are some typedef's for global data 25 | */ 26 | typedef struct{ 27 | char *devpath; // path to serial device 28 | char *pidfile; // name of PID file 29 | char *logfile; // logging to this file 30 | char *path; // path to socket file 31 | char *fitshdr; // path to file with FITS header output 32 | int minsteps[3]; // min steps for each axe 33 | int maxsteps[3]; 34 | int terminal; // run as terminal 35 | int speed; // connection speed 36 | int verbose; // verbose level: for messages & logging 37 | int client; // ==1 if application runs in client mode 38 | int wait; // wait for stop 39 | int gotozero; // run 'gotoz' for all three axis 40 | double x; // coordinates to set (when run as client) 41 | double y; 42 | double z; 43 | } glob_pars; 44 | 45 | glob_pars *parse_args(int argc, char **argv); 46 | void verbose(int levl, const char *fmt, ...); 47 | 48 | #endif // CMDLNOPTS_H__ 49 | -------------------------------------------------------------------------------- /TeAmanagement/out.fits: -------------------------------------------------------------------------------- 1 | INSTRUME= 'TeA - Telescope Analyzer' / Acquisition hardware 2 | XMM = 0 / Coordinate, mm 3 | YMM = 0 / Coordinate, mm 4 | ZMM = 0 / Coordinate, mm 5 | XSTAT = 'stop' / Status of given coordinate motor 6 | YSTAT = 'stop' / Status of given coordinate motor 7 | ZSTAT = 'stop' / Status of given coordinate motor 8 | -------------------------------------------------------------------------------- /TeAmanagement/sersock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the TeAman project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef SERSOCK_H__ 21 | #define SERSOCK_H__ 22 | 23 | #define BUFLEN (1024) 24 | // Max amount of connections 25 | #define MAXCLIENTS (30) 26 | 27 | #include 28 | 29 | #include "cmdlnopts.h" 30 | 31 | int start_socket(int server, glob_pars *P, TTY_descr **dev); 32 | int canberead(int fd); 33 | 34 | #endif // SERSOCK_H__ 35 | -------------------------------------------------------------------------------- /TeAmanagement/teacmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the TeAman project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "cmdlnopts.h" 22 | 23 | int client_proc(int sock, glob_pars *P); 24 | void set_validator(glob_pars *P); 25 | int parse_incoming_string(char *str, int l, char *hdrname); 26 | int validate_cmd(char *str, int l); 27 | 28 | 29 | // steps into MM and vice versa 30 | #define TEASTEPS_MM(steps) (steps/200.) 31 | #define TEAMM_STEPS(mm) ((int)(mm * 200.)) 32 | 33 | // tea commands 34 | #define TEACMD_POSITION "abspos" 35 | #define TEACMD_RELPOSITION "relpos" 36 | #define TEACMD_SLOWMOVE "relslow" 37 | #define TEACMD_SETPOS "setpos" 38 | #define TEACMD_GOTOZERO "gotoz" 39 | #define TEACMD_STATUS "state" 40 | 41 | typedef enum{ 42 | STP_RELAX, // 0 - no moving 43 | STP_ACCEL, // 1 - start moving with acceleration 44 | STP_MOVE, // 2 - moving with constant speed 45 | STP_MVSLOW, // 3 - moving with slowest constant speed (end of moving) 46 | STP_DECEL, // 4 - moving with deceleration 47 | STP_STALL, // 5 - stalled 48 | STP_ERR, // 6 - wrong/error state 49 | STP_AMOUNT 50 | } teastate; 51 | -------------------------------------------------------------------------------- /Tetris/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := tetris 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += `pkg-config --libs ncurses` -lusefull_macros 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) 7 | # -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 8 | OBJDIR := mk 9 | CFLAGS += -O2 -Wno-trampolines -std=gnu99 10 | CFLAGS += `pkg-config --cflags ncurses` 11 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 12 | DEPS := $(OBJS:.o=.d) 13 | CC = gcc 14 | #CXX = g++ 15 | 16 | 17 | all : $(OBJDIR) $(PROGRAM) 18 | 19 | debug: CFLAGS += -DEBUG -Werror -Wall -Wextra 20 | debug: all 21 | 22 | $(PROGRAM) : $(OBJS) 23 | @echo -e "\t\tLD $(PROGRAM)" 24 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 25 | 26 | $(OBJDIR): 27 | mkdir $(OBJDIR) 28 | 29 | ifneq ($(MAKECMDGOALS),clean) 30 | -include $(DEPS) 31 | endif 32 | 33 | $(OBJDIR)/%.o: %.c 34 | @echo -e "\t\tCC $<" 35 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 36 | 37 | clean: 38 | @echo -e "\t\tCLEAN" 39 | @rm -f $(OBJS) $(DEPS) 40 | @rmdir $(OBJDIR) 2>/dev/null || true 41 | 42 | xclean: clean 43 | @rm -f $(PROGRAM) 44 | 45 | .PHONY: clean xclean 46 | -------------------------------------------------------------------------------- /Tetris/disp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the tetris project. 3 | * Copyright 2020 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "displaybuf.h" 20 | #define closescreen() endwin() 21 | 22 | typedef enum{ 23 | KEY_NONE, 24 | KEY_L, 25 | KEY_R, 26 | KEY_U, 27 | KEY_D, 28 | KEY_Q, 29 | KEY_0, 30 | KEY_ROTL, 31 | KEY_ROTR 32 | } keycode; 33 | 34 | void initscreen(int *maxx, int *maxy); 35 | void redisplay(); 36 | keycode getkey(); 37 | 38 | void shownext(const figure *F); 39 | 40 | -------------------------------------------------------------------------------- /Tetris/displaybuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the tetris project. 3 | * Copyright 2020 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #pragma once 19 | #ifndef DISPLAYBUF_H__ 20 | #define DISPLAYBUF_H__ 21 | 22 | #include 23 | 24 | #define ROWS 30 25 | #define COLS 15 26 | #define xmax (COLS-1) 27 | #define ymax (ROWS-1) 28 | 29 | // get coordinates by figure member 30 | #define GETX(u) (((u) >> 4) - 2) 31 | #define GETY(u) (((u) & 0xf) - 2) 32 | 33 | typedef struct{ 34 | uint8_t f[4]; 35 | uint8_t color; 36 | } figure; 37 | 38 | #define FIGURESNUM (4) 39 | extern const figure L, J, O, I; 40 | extern uint8_t cup[ROWS][COLS]; 41 | 42 | int chkfigure(int x, int y, const figure *F); 43 | void clearfigure(int x, int y, const figure *F); 44 | void putfigure(int x, int y, const figure *F); 45 | void rotatefigure(int dir, figure *F); 46 | int checkandroll(); 47 | 48 | #endif // DISPLAYBUF_H__ 49 | -------------------------------------------------------------------------------- /Tetris/tetris.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /Tetris/tetris.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | #define EBUG 4 | -------------------------------------------------------------------------------- /Tetris/tetris.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /Tetris/tetris.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /Tetris/tetris.files: -------------------------------------------------------------------------------- 1 | disp.c 2 | disp.h 3 | displaybuf.c 4 | displaybuf.h 5 | main.c 6 | -------------------------------------------------------------------------------- /Tetris/tetris.includes: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /Trinamic/SHA_client/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = client 2 | LDFLAGS = 3 | SRCS = client.c 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=501 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) clean 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /Trinamic/SHA_client/client.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/Trinamic/SHA_client/client.c -------------------------------------------------------------------------------- /Trinamic/SHA_client_cmdline/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = client 2 | LDFLAGS = 3 | SRCS = client.c parceargs.c cmdlnopts.c 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=701 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) clean 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /Trinamic/SHA_client_cmdline/cmdlnopts.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/Trinamic/SHA_client_cmdline/cmdlnopts.c -------------------------------------------------------------------------------- /Trinamic/SHA_client_cmdline/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cmdlnopts.h - comand line options for parceargs 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __CMDLNOPTS_H__ 24 | #define __CMDLNOPTS_H__ 25 | 26 | #include "parceargs.h" 27 | 28 | /* 29 | * here are some typedef's for global data 30 | */ 31 | 32 | typedef struct{ 33 | char *comdev; // input device 34 | int relaycmd; // -1 - nothing, 1 - on, 0 - off 35 | int erasecmd; // 1 to erase old 36 | char *gotopos; // position name: refmir, diagmir, shack 37 | }glob_pars; 38 | 39 | extern glob_pars G; 40 | 41 | glob_pars *parce_args(int argc, char **argv); 42 | 43 | #endif // __CMDLNOPTS_H__ 44 | -------------------------------------------------------------------------------- /Trinamic/client/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = client 2 | LDFLAGS = 3 | SRCS = client.c 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=501 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) clean 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /Trinamic/websock_simple/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = websocktest 2 | LDFLAGS = $(shell pkg-config --libs libwebsockets) -lpthread 3 | SRCS = test.c 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=501 -DCUR_PATH=\"$(shell pwd)\" 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror -Wextra $(DEFINES) $(shell pkg-config --cflags libwebsockets) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) clean 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /USB_reset.c: -------------------------------------------------------------------------------- 1 | // https://askubuntu.com/a/661/501233 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | 11 | int main(int argc, char **argv) 12 | { 13 | const char *filename; 14 | int fd; 15 | int rc; 16 | 17 | if (argc != 2) { 18 | fprintf(stderr, "Usage: usbreset device-filename\n"); 19 | return 1; 20 | } 21 | filename = argv[1]; 22 | 23 | fd = open(filename, O_WRONLY); 24 | if (fd < 0) { 25 | perror("Error opening output file"); 26 | return 1; 27 | } 28 | 29 | printf("Resetting USB device %s\n", filename); 30 | rc = ioctl(fd, USBDEVFS_RESET, 0); 31 | if (rc < 0) { 32 | perror("Error in ioctl"); 33 | return 1; 34 | } 35 | printf("Reset successful\n"); 36 | 37 | close(fd); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /USBrelay/99-hidrelay.rules: -------------------------------------------------------------------------------- 1 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05df", MODE:="0666", SYMLINK+="relay%n" 2 | -------------------------------------------------------------------------------- /USBrelay/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := relay_manage 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lusefull_macros -ludev 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | DEFINES += -DEBUG 8 | OBJDIR := mk 9 | CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99 10 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 11 | DEPS := $(OBJS:.o=.d) 12 | CC = gcc 13 | #CXX = g++ 14 | TARGET := RELEASE 15 | 16 | all: $(OBJDIR)/RELEASE 17 | all: $(PROGRAM) 18 | release: all 19 | 20 | debug: CFLAGS += -DEBUG -Werror 21 | debug: TARGET := DEBUG 22 | debug: $(OBJDIR)/DEBUG 23 | debug: $(PROGRAM) 24 | 25 | $(OBJDIR)/DEBUG: 26 | @make clean 27 | $(OBJDIR)/RELEASE: 28 | @make clean 29 | 30 | $(PROGRAM) : $(OBJDIR) $(OBJS) 31 | @echo -e "\t\tTARGET: $(TARGET)" 32 | @> $(OBJDIR)/$(TARGET) 33 | @echo -e "\t\tLD $(PROGRAM)" 34 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 35 | 36 | $(OBJDIR): 37 | @mkdir $(OBJDIR) 38 | 39 | ifneq ($(MAKECMDGOALS),clean) 40 | -include $(DEPS) 41 | endif 42 | 43 | $(OBJDIR)/%.o: %.c 44 | @echo -e "\t\tCC $<" 45 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 46 | 47 | clean: 48 | @echo -e "\t\tCLEAN" 49 | @rm -rf $(OBJDIR) 2>/dev/null || true 50 | 51 | xclean: clean 52 | @rm -f $(PROGRAM) 53 | 54 | gentags: 55 | CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] 2>/dev/null 56 | 57 | .PHONY: gentags clean xclean 58 | -------------------------------------------------------------------------------- /Zernike/Makefile: -------------------------------------------------------------------------------- 1 | LOADLIBES = -lm -lgsl -lgslcblas 2 | SRCS = zernike.c zernikeR.c zernike_annular.c Z-BTA_test.c simple_list.c spots.c 3 | CC = gcc 4 | DEFINES = -D_GNU_SOURCE 5 | #-D_XOPEN_SOURCE=501 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | 10 | all : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LOADLIBES) -o btatest 12 | clean: 13 | /bin/rm -f *.o *~ 14 | depend: 15 | $(CXX) -MM $(SRCS) 16 | -------------------------------------------------------------------------------- /Zernike/README: -------------------------------------------------------------------------------- 1 | Here is my realisation of wavefront decomposition and restoration based on 2 | Zernike polynomials (up to 100th order). 3 | 4 | The base functions are: 5 | 6 | double *zernfunR(int n, int m, int W, int H, double *norm); 7 | calculates Zernike polynomial of order n and angular order m on 8 | equidistance rectangular grid WxH (norm is NULL or value to store 9 | sum(Z_i^2) for normalisation on decomposition. 10 | 11 | double *zernfunNR(int p, int W, int H, double *norm); 12 | the same but in Noll notation 13 | 14 | double *Zdecompose(int Nmax, int W, int H, double *image, int *Zsz, int *lastIdx); 15 | decompose image by Zernike polynomials with order <= Nmax, 16 | Zsz is size of returned array (in Noll notation) 17 | lastidx is last non-zero coefficient 18 | 19 | double *Zcompose(int Zsz, double *Zidxs, int W, int H); 20 | build image based on Zernike coeffs Zidxs 21 | Zsz - size of array in Noll notation 22 | W, H - size of future image 23 | 24 | void set_prec(double val); 25 | set precision of Zernike transforms 26 | 27 | -------------------------------------------------------------------------------- /Zernike/Z-BTA_test.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/Zernike/Z-BTA_test.c -------------------------------------------------------------------------------- /Zernike/simple_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * simple_list.h - header file for simple list support 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __SIMPLE_LIST_H__ 24 | #define __SIMPLE_LIST_H__ 25 | 26 | #define LIST_T(x) ((void*) x) 27 | 28 | typedef struct list_{ 29 | void *data; 30 | struct list_ *next; 31 | } List; 32 | 33 | // add element v to list with root root (also this can be last element) 34 | List *list_add(List **root, void *v); 35 | // set listdata_free() 36 | void listfree_function(void (*fn)(void *node)); 37 | void list_free(List **root); 38 | 39 | #endif // __SIMPLE_LIST_H__ 40 | -------------------------------------------------------------------------------- /Zernike/zern_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * zern_private.h - private variables for zernike.c & zernikeR.c 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __ZERN_PRIVATE_H__ 24 | #define __ZERN_PRIVATE_H__ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #ifndef iabs 32 | #define iabs(a) (((a)<(0)) ? (-a) : (a)) 33 | #endif 34 | 35 | #ifndef DBG 36 | #define DBG(...) do{fprintf(stderr, __VA_ARGS__); }while(0) 37 | #endif 38 | 39 | extern double *FK; 40 | extern double Z_prec; 41 | 42 | // zernike.c 43 | void build_factorial(); 44 | void free_rpow(double ***Rpow, int n); 45 | void build_rpow(int W, int H, int n, double **Rad, double ***Rad_pow); 46 | double **build_rpowR(int n, int Sz, polar *P); 47 | 48 | // zernike_annular.c 49 | polar *conv_r(polar *r0, int Sz); 50 | 51 | #endif // __ZERN_PRIVATE_H__ 52 | -------------------------------------------------------------------------------- /astrosib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ########## Tutorial two ############## 2 | add_executable(astrosib astrosib.cpp) 3 | 4 | target_link_libraries(astrosib indidriver) 5 | 6 | 7 | -------------------------------------------------------------------------------- /astrosib/Readme.md: -------------------------------------------------------------------------------- 1 | INDI driver for ASTROSIB telescopes 2 | 3 | 4 | 5 | *Write at level upper to CMakeLists.txt:* 6 | add_subdirectory(astrosib) 7 | -------------------------------------------------------------------------------- /avx/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS= -march=native -O3 3 | 4 | all: add dotproduct 5 | 6 | %: %.c 7 | @echo -e "\t\tCC $<" 8 | $(CC) $(CFLAGS) -o $@ $< 9 | 10 | -------------------------------------------------------------------------------- /avx/SIMD_SSE_AVX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/avx/SIMD_SSE_AVX -------------------------------------------------------------------------------- /avx/add.c: -------------------------------------------------------------------------------- 1 | /* Construct a 256-bit vector from 4 64-bit doubles. Add it to itself 2 | * and print the result. 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int main() { 9 | 10 | __m256i hello; 11 | // Construction from scalars or literals. 12 | __m256d a = _mm256_set_pd(1.0, 2.0, 3.0, 4.0); 13 | 14 | // Does GCC generate the correct mov, or (better yet) elide the copy 15 | // and pass two of the same register into the add? Let's look at the assembly. 16 | __m256d b = _mm256_set_pd(0.0, 0.0, 0.0, 0.0), c; 17 | for(int i = 0; i < 1000000000; ++i){ 18 | // Add the two vectors, interpreting the bits as 4 double-precision 19 | // floats. 20 | c = _mm256_add_pd(a, b); 21 | b = c; 22 | 23 | } 24 | 25 | // Do we ever touch DRAM or will these four be registers? 26 | __attribute__ ((aligned (32))) double output[4]; 27 | _mm256_store_pd(output, c); 28 | 29 | printf("%f %f %f %f\n", 30 | output[0], output[1], output[2], output[3]); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /bidirectional_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * bidirectional_list.h 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #pragma once 22 | #ifndef __BIDIRECTIONAL_LIST_H__ 23 | #define __BIDIRECTIONAL_LIST_H__ 24 | 25 | typedef struct list_node{ 26 | int data; 27 | struct list_node *left_p, *right_p; 28 | } List; 29 | 30 | List *l_search(List *root, int v, List **Left, List **Right); 31 | List *l_insert(List *root, int v); 32 | void l_remove(List **root, int v); 33 | 34 | #endif // __BIDIRECTIONAL_LIST_H__ 35 | -------------------------------------------------------------------------------- /calcAP/Makefile: -------------------------------------------------------------------------------- 1 | LDFLAGS = -lm -lsla -lsofa_c 2 | SRCS = $(wildcard *.c) 3 | CC = gcc 4 | DEFINES = -D_XOPEN_SOURCE=1111 5 | CFLAGS = -Wall -Werror -Wextra $(DEFINES) 6 | TARGS = $(SRCS:.c=) 7 | all : $(TARGS) 8 | slalib_and_sofa : slalib_and_sofa.c 9 | $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ 10 | slalib_sofa_nova : slalib_sofa_nova.c 11 | $(CC) $(CFLAGS) $(LDFLAGS) -lnova -lerfa $< -o $@ 12 | 13 | clean: 14 | /bin/rm -f *.o *~ 15 | -------------------------------------------------------------------------------- /calcAP/Readme: -------------------------------------------------------------------------------- 1 | Comparison of apparent place calculation in different libraries 2 | -------------------------------------------------------------------------------- /clr.c: -------------------------------------------------------------------------------- 1 | // make a simple "CLS" 2 | 3 | #include 4 | #include 5 | 6 | void printstrings(const char *add){ 7 | for(int i = 0; i < 40; ++i) 8 | printf("String %d - %s\n", i, add); 9 | } 10 | 11 | const char *x[] = {"first", "second", "third"}; 12 | 13 | int main(){ 14 | for(int i = 0; i < 3; ++i){ 15 | printf("\033c"); 16 | printstrings(x[i]); 17 | sleep(1); 18 | } 19 | printf("\033c"); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /cmakelists_/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := dumpregs 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lusefull_macros 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | OBJDIR := mk 8 | CFLAGS += -O2 -Wall -Wextra -Wno-trampolines 9 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 10 | DEPS := $(OBJS:.o=.d) 11 | TARGFILE := $(OBJDIR)/TARGET 12 | CC = gcc 13 | #TARGET := RELEASE 14 | 15 | ifeq ($(shell test -e $(TARGFILE) && echo -n yes),yes) 16 | TARGET := $(file < $(TARGFILE)) 17 | else 18 | TARGET := RELEASE 19 | endif 20 | 21 | ifeq ($(TARGET), DEBUG) 22 | .DEFAULT_GOAL := debug 23 | endif 24 | 25 | release: CFLAGS += -flto 26 | release: LDFLAGS += -flto 27 | release: $(PROGRAM) 28 | 29 | debug: CFLAGS += -DEBUG -Werror 30 | debug: TARGET := DEBUG 31 | debug: $(PROGRAM) 32 | 33 | $(TARGFILE): $(OBJDIR) 34 | @echo -e "\t\tTARGET: $(TARGET)" 35 | @echo "$(TARGET)" > $(TARGFILE) 36 | 37 | $(PROGRAM) : $(TARGFILE) $(OBJS) 38 | @echo -e "\t\tLD $(PROGRAM)" 39 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 40 | 41 | $(OBJDIR): 42 | @mkdir $(OBJDIR) 43 | 44 | ifneq ($(MAKECMDGOALS),clean) 45 | -include $(DEPS) 46 | endif 47 | 48 | $(OBJDIR)/%.o: %.c 49 | @echo -e "\t\tCC $<" 50 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 51 | 52 | clean: 53 | @echo -e "\t\tCLEAN" 54 | @rm -rf $(OBJDIR) 2>/dev/null || true 55 | 56 | xclean: clean 57 | @rm -f $(PROGRAM) 58 | 59 | .PHONY: clean xclean 60 | -------------------------------------------------------------------------------- /cmakelists_/get_proc_count: -------------------------------------------------------------------------------- 1 | getconf _NPROCESSORS_ONLN 2 | -------------------------------------------------------------------------------- /count_bits.c: -------------------------------------------------------------------------------- 1 | __builtin_popcount(x) - counts all non-zero bits in number 2 | -------------------------------------------------------------------------------- /cryptpass.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include // gcc -lcrypt 3 | #include 4 | #include 5 | 6 | int main(int argc, char **argv){ 7 | if(argc != 3){ 8 | printf("USAGE:\n\t%s \n", argv[0]); 9 | printf("Example:\n\t%s password \\$6\\$salt -> SHA512 with given salt (see man 3 crypt)\n", argv[0]); 10 | return 1; 11 | } 12 | struct crypt_data x; 13 | x.initialized = 0; 14 | 15 | char *c = crypt_r(argv[1], argv[2], &x); 16 | int e = errno; 17 | if(!c){ 18 | switch(e){ 19 | case EINVAL: 20 | fprintf(stderr, "Wrong SALT format!\n"); 21 | break; 22 | case ENOSYS: 23 | fprintf(stderr, "crypt() not realized!\n"); 24 | break; 25 | case EPERM: 26 | fprintf(stderr, "/proc/sys/crypto/fips_enabled prohibits this encryption method!\n"); 27 | default: 28 | fprintf(stderr, "Unknown error!\n"); 29 | } 30 | return e; 31 | } 32 | printf("Result of crypt_r():\n%s\n", c); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /erosion-dilation/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = binmorph_test 2 | CXX.SRCS = binmorph.c main.c 3 | CC = gcc 4 | LDFLAGS = -lm -fopenmp 5 | CXX = gcc 6 | DEFINES = -DEBUG -DOMP 7 | CFLAGS = -fopenmp -Wall -Werror -O3 -std=gnu99 $(DEFINES) 8 | OBJS = $(CXX.SRCS:.c=.o) 9 | all : $(PROGRAM) clean 10 | binmorph.c : cclabling.h cclabling_1.h dilation.h fs_filter.h fc_filter.h 11 | $(PROGRAM) : $(OBJS) 12 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 13 | clean: 14 | /bin/rm -f *.o *~ 15 | depend: 16 | $(CXX) -MM $(CXX.SRCS) 17 | 18 | ### 19 | # name1.o : header1.h header2.h ... 20 | -------------------------------------------------------------------------------- /erosion-dilation/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/erosion-dilation/README -------------------------------------------------------------------------------- /erosion-dilation/fc_filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fc_filter.h - inner part of function `FC_filter` 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | // The same shit as for dilation.h 23 | 24 | #if ! defined IM_UP && ! defined IM_DOWN 25 | OMP_FOR() 26 | for(y = 1; y < h; y++) 27 | #endif 28 | { 29 | unsigned char *iptr = &image[W*y]; 30 | unsigned char *optr = &ret[W*y]; 31 | unsigned char p = *iptr << 1 | *iptr >> 1 32 | #ifndef IM_UP 33 | | iptr[-W] 34 | #endif 35 | #ifndef IM_DOWN 36 | | iptr[W] 37 | #endif 38 | ; 39 | int x; 40 | if(iptr[1] & 0x80) p |= 1; 41 | *optr = p & *iptr; 42 | optr++; iptr++; 43 | for(x = 1; x < w; x++, iptr++, optr++){ 44 | p = *iptr << 1 | *iptr >> 1 45 | #ifndef IM_UP 46 | | iptr[-W] 47 | #endif 48 | #ifndef IM_DOWN 49 | | iptr[W] 50 | #endif 51 | ; 52 | if(iptr[1] & 0x80) p |= 1; 53 | if(iptr[-1] & 1) p |= 0x80; 54 | *optr = p & *iptr; 55 | } 56 | p = *iptr << 1 | *iptr >> 1 57 | #ifndef IM_UP 58 | | iptr[-W] 59 | #endif 60 | #ifndef IM_DOWN 61 | | iptr[W] 62 | #endif 63 | ; 64 | if(iptr[-1] & 1) p |= 0x80; 65 | *optr = p & *iptr; 66 | optr++; iptr++; 67 | } 68 | -------------------------------------------------------------------------------- /erosion-dilation/fs_filter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/erosion-dilation/fs_filter.h -------------------------------------------------------------------------------- /fifo_lifo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fifo_lifo.h 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __FIFO_LIFO_H__ 24 | #define __FIFO_LIFO_H__ 25 | 26 | typedef int Ldata; 27 | 28 | typedef struct buff_node{ 29 | Ldata data; 30 | struct buff_node *next, *last; 31 | } List; 32 | 33 | List *push_tail(List **lst, Ldata v); 34 | List *push(List **lst, Ldata v); 35 | Ldata pop(List **lst); 36 | 37 | #endif // __FIFO_LIFO_H__ 38 | -------------------------------------------------------------------------------- /get_avail_mem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static unsigned long long get_available_mem(){ 5 | return sysconf(_SC_AVPHYS_PAGES) * (unsigned long long) sysconf(_SC_PAGE_SIZE); 6 | } 7 | 8 | int main(){ 9 | unsigned long long m = get_available_mem(); 10 | printf("MEM: %llu == %lluGB\n", m, m/1024/1024/1024); 11 | return 0; 12 | } 13 | 14 | // Never allocate memory by big pieces with malloc! Only mmap with MAP_POPULATE!!!!!!!!!11111111111 15 | -------------------------------------------------------------------------------- /getopt/README: -------------------------------------------------------------------------------- 1 | 1. Functions for simplify control of complex parameters 2 | cmdlnopts.c - example of use 3 | parceargs.c - main functions 4 | parceargs.h - their header 5 | 6 | 2. Functions for regular getopt_long 7 | getopt.c - snippet file 8 | getopt.h - its header 9 | 10 | -------------------------------------------------------------------------------- /getopt/cmdlnopts/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = myopt_example 2 | LDFLAGS = -lm 3 | SRCS = $(wildcard *.c) 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=1111 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror -Wextra $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /getopt/cmdlnopts/parseargs.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/getopt/cmdlnopts/parseargs.c -------------------------------------------------------------------------------- /getopt/cmdlnopts_deprecated/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cmdlnopts.h - comand line options for parceargs 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __CMDLNOPTS_H__ 24 | #define __CMDLNOPTS_H__ 25 | 26 | #include "parceargs.h" 27 | 28 | /* 29 | * here are some typedef's for global data 30 | */ 31 | 32 | typedef SomeType glob_pars; 33 | 34 | glob_pars *parce_args(int argc, char **argv); 35 | 36 | #endif // __CMDLNOPTS_H__ 37 | -------------------------------------------------------------------------------- /getopt/getopt/getopt.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/getopt/getopt/getopt.c -------------------------------------------------------------------------------- /getopt/getopt/getopt.h: -------------------------------------------------------------------------------- 1 | #ifndef __USAGE_H__ 2 | #define __USAGE_H__ 3 | 4 | #include "takepic.h" 5 | #include 6 | #include 7 | 8 | /* 9 | * here are global variables and global data structures definition, like 10 | * int val; 11 | * enum{reset = 0, set}; 12 | */ 13 | 14 | extern char *__progname; 15 | void usage(char *fmt, ...); 16 | void parse_args(int argc, char **argv); 17 | 18 | #endif // __USAGE_H__ 19 | -------------------------------------------------------------------------------- /guard.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int child_killed = 0; 9 | pthread_t athread; 10 | 11 | void sighndlr(int sig){ 12 | printf("got signal %d\n", sig); 13 | if(sig == SIGCHLD){ 14 | printf("Child was killed\n"); 15 | child_killed = 1; 16 | }else if(sig == SIGSEGV){ 17 | printf("suicide\n"); 18 | pthread_exit(NULL); 19 | }else 20 | exit(sig); 21 | } 22 | 23 | void dummy(){ 24 | int i; 25 | char *ptr = malloc(10000); 26 | for(i = 0; i < 256; ++i, ptr += 1024){ 27 | *ptr += i; 28 | } 29 | } 30 | 31 | pid_t create_child(){ 32 | child_killed = 0; 33 | pid_t p = fork(); 34 | if(p == 0){ 35 | printf("child\n"); 36 | dummy(); 37 | } 38 | return p; 39 | } 40 | 41 | void *thrfnctn(void *buf){ 42 | dummy(); 43 | } 44 | 45 | int main(){ 46 | int i; 47 | //for(i = 0; i < 255; ++i) 48 | // signal(i, sighndlr); 49 | signal(SIGCHLD, sighndlr); 50 | signal(SIGSEGV, sighndlr); 51 | for(i = 0; i < 10; ++i){ 52 | pid_t p = create_child(); 53 | if(p){ 54 | printf("child #%d with PID %d\n", i, p); 55 | while(!child_killed) 56 | usleep(10000); 57 | }else return 0; 58 | } 59 | for(i = 0; i < 10; ++i){ 60 | if(pthread_create(&athread, NULL, thrfnctn, NULL)) 61 | return -1; 62 | printf("thread #%d\n", i); 63 | while(pthread_kill(athread, 0) != ESRCH) 64 | usleep(1000); 65 | pthread_join(athread, NULL); 66 | } 67 | return 0; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /image_view_module/README: -------------------------------------------------------------------------------- 1 | GLUT -> GLFW 2 | For GUI: look for analog of GLUI 3 | -------------------------------------------------------------------------------- /image_view_module/events.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/image_view_module/events.c -------------------------------------------------------------------------------- /image_view_module/events.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/image_view_module/events.h -------------------------------------------------------------------------------- /image_view_module/imageview.h: -------------------------------------------------------------------------------- 1 | /* 2 | * imageview.h 3 | * 4 | * Copyright 2015 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #pragma once 22 | #ifndef __BMPVIEW_H__ 23 | #define __BMPVIEW_H__ 24 | 25 | #include 26 | #include 27 | #include 28 | #include "events.h" 29 | #include "list.h" 30 | 31 | typedef enum{ 32 | INNER, 33 | OPENGL 34 | } winIdType; 35 | 36 | void imageview_init(); 37 | windowData *createGLwin(char *title, int w, int h, rawimage *rawdata); 38 | //void window_redraw(windowData *win); 39 | int destroyWindow(int window, winIdType type); 40 | void renderBitmapString(float x, float y, void *font, char *string, GLubyte *color); 41 | void clear_GL_context(); 42 | 43 | void calc_win_props(windowData *win, GLfloat *Wortho, GLfloat *Hortho); 44 | 45 | void conv_mouse_to_image_coords(int x, int y, float *X, float *Y, windowData *window); 46 | void conv_image_to_mouse_coords(float X, float Y, int *x, int *y, windowData *window); 47 | 48 | void destroyWindow_async(int window_GL_ID); 49 | 50 | #endif // __BMPVIEW_H__ 51 | -------------------------------------------------------------------------------- /image_view_module/locale/ru/LC_MESSAGES/image_view_module.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/image_view_module/locale/ru/LC_MESSAGES/image_view_module.mo -------------------------------------------------------------------------------- /image_view_module/locale/ru/messages.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/image_view_module/locale/ru/messages.po -------------------------------------------------------------------------------- /image_view_module/locale/ru/ru.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/image_view_module/locale/ru/ru.po -------------------------------------------------------------------------------- /image_view_module/main.h: -------------------------------------------------------------------------------- 1 | // pthread_t thread, thread_m; 2 | #include "events.h" // GLubyte etc 3 | 4 | // GLubyte *prepareImage(); 5 | void help(char *s); 6 | 7 | -------------------------------------------------------------------------------- /kicad-copy/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = copy_pcb 2 | LDFLAGS = 3 | SRCS = cmdlnopts.c copy_pcb.c parceargs.c usefull_macros.c 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=1001 -DGETTEXT_PACKAGE=\"copy_pcb\" -DLOCALEDIR=\".\" 6 | DEFINES +=-DEBUG 7 | CXX = gcc 8 | CFLAGS = -std=gnu99 -Wall -Werror $(DEFINES) 9 | OBJS = $(SRCS:.c=.o) 10 | all : $(PROGRAM) 11 | $(PROGRAM) : $(OBJS) 12 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 13 | 14 | # some addition dependencies 15 | # %.o: %.c 16 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 17 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 18 | # @touch $@ 19 | 20 | clean: 21 | /bin/rm -f *.o *~ 22 | depend: 23 | $(CXX) -MM $(SRCS) 24 | -------------------------------------------------------------------------------- /kicad-copy/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cmdlnopts.h - comand line options for parceargs 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __CMDLNOPTS_H__ 24 | #define __CMDLNOPTS_H__ 25 | 26 | #include "parceargs.h" 27 | 28 | /* 29 | * here are some typedef's for global data 30 | */ 31 | 32 | typedef struct{ 33 | char *format; // printf-like format: "%s_%d" 34 | int nparts; // number of parts from list 35 | char *list; // comma-separated list 36 | char *ifile; // input file 37 | }glob_pars; 38 | 39 | extern glob_pars G; 40 | 41 | glob_pars *parce_args(int argc, char **argv); 42 | 43 | #endif // __CMDLNOPTS_H__ 44 | -------------------------------------------------------------------------------- /kicad-copy/copy_pcb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copy_pcb.h 3 | * 4 | * Copyright 2014 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __COPY_PCB_H__ 24 | #define __COPY_PCB_H__ 25 | 26 | #include "usefull_macros.h" 27 | #include "cmdlnopts.h" 28 | 29 | #endif // __COPY_PCB_H__ 30 | 31 | 32 | -------------------------------------------------------------------------------- /modbus_relay/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := modbus_relay 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lusefull_macros -lmodbus 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | OBJDIR := mk 8 | CFLAGS += -O2 -Wall -Wextra -Wno-trampolines 9 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 10 | DEPS := $(OBJS:.o=.d) 11 | TARGFILE := $(OBJDIR)/TARGET 12 | CC = gcc 13 | #TARGET := RELEASE 14 | 15 | ifeq ($(shell test -e $(TARGFILE) && echo -n yes),yes) 16 | TARGET := $(file < $(TARGFILE)) 17 | else 18 | TARGET := RELEASE 19 | endif 20 | 21 | ifeq ($(TARGET), DEBUG) 22 | .DEFAULT_GOAL := debug 23 | endif 24 | 25 | release: CFLAGS += -flto 26 | release: LDFLAGS += -flto 27 | release: $(PROGRAM) 28 | 29 | debug: CFLAGS += -DEBUG -Werror 30 | debug: TARGET := DEBUG 31 | debug: $(PROGRAM) 32 | 33 | $(TARGFILE): $(OBJDIR) 34 | @echo -e "\t\tTARGET: $(TARGET)" 35 | @echo "$(TARGET)" > $(TARGFILE) 36 | 37 | $(PROGRAM) : $(TARGFILE) $(OBJS) 38 | @echo -e "\t\tLD $(PROGRAM)" 39 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 40 | 41 | $(OBJDIR): 42 | @mkdir $(OBJDIR) 43 | 44 | ifneq ($(MAKECMDGOALS),clean) 45 | -include $(DEPS) 46 | endif 47 | 48 | $(OBJDIR)/%.o: %.c 49 | @echo -e "\t\tCC $<" 50 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 51 | 52 | clean: 53 | @echo -e "\t\tCLEAN" 54 | @rm -rf $(OBJDIR) 2>/dev/null || true 55 | 56 | xclean: clean 57 | @rm -f $(PROGRAM) 58 | 59 | .PHONY: clean xclean 60 | -------------------------------------------------------------------------------- /modbus_relay/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the modbus_relay project. 3 | * Copyright 2025 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | /* 24 | * here are some typedef's for global data 25 | */ 26 | typedef struct{ 27 | int verbose; // verbose level 28 | int baudrate; // interface baudrate (default: 9600) 29 | int setall; // set all relays 30 | int resetall; // reset all relays 31 | int nodenum; // node number (default: 1) 32 | int readn; // read node number 33 | int setn; // set node number 34 | int relaytype; // type of relay 35 | int **setrelay; // set relay number N 36 | int **resetrelay; // reset relay number N 37 | int **getinput; // read Nth input 38 | int **getrelay; // read Nth relay 39 | char *logfile; // logfile name 40 | char *device; // serial device path (default: /dev/ttyUSB0) 41 | } glob_pars; 42 | 43 | extern glob_pars GP; 44 | extern sl_loglevel_e verblvl; 45 | void parse_args(int argc, char **argv); 46 | void verbose(sl_loglevel_e lvl, const char *fmt, ...); 47 | 48 | #define VMSG(...) verbose(LOGLEVEL_MSG, __VA_ARGS__) 49 | #define VDBG(...) verbose(LOGLEVEL_DBG, __VA_ARGS__) 50 | #define VANY(...) verbose(LOGLEVEL_ANY, __VA_ARGS__) 51 | -------------------------------------------------------------------------------- /modbus_relay/modbus_relay.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /modbus_relay/modbus_relay.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | -------------------------------------------------------------------------------- /modbus_relay/modbus_relay.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /modbus_relay/modbus_relay.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /modbus_relay/modbus_relay.files: -------------------------------------------------------------------------------- 1 | cmdlnopts.c 2 | cmdlnopts.h 3 | main.c 4 | -------------------------------------------------------------------------------- /modbus_relay/modbus_relay.includes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/modbus_relay/modbus_relay.includes -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := modbus_relay 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lusefull_macros -lmodbus 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | OBJDIR := mk 8 | CFLAGS += -O2 -Wall -Wextra -Wno-trampolines 9 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 10 | DEPS := $(OBJS:.o=.d) 11 | TARGFILE := $(OBJDIR)/TARGET 12 | CC = gcc 13 | #TARGET := RELEASE 14 | 15 | ifeq ($(shell test -e $(TARGFILE) && echo -n yes),yes) 16 | TARGET := $(file < $(TARGFILE)) 17 | else 18 | TARGET := RELEASE 19 | endif 20 | 21 | ifeq ($(TARGET), DEBUG) 22 | .DEFAULT_GOAL := debug 23 | endif 24 | 25 | release: CFLAGS += -flto 26 | release: LDFLAGS += -flto 27 | release: $(PROGRAM) 28 | 29 | debug: CFLAGS += -DEBUG -Werror 30 | debug: TARGET := DEBUG 31 | debug: $(PROGRAM) 32 | 33 | $(TARGFILE): $(OBJDIR) 34 | @echo -e "\t\tTARGET: $(TARGET)" 35 | @echo "$(TARGET)" > $(TARGFILE) 36 | 37 | $(PROGRAM) : $(TARGFILE) $(OBJS) 38 | @echo -e "\t\tLD $(PROGRAM)" 39 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 40 | 41 | $(OBJDIR): 42 | @mkdir $(OBJDIR) 43 | 44 | ifneq ($(MAKECMDGOALS),clean) 45 | -include $(DEPS) 46 | endif 47 | 48 | $(OBJDIR)/%.o: %.c 49 | @echo -e "\t\tCC $<" 50 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 51 | 52 | clean: 53 | @echo -e "\t\tCLEAN" 54 | @rm -rf $(OBJDIR) 2>/dev/null || true 55 | 56 | xclean: clean 57 | @rm -f $(PROGRAM) 58 | 59 | .PHONY: clean xclean 60 | -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the modbus_relay project. 3 | * Copyright 2025 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | /* 24 | * here are some typedef's for global data 25 | */ 26 | typedef struct{ 27 | int verbose; // verbose level 28 | int baudrate; // interface baudrate (default: 9600) 29 | int nodenum; // node number (default: 1) 30 | char *port; // socket port (default: 9000) 31 | char *logfile; // logfile name 32 | char *device; // serial device path (default: /dev/ttyUSB0) 33 | } glob_pars; 34 | 35 | extern glob_pars GP; 36 | extern sl_loglevel_e verblvl; 37 | void parse_args(int argc, char **argv); 38 | void verbose(sl_loglevel_e lvl, const char *fmt, ...); 39 | 40 | #define VMSG(...) verbose(LOGLEVEL_MSG, __VA_ARGS__) 41 | #define VDBG(...) verbose(LOGLEVEL_DBG, __VA_ARGS__) 42 | #define VANY(...) verbose(LOGLEVEL_ANY, __VA_ARGS__) 43 | -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/modbus_relay: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/modbus_relay/web_management/relay_daemon/modbus_relay -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/modbus_relay.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/modbus_relay.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | #define _DEFAULT_SOURCE 4 | -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/modbus_relay.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/modbus_relay.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/modbus_relay.files: -------------------------------------------------------------------------------- 1 | cmdlnopts.c 2 | cmdlnopts.h 3 | main.c 4 | server.c 5 | server.h 6 | -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/modbus_relay.includes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/modbus_relay/web_management/relay_daemon/modbus_relay.includes -------------------------------------------------------------------------------- /modbus_relay/web_management/relay_daemon/server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the modbus_relay project. 3 | * Copyright 2025 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | // timeout for socket closing if nothing received 22 | #define SOCKET_TIMEOUT (60.0) 23 | // timeout to turn relays off 24 | #define RELAYS_TIMEOUT (10.0) 25 | // time interval for MODBUS data polling (seconds) 26 | #define T_INTERVAL (1.) 27 | 28 | void runserver(const char *port, modbus_t *ctx); 29 | int closeserver(); 30 | -------------------------------------------------------------------------------- /mydiff.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/mydiff.c -------------------------------------------------------------------------------- /netdaemon/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := netdaemon 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all -pthread 4 | SRCS := $(wildcard *.c) 5 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 6 | DEFINES += -DEBUG 7 | # baudrate for USB<->UART converter 8 | DEFINES += -DBAUD_RATE=B115200 9 | OBJDIR := mk 10 | CFLAGS += -O2 -Wall -Werror -Wextra -Wno-trampolines 11 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 12 | DEPS := $(OBJS:.o=.d) 13 | CC = gcc 14 | 15 | all : $(OBJDIR) $(PROGRAM) 16 | 17 | $(PROGRAM) : $(OBJS) 18 | @echo -e "\t\tLD $(PROGRAM)" 19 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 20 | 21 | $(OBJDIR): 22 | mkdir $(OBJDIR) 23 | 24 | ifneq ($(MAKECMDGOALS),clean) 25 | -include $(DEPS) 26 | endif 27 | 28 | $(OBJDIR)/%.o: %.c 29 | @echo -e "\t\tCC $<" 30 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 31 | 32 | clean: 33 | @echo -e "\t\tCLEAN" 34 | @rm -f $(OBJS) $(DEPS) 35 | @rmdir $(OBJDIR) 2>/dev/null || true 36 | 37 | xclean: clean 38 | @rm -f $(PROGRAM) 39 | 40 | gentags: 41 | CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] 2>/dev/null 42 | 43 | .PHONY: gentags clean xclean 44 | -------------------------------------------------------------------------------- /netdaemon/Readme.md: -------------------------------------------------------------------------------- 1 | Network daemon snippet 2 | ================== 3 | 4 | This isn't an end-product, but just a template for different net-daemons. 5 | 6 | Open a socket at given port (default: 4444), works with http & direct requests. 7 | Can read and send commands over serial interface. 8 | 9 | Pieces with user code marked as 'INSERT CODE HERE'. 10 | -------------------------------------------------------------------------------- /netdaemon/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* geany_encoding=koi8-r 2 | * cmdlnopts.h - comand line options for parceargs 3 | * 4 | * Copyright 2018 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __CMDLNOPTS_H__ 24 | #define __CMDLNOPTS_H__ 25 | 26 | #include "parseargs.h" 27 | #include "term.h" 28 | 29 | /* 30 | * here are some typedef's for global data 31 | */ 32 | typedef struct{ 33 | char *device; // serial device name 34 | char *port; // port to connect 35 | char *logfile; // logfile name 36 | int terminal; // run as terminal 37 | int echo; // echo user commands back 38 | int rest_pars_num; // number of rest parameters 39 | char** rest_pars; // the rest parameters: array of char* (path to logfile and thrash) 40 | } glob_pars; 41 | 42 | 43 | glob_pars *parse_args(int argc, char **argv); 44 | #endif // __CMDLNOPTS_H__ 45 | -------------------------------------------------------------------------------- /netdaemon/netdaemon.c.tags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/netdaemon/netdaemon.c.tags -------------------------------------------------------------------------------- /netdaemon/parseargs.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/netdaemon/parseargs.c -------------------------------------------------------------------------------- /netdaemon/socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * geany_encoding=koi8-r 3 | * socket.h 4 | * 5 | * Copyright 2017 Edward V. Emelianov 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 20 | * MA 02110-1301, USA. 21 | * 22 | */ 23 | #pragma once 24 | #ifndef __SOCKET_H__ 25 | #define __SOCKET_H__ 26 | 27 | // timeout for socket closing 28 | #define SOCKET_TIMEOUT (5.0) 29 | // time interval for data polling (seconds) 30 | #define T_INTERVAL (10.) 31 | 32 | void daemonize(char *port); 33 | 34 | #endif // __SOCKET_H__ 35 | -------------------------------------------------------------------------------- /netdaemon/term.h: -------------------------------------------------------------------------------- 1 | /* geany_encoding=koi8-r 2 | * term.h 3 | * 4 | * Copyright 2018 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #pragma once 22 | #ifndef __TERM_H__ 23 | #define __TERM_H__ 24 | 25 | #define FRAME_MAX_LENGTH (300) 26 | #define MAX_MEMORY_DUMP_SIZE (0x800 * 4) 27 | // Terminal timeout (seconds) 28 | #define WAIT_TMOUT (0.5) 29 | // Terminal polling timeout - 1 second 30 | #define T_POLLING_TMOUT (1.0) 31 | 32 | void run_terminal(); 33 | void try_connect(char *device); 34 | char *poll_device(); 35 | 36 | #endif // __TERM_H__ 37 | -------------------------------------------------------------------------------- /netdaemon/usefull_macros.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/netdaemon/usefull_macros.c -------------------------------------------------------------------------------- /opengl.c: -------------------------------------------------------------------------------- 1 | // the simplest opengl example 2 | 3 | #include 4 | #include 5 | // compile: 6 | // gcc -Wall -Wextra -Werror -lglut -lGL -lm -std=gnu99 -D_GNU_SOURCE opengl.c -o openglcircle 7 | 8 | #define _U_ __attribute__((__unused__)) 9 | // exit by ctrl+q or escape 10 | void keyPressed(unsigned char key, _U_ int x, _U_ int y){ 11 | int mod = glutGetModifiers(); // window = glutGetWindow() 12 | if(mod == GLUT_ACTIVE_CTRL && key == 'q') exit(0); 13 | else if(key == 27) exit(0); 14 | } 15 | 16 | void DrawCircle(float cx, float cy, float r, int num_segments){ 17 | float theta = 2. * M_PI / (float)num_segments; 18 | float c, s, t, x = r, y = 0.; 19 | sincosf(theta, &s, &c); 20 | glBegin(GL_LINE_LOOP); 21 | for(int ii = 0; ii < num_segments; ii++){ 22 | glVertex2f(x + cx, y + cy); 23 | t = x; 24 | x = c * x - s * y; 25 | y = s * t + c * y; 26 | } 27 | glEnd(); 28 | } 29 | 30 | void display(){ 31 | glClear(GL_COLOR_BUFFER_BIT); 32 | DrawCircle(0.,0.,0.5,100); 33 | glFlush(); 34 | } 35 | 36 | int main(int argc, char** argv){ 37 | glutInit(&argc, argv); 38 | glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 39 | glutInitWindowSize(400, 400); 40 | glutCreateWindow("A Simple Circle"); 41 | glutDisplayFunc(display); 42 | glutKeyboardFunc(keyPressed); 43 | glutMainLoop(); 44 | } 45 | -------------------------------------------------------------------------------- /powerof2.c: -------------------------------------------------------------------------------- 1 | int IsPowerOfTwo(uint64_t x){ 2 | return (x != 0) && ((x & (x - 1)) == 0); 3 | } 4 | -------------------------------------------------------------------------------- /randomstring.c: -------------------------------------------------------------------------------- 1 | // returns symbols from 32 to 126 read from /dev/urandom, not thread-safe 2 | // s - length of data with trailing zero 3 | 4 | #include 5 | char *randstring(size_t *s){ 6 | static char buf[256]; 7 | char rbuf[255]; 8 | ssize_t L = getrandom(rbuf, 255, 0); 9 | if(L < 1){ 10 | *s = 0; 11 | return NULL; 12 | } 13 | size_t total = 0; 14 | for(size_t x = 0; x < (size_t)L; ++x){ 15 | char s = rbuf[x]; 16 | if(s > 31 && s < 127) buf[total++] = s; 17 | } 18 | buf[total++] = 0; 19 | *s = total; 20 | return buf; 21 | } 22 | -------------------------------------------------------------------------------- /serialsock/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := serialsock 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lusefull_macros -lm -L/usr/local/lib/ 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | OBJDIR := mk 8 | CFLAGS += -O3 -Wno-trampolines -std=gnu99 9 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 10 | DEPS := $(OBJS:.o=.d) 11 | CC = gcc 12 | #CXX = g++ 13 | 14 | 15 | all : $(PROGRAM) 16 | 17 | debug: CFLAGS += -DEBUG -Werror -Wall -Wextra 18 | debug: all 19 | 20 | $(OBJS): $(OBJDIR) 21 | 22 | $(PROGRAM) : $(OBJS) 23 | @echo -e "\t\tLD $(PROGRAM)" 24 | $(CC) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 25 | 26 | $(OBJDIR): 27 | mkdir $(OBJDIR) 28 | 29 | ifneq ($(MAKECMDGOALS),clean) 30 | -include $(DEPS) 31 | endif 32 | 33 | $(OBJDIR)/%.o: %.c 34 | @echo -e "\t\tCC $<" 35 | $(CC) $< -MD -c $(CFLAGS) $(DEFINES) -o $@ 36 | 37 | clean: 38 | @echo -e "\t\tCLEAN" 39 | @rm -f $(OBJS) $(DEPS) 40 | @rmdir $(OBJDIR) 2>/dev/null || true 41 | 42 | xclean: clean 43 | @rm -f $(PROGRAM) 44 | 45 | .PHONY: clean xclean 46 | -------------------------------------------------------------------------------- /serialsock/Readme: -------------------------------------------------------------------------------- 1 | Socket server for any serial device 2 | 3 | -------------------------------------------------------------------------------- /serialsock/canserver.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /serialsock/canserver.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | #define EBUG 4 | #define _GNU_SOURCE 5 | #define _XOPEN_SOURCE=1111 6 | 7 | -------------------------------------------------------------------------------- /serialsock/canserver.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /serialsock/canserver.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /serialsock/canserver.files: -------------------------------------------------------------------------------- 1 | cmdlnopts.c 2 | cmdlnopts.h 3 | main.c 4 | sersock.c 5 | sersock.h 6 | -------------------------------------------------------------------------------- /serialsock/canserver.includes: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /serialsock/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the canserver project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef CMDLNOPTS_H__ 21 | #define CMDLNOPTS_H__ 22 | 23 | /* 24 | * here are some typedef's for global data 25 | */ 26 | typedef struct{ 27 | char *devpath; // path to serial device 28 | char *pidfile; // name of PID file 29 | char *logfile; // logging to this file 30 | char *path; // path to socket file 31 | int speed; // connection speed 32 | int verbose; // verbose level: for messages & logging 33 | int client; // ==1 if application runs in client mode 34 | } glob_pars; 35 | 36 | extern glob_pars *GP; 37 | 38 | void parse_args(int argc, char **argv); 39 | void verbose(int levl, const char *fmt, ...); 40 | 41 | #endif // CMDLNOPTS_H__ 42 | -------------------------------------------------------------------------------- /serialsock/sersock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the canserver project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef SERSOCK_H__ 21 | #define SERSOCK_H__ 22 | 23 | #define BUFLEN (1024) 24 | // Max amount of connections 25 | #define MAXCLIENTS (30) 26 | 27 | #include 28 | 29 | int start_socket(int server, char *path, sl_tty_t **dev); 30 | 31 | #endif // SERSOCK_H__ 32 | -------------------------------------------------------------------------------- /serialsockCANmanage/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := SEWcontrol 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lusefull_macros -lm -L/usr/local/lib/ 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | OBJDIR := mk 8 | CFLAGS += -O3 -Wno-trampolines -std=gnu99 9 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 10 | DEPS := $(OBJS:.o=.d) 11 | CC = gcc 12 | #CXX = g++ 13 | 14 | 15 | all : $(PROGRAM) 16 | 17 | debug: CFLAGS += -DEBUG -Werror -Wall -Wextra 18 | debug: all 19 | 20 | $(OBJS): $(OBJDIR) 21 | 22 | $(PROGRAM) : $(OBJS) 23 | @echo -e "\t\tLD $(PROGRAM)" 24 | $(CC) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 25 | 26 | $(OBJDIR): 27 | mkdir $(OBJDIR) 28 | 29 | ifneq ($(MAKECMDGOALS),clean) 30 | -include $(DEPS) 31 | endif 32 | 33 | $(OBJDIR)/%.o: %.c 34 | @echo -e "\t\tCC $<" 35 | $(CC) $< -MD -c $(CFLAGS) $(DEFINES) -o $@ 36 | 37 | clean: 38 | @echo -e "\t\tCLEAN" 39 | @rm -f $(OBJS) $(DEPS) 40 | @rmdir $(OBJDIR) 2>/dev/null || true 41 | 42 | xclean: clean 43 | @rm -f $(PROGRAM) 44 | 45 | .PHONY: clean xclean 46 | -------------------------------------------------------------------------------- /serialsockCANmanage/Readme: -------------------------------------------------------------------------------- 1 | Simplest SEW motor controllers manage using serialsock and CAN-USB 2 | 3 | 4 | -------------------------------------------------------------------------------- /serialsockCANmanage/SEWmanage.cflags: -------------------------------------------------------------------------------- 1 | -std=c17 -------------------------------------------------------------------------------- /serialsockCANmanage/SEWmanage.config: -------------------------------------------------------------------------------- 1 | // Add predefined macros for your project here. For example: 2 | // #define THE_ANSWER 42 3 | #define EBUG 4 | #define _GNU_SOURCE 5 | #define _XOPEN_SOURCE=1111 6 | 7 | -------------------------------------------------------------------------------- /serialsockCANmanage/SEWmanage.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /serialsockCANmanage/SEWmanage.cxxflags: -------------------------------------------------------------------------------- 1 | -std=c++17 -------------------------------------------------------------------------------- /serialsockCANmanage/SEWmanage.files: -------------------------------------------------------------------------------- 1 | cmdlnopts.c 2 | cmdlnopts.h 3 | main.c 4 | sersock.c 5 | sersock.h 6 | -------------------------------------------------------------------------------- /serialsockCANmanage/SEWmanage.includes: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /serialsockCANmanage/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SEWmanage project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef CMDLNOPTS_H__ 21 | #define CMDLNOPTS_H__ 22 | 23 | /* 24 | * here are some typedef's for global data 25 | */ 26 | typedef struct{ 27 | char *logfile; // logging to this file 28 | char *path; // path to socket file 29 | int stop; // stop motor 30 | int setspeed; // set this speed (rev/min) 31 | int verbose; // verbose level: for messages & logging 32 | } glob_pars; 33 | 34 | extern glob_pars *GP; 35 | 36 | void parse_args(int argc, char **argv); 37 | void verbose(int levl, const char *fmt, ...); 38 | 39 | #endif // CMDLNOPTS_H__ 40 | -------------------------------------------------------------------------------- /serialsockCANmanage/sersock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SEWmanage project. 3 | * Copyright 2022 Edward V. Emelianov . 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | #ifndef SERSOCK_H__ 21 | #define SERSOCK_H__ 22 | 23 | #define BUFLEN (1024) 24 | // timeout for answer from socket 25 | #define TIMEOUT (5.) 26 | // motors amount 27 | #define NMOTORS (3) 28 | 29 | typedef enum{ 30 | CMD_GETSPEED, // just get speed 31 | CMD_SETSPEED, // set given speed 32 | CMD_STOP, // stop motor 33 | } CANcmd; 34 | 35 | int start_socket(char *path, CANcmd cmd, int par); 36 | 37 | #endif // SERSOCK_H__ 38 | -------------------------------------------------------------------------------- /serialsockCANmanage/www/bin/acc: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Access-Control-Allow-Origin: * 3 | Content-type: text/html 4 | 5 | -------------------------------------------------------------------------------- /serialsockCANmanage/www/bin/runSpeedCtrl: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | while true; do 4 | NewVal=$((cat /home/eddy/bin/acc; /home/eddy/bin/SEWcontrol) | nc -w0 -lp 8080 | grep GET) 5 | E=$(echo $NewVal | sed 's|.*setspeed=\([0-9\.]\+\).*|\1|' | grep "^[0-9]*[.]*[0-9]*$") 6 | #' 7 | if [ "x$E" != "x" ]; then 8 | echo "SPEED=$E" 9 | (( E > 299 )) && (( E < 1301 )) && /home/eddy/bin/SEWcontrol -s $E || /home/eddy/bin/SEWcontrol -0 10 | fi 11 | done 12 | -------------------------------------------------------------------------------- /serialsockCANmanage/www/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/serialsockCANmanage/www/favicon.ico -------------------------------------------------------------------------------- /sharedlib_template/CMake.readme: -------------------------------------------------------------------------------- 1 | cmake defines: 2 | -DDEBUG=1 - debug mode 3 | -DNOGETTEXT=1 - don't run xgettext 4 | -DEXAMPLES=1 - to compile examples 5 | -------------------------------------------------------------------------------- /sharedlib_template/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | project(examples) 3 | link_libraries(usefull_macros) 4 | include_directories(../) 5 | 6 | #target_link_libraries(hello -lm) 7 | add_executable(hello helloworld.c) 8 | -------------------------------------------------------------------------------- /sharedlib_template/examples/helloworld.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | setlocale(LC_ALL, ""); 7 | setlocale(LC_NUMERIC, "C"); 8 | #if defined GETTEXT_PACKAGE && defined LOCALEDIR 9 | bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); 10 | textdomain(GETTEXT_PACKAGE); 11 | #endif 12 | 13 | helloworld(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /sharedlib_template/locale/ru/LC_MESSAGES/usefull_macros.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/sharedlib_template/locale/ru/LC_MESSAGES/usefull_macros.mo -------------------------------------------------------------------------------- /sharedlib_template/locale/ru/ru.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/sharedlib_template/locale/ru/ru.po -------------------------------------------------------------------------------- /sharedlib_template/usefull_macros.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/sharedlib_template/usefull_macros.c -------------------------------------------------------------------------------- /sharedlib_template/usefull_macros.h: -------------------------------------------------------------------------------- 1 | void helloworld(); 2 | -------------------------------------------------------------------------------- /sharedlib_template/usefull_macros.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: @PROJ@ 7 | Description: Library with a lot of usefull snippets 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -l@PROJ@ 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /sigtest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | volatile pid_t childpid = 0; 9 | 10 | void signal_handler(int sig){ 11 | printf("PID %zd got signal %d, die\n", getpid(), sig); 12 | if(childpid) 13 | kill(childpid, SIGTERM); 14 | exit(sig); 15 | } 16 | 17 | pid_t create_child(){ 18 | int i; 19 | pid_t p = fork(); 20 | if(p == 0){ 21 | prctl(PR_SET_PDEATHSIG, SIGTERM); // send SIGTERM to child when parent dies 22 | printf("child\n"); 23 | sleep(1); 24 | } 25 | return p; 26 | } 27 | 28 | int main(){ 29 | int i = 0; 30 | signal(SIGTERM, signal_handler); // kill (-15) 31 | signal(SIGINT, signal_handler); // ctrl+C 32 | signal(SIGQUIT, signal_handler); // ctrl+\ . 33 | signal(SIGTSTP, SIG_IGN); // ctrl+Z 34 | signal(SIGSEGV, signal_handler); 35 | printf("my PID: %zd\n", getpid()); 36 | while(1){ 37 | childpid = create_child(); 38 | if(childpid){ 39 | printf("child #%d with PID %d\n", ++i, childpid); 40 | wait(NULL); 41 | printf("died\n"); 42 | }else return 0; 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /simple_Eratosfen_sieve.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | // 1GB of RAM 9 | #define MASKSZ (1073741824L) 10 | #define MNUMBERS (MASKSZ*8) 11 | static uint8_t *masks; 12 | 13 | static inline __attribute__((always_inline)) uint8_t get(uint64_t idx){ 14 | register uint64_t i = idx >> 3; 15 | register uint8_t j = idx - (i<<3); 16 | return masks[i] & (1<> 3; 21 | register uint8_t j = idx - (i<<3); 22 | masks[i] &= ~(1< 1000; --last){ 54 | if(get(last)){ printf("last in list: %zd\n", last); break;} 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /simple_gettext/1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/simple_gettext/1.c -------------------------------------------------------------------------------- /simple_gettext/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = test 2 | LDFLAGS = 3 | DEFINES = -D_XOPEN_SOURCE=501 -DGETTEXT_PACKAGE=\"$(PROGRAM)\" -DLOCALEDIR=\".\" 4 | SRCS = 1.c 5 | CC = gcc 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | PO_FILE = $(PROGRAM).po 10 | RU_FILE = $(PROGRAM)_ru.po 11 | LDIR = "ru/LC_MESSAGES" 12 | MO_FILE = $(LDIR)/$(PROGRAM).mo 13 | 14 | all : $(PROGRAM) $(MO_FILE) 15 | 16 | $(PROGRAM) : $(OBJS) 17 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 18 | 19 | $(PO_FILE): $(SRCS) 20 | xgettext -D. --from-code=koi8-r $(SRCS) -c -k_ -kN_ -o $(PO_FILE) 21 | sed -i 's/charset=.*\\n/charset=koi8-r\\n/' $(PO_FILE) && enconv $(PO_FILE) 22 | $(RU_FILE): $(PO_FILE) 23 | [ -e $(RU_FILE) ] && msgmerge -Uis $(RU_FILE) $(PO_FILE) || cp $(PO_FILE) $(RU_FILE) 24 | $(MO_FILE): $(LDIR) $(RU_FILE) 25 | msgfmt $(RU_FILE) -o $(MO_FILE) 26 | $(LDIR): 27 | [ -e $(LDIR) ] || mkdir -p $(LDIR) 28 | clean: 29 | /bin/rm -f *.o *~ 30 | depend: 31 | $(CXX) -MM $(CXX.SRCS) 32 | -------------------------------------------------------------------------------- /simple_gettext/test_ru.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/simple_gettext/test_ru.po -------------------------------------------------------------------------------- /simple_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * simple_list.h - header file for simple list support 3 | * TO USE IT you must define the type of data as 4 | * typedef your_type listdata 5 | * or at compiling time 6 | * -Dlistdata=your_type 7 | * or by changing this file 8 | * 9 | * Copyright 2013 Edward V. Emelianoff 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 24 | * MA 02110-1301, USA. 25 | */ 26 | #pragma once 27 | #ifndef __SIMPLE_LIST_H__ 28 | #define __SIMPLE_LIST_H__ 29 | 30 | #ifdef STANDALONE 31 | typedef int listdata; 32 | #endif 33 | 34 | typedef struct list_{ 35 | listdata data; 36 | struct list_ *next; 37 | } List; 38 | 39 | // add element v to list with root root (also this can be last element) 40 | List *list_add(List **root, listdata v); 41 | // set listdata_free() 42 | void listfree_function(void (*fn)(listdata node)); 43 | 44 | #endif // __SIMPLE_LIST_H__ 45 | -------------------------------------------------------------------------------- /simple_websockets/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = websocktest 2 | LDFLAGS = $(shell pkg-config --libs libwebsockets) -lpthread -lcrypto 3 | SRCS = main.c que.c 4 | CC = gcc 5 | DEFINES += -DEBUG 6 | CXX = gcc 7 | CFLAGS = -Werror -Wextra $(DEFINES) $(shell pkg-config --cflags libwebsockets) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /simple_websockets/Readme.md: -------------------------------------------------------------------------------- 1 | ### Websockets test 2 | 3 | 4 | -------------------------------------------------------------------------------- /simple_websockets/dbg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dbg.h 3 | * 4 | * Copyright 2016 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __DBG_H__ 24 | #define __DBG_H__ 25 | 26 | #if defined EBUG || defined DEBUG 27 | #ifndef DBG 28 | #define DBG(...) do{fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n");}while(0) 29 | #endif 30 | #else 31 | #define DBG(...) 32 | #endif 33 | 34 | 35 | #ifndef _U_ 36 | #define _U_ __attribute__((__unused__)) 37 | #endif 38 | 39 | #endif // __DBG_H__ 40 | -------------------------------------------------------------------------------- /simple_websockets/que.c: -------------------------------------------------------------------------------- 1 | /* 2 | * que.c 3 | * 4 | * Copyright 2016 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #include 22 | #include "que.h" 23 | 24 | char que[MESSAGE_LEN]; 25 | control_data global_que; 26 | 27 | void put_message_to_que(char *msg, control_data *dat){ 28 | int L = strlen(msg); 29 | if(dat->num >= MESSAGE_QUE_SIZE) return; 30 | ++dat->num; 31 | if(L < 1 || L > MESSAGE_LEN - 1) L = MESSAGE_LEN - 1; 32 | strncpy(dat->message[dat->idxwr], msg, L); 33 | dat->message[dat->idxwr][L] = 0; 34 | if((++(dat->idxwr)) >= MESSAGE_QUE_SIZE) dat->idxwr = 0; 35 | } 36 | 37 | void glob_que(char *buf){ 38 | put_message_to_que(buf, &global_que); 39 | } 40 | 41 | char *get_message_from_que(control_data *dat){ 42 | char *R = dat->message[dat->idxrd]; 43 | if(dat->num <= 0) return NULL; 44 | if((++dat->idxrd) >= MESSAGE_QUE_SIZE) dat->idxrd = 0; 45 | --dat->num; 46 | return R; 47 | } 48 | -------------------------------------------------------------------------------- /simple_websockets/que.h: -------------------------------------------------------------------------------- 1 | /* 2 | * que.h 3 | * 4 | * Copyright 2016 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #pragma once 22 | #ifndef __QUE_H__ 23 | #define __QUE_H__ 24 | 25 | #define MESSAGE_LEN (512) 26 | #define MESSAGE_QUE_SIZE (16) 27 | 28 | 29 | typedef enum{ 30 | UNDEFINED = 0, 31 | SALT_SENT, 32 | VERIFIED, 33 | }client_state; 34 | 35 | typedef struct { 36 | int num; 37 | int idxwr; 38 | int idxrd; 39 | char message[MESSAGE_QUE_SIZE][MESSAGE_LEN]; 40 | int already_connected; 41 | client_state state; 42 | } control_data; 43 | 44 | extern char que[]; 45 | extern control_data global_que; 46 | void glob_que(char *buf); 47 | void put_message_to_que(char *msg, control_data *dat); 48 | char *get_message_from_que(control_data *dat); 49 | 50 | //#define GLOB_MESG(...) do{snprintf(que, 512, __VA_ARGS__); glob_que();}while(0) 51 | #endif // __QUE_H__ 52 | -------------------------------------------------------------------------------- /simple_websockets/www/getpass.js: -------------------------------------------------------------------------------- 1 | ;(function () { 'use strict'; 2 | var Pass = {}; 3 | var pwform = null, pw = null; 4 | var onenter = function(){}; 5 | function retPass(){ 6 | if(!pwform) return; 7 | var p = pw.value, c; 8 | while(c = pwform.firstChild) pwform.removeChild(c); 9 | pwform.parentNode.removeChild(pwform); 10 | pw = null; 11 | pwform = null; 12 | Pass.onenter(p); 13 | } 14 | function askPass(){ 15 | pwform = document.createElement("div"); 16 | pwform.style = "width: 100%; height: 100%; position: absolute; top: 0; left: 0; background: lightgray; opacity: 0.75;" 17 | document.body.appendChild(pwform); 18 | var d = document.createElement("div"); 19 | d.style = "position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);"; 20 | d.innerHTML = "

Enter password:
" 21 | pw = document.createElement("input"); 22 | pw.setAttribute("type", "password"); 23 | pw.onchange = retPass; 24 | d.appendChild(pw); 25 | pwform.appendChild(d); 26 | } 27 | Pass.get = askPass; 28 | Pass.onenter = onenter; 29 | window.GetPass = Pass; 30 | }()); 31 | -------------------------------------------------------------------------------- /simple_websockets/www/localstore.js: -------------------------------------------------------------------------------- 1 | ;(function () { 'use strict'; 2 | var localCookies = function(){ 3 | function get(nm){ 4 | var name = nm + "="; 5 | var ca = document.cookie.split(';'); 6 | for(var i=0; i < ca.length; i++){ 7 | var c = ca[i]; 8 | while (c.charAt(0)==' ') c = c.substring(1); 9 | if (c.indexOf(name) != -1) 10 | return c.substring(name.length,c.length); 11 | } 12 | return ""; 13 | } 14 | function set(nm, val){ 15 | var date = new Date(); 16 | date.setFullYear(date.getFullYear() + 1); 17 | document.cookie = nm + "=" + val + ";" + "expires=" + date.toUTCString() + ";"; 18 | } 19 | return{ 20 | getItem : get, 21 | setItem : set 22 | }; 23 | }(); 24 | 25 | var stor; 26 | 27 | if(!window.localStorage){ 28 | console.log("No localStorage found, use cookies"); 29 | stor = localCookies; 30 | }else 31 | stor = window.localStorage; 32 | 33 | /* 34 | * Load object nm from local storage 35 | * if it's absent set it to defval or return null if devfal undefined 36 | */ 37 | function LoadObject(nm, defval){ 38 | var val = null; 39 | try{ 40 | var X = stor.getItem(nm); 41 | console.log("get "+nm+", got: "+X); 42 | val = JSON.parse(X); 43 | }catch(e){ 44 | console.log(e); 45 | } 46 | if(val == null && typeof(defval) != "undefined"){ 47 | val = defval; 48 | } 49 | console.log("load: " + nm +" ("+val+")"); 50 | return val; 51 | } 52 | /* 53 | * Save object obj in local storage as nm 54 | */ 55 | function SaveObject(nm, obj){ 56 | stor.setItem(nm, JSON.stringify(obj)); 57 | console.log("save: " + nm +" ("+JSON.stringify(obj)+")"); 58 | } 59 | window.Storage = {}; 60 | window.Storage.load = LoadObject; 61 | window.Storage.save = SaveObject; 62 | }()); 63 | -------------------------------------------------------------------------------- /stellarium_emul/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = stellariumdaemon 2 | #LDFLAGS = -lcrypt -lm 3 | SRCS = $(wildcard *.c) 4 | CC = gcc 5 | DEFINES = -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=1111 -DEBUG 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror -Wextra -Wno-trampolines $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /stellarium_emul/Readme: -------------------------------------------------------------------------------- 1 | Stellarium control of 10-micron mount 2 | -------------------------------------------------------------------------------- /stellarium_emul/cmdlnopts.h: -------------------------------------------------------------------------------- 1 | /* geany_encoding=koi8-r 2 | * cmdlnopts.h - comand line options for parceargs 3 | * 4 | * Copyright 2013 Edward V. Emelianoff 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | 22 | #pragma once 23 | #ifndef __CMDLNOPTS_H__ 24 | #define __CMDLNOPTS_H__ 25 | 26 | #include "parseargs.h" 27 | 28 | /* 29 | * here are some typedef's for global data 30 | */ 31 | typedef struct{ 32 | char *device; // serial device name 33 | char *port; // port to connect 34 | char *pidfile; // name of PID file 35 | char *logfile; // logging to this file 36 | int emulation; // run in emulation mode 37 | int rest_pars_num; // number of rest parameters 38 | char** rest_pars; // the rest parameters: array of char* 39 | } glob_pars; 40 | 41 | 42 | glob_pars *parse_args(int argc, char **argv); 43 | #endif // __CMDLNOPTS_H__ 44 | -------------------------------------------------------------------------------- /stellarium_emul/emulation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * geany_encoding=koi8-r 3 | * emulation.h 4 | * 5 | * Copyright 2018 Edward V. Emelianov 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 20 | * MA 02110-1301, USA. 21 | * 22 | */ 23 | #pragma once 24 | #ifndef __EMULATION_H__ 25 | #define __EMULATION_H__ 26 | 27 | int point_emulation(double ra, double decl); 28 | int get_emul_coords(double *ra, double *decl); 29 | 30 | #endif // __EMULATION_H__ 31 | -------------------------------------------------------------------------------- /stellarium_emul/main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * main.h 3 | * 4 | * Copyright 2014 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #pragma once 22 | #ifndef __MAIN_H__ 23 | #define __MAIN_H__ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "cmdlnopts.h" 37 | #include "usefull_macros.h" 38 | 39 | // global parameters 40 | extern glob_pars *Global_parameters; 41 | 42 | #endif // __MAIN_H__ 43 | -------------------------------------------------------------------------------- /stellarium_emul/parseargs.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/stellarium_emul/parseargs.c -------------------------------------------------------------------------------- /stellarium_emul/telescope.c: -------------------------------------------------------------------------------- 1 | /* 2 | * geany_encoding=koi8-r 3 | * telescope.c 4 | * 5 | * Copyright 2018 Edward V. Emelianov 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 20 | * MA 02110-1301, USA. 21 | * 22 | */ 23 | #include "telescope.h" 24 | #include "usefull_macros.h" 25 | 26 | /** 27 | * connect telescope device 28 | * @param dev (i) - device name to connect 29 | * @return 1 if all OK 30 | */ 31 | int connect_telescope(char *dev){ 32 | DBG("Connect to device %s\n", dev); 33 | putlog("Connect to device %s\n", dev); 34 | /* 35 | * Main code here 36 | */ 37 | return 0; 38 | } 39 | 40 | /** 41 | * send coordinates to telescope 42 | * @param ra - right ascention (hours) 43 | * @param decl - declination (degrees) 44 | * @return 1 if all OK 45 | */ 46 | int point_telescope(double ra, double decl){ 47 | DBG("Send ra=%g, decl=%g", ra, decl); 48 | putlog("Send ra=%g, decl=%g", ra, decl); 49 | /* 50 | * Main code here 51 | */ 52 | return 0; 53 | } 54 | 55 | /** 56 | * get coordinates 57 | * @return 1 if all OK 58 | */ 59 | int get_telescope_coords(double *ra, double *decl){ 60 | (void)ra; 61 | (void)decl; 62 | /* 63 | * Main code here 64 | */ 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /stellarium_emul/telescope.h: -------------------------------------------------------------------------------- 1 | /* 2 | * geany_encoding=koi8-r 3 | * telescope.h 4 | * 5 | * Copyright 2018 Edward V. Emelianov 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 20 | * MA 02110-1301, USA. 21 | * 22 | */ 23 | #pragma once 24 | #ifndef __TELESCOPE_H__ 25 | #define __TELESCOPE_H__ 26 | 27 | int connect_telescope(char *dev); 28 | int point_telescope(double ra, double decl); 29 | int get_telescope_coords(double *ra, double *decl); 30 | 31 | #endif // __TELESCOPE_H__ 32 | -------------------------------------------------------------------------------- /stellarium_emul/usefull_macros.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/stellarium_emul/usefull_macros.c -------------------------------------------------------------------------------- /stringHash4MCU_/Readme: -------------------------------------------------------------------------------- 1 | hashtest.c allows to test different hash functions on your dictionary (test En_words for example) 2 | hashgen.c will generate two files by dictionary: source and header 3 | 4 | another files used for test: use script ./run for it 5 | 6 | Compile: gcc -lusefull_macro file.c -o file 7 | gcc -lusefull_macro test.c hash.c -o test 8 | -------------------------------------------------------------------------------- /stringHash4MCU_/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | gcc hashgen.c -o hashgen -lusefull_macros 4 | ./hashgen -d testdic -H hdr.h -S hdr.c -F 5 | gcc hdr.c test.c strfunc.c -o test 6 | ./test "time 54 = some" 7 | ./test "voltage12 more" 8 | ./test "esw45 = some text" 9 | ./test "goto 55 = " 10 | ./test "stop 3256" 11 | -------------------------------------------------------------------------------- /stringHash4MCU_/strfunc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | void hexdump(int (*sendfun)(const char *s), uint8_t *arr, uint16_t len); 7 | char *u2str(uint32_t val); 8 | char *i2str(int32_t i); 9 | char *uhex2str(uint32_t val); 10 | const char *getnum(const char *txt, uint32_t *N); 11 | const char *omit_spaces(const char *buf); 12 | const char *getint(const char *txt, int32_t *I); 13 | //void mymemcpy(char *dest, const char *src, int len); 14 | -------------------------------------------------------------------------------- /stringHash4MCU_/testdic: -------------------------------------------------------------------------------- 1 | pos 2 | temp 3 | voltage 4 | time 5 | reboot 6 | stop 7 | goto 8 | esw 9 | -------------------------------------------------------------------------------- /table_sincos/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = gentab 2 | LDFLAGS = -lm 3 | SRCS = gentab.c 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=1111 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror -Wextra $(DEFINES) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /table_sincos/README: -------------------------------------------------------------------------------- 1 | Generate table and functions for calculation of sin and cos on MCU (in integers) 2 | 3 | compile: make 4 | defines: 5 | -DMAX_LEN=val - maximal length of generated array (128 by default) 6 | -DDATATYPE=\"type\" - type of data (\"int32_t\" by default) 7 | 8 | 9 | run: 10 | gentab number 11 | where 'number' is desired precision - step of sin/cos (for example, 0.001) 12 | sin is integer, for "1" if precision is 0.001 would be 1000 13 | 14 | -------------------------------------------------------------------------------- /table_sincos/sqrt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sqrt.c - Newton sqrt 3 | * 4 | * Copyright 2016 Edward V. Emelianov 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | #define _XOPEN_SOURCE 1111 22 | #include 23 | #include 24 | #include 25 | 26 | float SQRT(float x, int iter){ 27 | float Result; 28 | int i = 0; 29 | Result = x; 30 | for (i; i < iter; i++) 31 | Result = (Result + x / Result) / 2; 32 | return Result; 33 | } 34 | 35 | int main(int argc, char **argv){ 36 | if(argc != 2) return 1; 37 | float x = strtof(argv[1], NULL); 38 | if(x < 0) return 2; 39 | printf("sqr(%f) = %f, by 6iter: %f, by 8iter: %f, by 16iter: %f\n", x, sqrtf(x), 40 | SQRT(x, 6), SQRT(x, 8), SQRT(x, 16)); 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /thread_array_management/Makefile: -------------------------------------------------------------------------------- 1 | # run `make DEF=...` to add extra defines 2 | PROGRAM := array 3 | LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all 4 | LDFLAGS += -lreadline -lusefull_macros -pthread 5 | SRCS := $(wildcard *.c) 6 | DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 7 | OBJDIR := mk 8 | CFLAGS += -O2 -Wno-trampolines -std=gnu99 9 | OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) 10 | DEPS := $(OBJS:.o=.d) 11 | CC = gcc 12 | #CXX = g++ 13 | 14 | 15 | all : $(OBJDIR) $(PROGRAM) 16 | 17 | debug: CFLAGS += -DEBUG -Werror -Wall -Wextra 18 | debug: all 19 | 20 | $(PROGRAM) : $(OBJS) 21 | @echo -e "\t\tLD $(PROGRAM)" 22 | $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) 23 | 24 | $(OBJDIR): 25 | mkdir $(OBJDIR) 26 | 27 | ifneq ($(MAKECMDGOALS),clean) 28 | -include $(DEPS) 29 | endif 30 | 31 | $(OBJDIR)/%.o: %.c 32 | @echo -e "\t\tCC $<" 33 | $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< 34 | 35 | clean: 36 | @echo -e "\t\tCLEAN" 37 | @rm -f $(OBJS) $(DEPS) 38 | @rmdir $(OBJDIR) 2>/dev/null || true 39 | 40 | xclean: clean 41 | @rm -f $(PROGRAM) 42 | 43 | .PHONY: clean xclean 44 | -------------------------------------------------------------------------------- /thread_array_management/Readme: -------------------------------------------------------------------------------- 1 | Work with named threads list, communicate by FIFO messages 2 | -------------------------------------------------------------------------------- /usb_reset/reset.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/usb_reset/reset.c -------------------------------------------------------------------------------- /usefull_macros.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/usefull_macros.c -------------------------------------------------------------------------------- /websockets/Makefile: -------------------------------------------------------------------------------- 1 | PROGRAM = websocktest 2 | LDFLAGS = $(shell pkg-config --libs libwebsockets) -lpthread 3 | SRCS = test.c 4 | CC = gcc 5 | DEFINES = -D_XOPEN_SOURCE=501 -DCUR_PATH=\"$(shell pwd)\" 6 | CXX = gcc 7 | CFLAGS = -Wall -Werror -Wextra $(DEFINES) $(shell pkg-config --cflags libwebsockets) 8 | OBJS = $(SRCS:.c=.o) 9 | all : $(PROGRAM) clean 10 | $(PROGRAM) : $(OBJS) 11 | $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) 12 | 13 | # some addition dependencies 14 | # %.o: %.c 15 | # $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 16 | #$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS) 17 | # @touch $@ 18 | 19 | clean: 20 | /bin/rm -f *.o *~ 21 | depend: 22 | $(CXX) -MM $(CXX.SRCS) 23 | -------------------------------------------------------------------------------- /websockets/leaf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/websockets/leaf.jpg -------------------------------------------------------------------------------- /websockets/leaf1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eddyem/eddys_snippets/01abbf4a252e85af99df24ca01b7f7ab612ee245/websockets/leaf1.jpg -------------------------------------------------------------------------------- /websockets/testlog2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static inline uint32_t log_2(const uint32_t x){ 5 | if(x == 0) return 0; 6 | return (31 - __builtin_clz (x)); 7 | } 8 | 9 | int main(){ 10 | uint32_t i; 11 | for(i = 0; i < 150; i++){ 12 | printf("log2(%u) = %u\n", i, log_2(i)); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /xor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void xor(char *buf, char *pattern, size_t l){ 10 | size_t i; 11 | for(i = 0; i < l; ++i) 12 | printf("%c", buf[i] ^ pattern[i]); 13 | } 14 | 15 | int main(int argc, char **argv){ 16 | if(argc != 3){ 17 | printf("Usage: %s \n", argv[0]); 18 | return -1; 19 | } 20 | char *key = strdup(argv[2]); 21 | size_t n = 0, keylen = strlen(key); 22 | char *buff = malloc(keylen); 23 | int f = open(argv[1], O_RDONLY); 24 | if(f < 0){ 25 | perror("Can't open file"); 26 | return f; 27 | } 28 | do{ 29 | n = read(f, buff, keylen); 30 | xor(buff, key, n); 31 | }while(n); 32 | return 0; 33 | } 34 | --------------------------------------------------------------------------------