Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit 55321b8

Browse files
committed
Initial commit
0 parents  commit 55321b8

7 files changed

Lines changed: 210 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build
2+
on:
3+
- push
4+
- pull_request
5+
6+
env:
7+
GOVER: ^1.20
8+
NAME: simpleudpdebugreader
9+
10+
jobs:
11+
build:
12+
name: build
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
GOOS: [ windows, linux, darwin ]
17+
GOARCH: [ amd64, 386, arm, arm64 ]
18+
exclude:
19+
- GOOS: windows
20+
GOARCH: arm
21+
- GOOS: darwin
22+
GOARCH: 386
23+
- GOOS: darwin
24+
GOARCH: arm
25+
26+
steps:
27+
- name: Checkout repo
28+
uses: actions/checkout@v3
29+
30+
- name: Cache
31+
uses: actions/cache@v2
32+
with:
33+
path: |
34+
~/.cache/go-build
35+
~/go/pkg/mod
36+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
37+
restore-keys: |
38+
${{ runner.os }}-go-
39+
40+
- name: Setup Go
41+
uses: actions/setup-go@v2
42+
with:
43+
go-version: ${{ env.GOVER }}
44+
45+
- name: Build
46+
env:
47+
GOOS: ${{ matrix.GOOS }}
48+
GOARCH: ${{ matrix.GOARCH }}
49+
run: go build -ldflags="-s -w" -o dist/$NAME-$GOOS-$GOARCH
50+
51+
- name: Rename binaries (Windows)
52+
if: matrix.GOOS == 'windows'
53+
run: for x in dist/$NAME-windows-*; do mv $x $x.exe; done
54+
55+
- name: Upload binary
56+
uses: actions/upload-artifact@v3
57+
with:
58+
name: ${{env.NAME}}-${{ matrix.GOOS }}-${{ matrix.GOARCH }}-${{github.sha}}
59+
path: dist/*
60+
retention-days: 90
61+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
*.iml
3+
GeckoLog.txt

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Simple UDP Debug Reader
2+
3+
Simple UDP Debug Reader for Wii U homebrew and plugin development. *99% coded with GPT-4!*
4+
5+
## Used prompt
6+
7+
**System**: You are a sophisticated, accurate, and modern AI programming assistant
8+
9+
**User**: How would I write a Go program that receives data sent by another device on the same network over UDP
10+
broadcast? Port is 4405 and buffer size is 4096. It should show the output in the terminal and log it into a file
11+
named "GeckoLog.txt". The program should also quit when the user presses "q" and clear the console if "c" is pressed.
12+
They keys should be detected without needing to press the return key.

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/WiiDatabase/SimpleUdpDebugReader
2+
3+
go 1.20
4+
5+
require github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203
6+
7+
require golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 h1:XBBHcIb256gUJtLmY22n99HaZTz+r2Z51xUPi01m3wg=
2+
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203/go.mod h1:E1jcSv8FaEny+OP/5k9UxZVw9YFWGj7eI4KR/iOBqCg=
3+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
4+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

main.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net"
7+
"os"
8+
"os/signal"
9+
"syscall"
10+
"time"
11+
12+
"github.com/eiannone/keyboard"
13+
)
14+
15+
const (
16+
address = "0.0.0.0:4405"
17+
bufferSize = 4096
18+
logFile = "GeckoLog.txt"
19+
)
20+
21+
func main() {
22+
// Open log file
23+
logFile, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
24+
if err != nil {
25+
log.Fatalf("Error opening log file: %v", err)
26+
}
27+
defer logFile.Close()
28+
29+
// Setup UDP connection
30+
conn, err := net.ListenPacket("udp4", address)
31+
if err != nil {
32+
log.Fatalf("Error setting up UDP connection: %v", err)
33+
}
34+
defer conn.Close()
35+
36+
// Create channel to control goroutines
37+
done := make(chan bool)
38+
39+
fmt.Println("Welcome to Simple UDP Debug Reader!")
40+
fmt.Println("")
41+
fmt.Println("Log is automatically saved to \"GeckoLog.txt\"")
42+
fmt.Println("c - Clear console")
43+
fmt.Println("q - Exit")
44+
fmt.Println("")
45+
46+
// Handle incoming packets
47+
go func() {
48+
buf := make([]byte, bufferSize)
49+
for {
50+
n, _, err := conn.ReadFrom(buf)
51+
if err != nil {
52+
log.Printf("Error reading from UDP: %v", err)
53+
continue
54+
}
55+
56+
data := buf[:n]
57+
msg := fmt.Sprintf("[%s] %s\n", time.Now().Format(time.RFC3339), string(data))
58+
fmt.Print(msg)
59+
60+
if _, err := logFile.WriteString(msg); err != nil {
61+
log.Printf("Error writing to log file: %v", err)
62+
}
63+
}
64+
}()
65+
66+
// Handle keyboard input
67+
go func() {
68+
if err := keyboard.Open(); err != nil {
69+
log.Fatalf("Error opening keyboard: %v", err)
70+
}
71+
defer keyboard.Close()
72+
73+
for {
74+
char, key, err := keyboard.GetKey()
75+
if err != nil {
76+
log.Printf("Error reading keyboard input: %v", err)
77+
continue
78+
}
79+
80+
if key == keyboard.KeyCtrlC || char == 'q' {
81+
done <- true
82+
break
83+
} else if char == 'c' {
84+
print("\033[H\033[2J")
85+
}
86+
}
87+
}()
88+
89+
// Wait for exit signal
90+
sig := make(chan os.Signal, 1)
91+
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
92+
93+
select {
94+
case <-sig:
95+
case <-done:
96+
}
97+
98+
fmt.Println("Exiting...")
99+
}

0 commit comments

Comments
 (0)