uint8_t read_byte(void)
{
- return sdGet(&SD3);
+ return (uint8_t)sdGet(&SD3);
}
void write_byte(uint8_t b)
void debug(char *fmt, ...)
{
- //unsigned int i;
- //write_byte('m');
- //for(i = 0; i<strlen(fmt); i++){
- // write_byte((uint8_t)fmt[i]);
- //}
- //write_byte('\n');
+// unsigned int i;
+// write_byte((uint8_t)'m');
+// for(i = 0; i<strlen(fmt); i++){
+// write_byte((uint8_t)fmt[i]);
+// }
+// write_byte('\n');
(void)fmt;
}
'\0' = MTEmpty
'\n' = MTEmpty
'm' = MTMessage x
+ 't' = MTTaskAdded (from16bit (x % (1,3)))
'u' = MTPub (from16bit (x % (1,3))) (x % (3,5))
_ = MTMessage x//abort ("Didn't understand message: " +++ join " " [toString (toInt c)\\c<-: x] +++ "\n")
instance toString MTaskMSGRecv where
toString (MTPub i v) = "Publish id: " +++ toString i
+++ " value " +++ safePrint v
+ toString (MTTaskAdded i) = "Task added with id: " +++ toString i
toString MTEmpty = "Empty message"
bclength :: BC -> Int
)
)}
-deviceSelector :: (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) -> Task ()
-deviceSelector ch = enterInformation "Type" []
+withDevice :: ((Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) -> Task a) -> Task a | iTask a
+withDevice t = withShared ([], [], False) \ch->
+ enterInformation "Type" []
>>= \ty->case ty of
TCP = (enterInformation "Host" [] -&&- enterInformation "Port" [])
- >>= \(port,host)->syncNetworkChannel host port ch
+ >>= \(port,host)->t ch -|| syncNetworkChannel host port ch
Serial = accWorld getDevices
>>= \dl->(enterChoice "Device" [] dl -&&- updateInformation "Settings" [] zero)
- >>= \(dev,set)->syncSerialChannel dev set ch
+ >>= \(dev,set)->t ch -|| syncSerialChannel dev set ch
where
getDevices :: !*World -> *(![String], !*World)
getDevices w = case readDirectory "/dev" w of
mTaskTask :: Task ()
mTaskTask = let (msgs, sdsShares) = makeMsgs 1000 bc in
- withShared ([], msgs, False) (\ch->
- deviceSelector ch
+ withDevice (\ch->
+ sendMsg msgs ch
||- processMessages ch messageShare sdsShares
||- viewSharedInformation "channels" [ViewWith lens] ch
||- viewSharedInformation "messages" [] messageShare
updateSDSs :: [(Int, Shared Int)] (Shared [String]) MTaskMSGRecv -> Task ()
updateSDSs _ m (MTMessage s) = upd (\l->take 20 [s:l]) m @! ()
- updateSDSs _ _ MTEmpty = return ()
updateSDSs [(id, sh):xs] m n=:(MTPub i d)
| id == i = set ((toInt d.[0])*265 + toInt d.[1]) sh @! ()
= updateSDSs xs m n
+ updateSDSs _ _ _ = return ()
lens :: ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> ([String], [String])
lens (r,s,_) = (map toString r, map toString s)