-
Notifications
You must be signed in to change notification settings - Fork 0
Full refactor, to many changes, to lazy to write commit messages #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0f1a9b4
2902360
44c7b3f
c750504
50a8305
e7869b7
82dfbeb
9486593
1a4c0a2
477b638
6cad070
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
BasedOnStyle: LLVM | ||
IndentWidth: 4 | ||
ColumnLimit: 140 | ||
TabWidth: 4 | ||
Katze719 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
UseTab: Never | ||
BreakBeforeBraces: Allman | ||
AllowShortFunctionsOnASingleLine: Empty | ||
PointerAlignment: Left | ||
DerivePointerAlignment: false | ||
SpaceBeforeParens: ControlStatements | ||
SortIncludes: true | ||
IncludeBlocks: Regroup | ||
ReflowComments: true | ||
ContinuationIndentWidth: 4 | ||
BinPackParameters: false | ||
BinPackArguments: false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Checks: > | ||
-*, | ||
readability-* , | ||
modernize-* , | ||
-modernize-use-trailing-return-type, | ||
-readability-magic-numbers, | ||
|
||
WarningsAsErrors: > | ||
bugprone-* , | ||
performance-* , | ||
clang-analyzer-* | ||
|
||
HeaderFilterRegex: 'src/.*' | ||
Katze719 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FormatStyle: file | ||
|
||
CheckOptions: | ||
- key: modernize-use-auto.MinTypeNameLength | ||
value: '5' | ||
- key: modernize-use-auto.RemoveStars | ||
value: 'false' | ||
- key: readability-identifier-naming.VariableCase | ||
value: lower_case | ||
- key: readability-identifier-naming.MemberCase | ||
value: lower_case | ||
- key: readability-identifier-naming.PrivateMemberPrefix | ||
value: '_' | ||
- key: readability-function-size.ParameterThreshold | ||
value: '8' | ||
- key: readability-braces-around-statements.ShortStatementLines | ||
value: '0' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM fedora:42 | ||
|
||
RUN dnf install -y \ | ||
clang \ | ||
clang-tools-extra \ | ||
clangd \ | ||
clang-format \ | ||
clang-tidy \ | ||
clang-analyzer \ | ||
cmake \ | ||
git \ | ||
ninja-build \ | ||
&& dnf clean all |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"build": { | ||
"dockerfile": "./Dockerfile.dev" | ||
}, | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"mhutchie.git-graph", | ||
"ms-azuretools.vscode-docker", | ||
"vivaxy.vscode-conventional-commits", | ||
"github.vscode-github-actions", | ||
"llvm-vs-code-extensions.vscode-clangd", | ||
"ms-vscode.cmake-tools" | ||
] | ||
} | ||
}, | ||
"runArgs": [ | ||
"--network", | ||
"host", | ||
"--privileged", | ||
"--device", | ||
"/dev/bus/usb:/dev/bus/usb", | ||
"--device-cgroup-rule=c 188:* rwm", | ||
"--device-cgroup-rule=c 166:* rwm", | ||
"--group-add=dialout", | ||
"--volume=/dev/serial/by-id:/dev/serial/by-id:ro" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Build & Release CPP-Unix-Bindings | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "**" ] | ||
release: | ||
types: [ created ] | ||
|
||
jobs: | ||
build: | ||
name: Build shared library | ||
runs-on: ubuntu-latest | ||
env: | ||
CC: clang | ||
CXX: clang++ | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install build dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y build-essential cmake clang make | ||
|
||
- name: Configure CMake | ||
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release | ||
|
||
- name: Compile | ||
run: cmake --build build -j $(nproc) | ||
|
||
- name: Upload library artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: libCPP-Unix-Bindings | ||
path: build/libCPP-Unix-Bindings.so | ||
retention-days: 14 | ||
|
||
- name: Attach library to release | ||
if: github.event_name == 'release' | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: build/libCPP-Unix-Bindings.so |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vscode/ | ||
build/ | ||
src/version_config.cpp | ||
.cache/ | ||
.cache/ | ||
compile_commands.json |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1 +1,79 @@ | ||||||
# Serial | ||||||
# CPP-Unix-Bindings | ||||||
|
||||||
A compact C++23 library for talking to serial devices on Linux (e.g. Arduino). | ||||||
Katze719 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
The project builds a **shared library `libCPP-Unix-Bindings.so`** that can be used via | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer the following name:
Suggested change
Maybe we should rename all repositories to be snake_case... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renaming is done in #2, and will be linux conform |
||||||
Deno's native FFI. | ||||||
|
||||||
--- | ||||||
|
||||||
## 1 Building the library | ||||||
|
||||||
```bash | ||||||
# Clone | ||||||
git clone https://github.com/Serial-IO/cpp-bindings-unix.git cpp-bindings-unix | ||||||
cd cpp-bindings-unix | ||||||
|
||||||
# Dependencies (Debian/Ubuntu) | ||||||
sudo apt-get install build-essential cmake clang make | ||||||
|
||||||
# Compile | ||||||
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release | ||||||
cmake --build build -j | ||||||
|
||||||
# The resulting library will be located at | ||||||
# build/libCPP-Unix-Bindings.so | ||||||
Katze719 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
``` | ||||||
|
||||||
> Because `CMAKE_EXPORT_COMPILE_COMMANDS` is enabled, the build also generates a | ||||||
> `compile_commands.json` that is automatically copied to the project root — | ||||||
> handy for clang-tools (clangd, clang-tidy, …). | ||||||
|
||||||
--- | ||||||
|
||||||
## 2 Using the library from **Deno** (v1.42 or newer) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Deno ships with a first-class FFI API. | ||||||
|
||||||
```ts | ||||||
// serial_deno.ts | ||||||
const lib = Deno.dlopen('./build/libCPP-Unix-Bindings.so', { | ||||||
serialOpen: { parameters: [ 'buffer', 'i32', 'i32', 'i32', 'i32' ], result: 'pointer' }, | ||||||
serialClose: { parameters: [ 'pointer' ], result: 'void' }, | ||||||
serialRead: { parameters: [ 'pointer', 'buffer', 'i32', 'i32', 'i32' ], result: 'i32' }, | ||||||
serialWrite: { parameters: [ 'pointer', 'buffer', 'i32', 'i32', 'i32' ], result: 'i32' }, | ||||||
}); | ||||||
|
||||||
const enc = new TextEncoder(); | ||||||
const dec = new TextDecoder(); | ||||||
|
||||||
// Note: device path must be null-terminated | ||||||
const handle = lib.symbols.serialOpen(enc.encode('/dev/ttyUSB0\0'), 115200, 8, 0, 0); | ||||||
|
||||||
const writeBuf = enc.encode('Hello\n'); | ||||||
lib.symbols.serialWrite(handle, writeBuf, writeBuf.length, 100, 1); | ||||||
|
||||||
const readBuf = new Uint8Array(128); | ||||||
const n = lib.symbols.serialRead(handle, readBuf, readBuf.length, 500, 1); | ||||||
console.log(dec.decode(readBuf.subarray(0, n))); | ||||||
|
||||||
lib.symbols.serialClose(handle); | ||||||
lib.close(); | ||||||
``` | ||||||
|
||||||
--- | ||||||
|
||||||
## 3 C API reference | ||||||
|
||||||
| Function | Description | | ||||||
|----------|-------------| | ||||||
| `intptr_t serialOpen(const char* dev, int baud, int bits, int parity, int stop)` | Open a device and return a handle. | | ||||||
| `void serialClose(intptr_t handle)` | Close the port. | | ||||||
| `int serialRead(...)` | Read bytes with timeout. | | ||||||
| `int serialWrite(...)` | Write bytes with timeout. | | ||||||
| `int serialGetPortsInfo(char* buffer, int len, const char* sep)` | List ports under `/dev/serial/by-id`. | | ||||||
| `void serialOnError(void (*)(int))` | Register an error callback. | | ||||||
| *(others in `serial.h`)* | | ||||||
|
||||||
Return values ≤ 0 indicate error codes defined in `status_codes.h`. | ||||||
|
||||||
--- |
Uh oh!
There was an error while loading. Please reload this page.