From: Mart Lubbers Date: Fri, 17 Mar 2017 14:53:53 +0000 (+0100) Subject: hopefully improved tcp and serial connection X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=639cdcf1c26177c87237bd5790e89184f531731d;p=mTask.git hopefully improved tcp and serial connection --- diff --git a/Devices/mTaskDevice.icl b/Devices/mTaskDevice.icl index eb32f49..ef94a06 100644 --- a/Devices/mTaskDevice.icl +++ b/Devices/mTaskDevice.icl @@ -136,7 +136,8 @@ deviceTaskAcked dev i [{t & ident=i}:ts] [t:ackFirst ts] deviceTaskDelete :: MTaskDevice MTaskTask -> Task () -deviceTaskDelete dev task = sendMessages [MTTaskDel task.ident] dev @! () +deviceTaskDelete dev task = sendMessages [MTTaskDel task.ident] dev + >>| upd (\ds->filter ((<>) dev) ds) deviceStore @! () deviceTaskDeleteAcked :: MTaskDevice Int -> Task () deviceTaskDeleteAcked d i = withDevices d $ deleteTask diff --git a/Devices/mTaskTCP.icl b/Devices/mTaskTCP.icl index 314799b..4e3aba6 100644 --- a/Devices/mTaskTCP.icl +++ b/Devices/mTaskTCP.icl @@ -4,6 +4,8 @@ import GenPrint import StdDebug import Devices.mTaskDevice import iTasks +from Data.Tuple import appSnd +from Text import class Text(indexOf), instance Text String derive class iTask TCPSettings derive gPrint MTaskMSGRecv @@ -20,12 +22,25 @@ instance MTaskDuplex TCPSettings where onDisconnect=onDisconnect} @! () where onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool) - onConnect _ (msgs,send,sendStopped) = (Ok "", Just (msgs,[],sendStopped), map encode send, False) + onConnect acc (msgs,send,sendStopped) = (Ok acc, Just (msgs,[],sendStopped), map encode send, False) whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool) - whileConnected Nothing _ (_,[],_) = (Ok "", Nothing, [], False) - whileConnected md _ (msgs,send,sendStopped) - = (Ok "", Just (msgs++map decode (maybeToList md),[],sendStopped), map encode send, False) + //We stop + whileConnected _ _ (_,_,True) = (Ok "", Nothing, [], True) + + //No new data and nothing to send + whileConnected Nothing acc (_,[],_) = (Ok acc, Nothing, [], False) + + //New data and possibly something to send + whileConnected (Just newdata) acc (msgs,send,sendStopped) + # (acc, nd) = process (acc +++ newdata) + | isEmpty nd && isEmpty send = (Ok acc, Nothing, [], False) + = (Ok acc, Just (msgs++map decode nd,[],sendStopped), map encode send, False) + + process :: String -> (String, [String]) + process s = case indexOf "\n" s of + -1 = (s, []) + i = appSnd (\ss->[s % (0,i):ss]) (process (s % (i, size s))) onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool)) onDisconnect _ (msgs,send,sendStopped) = (Ok "", Nothing) diff --git a/Tasks/Examples.dcl b/Tasks/Examples.dcl index f3a8a3a..414fd68 100644 --- a/Tasks/Examples.dcl +++ b/Tasks/Examples.dcl @@ -8,5 +8,6 @@ blink :: UserLED -> Main (ByteCode () Stmt) blinkShare :: Main (ByteCode () Stmt) ledtOn :: UserLED -> Main (ByteCode () Stmt) ledtOff :: UserLED -> Main (ByteCode () Stmt) +readDPin :: DigitalPin -> Main (ByteCode () Stmt) allmTasks :: Map String (Task (Main (ByteCode () Stmt))) diff --git a/Tasks/Examples.icl b/Tasks/Examples.icl index d82a767..9404274 100644 --- a/Tasks/Examples.icl +++ b/Tasks/Examples.icl @@ -46,14 +46,21 @@ ledtOn d = {main = ledOn (lit d) :. noOp} ledtOff :: UserLED -> Main (ByteCode () Stmt) ledtOff d = {main = ledOff (lit d) :. noOp} +readDPin :: DigitalPin -> Main (ByteCode () Stmt) +readDPin d = sds \pin=False In {main=pin =. digitalRead d :. noOp} + ledSelection :: Task UserLED ledSelection = enterInformation "Select LED" [] +pinSelection :: Task DigitalPin +pinSelection = enterInformation "Select digital pin" [] + allmTasks :: Map String (Task (Main (ByteCode () Stmt))) allmTasks = 'DM'.fromList [("countAndLed", treturn countAndLed) ,("ledOn", ledSelection @ ledtOn) ,("ledOff", ledSelection @ ledtOff) + ,("readDPin", pinSelection @ readDPin) ,("blink", ledSelection @ blink) ,("blinkShare", treturn blinkShare) ] diff --git a/client/interface.c b/client/interface.c index 8106945..0b994ea 100644 --- a/client/interface.c +++ b/client/interface.c @@ -4,6 +4,7 @@ #include #include +#include "chprintf.h" #include "interface.h" #include "ch.h" #include "hal.h" @@ -35,9 +36,6 @@ void write_dpin(uint8_t i, bool b) bool read_dpin(uint8_t i) { - if(i == 3){ - return palReadLine(LINE_BUTTON) == PAL_HIGH; - } return palReadLine(dpins[i]) == PAL_HIGH; } @@ -93,13 +91,10 @@ void setup(void) void debug(char *fmt, ...) { -// unsigned int i; -// write_byte((uint8_t)'m'); -// for(i = 0; i