Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blocktrron committed Aug 16, 2024
0 parents commit 47fcf7b
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build App

on:
push:
pull_request:

env:
COMPILER_VERSION: arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download Toolchain
run: wget -O /tmp/toolchain.tar.xz https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu/13.3.rel1/binrel/${{ env.COMPILER_VERSION }}.tar.xz

- name: Extract Toolchain
run: tar -xf /tmp/toolchain.tar.xz -C /tmp

- name: Compile App
run: make CROSS_COMPILE=/tmp/${{ env.COMPILER_VERSION }}/bin/arm-none-linux-gnueabihf-

- name: Upload Build output
uses: actions/upload-artifact@v4
with:
name: build-output
path: output/

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
if: github.event_name == 'push' && github.ref_type == 'tag'
with:
body: "Version ${{ github.ref_name }}"
files: |
output/*
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode/
output/
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CROSS_COMPILE ?=
GCC ?= $(CROSS_COMPILE)gcc
STRIP ?= $(CROSS_COMPILE)strip

# Take git short-hash as version
VERSION ?= $(shell git rev-parse --short HEAD)

# Flags
CFLAGS = --static -O2 -DVERSION=\"$(VERSION)\"

all:
mkdir -p output
$(GCC) $(CFLAGS) -o output/t5g-at t5g.c
$(STRIP) output/t5g-at
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# t5g-at-interface

Quick and dirty programm for interfacing with the Modem AT Command interface on the host system of a Telekom 5G Empfänger SE.

## TL;DR

ToDo

## How to compile

```bash
wget -O /tmp/toolchain.tar.xz https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz
tar -xf /tmp/toolchain.tar.xz -C /tmp
make CROSS_COMPILE=/tmp/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-
```

## How to use

```bash
./t5g-at-interface
```
98 changes: 98 additions & 0 deletions t5g.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <errno.h>

#define AT_COMMAND_FILE "/dev/smd7"

int open_file(char *filename, int mode) {
int file = open(filename, mode);
if (file < 0) {
printf("Error: Could not open file %s\n", filename);
return file;
}
return file;
}

int main(int argc, char *argv[]) {
char *file_path = NULL;
int file_in = 0, file_out = 0;
int ret = 0;
int i;
int n;

file_path = AT_COMMAND_FILE;
if (argc == 2) {
file_path = argv[1];
}

/* Set stdin non-blocking */
int flags = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);

/* Open /dev/smd7 */
file_in = open_file(file_path, O_RDONLY);
if (file_in < 0) {
fprintf(stderr, "Error: Could not open AT command file\n");
ret = 1;
goto out_free;
}
flags = fcntl(file_in, F_GETFL, 0);
fcntl(file_in, F_SETFL, flags | O_NONBLOCK);

file_out = open_file(file_path, O_WRONLY);
if (file_out < 0) {
fprintf(stderr, "Error: Could not open AT command file\n");
ret = 1;
goto out_free;
}

while (1) {
char buf[1024];

/* Read non-blocking from file */
n = read(file_in, buf, sizeof(buf));
if (n < 0 && errno != EAGAIN) {
ret = 1;
fprintf(stderr, "Error: Could not read from AT command file\n");
goto out_free;
} else if (n > 0) {
buf[n] = '\0';
fprintf(stdout, "%s", buf);
}

/* Read non-blocking from stdin */
n = read(STDIN_FILENO, buf, sizeof(buf));
if (n < 0) {
if (errno == EAGAIN)
continue;
ret = 1;
fprintf(stderr, "Error: Could not read from AT command file\n");
goto out_free;
}

/* Print all character codes */
buf[n - 1] = '\r';
buf[n] = '\n';

//printf("Writing %d bytes to file\n", n);
if (write(file_out, buf, n + 1) != n + 1) {
fprintf(stderr, "Error: Could not write to AT command file\n");
ret = 1;
goto out_free;
}
}

out_free:
if (file_in > 0) {
close(file_in);
}

if (file_out > 0) {
close(file_out);
}
return 0;
}

0 comments on commit 47fcf7b

Please sign in to comment.