xcp-0.1.0.1: Partial implementation of the XCP protocol with ethernet as transport layer.

Safe HaskellNone
LanguageHaskell2010

Network.XcpEth

Contents

Description

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.

Synopsis

XcpEth Monad

data XcpEth a Source

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

connect Source

Arguments

:: 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.

setVariable Source

Arguments

:: 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.

getVariable Source

Arguments

:: 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.

logString :: String -> XcpEth () Source

Stores a log message in the internal log.

Reading strings with XcpCommands

Name to address maps and operations

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

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.

Minimal complete definition

toByteString

Other Types