<commit_before>// Copyright (c) 2016-2017 <NAME>. All rights reserved.
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.

package main

import (
	"time"

	"github.com/ebarkie/davis-station/internal/events"
	"github.com/ebarkie/weatherlink"
)

// Loop is a weatherlink.Loop with a sequence and timestamp
// added in.
type Loop struct {
	Seq       int64     `json:"sequence"`
	Timestamp time.Time `json:"timestamp"`
	weatherlink.Loop
}

func stationEvents(sc serverCtx, device string) (ec chan interface{}, err error) {
	// If a device name of "/dev/null" is specified launch
	// a primitive test server instead of attaching to the
	// Weatherlink.
	switch device {
	case "/dev/null":
		Info.Print("Test poller started")

		ec = make(chan interface{})

		// Send a mostly empty loop packet, except for a few
		// things initialized so it passes QC,  every 2s.
		l := weatherlink.Loop{}
		l.Bar.Altimeter = 6.8 // QC minimums
		l.Bar.SeaLevel = 25.0
		l.Bar.Station = 6.8

		go func() {
			for {
				ec <- l
				time.Sleep(2 * time.Second)
			}
		}()
	default:
		Info.Print("Weatherlink poller started")

		// Connect the weatherlink loggers
		weatherlink.Trace.SetOutput(Trace)
		weatherlink.Debug.SetOutput(Debug)
		weatherlink.Info.SetOutput(Info)
		weatherlink.Warn.SetOutput(Warn)
		weatherlink.Error.SetOutput(Error)

		// Open connection and start command broker
		var wl weatherlink.Weatherlink
		wl, err = weatherlink.Dial(device)
		if err != nil {
			return
		}
		defer wl.Close()
		wl.LastDmpTime = sc.ad.Last()
		ec <- weatherlink.CmdGetDmps
		ec = wl.Start()<commit_msg>Fix ordering to prevent a deadlock<commit_after>// Copyright (c) 2016-2017 <NAME>. All rights reserved.
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.

package main

import (
	"time"

	"github.com/ebarkie/davis-station/internal/events"
	"github.com/ebarkie/weatherlink"
)

// Loop is a weatherlink.Loop with a sequence and timestamp
// added in.
type Loop struct {
	Seq       int64     `json:"sequence"`
	Timestamp time.Time `json:"timestamp"`
	weatherlink.Loop
}

func stationEvents(sc serverCtx, device string) (ec chan interface{}, err error) {
	// If a device name of "/dev/null" is specified launch
	// a primitive test server instead of attaching to the
	// Weatherlink.
	switch device {
	case "/dev/null":
		Info.Print("Test poller started")

		ec = make(chan interface{})

		// Send a mostly empty loop packet, except for a few
		// things initialized so it passes QC,  every 2s.
		l := weatherlink.Loop{}
		l.Bar.Altimeter = 6.8 // QC minimums
		l.Bar.SeaLevel = 25.0
		l.Bar.Station = 6.8

		go func() {
			for {
				ec <- l
				time.Sleep(2 * time.Second)
			}
		}()
	default:
		Info.Print("Weatherlink poller started")

		// Connect the weatherlink loggers
		weatherlink.Trace.SetOutput(Trace)
		weatherlink.Debug.SetOutput(Debug)
		weatherlink.Info.SetOutput(Info)
		weatherlink.Warn.SetOutput(Warn)
		weatherlink.Error.SetOutput(Error)

		// Open connection and start command broker
		var wl weatherlink.Weatherlink
		wl, err = weatherlink.Dial(device)
		if err != nil {
			return
		}
		defer wl.Close()
		wl.LastDmpTime = sc.ad.Last()
		ec = wl.Start()
		ec <- weatherlink.CmdGetDmps
{'fraction_non_alphanumeric': 0.11398963730569948, 'fraction_numerical': 0.011581834806461445, 'mean_word_length': 3.229381443298969, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 5, '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': '442134', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1072, 'n_words': 334}