<commit_before>package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/SpaceLeap/go-mavlink/mavlink"
	"github.com/SpaceLeap/go-mavlink/mavlink/common"
	"github.com/ungerik/go-dry"
	"github.com/ungerik/goserial"
)

var (
	port       string
	baud       int
	maxPackets int
	quitAfter  time.Duration
	timeout    time.Duration

	stop bool
)

func main() {
	common.Init()

	flag.StringVar(&port, "port", "", "Serial port to connect to")
	flag.IntVar(&baud, "baud", 115200, "Speed of the connection")
	flag.IntVar(&maxPackets, "max", 10, "Quit program after this number of packets")
	flag.DurationVar(&quitAfter, "quitafter", time.Second*3, "Quit program after this duration")
	flag.DurationVar(&timeout, "timeout", time.Second, "Read timeout per packet")
	flag.Parse()

	if port == "" && flag.NArg() == 0 {
		ports := serial.ListPorts()
		if len(ports) == 1 {
			port = ports[0]
		} else {
			fmt.Fprintln(os.Stderr, "Call listmavlink -port=PORT")
			flag.PrintDefaults()
			fmt.Fprintln(os.Stderr, "\nAvailable as PORT are:")
			for _, p := range ports {
				fmt.Fprintln(os.Stderr, "  ", p)
			}
			return
		}
	}
	if port == "" {
		port = flag.Arg(0)
	}

	serialConn, err := serial.OpenDefault(port, serial.Baud(baud), timeout)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Opened serial port", port)
	defer func() {
		log.Println("Closed serial port", port, "with error", serialConn.Close())
	}()

	//conn := mavlink.NewConnection(serialConn, 99)

	err = mavlink.Send(serialConn, 0, 0, 0, common.NewHeartbeat())
	if err != nil {
		log.Println(err)
	}

	err = mavlink.Send(serialConn, 0, 0, 0, &common.Ping{})
	if err != nil {
		log.Println(err)
	}

	err = mavlink.Send(serialConn, 0, 0, 0, &common.ParamRequestList{})
	if err != nil {
		log.Println(err)
	}

	go func() {
		dry.WaitForStdin("Press any key to quit")
		stop = true
	}()

	time.AfterFunc(quitAfter, func() { stop = true })

	for i := 0; i < maxPackets && !stop; i++ {
		packet, err := mavlink.Receive(serialConn)
		if err == nil {
			log.Println(packet)
		} else {
			log.Println(err)
		}
	}
}
<commit_msg>connect with default serial port<commit_after>package main

import (
	"flag"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/SpaceLeap/go-mavlink/mavlink"
	"github.com/SpaceLeap/go-mavlink/mavlink/common"
	"github.com/ungerik/go-dry"
	"github.com/ungerik/goserial"
)

var (
	port       string
	baud       int
	maxPackets int
	quitAfter  time.Duration
	timeout    time.Duration

	stop bool
)

func main() {
	common.Init()

	flag.StringVar(&port, "port", "", "Serial port to connect to")
	flag.IntVar(&baud, "baud", 115200, "Speed of the connection")
	flag.IntVar(&maxPackets, "max", 10, "Quit program after this number of packets")
	flag.DurationVar(&quitAfter, "quitafter", time.Second*3, "Quit program after this duration")
	flag.DurationVar(&timeout, "timeout", time.Second, "Read timeout per packet")
	flag.Parse()

	if port == "" {
		if flag.NArg() > 0 {
			port = flag.Arg(0)
		} else {
			ports := serial.ListPorts()
			if len(ports) == 1 {
				port = ports[0]
			} else {
				fmt.Fprintln(os.Stderr, "Call with -port=PORT")
				flag.PrintDefaults()
				fmt.Fprintln(os.Stderr, "\nAvailable as PORT are:")
				for _, p := range ports {
					fmt.Fprintln(os.Stderr, "  ", p)
				}
				return
			}
		}
	}

	serialConn, err := serial.OpenDefault(port, serial.Baud(baud), timeout)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Opened serial port", port)
	defer func() {
		log.Println("Closed serial port", port, "with error", serialConn.Close())
	}()

	//conn := mavlink.NewConnection(serialConn, 99)

	err = mavlink.Send(serialConn, 0, 0, 0, common.NewHeartbeat())
	if err != nil {
		log.Println(err)
	}

	err = mavlink.Send(serialConn, 0, 0, 0, &common.Ping{})
	if err != nil {
		log.Println(err)
	}

	err = mavlink.Send(serialConn, 0, 0, 0, &common.ParamRequestList{})
	if err != nil {
		log.Println(err)
	}

	go func() {
		dry.WaitForStdin("Press any key to quit")
		stop = true
	}()

	time.AfterFunc(quitAfter, func() { stop = true })

	for i := 0; i < maxPackets && !stop; i++ {
		packet, err := mavlink.Receive(serialConn)
		if err == nil {
			log.Println(packet)
		} else {
			log.Println(err)
		}
	}
}

{'fraction_non_alphanumeric': 0.16353249226374672, 'fraction_numerical': 0.011901928112354201, 'mean_word_length': 3.4845250800426895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1647932', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1614, 'n_words': 374}