-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
105 lines (90 loc) · 1.98 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"bufio"
"fmt"
"go.bug.st/serial"
"log"
"lora-project/protocol/messages"
"lora-project/protocol/routing"
"lora-project/serial_handlers"
"os"
)
func main() {
/* rand.Seed(time.Now().UnixNano())
app := &cli.App{
Name: "boom",
Usage: "make an explosive entrance",
Action: func(*cli.Context) error {
fmt.Println("boom! I say!")
return nil
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
mode := &serial.Mode{
BaudRate: 115200,
}
port, err := serial.Open("/home/Hannes/dev/ttyS21", mode)
if err != nil {
log.Fatal(err)
}
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
go func() {
<-sig
fmt.Println("Interrupt signal received, closing serial port...")
port.Close()
os.Exit(0)
}()
write(port)
scanner := bufio.NewScanner(port)
for scanner.Scan() {
line := scanner.Text()
fmt.Println("received: " + line)
write(port)
}*/
mode := &serial.Mode{
BaudRate: 115200,
}
port, err := serial.Open("/dev/ttyUSB0", mode)
defer func(port serial.Port) {
err := port.Close()
if err != nil {
}
}(port)
if err != nil {
log.Fatal(err)
}
handler := serial_handlers.NewATHandler(port)
aodv := routing.NewAODV(handler)
aodv.Run()
go func() {
for data := range aodv.IncomingDataQueue {
fmt.Printf("Received message: %s from %s\n", string(data.Payload), data.OriginatorAddress.String())
}
}()
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Print("Enter destination address: ")
scanned := scanner.Scan()
if !scanned {
fmt.Println("Failed to scan address!")
return
}
destination := scanner.Text()
var address messages.Address
if address.UnmarshalText([]byte(destination)) != nil {
fmt.Println("Invalid address..")
continue
}
fmt.Print("Enter message: ")
scanned = scanner.Scan()
if !scanned {
fmt.Println("Failed to scan message!")
return
}
message := scanner.Text()
aodv.SendData(message, address)
}
}