data parser in monitor app
- created code format for sent data - created parser for data - go.mod and go.sum added
This commit is contained in:
parent
193e46bbda
commit
90bde3740b
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,12 +1,3 @@
|
||||
2024*.txt
|
||||
test/*
|
||||
|
||||
serial_read/go.mod
|
||||
|
||||
serial_read/go.sum
|
||||
|
||||
*.exe
|
||||
|
||||
monitor/go.sum
|
||||
|
||||
monitor/go.mod
|
||||
|
||||
48
README.md
48
README.md
@ -2,14 +2,31 @@
|
||||
|
||||
## Installation and compilation
|
||||
|
||||
### Serial monitor tool
|
||||
|
||||
```bash
|
||||
git clone https://www.github.com/foglar/cobraV2.git
|
||||
cd cobraV2/serial_read
|
||||
|
||||
go get "github.com/tarm/serial"
|
||||
|
||||
# Building serial read code yourself
|
||||
go build .
|
||||
```
|
||||
|
||||
### Monitor tool
|
||||
|
||||
```bash
|
||||
git clone https://www.github.com/foglar/cobraV2.git
|
||||
cd cobraV2/monitor
|
||||
|
||||
# Installing required packages
|
||||
go get "github.com/tarm/serial"
|
||||
# go get "github.com/gopxl/pixel/v2"
|
||||
|
||||
go build .
|
||||
```
|
||||
|
||||
Upload sender and reciever code on the 2 arduino's
|
||||
|
||||
## Overview
|
||||
@ -17,6 +34,30 @@ Upload sender and reciever code on the 2 arduino's
|
||||
`reciever_module/` - folder with code for reciver which will send data to the pc
|
||||
`sender_module/` - folder with code for sender, which transmit data to the reciever and save it on the micro sd card
|
||||
`serial_read/` - read serial input and save it
|
||||
`monitor` - folder with code for monitor which will recieve data and print them into the gui application
|
||||
|
||||
### Arduino Sender Format
|
||||
|
||||
- sender sends data via antenna to reciever in this format **$[code of message];[value]\***
|
||||
- in future will be added some other values, like gps and so on
|
||||
|
||||
| Identifier | Message Code | Value | Verificator |
|
||||
| ---------- | ------------ | -------------------------------- | ------------|
|
||||
| $ | **1**; | temperature [degrees of Celsius] | * |
|
||||
| $ | **2**; | pressure | * |
|
||||
| $ | **3**; | altitude | * |
|
||||
| $ | **4**; | roll | * |
|
||||
| $ | **5**; | pitch | * |
|
||||
| $ | **6**; | yaw | * |
|
||||
| $ | **7**; | gyroscope x | * |
|
||||
| $ | **8**; | gyroscope y | * |
|
||||
| $ | **9**; | gyroscope z | * |
|
||||
| $ | **10**; | accelerometer x | * |
|
||||
| $ | **11**; | accelerometer y | * |
|
||||
| $ | **12**; | accelerometer z | * |
|
||||
| $ | **13**; | magnitude x | * |
|
||||
| $ | **14**; | magnitude y | * |
|
||||
| $ | **15**; | magnitude z | * |
|
||||
|
||||
## Modules
|
||||
|
||||
@ -92,6 +133,13 @@ Fix Quality:
|
||||
| MOSI | 11~ | SPI master out |
|
||||
| MISO | 12 | SPI master in |
|
||||
|
||||
## Issues / features
|
||||
|
||||
- data stops being transmitted after some short time
|
||||
- no gui
|
||||
- parser should be updated
|
||||
- sender code should be updated
|
||||
|
||||
## Sources
|
||||
|
||||
Datasheets, documentation and sources
|
||||
|
||||
7
monitor/go.mod
Normal file
7
monitor/go.mod
Normal file
@ -0,0 +1,7 @@
|
||||
module foglar/monitor
|
||||
|
||||
go 1.21.6
|
||||
|
||||
require github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
|
||||
|
||||
require golang.org/x/sys v0.16.0 // indirect
|
||||
4
monitor/go.sum
Normal file
4
monitor/go.sum
Normal file
@ -0,0 +1,4 @@
|
||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
|
||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
@ -2,9 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
p "foglar/monitor/parse"
|
||||
"foglar/monitor/serial_read"
|
||||
"log"
|
||||
// "foglar/monitor/parse"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -16,11 +16,14 @@ func main() {
|
||||
|
||||
defer serialHandler.Close()
|
||||
|
||||
// Read serial data
|
||||
data, err := serialHandler.ReadSerial()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for {
|
||||
// Read serial data
|
||||
data, err := serialHandler.ReadSerial()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println("Received data:", data)
|
||||
fmt.Println("Received data:", data)
|
||||
fmt.Println(p.Parser(data))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,32 @@
|
||||
package parse
|
||||
|
||||
func parse() {}
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Parser(s string) map[int]string {
|
||||
|
||||
// TODO: check if line isn't comment
|
||||
// improve reading data
|
||||
lines := strings.Split(s, "\n")
|
||||
data_structure := make(map[int]string)
|
||||
for _, line := range lines {
|
||||
// find $ and * in text and get value between them
|
||||
startIndex := strings.Index(line, "$")
|
||||
endIndex := strings.Index(line, "*")
|
||||
if startIndex != -1 && endIndex != -1 {
|
||||
value := line[startIndex+1 : endIndex]
|
||||
data := strings.Split(strings.TrimSpace(value), ";")
|
||||
ident, err := strconv.Atoi(strings.TrimSpace(data[0]))
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
info := data[1]
|
||||
data_structure[ident] = info
|
||||
}
|
||||
}
|
||||
|
||||
return data_structure
|
||||
}
|
||||
|
||||
@ -53,6 +53,9 @@ void loop() {
|
||||
|
||||
char temp_str[8], pressure_str[8], altitude_str[8];
|
||||
char roll_str[8], pitch_str[8], yaw_str[8];
|
||||
char gyro_x_str[8], gyro_y_str[8], gyro_z_str[8];
|
||||
char accel_x_str[8], accel_y_str[8], accel_z_str[8];
|
||||
char magn_x_str[8], magn_y_str[8], magn_z_str[8];
|
||||
|
||||
float temperature = (s32TemperatureVal / 100);
|
||||
float pressure = (s32PressureVal / 100);
|
||||
@ -62,6 +65,18 @@ void loop() {
|
||||
float pitch = stAngles.fPitch;
|
||||
float yaw = stAngles.fYaw;
|
||||
|
||||
float gyro_x = stGyroRawData.s16X;
|
||||
float gyro_y = stGyroRawData.s16Y;
|
||||
float gyro_z = stGyroRawData.s16Z;
|
||||
|
||||
float accel_x = stAccelRawData.s16X;
|
||||
float accel_y = stAccelRawData.s16Y;
|
||||
float accel_z = stAccelRawData.s16Z;
|
||||
|
||||
float magn_x = stMagnRawData.s16X;
|
||||
float magn_y = stMagnRawData.s16Y;
|
||||
float magn_z = stMagnRawData.s16Z;
|
||||
|
||||
dtostrf(temperature, 6, 2, temp_str);
|
||||
dtostrf(pressure, 6, 2, pressure_str);
|
||||
dtostrf(altitude, 6, 2, altitude_str);
|
||||
@ -70,6 +85,18 @@ void loop() {
|
||||
dtostrf(pitch, 6, 2, pitch_str);
|
||||
dtostrf(yaw, 6, 2, yaw_str);
|
||||
|
||||
dtostrf(gyro_x, 6, 2, gyro_x_str);
|
||||
dtostrf(gyro_y, 6, 2, gyro_y_str);
|
||||
dtostrf(gyro_z, 6, 2, gyro_z_str);
|
||||
|
||||
dtostrf(accel_x, 6, 2, accel_x_str);
|
||||
dtostrf(accel_y, 6, 2, accel_y_str);
|
||||
dtostrf(accel_z, 6, 2, accel_z_str);
|
||||
|
||||
dtostrf(magn_x, 6, 2, magn_x_str);
|
||||
dtostrf(magn_y, 6, 2, magn_y_str);
|
||||
dtostrf(magn_z, 6, 2, magn_z_str);
|
||||
|
||||
//Serial.println(roll, pitch, yaw);
|
||||
//Serial.println(temperature, pressure, altitude);
|
||||
|
||||
@ -81,11 +108,46 @@ void loop() {
|
||||
String croll = ("$4;"+String(roll_str)+"*");
|
||||
String cpitch = ("$5;"+String(pitch_str)+"*");
|
||||
String cyaw = ("$6;"+String(yaw_str) + "*");
|
||||
String cgyro_x = ("$7;"+String(gyro_x_str)+"*");
|
||||
String cgyro_y = ("$8;"+String(gyro_y_str)+"*");
|
||||
String cgyro_z = ("$9;"+String(gyro_z_str)+"*");
|
||||
String caccel_x = ("$10;"+String(accel_x_str)+"*");
|
||||
String caccel_y = ("$11;"+String(accel_y_str)+"*");
|
||||
String caccel_z = ("$12;"+String(accel_z_str)+"*");
|
||||
String cmagn_x = ("$13;"+String(magn_x_str)+"*");
|
||||
String cmagn_y = ("$14;"+String(magn_y_str)+"*");
|
||||
String cmagn_z = ("$15;"+String(magn_z_str)+"*");
|
||||
|
||||
ctemp.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
cpressure.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
caltitude.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
croll.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
cpitch.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
cyaw.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
cgyro_x.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
cgyro_y.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
cgyro_z.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
caccel_x.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
caccel_y.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
caccel_z.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
cmagn_x.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
cmagn_y.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
cmagn_z.toCharArray(msg, sizeof(msg));
|
||||
radio.write(&msg, sizeof(msg));
|
||||
|
||||
delay(200);
|
||||
//delay(200);
|
||||
}
|
||||
|
||||
10
serial_read/go.mod
Normal file
10
serial_read/go.mod
Normal file
@ -0,0 +1,10 @@
|
||||
module main
|
||||
|
||||
go 1.21.6
|
||||
|
||||
require github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
|
||||
|
||||
require (
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
golang.org/x/sys v0.16.0 // indirect
|
||||
)
|
||||
6
serial_read/go.sum
Normal file
6
serial_read/go.sum
Normal file
@ -0,0 +1,6 @@
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
|
||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
Loading…
Reference in New Issue
Block a user