From 1c438910edfbc9bdea24133b4e3592e52a9d7809 Mon Sep 17 00:00:00 2001 From: Pasi Miettinen Date: Fri, 22 Mar 2019 11:27:06 +0200 Subject: [PATCH] sbp2prettyjson: Filter out SBPMsgBadCrc and SBPMsgUnknown --- haskell/main/SBP2PRETTYJSON.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/haskell/main/SBP2PRETTYJSON.hs b/haskell/main/SBP2PRETTYJSON.hs index 716fee9e39..b605839f5a 100644 --- a/haskell/main/SBP2PRETTYJSON.hs +++ b/haskell/main/SBP2PRETTYJSON.hs @@ -26,20 +26,24 @@ import SwiftNav.SBP import System.Console.CmdArgs import System.IO -data Cfg = Cfg {skiporder :: Bool - ,spaces :: Int} +data Cfg = Cfg { skiporder :: Bool + , spaces :: Int + , skipfilter :: Bool } deriving (Show, Data, Typeable) defaultCfg :: Cfg -defaultCfg = Cfg{skiporder = False - ,spaces = 0} +defaultCfg = Cfg { skiporder = False + , spaces = 0 + , skipfilter = False } -- | Encode a SBPMsg to a line of JSON. encodeLine :: Cfg -> SBPMsg -> ByteString -encodeLine c v = toStrict - $ encodePretty' - (defConfig {confIndent = Spaces (spaces c), - confCompare = if (skiporder c) then mempty else compare}) v <> "\n" +encodeLine c (SBPMsgBadCrc _v) | not (skipfilter c) = mempty +encodeLine c (SBPMsgUnknown _v) | not (skipfilter c) = mempty +encodeLine c v = toStrict $ encodePretty' (defConfig + { confIndent = Spaces (spaces c) + , confCompare = if (skiporder c) then mempty else compare + }) v <> "\n" main :: IO () main = do