From 848fc4010b60bd970266e7f2293ac02490f28927 Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Thu, 13 Apr 2023 18:45:10 +0200 Subject: [PATCH] examples: relocating --- CMakeLists.txt | 36 --------------- examples/recv-with-ack.c | 92 ------------------------------------- examples/send-with-ack.c | 82 --------------------------------- examples/standalone/CMakeLists.txt | 36 +++++++++++++++ examples/standalone/recv-with-ack.c | 92 +++++++++++++++++++++++++++++++++++++ examples/standalone/send-with-ack.c | 82 +++++++++++++++++++++++++++++++++ 6 files changed, 210 insertions(+), 210 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 examples/recv-with-ack.c delete mode 100644 examples/send-with-ack.c create mode 100644 examples/standalone/CMakeLists.txt create mode 100644 examples/standalone/recv-with-ack.c create mode 100644 examples/standalone/send-with-ack.c diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 4f446fc..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required(VERSION 3.5) -project(si24 - VERSION 0.30.0 - LANGUAGES C -) -set(PROJECT_DESCRIPTION "si24r1 library") -set(PROJECT_HOMEPAGE_URL https://github.com/robinkrens/libsi24) - -add_compile_options(-Wall -Wextra -pedantic) - -add_library(si24 libsi24.c) - -target_include_directories(si24 - PUBLIC - $ - $ - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} -) - -include(GNUInstallDirs) - -install(TARGETS si24 - EXPORT libsi24-export - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) -install(FILES libsi24.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} -) -install(EXPORT libsi24-export - FILE libsi24.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libsi24 -) - -include(CPack) diff --git a/examples/recv-with-ack.c b/examples/recv-with-ack.c deleted file mode 100644 index 857a5ab..0000000 --- a/examples/recv-with-ack.c +++ /dev/null @@ -1,92 +0,0 @@ -/** - * File : recv-with-ack.c - * Author : Robin Krens - * Date : 23.01.2023 - * Last Modified Date: 23.01.2023 - * Last Modified By : Robin Krens - */ -#include -#include -#include -#include -#include - -#include "libsi24.h" - -#define MSG_SIZE 32 - -int example_spi_write_read(unsigned char* data, size_t sz) -{ - (void)data; - (void)sz; - return 0; -} - -void example_ce(unsigned val) -{ - (void)val; -} - -void example_event_handler(si24_t* si, si24_event_t* e) -{ - (void)si; - - switch (e->type) { - case EV_RX_COMPLETE: - break; - case EV_TX_COMPLETE: - break; - case EV_TX_FULL: - break; - case EV_RX_EMPTY: - break; - case EV_ERR_TIMEOUT: - break; - case EV_ERR_BUS: - break; - case EV_ERR_MAX_RETRIES: - break; - case EV_ERR_CRC: - break; - case EV_ERR_CONFIG: - break; - default: - break; - } -} - -int main(void) -{ - unsigned char recv_buf[MSG_SIZE]; - - si24_ioctl_t ctl = { - .write_and_read = example_spi_write_read, - .chip_enable = example_ce, - }; - - const si24_opts_t opts = { - .mode = RECV_MODE, - .enable_ack = 1, - .non_blocking = 0, - .enable_crc = 1, - .enable_dynpd = 1, - .crc = TWO_BYTE, - .ioctl = &ctl, - .speed = MBPS2, - .txpwr = PLUS4DB, - .payload = 5, - .timeout = 1, - .retries = 5, - .mac_addr = { 0xAB, 0xCD, 0xEF, 0xFF, 0xFF } - }; - - struct si24_t* si = si24_init(&opts, example_event_handler); - - while (1) { - int read = si24_recv(si, recv_buf, 32); - for (int i = 0; i < read; ++i) { - printf("%c", recv_buf[i]); - } - sleep(1); - } -} diff --git a/examples/send-with-ack.c b/examples/send-with-ack.c deleted file mode 100644 index c3ad53f..0000000 --- a/examples/send-with-ack.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include -#include -#include - -#include "libsi24.h" - -int example_spi_write_read(unsigned char* data, size_t sz) -{ - (void)data; - (void)sz; - return 0; -} - -void example_ce(unsigned val) -{ - (void)val; -} - -void example_event_handler(si24_t* si, si24_event_t* e) -{ - (void)si; - - switch (e->type) { - case EV_RX_COMPLETE: - break; - case EV_TX_COMPLETE: - break; - case EV_TX_FULL: - break; - case EV_RX_EMPTY: - break; - case EV_ERR_TIMEOUT: - break; - case EV_ERR_BUS: - break; - case EV_ERR_MAX_RETRIES: - break; - case EV_ERR_CRC: - break; - case EV_ERR_CONFIG: - break; - default: - break; - } -} - -int main(void) -{ - const unsigned char buf[] = "SAMPLE TEST MESSAGE!"; - - si24_ioctl_t ctl = { - .write_and_read = example_spi_write_read, - .chip_enable = example_ce, - }; - - const si24_opts_t opts = { - .mode = SEND_MODE, - .enable_ack = 1, - .non_blocking = 0, - .enable_crc = 1, - .enable_dynpd = 1, - .crc = TWO_BYTE, - .ioctl = &ctl, - .speed = MBPS2, - .txpwr = PLUS4DB, - .payload = 5, - .timeout = 5, - .retries = 5, - .mac_addr = { 0xAB, 0xCD, 0xEF, 0xFF, 0xFF } - }; - - struct si24_t* si = si24_init(&opts, example_event_handler); - - int bytes_sent = si24_send(si, buf, sizeof(buf)); - while (bytes_sent != sizeof(buf)) { - if (bytes_sent == -1) - break; - bytes_sent += si24_send(si, buf + bytes_sent, sizeof(buf) - bytes_sent); - } -} diff --git a/examples/standalone/CMakeLists.txt b/examples/standalone/CMakeLists.txt new file mode 100644 index 0000000..4f446fc --- /dev/null +++ b/examples/standalone/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.5) +project(si24 + VERSION 0.30.0 + LANGUAGES C +) +set(PROJECT_DESCRIPTION "si24r1 library") +set(PROJECT_HOMEPAGE_URL https://github.com/robinkrens/libsi24) + +add_compile_options(-Wall -Wextra -pedantic) + +add_library(si24 libsi24.c) + +target_include_directories(si24 + PUBLIC + $ + $ + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +include(GNUInstallDirs) + +install(TARGETS si24 + EXPORT libsi24-export + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) +install(FILES libsi24.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +install(EXPORT libsi24-export + FILE libsi24.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libsi24 +) + +include(CPack) diff --git a/examples/standalone/recv-with-ack.c b/examples/standalone/recv-with-ack.c new file mode 100644 index 0000000..857a5ab --- /dev/null +++ b/examples/standalone/recv-with-ack.c @@ -0,0 +1,92 @@ +/** + * File : recv-with-ack.c + * Author : Robin Krens + * Date : 23.01.2023 + * Last Modified Date: 23.01.2023 + * Last Modified By : Robin Krens + */ +#include +#include +#include +#include +#include + +#include "libsi24.h" + +#define MSG_SIZE 32 + +int example_spi_write_read(unsigned char* data, size_t sz) +{ + (void)data; + (void)sz; + return 0; +} + +void example_ce(unsigned val) +{ + (void)val; +} + +void example_event_handler(si24_t* si, si24_event_t* e) +{ + (void)si; + + switch (e->type) { + case EV_RX_COMPLETE: + break; + case EV_TX_COMPLETE: + break; + case EV_TX_FULL: + break; + case EV_RX_EMPTY: + break; + case EV_ERR_TIMEOUT: + break; + case EV_ERR_BUS: + break; + case EV_ERR_MAX_RETRIES: + break; + case EV_ERR_CRC: + break; + case EV_ERR_CONFIG: + break; + default: + break; + } +} + +int main(void) +{ + unsigned char recv_buf[MSG_SIZE]; + + si24_ioctl_t ctl = { + .write_and_read = example_spi_write_read, + .chip_enable = example_ce, + }; + + const si24_opts_t opts = { + .mode = RECV_MODE, + .enable_ack = 1, + .non_blocking = 0, + .enable_crc = 1, + .enable_dynpd = 1, + .crc = TWO_BYTE, + .ioctl = &ctl, + .speed = MBPS2, + .txpwr = PLUS4DB, + .payload = 5, + .timeout = 1, + .retries = 5, + .mac_addr = { 0xAB, 0xCD, 0xEF, 0xFF, 0xFF } + }; + + struct si24_t* si = si24_init(&opts, example_event_handler); + + while (1) { + int read = si24_recv(si, recv_buf, 32); + for (int i = 0; i < read; ++i) { + printf("%c", recv_buf[i]); + } + sleep(1); + } +} diff --git a/examples/standalone/send-with-ack.c b/examples/standalone/send-with-ack.c new file mode 100644 index 0000000..c3ad53f --- /dev/null +++ b/examples/standalone/send-with-ack.c @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include + +#include "libsi24.h" + +int example_spi_write_read(unsigned char* data, size_t sz) +{ + (void)data; + (void)sz; + return 0; +} + +void example_ce(unsigned val) +{ + (void)val; +} + +void example_event_handler(si24_t* si, si24_event_t* e) +{ + (void)si; + + switch (e->type) { + case EV_RX_COMPLETE: + break; + case EV_TX_COMPLETE: + break; + case EV_TX_FULL: + break; + case EV_RX_EMPTY: + break; + case EV_ERR_TIMEOUT: + break; + case EV_ERR_BUS: + break; + case EV_ERR_MAX_RETRIES: + break; + case EV_ERR_CRC: + break; + case EV_ERR_CONFIG: + break; + default: + break; + } +} + +int main(void) +{ + const unsigned char buf[] = "SAMPLE TEST MESSAGE!"; + + si24_ioctl_t ctl = { + .write_and_read = example_spi_write_read, + .chip_enable = example_ce, + }; + + const si24_opts_t opts = { + .mode = SEND_MODE, + .enable_ack = 1, + .non_blocking = 0, + .enable_crc = 1, + .enable_dynpd = 1, + .crc = TWO_BYTE, + .ioctl = &ctl, + .speed = MBPS2, + .txpwr = PLUS4DB, + .payload = 5, + .timeout = 5, + .retries = 5, + .mac_addr = { 0xAB, 0xCD, 0xEF, 0xFF, 0xFF } + }; + + struct si24_t* si = si24_init(&opts, example_event_handler); + + int bytes_sent = si24_send(si, buf, sizeof(buf)); + while (bytes_sent != sizeof(buf)) { + if (bytes_sent == -1) + break; + bytes_sent += si24_send(si, buf + bytes_sent, sizeof(buf) - bytes_sent); + } +} -- 2.7.4