Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module is the one to use when you want to use XCP over ethernet. Usage goes somewhat like this:
import Network.XcpEth import Data.Int main = do am <- loadAddressMap "myAddresses" a <- runXcpEth $ do connect "192.168.0.1" 12345 "192.168.0.2" 12345 a <- getVariable (0::Float) "myOwnVariable" setVariable "myOtherVariable" (42::Int8) return a disconnect putStrLn $ "Received " ++ show a
If you want to add other transport layer protocols,
just look at Xcp
and add the parts of the XCP message
that are specific to your transport layer protocol to the XCP packets
you get from Xcp
.
- data XcpEth a
- runXcpEth :: XcpEth a -> IO (Either String (a, [String]))
- connect :: IPAddress -> PortNumber -> IPAddress -> PortNumber -> XcpEth ()
- disconnect :: XcpEth ()
- setVariable :: ToByteString a => String -> a -> XcpEth ()
- getVariable :: ToByteString a => a -> String -> XcpEth a
- logString :: String -> XcpEth ()
- readCommands :: [String] -> XcpEth ()
- type AddressMap = Map String Word32
- loadAddressMap :: FilePath -> XcpEth ()
- setAddressMap :: AddressMap -> XcpEth ()
- module Network
- module Network.Udp
- throwError :: forall a. String -> XcpEth a
- class Storable a => ToByteString a
- type IPAddress = String
XcpEth Monad
The XcpEth monad. It is used to encapsulate sending commands from the host to the slave and receiving results.
runXcpEth :: XcpEth a -> IO (Either String (a, [String])) Source
Run an action and return either an error message, or the resulting value and log strings, if any.
XcpEth operations
:: IPAddress | Host IP (this computer). |
-> PortNumber | Host port number. |
-> IPAddress | Slave IP address. |
-> PortNumber | Slave port number. |
-> XcpEth () |
Connect to the given slave IP and portnumber, and send an XCP connect packet.
disconnect :: XcpEth () Source
Sends a disconnect XCP packet to the slave and closes the UDP socket.
:: ToByteString a | |
=> String | Name of the variable to set. |
-> a | Value to set. Must be of the correct type, otherwise funny things may happen on the slave. |
-> XcpEth () |
Set a variable in the slave memory.
:: ToByteString a | |
=> a | Just a dummy to fix the type of the variable to retrieve. |
-> String | Name of the variable. |
-> XcpEth a | Returns the retrieved value received from the slave. |
Get the value of a variable in the slave memory.
Reading strings with XcpCommand
s
readCommands :: [String] -> XcpEth () Source
Name to address maps and operations
type AddressMap = Map String Word32 Source
loadAddressMap :: FilePath -> XcpEth () Source
Reads a mapping from memory addresses to names from a simple text file. Each line is expected of the form address name.
setAddressMap :: AddressMap -> XcpEth () Source
Sets the address map to use by subsequent actions.
module Network
module Network.Udp
throwError :: forall a. String -> XcpEth a Source
class Storable a => ToByteString a Source
Class for types that can be converted to a lazy ByteString
for transmission.
toByteString