{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Data.Aviation.Stratux.Types.Situation(
Situation(..)
, HasSituation(..)
) where
import Control.Applicative(Applicative((<*>)))
import Control.Lens(makeClassy)
import Data.Aeson(FromJSON(parseJSON), ToJSON(toJSON), (.:), withObject, (.=), object)
import Data.Aviation.Stratux.Types.UTCTimes(HasUTCTimes(utcTimes))
import Data.Eq(Eq)
import Data.Int(Int)
import Data.Functor((<$>))
import Data.Ord(Ord)
import Data.Time(UTCTime)
import Prelude(Double, Show)
data Situation =
Situation {
_lat :: Double
, _lon :: Double
, _heightAboveEllipsoid :: Double
, _geoidSep :: Double
, _satellites :: Int
, _satellitesTracked :: Int
, _satellitesSeen :: Int
, _accuracy :: Double
, _nacp :: Int
, _alt :: Double
, _accuracyVert :: Double
, _gpsVertVel :: Double
, _lastFixLocalTime :: UTCTime
, _trueCourse :: Double
, _groundSpeed :: Int
, _lastGroundTrackTime :: UTCTime
, _lastGPSTimeTime :: UTCTime
, _lastNMEAMessage :: UTCTime
, _temp :: Double
, _pressureAlt :: Double
, _pitch :: Double
, _roll :: Double
, _gyroHeading :: Double
, _lastAttitudeTime :: UTCTime
} deriving (Eq, Ord, Show)
makeClassy ''Situation
instance FromJSON Situation where
parseJSON =
withObject "Situation" (\x ->
Situation <$>
x .: "Lat" <*>
x .: "Lng" <*>
x .: "HeightAboveEllipsoid" <*>
x .: "GeoidSep" <*>
x .: "Satellites" <*>
x .: "SatellitesTracked" <*>
x .: "SatellitesSeen" <*>
x .: "Accuracy" <*>
x .: "NACp" <*>
x .: "Alt" <*>
x .: "AccuracyVert" <*>
x .: "GPSVertVel" <*>
x .: "LastFixLocalTime" <*>
x .: "TrueCourse" <*>
x .: "GroundSpeed" <*>
x .: "LastGroundTrackTime" <*>
x .: "LastGPSTimeTime" <*>
x .: "LastNMEAMessage" <*>
x .: "Temp" <*>
x .: "Pressure_alt" <*>
x .: "Pitch" <*>
x .: "Roll" <*>
x .: "Gyro_heading" <*>
x .: "LastAttitudeTime"
)
instance ToJSON Situation where
toJSON (Situation lat_ lon_ heightAboveEllipsoid_ geoidSep_ satellites_ satellitesTracked_ satellitesSeen_ accuracy_ nacp_ alt_ accuracyVert_ gpsVertVel_ lastFixLocalTime_ trueCourse_ groundSpeed_ lastGroundTrackTime_ lastGPSTimeTime_ lastNMEAMessage_ temp_ pressureAlt_ pitch_ roll_ gyroHeading_ lastAttitudeTime_) =
object [
"Lat" .= lat_
, "Lng" .= lon_
, "HeightAboveEllipsoid" .= heightAboveEllipsoid_
, "GeoidSep" .= geoidSep_
, "Satellites" .= satellites_
, "SatellitesTracked" .= satellitesTracked_
, "SatellitesSeen" .= satellitesSeen_
, "Accuracy" .= accuracy_
, "NACp" .= nacp_
, "Alt" .= alt_
, "AccuracyVert" .= accuracyVert_
, "GPSVertVel" .= gpsVertVel_
, "LastFixLocalTime" .= lastFixLocalTime_
, "TrueCourse" .= trueCourse_
, "GroundSpeed" .= groundSpeed_
, "LastGroundTrackTime" .= lastGroundTrackTime_
, "LastGPSTimeTime" .= lastGPSTimeTime_
, "LastNMEAMessage" .= lastNMEAMessage_
, "Temp" .= temp_
, "Pressure_alt" .= pressureAlt_
, "Pitch" .= pitch_
, "Roll" .= roll_
, "Gyro_heading" .= gyroHeading_
, "LastAttitudeTime" .= lastAttitudeTime_
]
instance HasUTCTimes Situation where
utcTimes f (Situation lat_ lon_ heightAboveEllipsoid_ geoidSep_ satellites_ satellitesTracked_ satellitesSeen_ accuracy_ nacp_ alt_ accuracyVert_ gpsVertVel_ lastFixLocalTime_ trueCourse_ groundSpeed_ lastGroundTrackTime_ lastGPSTimeTime_ lastNMEAMessage_ temp_ pressureAlt_ pitch_ roll_ gyroHeading_ lastAttitudeTime_) =
(\lastFixLocalTime__ lastGroundTrackTime__ lastGPSTimeTime__ lastNMEAMessage__ lastAttitudeTime__ ->
Situation lat_ lon_ heightAboveEllipsoid_ geoidSep_ satellites_ satellitesTracked_ satellitesSeen_ accuracy_ nacp_ alt_ accuracyVert_ gpsVertVel_ lastFixLocalTime__ trueCourse_ groundSpeed_ lastGroundTrackTime__ lastGPSTimeTime__ lastNMEAMessage__ temp_ pressureAlt_ pitch_ roll_ gyroHeading_ lastAttitudeTime__) <$>
f lastFixLocalTime_ <*>
f lastGroundTrackTime_ <*>
f lastGPSTimeTime_ <*>
f lastNMEAMessage_ <*>
f lastAttitudeTime_