From 6e3b45dd6cef95c1577a91b15a1256fa4b06ca88 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 24 Jan 2017 10:45:33 +0100 Subject: [PATCH] working demo --- int/halconf.h | 2 +- int/interface.c | 6 ------ int/interface.h | 1 - int/interface_linux.c | 5 ----- int/main.c | 6 +++--- int/task.c | 4 ++-- miTask.icl | 32 ++++++++++++++++---------------- 7 files changed, 22 insertions(+), 34 deletions(-) diff --git a/int/halconf.h b/int/halconf.h index 1275a5f..e556d48 100644 --- a/int/halconf.h +++ b/int/halconf.h @@ -294,7 +294,7 @@ * default configuration. */ #if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__) -#define SERIAL_DEFAULT_BITRATE 38400 +#define SERIAL_DEFAULT_BITRATE 9600 #endif /** diff --git a/int/interface.c b/int/interface.c index 312689a..510f5cb 100644 --- a/int/interface.c +++ b/int/interface.c @@ -83,12 +83,6 @@ void debug(char *fmt, ...) write_byte('\n'); } -void debugi(int i) -{ - char m[10]; - debug(itoa(i, m, 10)); -} - void pdie(char *s) { (void)s; diff --git a/int/interface.h b/int/interface.h index 6141559..b2968a9 100644 --- a/int/interface.h +++ b/int/interface.h @@ -27,7 +27,6 @@ void delay(long ms); void setup(void); void debug(char *fmt, ...); -void debugi(int i); void pdie(char *s); void die(char *fmt, ...); diff --git a/int/interface_linux.c b/int/interface_linux.c index c62e36f..dd94993 100644 --- a/int/interface_linux.c +++ b/int/interface_linux.c @@ -152,11 +152,6 @@ void debug(char *fmt, ...) va_end(ap); } -void debugi(int i) -{ - debug("%d", i); -} - void pdie(char *s) { perror(s); diff --git a/int/main.c b/int/main.c index 5acebef..d6d5953 100644 --- a/int/main.c +++ b/int/main.c @@ -3,7 +3,8 @@ #include #include -#ifndef STM +#ifdef STM +#else #include #endif @@ -93,8 +94,7 @@ int main(int argc, char *argv[]){ setup(); sds_init(); task_init(); - - debug("booting up"); + //debug("booting up"); while(true){ //Check for newetasks // debug("loop"); diff --git a/int/task.c b/int/task.c index a08e791..4ac8ce5 100644 --- a/int/task.c +++ b/int/task.c @@ -39,8 +39,8 @@ int task_register(void) //Read task bytecode for(unsigned int i = 0; i>= \ty->case ty of TCP = (enterInformation "Host" [] -&&- enterInformation "Port" []) >>= \(port,host)->syncNetworkChannel host port ch -// Serial = accWorld getDevices -// >>= \dl->(enterChoice "Device" [] dl -&&- enterInformation "Settings" []) -// >>= \(dev,set)->syncSerialChannel dev set decode encode ch + Serial = accWorld getDevices + >>= \dl->(enterChoice "Device" [] dl -&&- updateInformation "Settings" [] zero) + >>= \(dev,set)->syncSerialChannel dev set ch where getDevices :: !*World -> *(![String], !*World) getDevices w = case readDirectory "/dev" w of @@ -75,7 +75,6 @@ mTaskTask :: Task () mTaskTask = let (msgs, sdsShares) = makeMsgs 1000 bc in withShared ([], msgs, False) (\ch-> deviceSelector ch -// ||- sendTasks msgs ch//sendMsg msgs ch ||- processMessages ch messageShare sdsShares ||- viewSharedInformation "channels" [ViewWith lens] ch ||- viewSharedInformation "messages" [] messageShare @@ -132,8 +131,8 @@ mTaskTask = let (msgs, sdsShares) = makeMsgs 1000 bc in sendMsg :: [MTaskMSGSend] (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) -> Task () sendMsg m ch = upd (\(r,s,ss)->(r,s ++ m,True)) ch @! () -syncSerialChannel :: String TTYSettings (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n -syncSerialChannel dev opts decodeFun encodeFun rw = Task eval +syncSerialChannel :: String TTYSettings (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) -> Task () +syncSerialChannel dev opts rw = Task eval where eval event evalOpts tree=:(TCInit taskId ts) iworld=:{IWorld|world} = case TTYopen dev opts world of @@ -142,7 +141,7 @@ syncSerialChannel dev opts decodeFun encodeFun rw = Task eval = (ExceptionResult (exception err), {iworld & world=world}) (True, tty, world) # iworld = {iworld & world=world, resources=Just (TTYd tty)} - = case addBackgroundTask 42 (BackgroundTask (serialDeviceBackgroundTask rw decodeFun encodeFun)) iworld of + = case addBackgroundTask 42 (BackgroundTask (serialDeviceBackgroundTask rw)) iworld of (Error e, iworld) = (ExceptionResult (exception "h"), iworld) (Ok _, iworld) = (ValueResult NoValue {TaskEvalInfo|lastEvent=ts,removedTasks=[],refreshSensitive=True} NoRep (TCBasic taskId ts JSONNull False), iworld) @@ -157,28 +156,29 @@ syncSerialChannel dev opts decodeFun encodeFun rw = Task eval (Error e, iworld) = (ExceptionResult (exception "h"), iworld) (Ok _, iworld) = (DestroyedResult, iworld) -serialDeviceBackgroundTask :: (Shared ([m],Bool,[n],Bool)) (String -> m) (n -> String) !*IWorld -> *IWorld -serialDeviceBackgroundTask rw de en iworld +serialDeviceBackgroundTask :: (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) !*IWorld -> *IWorld +serialDeviceBackgroundTask rw iworld = case read rw iworld of (Error e, iworld) = abort "share couldn't be read" - (Ok (r,rs,s,ss), iworld) + (Ok (r,s,ss), iworld) # (Just (TTYd tty)) = iworld.resources - # tty = writet (map en s) tty + # tty = writet (map encode s) tty # (ml, tty) = case TTYavailable tty of (False, tty) = ([], tty) (_, tty) # (l, tty) = TTYreadline tty - = ([de l], tty) + | not (trace_tn ("recv: '" +++ l +++ "'")) = undef + = ([decode l], tty) # iworld = {iworld & resources=Just (TTYd tty)} - = case write (r++ml,rs,[],ss) rw iworld of + = case write (r++ml,[],False) rw iworld of (Error e, iworld) = abort "share couldn't be written" (Ok _, iworld) = case notify rw iworld of (Error e, iworld) = abort "share couldn't be notified" (Ok _, iworld) = iworld where - writet :: [String] !*TTY -> *TTY - writet [] t = t - writet [x:xs] t = writet xs (TTYwrite x t) + writet :: [String] -> (*TTY -> *TTY) + writet [] = id + writet [x:xs] = writet xs o TTYwrite x syncNetworkChannel :: String Int (Shared ([MTaskMSGRecv], [MTaskMSGSend], Bool)) -> Task () -- 2.20.1