forked from tatut/data.nmea-0183
-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.clj
22 lines (20 loc) · 860 Bytes
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(ns data.nmea-0183.core
"NMEA 0183 parser and writer."
(:require [data.nmea-0183.message :as msg]
[data.nmea-0183.sentences :as sentences]))
(defn parse
"Read and parse one sentence from the input source."
[input]
(let [{:keys [sentence fields] :as m} (msg/read-message input)]
(when-not sentence
(throw (ex-info "No identifiable NMEA sentence found"
{:type :parse-error})))
(when-not (get-method sentences/parse-sentence sentence)
(throw (ex-info (str "Unsupported sentence " sentence)
{:type :unsupported-sentence})))
(try
(merge m (sentences/parse-sentence sentence fields))
(catch Exception e
(throw (ex-info (str "Cannot parse sentence " sentence " fields " fields)
{:type :parse-error}
e))))))