update spec, and shares
authorMart Lubbers <mart@martlubbers.net>
Tue, 21 Mar 2017 09:47:15 +0000 (10:47 +0100)
committerMart Lubbers <mart@martlubbers.net>
Tue, 21 Mar 2017 09:47:15 +0000 (10:47 +0100)
12 files changed:
CleanSerial
Devices/mTaskDevice.icl
Shares/mTaskShare.dcl
Shares/mTaskShare.icl
client/interface.c
client/interpret.c
client/main.c
client/spec.c
client/task.c
mTaskInterpret.dcl
mTaskInterpret.icl
todo.txt [new file with mode: 0644]

index 1b51061..948f49f 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 1b51061da5972a0cca502403496c12d731093960
+Subproject commit 948f49f132f17f55b2ac49c2771df13d9aac3b48
index 5c78b48..6f6480a 100644 (file)
@@ -63,7 +63,9 @@ addDevice devices processFun
 connectDevice :: (MTaskDevice (Shared Channels) -> Task ()) MTaskDevice -> Task ()
 connectDevice pf d = let ch = channels d in appendTopLevelTask 'DM'.newMap True
        (pf d ch -||- catchAll (getSynFun d.deviceData ch) errorHandle)
-       >>= \tid->withDevices d (\d->{d&deviceTask=Just tid,deviceError=Nothing}) @! ()
+       >>= \tid->withDevices d (\d->{d&deviceTask=Just tid,deviceError=Nothing})
+       >>| upd (\(r,s,ss)->(r,s++[MTSpec],ss)) ch
+       @! ()
        where
                errorHandle e = withDevices d (\d->{d&deviceTask=Nothing,deviceError=Just e})
 
@@ -93,6 +95,7 @@ deleteDevice :: MTaskDevice -> Task ()
 deleteDevice d = upd (\(r,s,ss)->(r,s,True)) (channels d)
        >>| maybe (treturn ()) (flip removeTask topLevelTasks) d.deviceTask
        >>| upd (filter ((<>)d)) deviceStore
+//     >>| upd (removeShares d) sdsStore
        @! ()
 
 sendToDevice :: String (Main (ByteCode () Stmt)) (MTaskDevice, MTaskInterval) -> Task ()
index 9110254..3cfd7a1 100644 (file)
@@ -8,7 +8,7 @@ derive class iTask MTaskShareType, MTaskShare
 
 :: MTaskShareType = MTaskWithShare String | MTaskLens String
 :: MTaskShare =
-               {withTask :: String
+               {withTask :: [String]
                ,identifier :: Int
                ,realShare :: MTaskShareType
                ,value :: BCValue
index 4a188c6..8c0ae61 100644 (file)
@@ -36,13 +36,15 @@ manageShares shares = withShared Nothing $ \cs->forever $
 //updateShare sh=:{withTask,identifier} a = getDeviceByName withTask
 //     >>= sendMessages [MTUpd identifier $ toString $ toByteCode a]
 //     >>| treturn sh
+//
+from StdFunc import flip
 
 viewSharesGrid :: (Shared (Maybe MTaskShare)) [MTaskShare] -> Task [BCValue]
 viewSharesGrid _ [] = viewInformation "No shares yet" [] []
 viewSharesGrid cs sh = (allTasks [watch (getSDSShare m)\\m<-sh] <<@ NoUserInterface)
-       >&^ \st->whileUnchanged st $ \mshs->enterChoice "" [ChooseFromGrid id]
+       >&^ \st->flip (<<@) NoUserInterface $ whileUnchanged st $ \mshs->enterChoice "" [ChooseFromGrid id]
                [{MTaskShare|ss&value=s}\\s<-fromJust mshs & ss<-sh]
-               >>* [OnValue (withValue $ \s->Just (set (Just s) cs))]
+//             >>* [OnValue (withValue $ \s->Just (set (Just s) cs))]
                @! fromJust mshs
 
 viewShare :: MTaskShare -> Task BCValue
@@ -55,7 +57,7 @@ getSDSShare s=:{realShare=(MTaskWithShare id),value} = memoryShare id value
 makeShare :: String Int BCValue -> Task MTaskShare
 makeShare withTask identifier value = treturn 
                {MTaskShare
-               |withTask=withTask
+               |withTask=[withTask]
                ,identifier=identifier
                ,value=value
                ,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier
index 59e750e..8afac28 100644 (file)
@@ -86,23 +86,22 @@ void delay(long ms)
 
 void setup(void)
 {
-       palSetPadMode(GPIOG, 9, PAL_MODE_ALTERNATE(8)); // USART6 TX
-       palSetPadMode(GPIOG, 14, PAL_MODE_ALTERNATE(8)); // USART6 RX
+//     palSetPadMode(GPIOG, 9, PAL_MODE_ALTERNATE(8)); // USART6 TX
+//     palSetPadMode(GPIOG, 14, PAL_MODE_ALTERNATE(8)); // USART6 RX
 
        halInit();
        chSysInit();
        sdStart(&SD3, NULL);
-//     sdStart(&SD6, NULL);
-
-//     while(1){
-//             sdPut(&SD3, sdGet(&SD6));
-//             delay(50);
-//     }
 }
 
 void debug(char *fmt, ...)
 {
-       (void)fmt;
+       write_byte('m');
+       for(unsigned int i = 0; i<strlen(fmt); i++){
+               write_byte(fmt[i]);
+       }
+       write_byte('\n');
+//     (void)fmt;
 }
 
 void pdie(char *s)
index b9d0c88..86e3964 100644 (file)
@@ -156,7 +156,7 @@ void run_task(struct task *t)
                        sp--;
                        break;
 #endif
-#if HAVELED == 1
+//#if HAVELED == 1
                case BCLEDON: trace("LedOn(%d)", program[pc]);
                        led_on(stack[sp-1]);
                        sp--;
@@ -165,7 +165,7 @@ void run_task(struct task *t)
                        led_off(stack[sp-1]);
                        sp--;
                        break;
-#endif
+//#endif
                default:
                        trace("unrecognized");
                        die("Unrecognized command: %d", program[pc-1]);
index 012e062..720fd1a 100644 (file)
@@ -20,6 +20,7 @@
 #define MSG_SDS_SPEC 's'
 #define MSG_SDS_DEL 'a'
 #define MSG_SDS_UPD 'u'
+#define MSG_SPEC 'c'
 
 void read_message(void)
 {
@@ -49,8 +50,12 @@ void read_message(void)
                        debug("Receiving a task");
                        task_register();
                        break;
+               case MSG_SPEC:
+                       debug("Receiving a spec request");
+                       spec_send();
+                       break;
                case '\0':
-                       die("Server closed connection");
+                       debug("Server closed connection");
                        break;
                case '\n':
                        break;
@@ -107,7 +112,6 @@ int main(int argc, char *argv[]){
        sds_init();
        task_init();
        debug("sending device spec");
-       spec_send();
        while(true){
                //Check for newetasks
                loop();
index 825e894..75def00 100644 (file)
@@ -4,11 +4,10 @@
 
 void spec_send(void)
 {
-       debug("Writing spec");
        write_byte('c');
        write_byte(0 | (HAVELED << 0) | (HAVEAIO << 1) | (HAVEDIO << 2));
        write16(MAXTASKS);
        write16(MAXSDSS);
        write_byte('\n');
-       debug("Done writing spec");
+       write_byte('\n');
 }
index 198aee3..1c16ce5 100644 (file)
@@ -26,6 +26,7 @@ void task_register(void)
        memset(&tasks[ct], 0, sizeof(struct task));
        //Read interval
        tasks[ct].interval = read16();
+       debug("interval: %d\n", tasks[ct].interval);
 
        //Interrupt task
        if(is_interrupt_task(&tasks[ct])) {
index f0795e1..84c1e3f 100644 (file)
@@ -25,6 +25,7 @@ from Generics.gCons import class gCons, generic conses, generic consName, generi
        | MTTaskDel Int
        | MTSds Int String
        | MTUpd Int String
+       | MTSpec
 
 :: MTaskInterval
        = OneShot
index aeceb92..bd5572a 100644 (file)
@@ -45,6 +45,7 @@ encode (MTTask to data) = "t" +++ toByteCode to +++ to16bit (size data) +++ data
 encode (MTTaskDel i) = "d" +++ to16bit i +++ "\n"
 encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n"
 encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n"
+encode (MTSpec) = "c\n"
 
 import StdDebug
 decode :: String -> MTaskMSGRecv
@@ -138,7 +139,7 @@ instance fromByteCode UserLED where fromByteCode s = conses{|*|} !! toInt s.[1]
 instance fromByteCode BCValue where fromByteCode s = parseBCValue s.[0] s
 
 instance toByteCode MTaskInterval where
-       toByteCode OneShot = toByteCode 0
+       toByteCode OneShot = toByteCode (OnInterval 0)
        //Intervals have the first bit 0 and the rest is a 15 bit unsigned int
        toByteCode (OnInterval i) = {toChar $ i/256 bitand 127, toChar $ i rem 256}
        //Intervals have the first bit 1 and the rest is a 15 bit unsigned int
diff --git a/todo.txt b/todo.txt
new file mode 100644 (file)
index 0000000..d53dcad
--- /dev/null
+++ b/todo.txt
@@ -0,0 +1,4 @@
+delete tasks when deleting device
+make sure shares are assigned to correct task and not propagated
+let tasks have a unique name
+add field in task that denotes to which device it belongs