--- /dev/null
+[submodule "clean-platform"]
+ path = clean-platform
+ url = https://gitlab.science.ru.nl/clean-and-itasks/clean-platform.git
+ branch = patch-JSON
-I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/StdEnv\
-I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/TCPIP\
-I $(CLEAN_HOME)/lib/iTasks-SDK/Server\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Independent/Deprecated/StdLib\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Posix\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Linux\
- -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/clean-platform/src/libraries/OS-Linux-64\
+ -I ./clean-platform/src/libraries/OS-Independent\
+ -I ./clean-platform/src/libraries/OS-Independent/Deprecated/StdLib\
+ -I ./clean-platform/src/libraries/OS-Posix\
+ -I ./clean-platform/src/libraries/OS-Linux\
+ -I ./clean-platform/src/libraries/OS-Linux-64\
-I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/graph_copy/linux64\
-I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/graph_copy/common\
-I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/SAPL\
--- /dev/null
+Subproject commit e79aa3e3f1704c704efc67655e6588a185578de1
--- /dev/null
+#ifndef MTASK_H
+#define MTASK_H
+#define BCNOP 1
+#define BCLAB 2
+#define BCPUSH 3
+#define BCPOP 4
+#define BCSDSSTORE 5
+#define BCSDSFETCH 6
+#define BCSDSPUBLISH 7
+#define BCNOT 8
+#define BCADD 9
+#define BCSUB 10
+#define BCMUL 11
+#define BCDIV 12
+#define BCAND 13
+#define BCOR 14
+#define BCEQ 15
+#define BCNEQ 16
+#define BCLES 17
+#define BCGRE 18
+#define BCLEQ 19
+#define BCGEQ 20
+#define BCJMP 21
+#define BCJMPT 22
+#define BCJMPF 23
+#define BCSERIALAVAIL 24
+#define BCSERIALPRINT 25
+#define BCSERIALPRINTLN 26
+#define BCSERIALREAD 27
+#define BCSERIALPARSEINT 28
+#define BCANALOGREAD 29
+#define BCANALOGWRITE 30
+#define BCDIGITALREAD 31
+#define BCDIGITALWRITE 32
+#define BCTEST 33
+#endif
CFLAGS:=-g -Wall -Wextra -Werror -DDEBUG
PROG:=main
-OBJS:=interpret.o sds.o task.o main.o
+OBJS:=interpret.o sds.o task.o main.o interface.o
all: mTaskSymbols.h $(PROG)
--- /dev/null
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef STM32F767xx
+#include "stm32f7xx_hal.h"
+#include "gpio.h"
+#include "usart.h"
+#else
+#include <stdio.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <signal.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+
+#include "interface.h"
+
+#define SET_LED_RED GPIOB->BSRR = GPIO_PIN_14
+#define RESET_LED_RED GPIOB->BSRR = GPIO_PIN_14 << 16
+
+#define SET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7
+#define RESET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 << 16
+
+#define SET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0
+#define RESET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 << 16
+
+//Globals
+#ifdef STM32F767xx
+volatile char uartf = 0;
+#else
+struct timeval tv1;
+int sock_fd = -1;
+int fd = -1;
+int gargc;
+char **gargv;
+#endif
+uint8_t bt;
+
+//Specifics
+#ifdef STM32F767xx
+void _exit(int i){
+ while(1);
+ (void)i;
+}
+
+void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
+{
+ uartf=1;
+}
+#else
+void killHandler(int i)
+{
+ printf("%i caught, Bye...\n", i);
+ exit(1);
+}
+
+void usage(FILE *o, char *arg0){
+ fprintf(o, "Usage: %s [opts]\n\nOptions\n"
+ "-p PORT Custom port number, default: 8123\n" , arg0);
+}
+#endif
+
+//Interface things
+long millis() {
+#ifdef STM32F767xx
+ return HAL_GetTick();
+#else
+ if (gettimeofday(&tv1, NULL) == -1)
+ pdie("gettimeofday");
+ return tv1.tv_sec*1000 + tv1.tv_usec/1000;
+#endif
+}
+
+bool input_available(){
+#ifdef STM32F767xx
+ return false;
+#else
+ struct timeval tv;
+ fd_set fds;
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ if (select(fd+1, &fds, NULL, NULL, &tv) == -1)
+ pdie("select");
+ return FD_ISSET(fd, &fds);
+#endif
+}
+
+uint8_t read_byte()
+{
+#ifdef STM32F767xx
+ HAL_UART_Receive(&huart3, &bt, 1, 1000);
+ return 0;
+#else
+ read(fd, &bt, 1);
+ return bt;
+#endif
+}
+
+void write_byte(uint8_t b)
+{
+#ifdef STM32F767xx
+ HAL_UART_Transmit_DMA(&huart3, &b, 1);
+#else
+ write(fd, &b, 1);
+#endif
+}
+
+void delay(long ms)
+{
+#ifdef STM32F767xx
+ HAL_Delay(ms);
+#else
+ usleep(ms*1000);
+#endif
+}
+
+void setup()
+{
+#ifdef STM32F767xx
+#else
+ int port = 8123, opti = 1;
+ //Register signal handler
+ if(signal(SIGINT, killHandler) == SIG_ERR){
+ die("Couldn't register signal handler...\n");
+ }
+ if(signal(SIGTERM, killHandler) == SIG_ERR){
+ die("Couldn't register signal handler...\n");
+ }
+ //Command line arguments
+ while(opti < gargc){
+ if(strcmp((*gargv)+opti, "-h") == 0){
+ usage(stdout, gargv[0]);
+ exit(EXIT_SUCCESS);
+ } else if(strcmp(gargv[opti], "-p") == 0 && opti+1<gargc){
+ port = atoi(gargv[++opti]);
+ if(port < 1)
+ die("Port numbers are > 1\n");
+ } else {
+ usage(stderr, gargv[0]);
+ exit(EXIT_FAILURE);
+ }
+ opti++;
+ }
+
+ //Open file descriptors
+ struct sockaddr_in sa;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sin_family = AF_INET;
+ sa.sin_addr.s_addr = INADDR_ANY;
+ sa.sin_port = htons(port);
+
+ if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
+ pdie("socket");
+ if(bind(sock_fd, (struct sockaddr*)&sa, sizeof(sa)) == -1)
+ pdie("bind");
+ if(listen(sock_fd, 10) == -1)
+ pdie("listen");
+
+ printf("Listening on %d\n", port);
+ fflush(stdout);
+ if((fd = accept(sock_fd, (struct sockaddr*)NULL, NULL)) == -1)
+ pdie("accept");
+#endif
+}
--- /dev/null
+#ifndef MAIN_H
+#define MAIN_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#ifndef STM32F767xx
+extern int gargc;
+extern char **gargv;
+#endif
+
+uint8_t read_byte();
+void write_byte(uint8_t b);
+
+void write_dpin(uint8_t i, bool b);
+bool read_dpin(uint8_t i);
+
+void write_apin(uint8_t i, uint8_t a);
+uint8_t read_apin(uint8_t i);
+
+long millis();
+bool input_available();
+void delay(long ms);
+
+void setup();
+
+#define read16() 256*read_byte() + read_byte()
+#ifdef STM32F767xx
+#define debug(s, ...) ;
+#define pdie(s) ;
+#define die(s, ...) ;
+#else
+
+#ifdef DEBUG
+#define debug(s, ...) printf(s, ##__VA_ARGS__);
+#else
+#define debug(s, ...) ;
+#endif
+
+#define pdie(s) {perror(s); exit(1);}
+#define die(s, ...) {fprintf(stderr, s, ##__VA_ARGS__); exit(1);}
+#endif
+
+#endif
#include "task.h"
#include "sds.h"
-#ifdef ARDUINO
+#ifdef STM32F767xx
#define trace(op, ...) ;
#else
-#define trace(op, ...) printf("pc: %d, sp: %d, op: " op, pc, sp, ##__VA_ARGS__);
+#define trace(op, ...) ;
+//printf("pc: %d, sp: %d, op: " op, pc, sp, ##__VA_ARGS__);
#endif
void run_task(struct task *t)
char stack[STACKSIZE] = {0};
printf("Running task with length: %d\n", plen);
while(pc != plen){
- printf("program: %d\n", program[pc]);
- printf("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
- stack[0], stack[1], stack[2], stack[3], stack[4],
- stack[5], stack[6], stack[7], stack[8], stack[9]);
+ //printf("program: %d\n", program[pc]);
+ //printf("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+ // stack[0], stack[1], stack[2], stack[3], stack[4],
+ // stack[5], stack[6], stack[7], stack[8], stack[9]);
switch(program[pc++]){
case BCNOP: trace("nop\n");
#include "mTaskSymbols.h"
#include "sds.h"
#include "task.h"
-#include "misc.h"
+#include "interface.h"
#define MSG_GET_TASK 't'
#define MSG_DEL_TASK 'd'
#define MSG_SDS_SPEC 's'
#define MSG_SDS_UPD 'u'
-void _exit(int i){
- while(1);
- (void)i;
-}
-
-//Globals
-#ifdef STM32F767xx
-volatile char uartf = 0;
-#else
-struct timeval tv1;
-int sock_fd = -1;
-int fd = -1;
-int *argc;
-char **argv;
-#endif
-uint8_t bt;
-
-#define SET_LED_RED GPIOB->BSRR = GPIO_PIN_14
-#define RESET_LED_RED GPIOB->BSRR = GPIO_PIN_14 << 16
-
-#define SET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7
-#define RESET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 << 16
-
-#define SET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0
-#define RESET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 << 16
-
-long millis() {
-#ifdef STM32F767xx
- return HAL_GetTick();
-#else
- if (gettimeofday(&tv1, NULL) == -1)
- pdie("gettimeofday");
- return tv1.tv_sec*1000 + tv1.tv_usec/1000;
-#endif
-}
-
-bool input_available(){
-#ifdef STM32F767xx
- return false;
-#else
- struct timeval tv;
- fd_set fds;
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- FD_ZERO(&fds);
- FD_SET(fd, &fds);
- if (select(fd+1, &fds, NULL, NULL, &tv) == -1)
- pdie("select");
- return FD_ISSET(fd, &fds);
-#endif
-}
-
-uint8_t read_byte()
-{
-#ifdef STM32F767xx
- HAL_UART_Receive(&huart3, &bt, 1, 1000);
- return 0;
-#else
- read(fd, &bt, 1);
- return bt;
-#endif
-}
-
-void write_byte(uint8_t b)
-{
-#ifdef STM32F767xx
- HAL_UART_Transmit_DMA(&huart3, &b, 1);
-#else
- write(fd, &b, 1);
-#endif
-}
-
-void delay(int ms)
-{
-#ifdef STM32F767xx
- HAL_Delay(ms);
-#else
- usleep(ms*1000);
-#endif
-}
-
-#ifndef STM32F767xx
-void killHandler(int i)
-{
- printf("%i caught, Bye...\n", i);
- exit(1);
-}
-#endif
-
-#ifdef STM32F767xx
-void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
-{
- uartf=1;
-}
-#endif
-
void read_message()
{
//Find next task
}
}
-void usage(FILE *o, char *arg0){
- fprintf(o, "Usage: %s [opts]\n\nOptions\n"
- "-p PORT Custom port number, default: 8123\n" , arg0);
-}
-
-void setup()
-{
-#ifdef STM32F767xx
-#else
- int port = 8123, opti = 1;
- //Register signal handler
- if(signal(SIGINT, killHandler) == SIG_ERR){
- die("Couldn't register signal handler...\n");
- }
- if(signal(SIGTERM, killHandler) == SIG_ERR){
- die("Couldn't register signal handler...\n");
- }
- //Command line arguments
- while(opti < *argc){
- if(strcmp((*argv)+opti, "-h") == 0){
- usage(stdout, argv[0]);
- exit(EXIT_SUCCESS);
- } else if(strcmp(argv[opti], "-p") == 0 && opti+1<*argc){
- port = atoi(argv[++opti]);
- if(port < 1)
- die("Port numbers are > 1\n");
- } else {
- usage(stderr, argv[0]);
- exit(EXIT_FAILURE);
- }
- opti++;
- }
-
- //Open file descriptors
- struct sockaddr_in sa;
-
- memset(&sa, 0, sizeof(sa));
- sa.sin_family = AF_INET;
- sa.sin_addr.s_addr = INADDR_ANY;
- sa.sin_port = htons(port);
-
- if((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
- pdie("socket");
- if(bind(sock_fd, (struct sockaddr*)&sa, sizeof(sa)) == -1)
- pdie("bind");
- if(listen(sock_fd, 10) == -1)
- pdie("listen");
-
- printf("Listening on %d\n", port);
- fflush(stdout);
- if((fd = accept(sock_fd, (struct sockaddr*)NULL, NULL)) == -1)
- pdie("accept");
-#endif
-
- //Initialize systems
- sds_init();
- task_init();
-}
-
void loop()
{
int ct;
long cyclestart;
struct task *curtask;
+
if(input_available())
read_message();
+
//Run tasks
cyclestart = millis();
for(ct = 0; ct<MAXTASKS; ct++){
// debug("Task %d not scheduled\n", ct);
continue;
}
-#ifdef DEBUG
printf("Current task to run: %d\n", ct);
- getchar();
-#endif
run_task(curtask);
+ curtask->lastrun = cyclestart;
}
write_byte('\n');
}
#ifdef STM32F767xx
-int main1(void)
+int main1(void){
#else
-int main(int ac, char *av[])
-#endif
-{
-#ifndef STM32F767xx
- argc = ∾
- argv = av;
+int main(int argc, char *argv[]){
+ gargc = argc;
+ gargv = argv;
#endif
+ //Initialize systems
setup();
+ sds_init();
+ task_init();
write_byte('\n');
while(true){
//Check for new tasks
loop();
- debug("Waiting for 500ms\n");
- delay(500);
- debug("done waiting\n");
- delay(500);
+ delay(10);
}
return 0;
}
+++ /dev/null
-#ifndef MAIN_H
-#define MAIN_H
-
-#include <stdint.h>
-
-uint8_t read_byte();
-void write_byte(uint8_t b);
-#endif
#ifndef MISC_H
#define MISC_H
-#include "main.h"
+#include "interface.h"
#define read16() 256*read_byte() + read_byte()
#ifdef STM32F767xx
#include <stdio.h>
#endif
-#include "main.h"
+#include "interface.h"
#include "interpret.h"
#include "misc.h"
#include "sds.h"
{
uint8_t cs, id;
//Read identifier
- id = read_byte();
+ id = read16();
for(cs = 0; cs<MAXSDSS; cs++){
if(!sdss[cs].used)
if(sdss[cs].id == id){
//Read value
sdss[cs].value = read16();
+ debug("\nReceived sds update %d: %d\n",
+ sdss[cs].id, sdss[cs].value);
return true;
}
}
//Return the task number for later removal
debug("Received a task of length %d\n", tasks[ct].tlen);
tasks[ct].used = true;
+ tasks[ct].lastrun = 0L;
return ct;
}
from Data.Monoid import class Semigroup, class Monoid
import mTask
-:: MTaskMessage
+:: MTaskMSGRecv
+ = MTPub Int String
+ | MTMessage String
+ | MTEmpty
+
+:: MTaskMSGSend
= MTSds Int String
| MTTask Int String
- | MTPub Int String
| MTUpd Int String
- | MTEmpty
-instance toString MTaskMessage
-encode :: MTaskMessage -> String
-decode :: String -> MTaskMessage
+instance toString MTaskMSGRecv
+instance toString MTaskMSGSend
+encode :: MTaskMSGSend -> String
+decode :: String -> MTaskMSGRecv
:: BC
= BCNop
instance boolExpr ByteCode
instance analogIO ByteCode
instance digitalIO ByteCode
-instance If ByteCode Stmt Stmt Stmt
-instance If ByteCode e Stmt Stmt
-instance If ByteCode Stmt e Stmt
-instance If ByteCode x y Expr
+//instance If ByteCode Stmt Stmt Stmt
+//instance If ByteCode e Stmt Stmt
+//instance If ByteCode Stmt e Stmt
+instance If ByteCode x y Stmt
instance IF ByteCode
instance noOp ByteCode
//pub :: (ByteCode a b) -> ByteCode a b
-toMessages :: Int (String, BCState) -> [MTaskMessage]
+toMessages :: Int (String, BCState) -> ([MTaskMSGSend], BCState)
+toSDSUpdate :: Int Int -> [MTaskMSGSend]
toByteVal :: BC -> [Char]
toReadableByteCode :: (ByteCode a b) -> (String, BCState)
import qualified Data.Map as DM
import Text.Encodings.Base64
-encode :: MTaskMessage -> String
+encode :: MTaskMSGSend -> String
encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n"
encode (MTTask to data) = "t" +++ to16bit to +++ to16bit (size data) +++ data +++ "\n"
-encode (MTPub i v) = "u" +++ to16bit i +++ v +++ "\n"
encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n"
-encode MTEmpty = ""
-decode :: String -> MTaskMessage
+
+decode :: String -> MTaskMSGRecv
decode x
| size x == 0 = MTEmpty
= case x.[0] of
'\0' = MTEmpty
- 'u' = MTUpd (from16bit (x % (1,3))) (x % (3,5))
+ 'u' = MTPub (from16bit (x % (1,3))) (x % (3,5))
_ = abort ("Didn't understand message: " +++ join " " [toString (toInt c)\\c<-: x] +++ "\n")
safePrint :== toString o toJSON
-derive gPrint MTaskMessage
-instance toString MTaskMessage where
+instance toString MTaskMSGSend where
toString (MTSds i v) = "Sds id: " +++ toString i
+++ " value " +++ safePrint v
toString (MTTask to data) = "Task timeout: " +++ toString to
+++ " data " +++ safePrint data
- toString (MTPub i v) = "Publish id: " +++ toString i
- +++ " value " +++ safePrint v
toString (MTUpd i v) = "Update id: " +++ toString i
+++ " value " +++ safePrint v
+
+instance toString MTaskMSGRecv where
+ toString (MTPub i v) = "Publish id: " +++ toString i
+ +++ " value " +++ safePrint v
toString MTEmpty = "Empty message"
bclength :: BC -> Int
toByteVal :: BC -> [Char]
toByteVal b
-# bt = toChar $ consIndex{|*|} b
+# bt = toChar $ consIndex{|*|} b + 1
= [bt:case b of
(BCPush i) = i
(BCLab i) = [toChar i]
digitalRead p = retrn [BCDigitalRead $ pin p]
digitalWrite p b = b <+-> [BCDigitalWrite $ pin p]
-instance If ByteCode Stmt Stmt Stmt where If b t e = BCIfStmt b t e
-instance If ByteCode e Stmt Stmt where If b t e = BCIfStmt b t e
-instance If ByteCode Stmt e Stmt where If b t e = BCIfStmt b t e
-instance If ByteCode x y Expr where If b t e = BCIfStmt b t e
+//instance If ByteCode Stmt Stmt Stmt where If b t e = BCIfStmt b t e
+//instance If ByteCode e Stmt Stmt where If b t e = BCIfStmt b t e
+//instance If ByteCode Stmt e Stmt where If b t e = BCIfStmt b t e
+instance If ByteCode x y Stmt where If b t e = BCIfStmt b t e
instance IF ByteCode where
IF b t e = BCIfStmt b t e
(?) b t = BCIfStmt b t $ retrn []
// where
// bc :: ByteCode Int Expr
// bc = (lit 36 +. lit 42) +. lit 44
-toMessages :: Int (String, BCState) -> [MTaskMessage]
-toMessages interval (bytes, {sdss}) = [MTSds i (toString b)\\(i,b)<-sdss] ++ [MTTask interval bytes]
+toMessages :: Int (String, BCState) -> ([MTaskMSGSend], BCState)
+toMessages interval (bytes, st=:{sdss}) = ([MTSds i (toString b)\\(i,b)<-sdss] ++ [MTTask interval bytes], st)
+
+toSDSUpdate :: Int Int -> [MTaskMSGSend]
+toSDSUpdate i v = [MTUpd i (to16bit v)]
Start = toMessages 500 $ toRealByteCode (unMain bc)
//Start = fst $ toReadableByteCode $ unMain bc
import iTasks
import mTask
-derive class iTask MTaskMessage
+derive class iTask MTaskMSGRecv, MTaskMSGSend
Start :: *World -> *World
Start world = startEngine (
enterInformation "Port Number?" []
>>= \port->withShared ([], False, [], False) (mTaskTask port)
) world
-Start world = startEngine mTaskTask world
+//Start world = startEngine mTaskTask world
-mTaskTask :: Int (Shared ([MTaskMessage],Bool,[MTaskMessage],Bool)) -> Task ()
+mTaskTask :: Int (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
mTaskTask port ch =
- syncNetworkChannel "localhost" port "\n" decode encode ch ||-
+ syncNetworkChannel "localhost" port "\n" decode encode` ch ||-
+ sendMsg msgs ch ||-
(
- sendMsg msgs ch >>= \_->
- viewSharedInformation "channels" [ViewWith lens] ch @! ()
- ) >>* [OnAction ActionFinish (always shutDown)]
+ (
+ consumeNetworkStream (processSDSs sdsShares messageShare) ch ||-
+ viewSharedInformation "channels" [ViewWith lens] ch ||-
+ viewSh sdsShares ch
+ ) >>* [OnAction ActionFinish (always shutDown)]
+ )
where
- lens :: ([MTaskMessage],Bool,[MTaskMessage],Bool) -> ([String], [String])
- lens (r,_,s,_) = (f r, f s)
+ encode` m
+ | not (trace_tn (toString (toJSON m))) = undef
+ = encode m
+
+ messageShare :: Shared [String]
+ messageShare = sharedStore "mTaskMessagesRecv" []
+
+ processSDSs :: [(Int, Shared Int)] (Shared [String]) [MTaskMSGRecv] -> Task ()
+ processSDSs _ _ [] = return ()
+ processSDSs s y [x:xs] = updateSDSs s y x >>= \_->processSDSs s y xs
+
+ updateSDSs :: [(Int, Shared Int)] (Shared [String]) MTaskMSGRecv -> Task ()
+ updateSDSs _ m (MTMessage s) = upd (\l->[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
+
+ lens :: ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool) -> ([String], [String])
+ lens (r,_,s,_) = (f r, map toString s)
where
f [] = []
f [MTEmpty:xs] = f xs
f [x:xs] = [toString x:f xs]
- msgs
- | not (trace_tn (fst (toReadableByteCode (unMain bc)))) = undef
- = toMessages 500 (toRealByteCode (unMain bc))
+ viewSh :: [(Int, Shared Int)] (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
+ viewSh [] ch = return ()
+ viewSh [(i, sh):xs] ch
+ # sharename = "SDS-" +++ toString i
+ = (
+ viewSharedInformation ("SDS-" +++ toString i) [] sh ||-
+ forever (
+ enterInformation sharename []
+ >>* [OnAction ActionOk
+ (ifValue (\j->j>=1 && j <= 3)
+ (\c->set c sh
+ >>= \_->sendMsg (toSDSUpdate i c) ch
+ @! ()
+ )
+ )]
+ )
+ ) ||- viewSh xs ch
+
+ sdsShares = makeShares st
- bc :: Main (ByteCode Int Stmt)
- bc = sds \x=1 In {main =
- If (x ==. lit 3)
- (x =. lit 1)
- (x =. x +. lit 1) :. pub x}
+ (msgs, st) = toMessages 500 (toRealByteCode (unMain bc))
-sendMsg :: [MTaskMessage] (Shared ([MTaskMessage],Bool,[MTaskMessage],Bool)) -> Task ()
-sendMsg m ch
-| not (trace_tn (join "\n" (map (toString o toJSON) m))) = undef
-= upd (\(r,rs,s,ss)->(r,rs,s ++ m,ss)) ch @! ()
+ bc :: Main (ByteCode () Stmt)
+ bc = sds \x=1 In sds \pinnetje=1 In {main =
+ x =. x +. lit 1 :.
+ pub x :.
+ IF (pinnetje ==. lit 1) (
+ analogWrite A0 (lit 1) :.
+ analogWrite A1 (lit 0) :.
+ analogWrite A2 (lit 0)
+ ) (
+ IF (pinnetje ==. lit 2) (
+ analogWrite A0 (lit 0) :.
+ analogWrite A1 (lit 1) :.
+ analogWrite A2 (lit 0)
+ ) (
+ analogWrite A0 (lit 0):.
+ analogWrite A1 (lit 0):.
+ analogWrite A2 (lit 1)
+ )
+ )}
+// bc :: Main (ByteCode Int Stmt)
+// bc = sds \x=1 In {main =
+// If (x ==. lit 3)
+// (x =. lit 1)
+// (x =. x +. lit 1) :. pub x}
+
+makeShares :: BCState -> [(Int, Shared Int)]
+makeShares {sdss=[]} = []
+makeShares s=:{sdss=[(i,d):xs]} =
+ [(i, sharedStore ("mTaskSDS-" +++ toString i) 0):makeShares {s & sdss=xs}]
+
+sendMsg :: [MTaskMSGSend] (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
+sendMsg m ch = upd (\(r,rs,s,ss)->(r,rs,s ++ m,ss)) ch @! ()
syncNetworkChannel :: String Int String (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n
syncNetworkChannel server port msgSeparator decodeFun encodeFun channel
onDisconnect l (received,receiveStopped,send,sendStopped)
= (Ok l,Just (received,True,send,sendStopped))
-//consumeNetworkStream :: ([m] -> Task ()) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n
-//consumeNetworkStream processTask channel
-// = ((watch channel >>* [OnValue (ifValue ifProcess process)]) <! id) @! ()
-// where
-// ifProcess (received,receiveStopped,_,_)
-// = receiveStopped || (not (isEmpty received))
-//
-// process (received,receiveStopped,_,_)
-// = upd empty channel
-// >>| if (isEmpty received) (return ()) (processTask received)
-// @! receiveStopped
-//
-// empty :: ([m],Bool,[m],Bool) -> ([m],Bool,[m],Bool)
-// empty (_,rs,s,ss) = ([],rs,s,ss)
+consumeNetworkStream :: ([m] -> Task ()) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n
+consumeNetworkStream processTask channel
+ = ((watch channel >>* [OnValue (ifValue ifProcess process)]) <! id) @! ()
+ where
+ ifProcess (received,receiveStopped,_,_)
+ = receiveStopped || (not (isEmpty received))
+
+ process (received,receiveStopped,_,_)
+ = upd empty channel
+ >>| if (isEmpty received) (return ()) (processTask received)
+ @! receiveStopped
+
+ empty :: ([m],Bool,[n],Bool) -> ([m],Bool,[n],Bool)
+ empty (_,rs,s,ss) = ([],rs,s,ss)