Skip to content

Commit

Permalink
Fixed printing, still has ccsds assertion error. assume unstable.
Browse files Browse the repository at this point in the history
  • Loading branch information
dangirsh committed Apr 24, 2014
1 parent 6e55df1 commit b4e5ee7
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 30 deletions.
7 changes: 6 additions & 1 deletion Auto.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ type Auto = Reader Config


runAuto :: Auto a -> Config -> a
runAuto = runReader
runAuto = runReader


class AutoShow a where

autoShow :: a -> Auto String
2 changes: 1 addition & 1 deletion CCSDS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packetDataLength m = do
return . bitVec 16 $ length (secondaryHeader m) + pl


class (Show a) => CCSDS a where
class CCSDS a where

packetType :: a -> BV

Expand Down
8 changes: 6 additions & 2 deletions Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ module Command (
Command (Command)
) where

import Control.Applicative ((<$>))
import Numeric (showHex)
import GHC.Generics (Generic)
import Data.Aeson (FromJSON)
import Auto
import Types
import Parameter()


instance FromJSON Command


instance Show Command where
instance AutoShow Command where

show (Command c ps) = "CMD: " ++ " cc:" ++ showHex c " " ++ show ps
autoShow (Command c ps) = do
sp <- concat <$> mapM autoShow ps
return $ "CMD::" ++ " cc:" ++ showHex c " " ++ sp
14 changes: 7 additions & 7 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ runner (Controller {meta=cm, sequenced=s, parallel=p}) =

run :: ControllerMeta -> MessageMeta -> IO ()
run (ControllerMeta {ip, port}) (MessageMeta {file, frequency}) = do
packed <- getPacked
forM_ packed $ (\p -> do
sendUDP ip port p
print p
packed <- (uncurry zip) <$> getPacked
forM_ packed $ (\(bs, s) -> do
sendUDP ip port bs
print s
hFlush stdout
threadDelay . round $ 1000000 / frequency
)
Expand All @@ -60,12 +60,12 @@ run (ControllerMeta {ip, port}) (MessageMeta {file, frequency}) = do
".cmd" -> pack <$> (parseFile file :: IO (MessageDef Command))


pack :: (FromJSON a, CCSDS (Message a)) => MessageDef a -> [B.ByteString]
pack :: (FromJSON a, CCSDS (Message a), AutoShow a) => MessageDef a -> ([B.ByteString], [String])
pack (MessageDef {variables=vs, message=m}) = do
map (runAuto (packCCSDS m)) $ makeEnvs vs
(map (runAuto (packCCSDS m)) envs, map (runAuto (autoShow m)) envs)
where
varToPairs (Variable id_ ds) = [(id_, Parameter id_ d) | d <- ds]
makeEnvs vs =
envs =
let jaggedPairs = map varToPairs vs in
let smallestLen = minimum . map length $ jaggedPairs in
let flushPairs = map (take smallestLen) jaggedPairs in
Expand Down
13 changes: 10 additions & 3 deletions Message.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Message (
import Data.Aeson (FromJSON, parseJSON, (.:), Value(Object))
import GHC.Generics (Generic)
import Control.Applicative ((<$>), (<*>))
import Numeric (showHex)
import Data.BitVector (fromBool)
import Common
import CCSDS
Expand All @@ -16,8 +17,7 @@ import Telemetry
import Parameter
import Variable
import Types


import Auto


instance (FromJSON a) => FromJSON (Message a) where
Expand Down Expand Up @@ -49,4 +49,11 @@ instance CCSDS (Message Command) where

secondaryHeader (Message _ (Command cc _)) = [cc, 0]

payload (Message _ (Command _ ps)) = concat <$> mapM packParam ps
payload (Message _ (Command _ ps)) = concat <$> mapM packParam ps


instance (AutoShow a) => AutoShow (Message a) where

autoShow (Message mid m) = do
sm <- autoShow m
return $ "MID: " ++ (showHex mid "") ++ " " ++ sm
9 changes: 5 additions & 4 deletions Parameter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ instance FromJSON Parameter where

parseJSON (Object o) = Parameter <$> o .:? "label" .!= "unnamed"<*> parseJSON (Object o)

parseJSON (String s) = return $ Parameter "var" (Var (T.unpack s))
parseJSON (String s) = return $ Parameter (T.unpack s) (Var (T.unpack s))

parseJSON _ = error "Invalid parameter type."


instance Show Parameter where
instance AutoShow Parameter where

show (Parameter _ (Var id_)) = id_ ++ ":" ++ "<var>"
show (Parameter s d) = s ++ ":" ++ concatMap (`showHex` "|") (packData d)
autoShow p@(Parameter s _) = do
packed <- packParam p
return $ s ++ ":" ++ concatMap (`showHex` "|") packed
8 changes: 6 additions & 2 deletions Telemetry.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ module Telemetry (
Telemetry(Telemetry)
) where

import Control.Applicative ((<$>))
import GHC.Generics (Generic)
import Data.Aeson (FromJSON)
import Types
import Auto
import Parameter()

instance FromJSON Telemetry


instance Show Telemetry where
instance AutoShow Telemetry where

show (Telemetry ps) = "TLM: " ++ show ps
autoShow (Telemetry ps) = do
sp <- concat <$> mapM autoShow ps
return $ "TLM: " ++ sp
10 changes: 5 additions & 5 deletions Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,32 @@ data Telemetry = Telemetry {
} deriving (Generic)


data Message a = Message MessageID a deriving (Show)
data Message a = Message MessageID a


data MessageDef a = MessageDef {
variables :: [Variable]
,message :: Message a
} deriving (Show, Generic)
} deriving (Generic)


data MessageMeta = MessageMeta {
file :: FilePath
,frequency :: Double
} deriving (Show, Generic)
} deriving (Generic)


data Controller = Controller {
meta :: ControllerMeta
,sequenced :: [MessageMeta]
,parallel :: [MessageMeta]
} deriving (Show, Generic)
} deriving (Generic)


data ControllerMeta = ControllerMeta {
ip :: String
,port :: Integer
} deriving (Show, Generic)
} deriving (Generic)


data Config = Config {
Expand Down
10 changes: 5 additions & 5 deletions ac_set_mode.tlm
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@
{
"type": "uint8",
"value": 0,
"label": "_"
"label": "GAC_on"
},
{
"type": "uint8",
"value": 0,
"label": "_"
"label": "CMGs_enabled"
},
{
"type": "uint8",
"value": 0,
"label": "_"
"label": "RCS_enabled"
},
{
"type": "uint8",
"value": 0,
"label": "_"
"label": "RWA_enabled"
},
{
"type": "array",
"element_type": "uint8",
"values": [0,0,0],
"label": "_"
"label": "padding"
}
]
}
Expand Down
Binary file modified auto
Binary file not shown.

0 comments on commit b4e5ee7

Please sign in to comment.