Esempio n. 1
0
File: main.go Progetto: yo3igc/aprss
func sendAck(packet *message.AprsMessage) {
	ack, err := packet.GetAck()
	if err == nil {
		aprsis.SendPacket(ack, conn)
		fmt.Println(ack)
	}
}
Esempio n. 2
0
File: main.go Progetto: yo3igc/aprss
func handleLine(rawData string) {
	packet, err := message.Parse(rawData)
	if err != nil || packet.To != serviceCallsign {
		return
	}

	fmt.Print(rawData)

	if packet.To == serviceCallsign {
		sendAck(packet)
	}

	returnString := ""
	switch {
	case strings.ToLower(packet.Message) == "ping":
		returnString = "pong"
		break

	case strings.ToLower(packet.Message) == "w":
		callsign, err1 := aprsfi.GetCallsign(packet.From, aprsfiApiKey)
		if err1 != nil {
			returnString = err1.Error()
			break
		}
		w, err2 := weather.GetByLocation(callsign.Entries[0].Lat, callsign.Entries[0].Lng, weatherApiKey)
		if err2 != nil {
			returnString = err2.Error()
			break
		}
		ts := time.Unix(int64(w.Dt), 0)
		returnString = fmt.Sprintf("%s, %s, %.1fC, %dhPa, Hum %d%%", ts.UTC().Format("2006-01-02 15:04 MST"), w.Weather[0].Description, w.Main.Temp, w.Main.Pressure, w.Main.Humidity)
		break

	default:
		return
	}

	retPacket := new(message.AprsMessage)
	retPacket.From = serviceCallsign
	retPacket.To = packet.From
	retPacket.Message = returnString
	retRawData, err := retPacket.GetData()
	if err == nil {
		aprsis.SendPacket(retRawData, conn)
		fmt.Println(retRawData)
	}
}