Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
- name: setup
run: sudo apt-get update && sudo apt-get -f install socat cppcheck clang-format-19 valgrind
- name: build
Expand All @@ -26,7 +26,7 @@ jobs:
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
- name: build
shell: cmd
run: |
Expand All @@ -35,7 +35,7 @@ jobs:
macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
- name: setup
run: brew install socat
- name: build
Expand Down
13 changes: 11 additions & 2 deletions simple_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,10 @@ static bool readfile(const char *dir, const char *filename, char *result, size_t
result[0] = '\0';
if ((fp = fopen(path, "rb")) != NULL) {
len = fread(result, 1, max_result_len - 1, fp);
if (len) {
result[len - 1] = '\0';
if (len > 0) {
while (isspace(result[len - 1]))
len--;
result[len] = '\0';
}
fclose(fp);
}
Expand Down Expand Up @@ -746,6 +748,13 @@ int simple_uart_describe(const char *uart, char *description, size_t max_desc_le
if (readfile(basePath, "serial", chrBuf, sizeof(chrBuf))) {
snprintf(description + strlen(description), max_desc_len - strlen(description), "serial=%s,", chrBuf);
}

// These only work on /dev/ttySx style UARTs
snprintf(unresolvedPath, sizeof(unresolvedPath), "/sys/class/tty/%s", basename((char *)uart));
if (readfile(unresolvedPath, "port", chrBuf, sizeof(chrBuf))) {
snprintf(description + strlen(description), max_desc_len - strlen(description), "port=%s,", chrBuf);
}

// MacOS
#else // Volunteers for MacOS wanted

Expand Down
7 changes: 6 additions & 1 deletion simple_uart_term.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <termios.h>
#include <unistd.h>
Expand All @@ -27,9 +28,13 @@ int main(int argc, char *argv[])
case 'l': {
char **names;
ssize_t nuarts = simple_uart_list(&names);
char description[256] = {0};
printf("Found %zd ports\n", nuarts);
for (ssize_t i = 0; i < nuarts; i++) {
printf("Port %zd: %s\n", i, names[i]);
printf("Port %zd: %s", i, names[i]);
if (simple_uart_describe(names[i], description, sizeof(description)) == 0 && strlen(description) > 0)
printf(" Description: %s", description);
printf("\n");
}

for (ssize_t i = 0; i < nuarts; i++) {
Expand Down
26 changes: 26 additions & 0 deletions simple_uart_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,38 @@ void test_logfile(void)
unlink(logfile);
}

void test_list(void)
{
// Describe only works on Linux/Windows
#if defined(__linux__) || defined(_WIN32)
char **names = NULL;
ssize_t count;

count = simple_uart_list(&names);

/* We assume the test machine has at least one serial port */
TEST_ASSERT(count > 0);
TEST_ASSERT(names != NULL);

for (ssize_t i = 0; i < count; i++) {
char description[256];
TEST_ASSERT(names[i] != NULL);
TEST_ASSERT(strlen(names[i]) > 0);
TEST_ASSERT(simple_uart_describe(names[i], description, sizeof(description)) == 0);
TEST_ASSERT(strlen(description) > 0);
free(names[i]);
}
free(names);
#endif
}

TEST_LIST = {
{"open", test_open},
{"loopback", test_loopback},
{"loopback_random", test_loopback_random},
{"read_line", test_read_line},
{"read_timeout", test_read_timeout},
{"logfile", test_logfile},
{"list", test_list},
{NULL, NULL},
};