go file that prints gps data from esp

This commit is contained in:
2023-07-20 22:43:00 -04:00
parent e3a5b42191
commit 2eb43d065d
2 changed files with 13 additions and 24 deletions
+3 -9
View File
@@ -1,20 +1,14 @@
// ============================================================================= // =============================================================================
// Auth: Alex Celani // Auth: Alex Celani
// File: gsp.go // File: gsp.go
// Revn: 07-13-2023 0.4 // Revn: 07-13-2023 1.0
// Func: asynchronously receive messages from another program, print // Func: asynchronously receive messages from another program, print
// //
// TODO: create // TODO: create
// ============================================================================= // =============================================================================
// CHANGE LOG // CHANGE LOG
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// 05-04-2022: init //*07-13-2023: copied over, removed call to alter()/forward()
// 05-09-2022: began commenting
// 05-10-2022: finished commenting
// added alter() and forward()
// made passed value to alter()/forward() a slice
// changed refs to recv byte array to slice of n bytes
// 07-13-2023: copied over, removed call to alter()/forward()
// removed any call to write // removed any call to write
// put read and print in a for loop // put read and print in a for loop
// wrote getFileName() to create a filename based off // wrote getFileName() to create a filename based off
@@ -32,7 +26,7 @@ import (
"os" // Args, Stderr, Exit, Create, Write "os" // Args, Stderr, Exit, Create, Write
"fmt" // Fprintf, Println "fmt" // Fprintf, Println
"strings" // ToLower, Compare "strings" // ToLower, Compare
"time" // Now, Year, Month, Day, Hour, Minute, Second "time" // Now, Format
) )
+10 -15
View File
@@ -1,27 +1,21 @@
// ============================================================================= // =============================================================================
// Auth: Alex Celani // Auth: Alex Celani
// File: gsp.go // File: gsp.go
// Revn: 07-13-2023 0.4 // Revn: 07-18-2023 2.0
// Func: asynchronously receive messages from another program, print // Func: asynchronously receive messages from another program, print
// //
// TODO: create // TODO: create
// ============================================================================= // =============================================================================
// CHANGE LOG // CHANGE LOG
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// 05-04-2022: init //*07-13-2023: copied over, removed call to alter()/forward()
// 05-09-2022: began commenting
// 05-10-2022: finished commenting
// added alter() and forward()
// made passed value to alter()/forward() a slice
// changed refs to recv byte array to slice of n bytes
// 07-13-2023: copied over, removed call to alter()/forward()
// removed any call to write // removed any call to write
// put read and print in a for loop // put read and print in a for loop
// wrote getFileName() to create a filename based off // wrote getFileName() to create a filename based off
// current time // current time
// write output to a logfile // write output to a logfile
// moved file writing to AFTER checking for fin // moved file writing to AFTER checking for fin
// //*07-20-2023:
// ============================================================================= // =============================================================================
package main package main
@@ -32,7 +26,7 @@ import (
"os" // Args, Stderr, Exit, Create, Write "os" // Args, Stderr, Exit, Create, Write
"fmt" // Fprintf, Println "fmt" // Fprintf, Println
"strings" // ToLower, Compare "strings" // ToLower, Compare
"time" // Now, Year, Month, Day, Hour, Minute, Second "time" // Now, Format
) )
@@ -59,11 +53,6 @@ func getFileName() string{
// function to handle incoming connections // function to handle incoming connections
func handleClient( conn net.Conn ) { func handleClient( conn net.Conn ) {
defer conn.Close() // barring any error, still close connection defer conn.Close() // barring any error, still close connection
filename := getFileName() // get filename
file, err := os.Create( filename ) // create new file
check( err ) // make sure it worked
defer file.Close() // barring any error, still close connection defer file.Close() // barring any error, still close connection
var buf [512]byte // declare large byte array, store messages var buf [512]byte // declare large byte array, store messages
@@ -82,6 +71,7 @@ func handleClient( conn net.Conn ) {
// if recv'd message is fin, break forloop // if recv'd message is fin, break forloop
if strings.Compare( string( buf[:n] ), "fin" ) == 0 { if strings.Compare( string( buf[:n] ), "fin" ) == 0 {
file.Close()
os.Exit( 2 ) // quit os.Exit( 2 ) // quit
} }
@@ -105,6 +95,10 @@ func handleClient( conn net.Conn ) {
} }
var file *os.File
var filename string
func main() { func main() {
// ip:port // ip:port
@@ -119,6 +113,7 @@ func main() {
listener, err := net.ListenTCP( "tcp", tcpAddr ) listener, err := net.ListenTCP( "tcp", tcpAddr )
check( err ) // check error check( err ) // check error
// iterate forever // iterate forever
// TODO i mean i can totally make this more user friendly // TODO i mean i can totally make this more user friendly
for { for {