Commit 829306 initial

7 files Merged and Committed by Richard Marko 2 years ago
initial

    
 1 @@ -0,0 +1,30 @@
 2 + Copyright Author name here (c) 2017
 3 + 
 4 + All rights reserved.
 5 + 
 6 + Redistribution and use in source and binary forms, with or without
 7 + modification, are permitted provided that the following conditions are met:
 8 + 
 9 +     * Redistributions of source code must retain the above copyright
10 +       notice, this list of conditions and the following disclaimer.
11 + 
12 +     * Redistributions in binary form must reproduce the above
13 +       copyright notice, this list of conditions and the following
14 +       disclaimer in the documentation and/or other materials provided
15 +       with the distribution.
16 + 
17 +     * Neither the name of Author name here nor the names of other
18 +       contributors may be used to endorse or promote products derived
19 +       from this software without specific prior written permission.
20 + 
21 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
32 \ No newline at end of file
1 @@ -0,0 +1,2 @@
2 + import Distribution.Simple
3 + main = defaultMain
 1 @@ -0,0 +1,65 @@
 2 + {-# LANGUAGE OverloadedStrings #-}
 3 + module Main where
 4 + 
 5 + import qualified Data.ByteString.Char8 as B
 6 + import System.IO
 7 + import System.Hardware.Serialport
 8 + 
 9 + import Control.Monad
10 + import Control.Exception
11 + import Control.Concurrent
12 + import Control.Concurrent.Async
13 + import Control.Concurrent.STM
14 + import Control.Concurrent.STM.TBQueue
15 + 
16 + import Network.Socket hiding (send, sendTo, recv, recvFrom)
17 + import Network.Socket.ByteString
18 + import Lib
19 + 
20 + settings = SerialPortSettings CS115200 8 One NoParity NoFlowControl 1
21 + --  - 0.1 second receive timeout
22 + --
23 + 
24 + --serialQueue = TBQueuea B.ByteString
25 + 
26 + --run :: Handle -> IO ()
27 + --run h = do
28 + --  hPutStrLn h "ip()"
29 + --  mapM_ (\x -> hGetLine h >>= print) [0..10]
30 + 
31 + toSerial q h = forever $ do
32 +   x <- atomically $ readTBQueue q
33 +   hPutStr h x
34 + 
35 + --  x <- atomically $ tryReadTBQueue q
36 + --  case x of
37 + --    Nothing -> threadDelay 100 >> return ()
38 + --    (Just y) -> hPutStr h y
39 +   --threadDelay 1000000
40 + 
41 + fromSerial q h = forever $ do
42 +   e <- hIsEOF h
43 +   if e
44 +     then threadDelay 100 -- 0000
45 +     else do
46 +             c <- hGetChar h
47 +             atomically $ writeTBQueue q c
48 + 
49 + toStdout q = forever $ do
50 +   --x <- atomically $ tryReadTBQueue q
51 +   x <- atomically $ readTBQueue q
52 +   putChar x
53 + 
54 + run qI qO h = do
55 +   runConcurrently $    Concurrently (toSerial qI h)
56 +                     *> Concurrently (fromSerial qO h)
57 +                     *> Concurrently (toStdout qO)
58 + 
59 + main :: IO ()
60 + main = do
61 +   sIn <- atomically $ newTBQueue 1000
62 +   sOut <- atomically $ newTBQueue 10000
63 + 
64 +   atomically $ writeTBQueue sIn ""
65 +   mapM_ (\x -> atomically $ writeTBQueue sIn "version\n") [0..900]
66 +   bracket (hOpenSerial "/dev/ttyACM0" settings) hClose (run sIn sOut)
 1 @@ -0,0 +1,46 @@
 2 + name:                hc
 3 + version:             0.1.0.0
 4 + synopsis:            hacked_cnc
 5 + description:         Machine control framework
 6 + homepage:            
 7 + license:             BSD3
 8 + license-file:        LICENSE
 9 + author:              Richard Marko
10 + maintainer:          srk@48.io
11 + copyright:           2017 Richard Marko
12 + category:            Web
13 + build-type:          Simple
14 + extra-source-files:  README.md
15 + cabal-version:       >=1.10
16 + 
17 + library
18 +   hs-source-dirs:      src
19 +   exposed-modules:     Lib
20 +   build-depends:       base >= 4.7 && < 5
21 +   default-language:    Haskell2010
22 + 
23 + executable hc
24 +   hs-source-dirs:      app
25 +   main-is:             Main.hs
26 +   ghc-options:         -threaded -rtsopts -with-rtsopts=-N
27 +   build-depends:       base
28 +                      , hc
29 +                      , bytestring
30 +                      , async
31 +                      , stm
32 +                      , network
33 +                      , serialport
34 +   default-language:    Haskell2010
35 + 
36 + test-suite hc-test
37 +   type:                exitcode-stdio-1.0
38 +   hs-source-dirs:      test
39 +   main-is:             Spec.hs
40 +   build-depends:       base
41 +                      , hc
42 +   ghc-options:         -threaded -rtsopts -with-rtsopts=-N
43 +   default-language:    Haskell2010
44 + 
45 + source-repository head
46 +   type:     git
47 +   location:
1 @@ -0,0 +1,6 @@
2 + module Lib
3 +     ( someFunc
4 +     ) where
5 + 
6 + someFunc :: IO ()
7 + someFunc = putStrLn "someFunc"
 1 @@ -0,0 +1,67 @@
 2 + # This file was automatically generated by 'stack init'
 3 + # 
 4 + # Some commonly used options have been documented as comments in this file.
 5 + # For advanced use and comprehensive documentation of the format, please see:
 6 + # http://docs.haskellstack.org/en/stable/yaml_configuration/
 7 + 
 8 + # Resolver to choose a 'specific' stackage snapshot or a compiler version.
 9 + # A snapshot resolver dictates the compiler version and the set of packages
10 + # to be used for project dependencies. For example:
11 + # 
12 + # resolver: lts-3.5
13 + # resolver: nightly-2015-09-21
14 + # resolver: ghc-7.10.2
15 + # resolver: ghcjs-0.1.0_ghc-7.10.2
16 + # resolver:
17 + #  name: custom-snapshot
18 + #  location: "./custom-snapshot.yaml"
19 + resolver: lts-7.14
20 + 
21 + # User packages to be built.
22 + # Various formats can be used as shown in the example below.
23 + # 
24 + # packages:
25 + # - some-directory
26 + # - https://example.com/foo/bar/baz-0.0.2.tar.gz
27 + # - location:
28 + #    git: https://github.com/commercialhaskell/stack.git
29 + #    commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
30 + # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
31 + #   extra-dep: true
32 + #  subdirs:
33 + #  - auto-update
34 + #  - wai
35 + # 
36 + # A package marked 'extra-dep: true' will only be built if demanded by a
37 + # non-dependency (i.e. a user package), and its test suites and benchmarks
38 + # will not be run. This is useful for tweaking upstream packages.
39 + packages:
40 + - '.'
41 + # Dependency packages to be pulled from upstream that are not in the resolver
42 + # (e.g., acme-missiles-0.3)
43 + extra-deps:
44 + - serialport-0.4.7
45 + 
46 + # Override default flag values for local packages and extra-deps
47 + flags: {}
48 + 
49 + # Extra package databases containing global packages
50 + extra-package-dbs: []
51 + 
52 + # Control whether we use the GHC we find on the path
53 + # system-ghc: true
54 + # 
55 + # Require a specific version of stack, using version ranges
56 + # require-stack-version: -any # Default
57 + # require-stack-version: ">=1.1"
58 + # 
59 + # Override the architecture used by stack, especially useful on Windows
60 + # arch: i386
61 + # arch: x86_64
62 + # 
63 + # Extra directories used by stack for building
64 + # extra-include-dirs: [/path/to/dir]
65 + # extra-lib-dirs: [/path/to/dir]
66 + # 
67 + # Allow a newer minor version of GHC than the snapshot specifies
68 + # compiler-check: newer-minor
1 @@ -0,0 +1,2 @@
2 + main :: IO ()
3 + main = putStrLn "Test suite not yet implemented"