module Data.Icao.AtsMessage
( AtsMessage(..)
, ArrivalContent(..)
, DepartureContent(..)
, DelayContent(..)
, module Data.Icao.Lang
, module Data.Icao.Location
, module Data.Icao.OtherInformation
, module Data.Icao.SupplementaryInformation
, module Data.Icao.Time
, F7.AircraftIdentification
, F7.SsrCode
, F8.FlightRules(..)
, F8.FlightType(..)
, F9.AircraftType
, F9.WakeTurbulenceCategory(..)
, F10.ComNavAppCapabilityCode(..)
, F10.SurveillanceCapabilityCode(..)
, F7.mkAircraftIdentification
, F7.mkSsrCode
, F9.mkAircraftType
, Parser
, Error(message, column)
, parse
, parser
) where
import Data.Aeromess.Parser
import qualified Data.Icao.F10 as F10
import qualified Data.Icao.F13 as F13
import qualified Data.Icao.F16 as F16
import qualified Data.Icao.F17 as F17
import qualified Data.Icao.F18 as F18
import qualified Data.Icao.F3 as F3
import qualified Data.Icao.F7 as F7
import qualified Data.Icao.F8 as F8
import qualified Data.Icao.F9 as F9
import Data.Icao.Lang
import Data.Icao.Location
import Data.Icao.OtherInformation
import Data.Icao.SupplementaryInformation
import Data.Icao.Time
import Data.Maybe ()
data ArrivalContent = ArrivalContent
{ arrAircraftIndentification :: F7.AircraftIdentification
, arrSsrCode :: Maybe F7.SsrCode
, arrAdep :: Aerodrome
, arrEobt :: Hhmm
, arrAdes :: Maybe Aerodrome
, arrAdar :: Aerodrome
, arrAta :: Hhmm
, arrAdarName :: Maybe FreeText
} deriving (Eq, Show)
data DepartureContent = DepartureContent
{ depAircraftIndentification :: F7.AircraftIdentification
, depSsrCode :: Maybe F7.SsrCode
, depAdep :: Aerodrome
, depAtd :: Hhmm
, depAdes :: Aerodrome
, depOtherInformation :: OtherInformation
} deriving (Eq, Show)
data DelayContent = DelayContent
{ dlaAircraftIndentification :: F7.AircraftIdentification
, dlaSsrCode :: Maybe F7.SsrCode
, dlaAdep :: Aerodrome
, dlaEobt :: Hhmm
, dlaAdes :: Aerodrome
, dlaOtherInformation :: OtherInformation
} deriving (Eq, Show)
data AtsMessage
= Arr ArrivalContent
| Dep DepartureContent
| Dla DelayContent
deriving (Eq, Show)
arrParser :: Parser AtsMessage
arrParser = do
f7 <- F7.parser
f13 <- F13.parser
ades <- optional (try F16.adesParser)
f17 <- F17.parser
return
(Arr
(ArrivalContent
(F7.aircraftIdentification f7)
(F7.ssrCode f7)
(F13.adep f13)
(F13.time f13)
ades
(F17.adar f17)
(F17.ata f17)
(F17.adarName f17)))
depParser' :: Parser (F7.AircraftIdentification, Maybe F7.SsrCode, Aerodrome, Hhmm, Aerodrome, OtherInformation)
depParser' = do
f7 <- F7.parser
f13 <- F13.parser
f16Ades <- F16.adesParser
f18 <- F18.parser
return (F7.aircraftIdentification f7, F7.ssrCode f7, F13.adep f13, F13.time f13, f16Ades, f18)
depParser :: Parser AtsMessage
depParser = do
c <- depParser'
let (ai, sc, d, t, s, o) = c
return (Dep (DepartureContent ai sc d t s o))
dlaParser :: Parser AtsMessage
dlaParser = do
c <- depParser'
let (ai, sc, d, t, s, o) = c
return (Dla (DelayContent ai sc d t s o))
contentParser :: Parser AtsMessage
contentParser = do
f3 <- F3.parser
case f3 of
"ARR" -> arrParser
"DEP" -> depParser
"DLA" -> dlaParser
_ -> unexpected ("unexpected message=" ++ show f3)
parser :: Parser AtsMessage
parser = between (char '(') (char ')') contentParser
parse :: String -> Either Error AtsMessage
parse = runParser parser