summaryrefslogtreecommitdiff
path: root/exec
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2012-03-17 23:22:57 +0100
committerYves Fischer <yvesf-git@xapek.org>2012-03-17 23:22:57 +0100
commitd4f4f4609b8a78f7303a6782ab28892a337d32e7 (patch)
tree0e1183e49e1e5064eaa261db028b3b6c835d781b /exec
parent78e2065268603217a5f0c3b2542023eb87bcc913 (diff)
downloadhaskell-ebus-d4f4f4609b8a78f7303a6782ab28892a337d32e7.tar.gz
haskell-ebus-d4f4f4609b8a78f7303a6782ab28892a337d32e7.zip
set correct ebus-type in parser, move main() program to exec/
Diffstat (limited to 'exec')
-rw-r--r--exec/ebus-dump-layer2.hs39
1 files changed, 38 insertions, 1 deletions
diff --git a/exec/ebus-dump-layer2.hs b/exec/ebus-dump-layer2.hs
index 84d72e2..c8fd1b5 100644
--- a/exec/ebus-dump-layer2.hs
+++ b/exec/ebus-dump-layer2.hs
@@ -1,4 +1,41 @@
module Main(main) where
+
+import Network.EBus.Layer2
+import Data.Enumerator (Enumerator, Iteratee, run, ($$))
+import Data.Enumerator.Binary (enumHandle)
+import System.IO (hSetBinaryMode,stdin)
+import Data.ByteString (ByteString)
+import Data.Attoparsec.Enumerator (iterParser)
main = do
- print "Hello ebus-dump-layer"
+ -- * Select binary mode (True) or text mode (False) on a open handle. (See also openBinaryFile.)
+ hSetBinaryMode stdin True
+ -- * run
+ -- Run an iteratee until it finishes, and return either the final value (if it succeeded) or the error (if it failed).
+ -- * run_
+ -- Like run, except errors are converted to exceptions and thrown. Primarily useful for small scripts or other simple cases.
+
+ loop 100
+
+loop :: Int -> IO()
+loop 0 = do
+ print "finished"
+loop n = do
+ readAndDumpPacket
+ loop (n - 1)
+
+readAndDumpPacket :: IO()
+readAndDumpPacket = do
+ maybePacket <- run( enumSource $$ runParser )
+ case maybePacket of
+ Right result -> print result
+ Left error -> print error
+
+
+enumSource :: Enumerator ByteString IO a
+enumSource = enumHandle 1 stdin
+
+runParser :: Iteratee ByteString IO EbusPacket
+runParser = do
+ p <- iterParser ebusParserLayer2
+ return p