From: Mart Lubbers Date: Sun, 21 May 2017 15:36:23 +0000 (+0200) Subject: add memory reset when resetting, add debug for share writes and add live share changi... X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=7d9088b54956fe56c36ca8d01ec386b48f0a1c47;p=mTask.git add memory reset when resetting, add debug for share writes and add live share changing to demo --- diff --git a/Shares/mTaskShare.dcl b/Shares/mTaskShare.dcl index 0963b51..1d38669 100644 --- a/Shares/mTaskShare.dcl +++ b/Shares/mTaskShare.dcl @@ -30,6 +30,7 @@ cleanSharesTask :: Int MTaskDevice -> Task [MTaskShare] updateShareFromPublish :: MTaskDevice Int BCValue -> Task [MTaskShare] //updateShare :: Int BCValue -> Task [MTaskShare] -getRealShare :: MTaskDevice BCShare -> Shared BCValue +getRealShare :: MTaskDevice MTaskShare -> Shared BCValue +//getRealShare :: MTaskDevice BCShare -> Shared BCValue //updateShare :: Int BCValue -> Task () diff --git a/Shares/mTaskShare.icl b/Shares/mTaskShare.icl index 68b519e..481d3ad 100644 --- a/Shares/mTaskShare.icl +++ b/Shares/mTaskShare.icl @@ -90,22 +90,24 @@ cleanSharesTask taskid d = updateShares d id //TODO // up :: [String] MTaskShare -> MTaskShare // up ns s = {MTaskShare | s & withTask=[t\\t<-s.withTask|not (isMember t ns)]} -getRealShare :: MTaskDevice BCShare -> Shared BCValue -getRealShare dev {sdsi} = SDSSource {SDSSource - | name = "mTaskShareMap-" +++ toString sdsi, read=rr, write=ww} +getRealShare :: MTaskDevice MTaskShare -> Shared BCValue +getRealShare dev {identifier} = SDSSource {SDSSource + | name = "mTaskShareMap-" +++ toString identifier, read=rr, write=ww} where rr name iworld = case read deviceStore iworld of (Error e, iworld) = (Error e, iworld) (Ok devices, iworld) = case find ((==)dev) devices of Nothing = (Error $ exception "Device doesn't exist anymore", iworld) - Just {deviceShares} = case find (\s->s.identifier == sdsi) deviceShares of + Just {deviceShares} = case find (\s->s.identifier == identifier) deviceShares of Nothing = (Error $ exception "Share doesn't exist", iworld) Just share = (Ok share.MTaskShare.value, iworld) // Also send messages - ww name value iworld = case modify (\r->((), map (modFun value) r)) deviceStore iworld of + ww name value iworld + | not (trace_tn ("Update to: " +++ printToString value)) = undef + = case modify (\r->((), map (modFun value) r)) deviceStore iworld of (Error e, iworld) = (Error e, iworld) - (Ok _, iworld) = case sendMessagesIW [MTUpd sdsi value] dev iworld of + (Ok _, iworld) = case sendMessagesIW [MTUpd identifier value] dev iworld of (Error e, iworld) = (Error e, iworld) (Ok _, iworld) = (Ok $ const True, iworld) @@ -116,5 +118,5 @@ getRealShare dev {sdsi} = SDSSource {SDSSource //Selects the correct share modFun2 value share - | sdsi == share.MTaskShare.identifier = {MTaskShare | share & value=value} + | identifier == share.MTaskShare.identifier = {MTaskShare | share & value=value} = share diff --git a/client/client.c b/client/client.c index a86de24..28c1609 100644 --- a/client/client.c +++ b/client/client.c @@ -12,6 +12,7 @@ #include "sds.h" #include "spec.h" #include "task.h" +#include "mem.h" #include "interface.h" #define MSG_GET_TASK 't' @@ -64,6 +65,7 @@ void read_message(void) break; case MSG_SHUTDOWN: debug("Shutdown received"); + mem_reset(); reset(); case '\0': debug("Server closed connection"); diff --git a/client/mem.c b/client/mem.c index 9b72b8a..42fb500 100644 --- a/client/mem.c +++ b/client/mem.c @@ -15,3 +15,11 @@ uint16_t mem_free(void) { return mem_sds-mem_task; } + +void mem_reset(void) +{ + mem_top = &mem[MEMSIZE-1]; + mem_bottom = &mem[0]; + mem_task = &mem[0]; + mem_sds = &mem[MEMSIZE-1]; +} diff --git a/client/mem.h b/client/mem.h index 1a1d39c..c31f4a1 100644 --- a/client/mem.h +++ b/client/mem.h @@ -13,6 +13,7 @@ uint8_t *mem_task; uint8_t *mem_sds; uint16_t mem_free(void); +void mem_reset(void); #ifdef __cplusplus } diff --git a/client/sds.c b/client/sds.c index 2570017..06d67a2 100644 --- a/client/sds.c +++ b/client/sds.c @@ -76,7 +76,20 @@ bool sds_update(uint8_t id) //Read identifier struct sds *s = sds_get(id); if(s != NULL){ - s->value = read16(); + switch(read_byte()){ + //Long + case 'l': + //Int + case 'i': + s->value = read16(); + break; + case 'b': //Bool + case 'c': //Character + case 'B': //Button + case 'L': //UserLED + s->value = read_byte(); + break; + } debug("Received sds update %d: %d", s->id, s->value); write_byte('u'); write16(s->id); @@ -111,7 +124,6 @@ void sds_publish(int id) } write_byte('\n'); return; - } else { debug("SDS identifier unknown: %d", id); die(""); diff --git a/miTask.icl b/miTask.icl index fd5dac5..cafbffa 100644 --- a/miTask.icl +++ b/miTask.icl @@ -30,7 +30,16 @@ Start world = startEngine [ publish "/" $ const demo ] world -demo = viewInformation "" [] "Hello world" +demo = viewSharedInformation "Devices" [] deviceStore + >>* [OnValue $ ifValue pred (cont o hd)] + where + pred [] = False + pred [x:_] = not $ isEmpty x.deviceShares + + cont :: MTaskDevice -> Task () + cont dev = updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares)) + >>| cont dev + mTaskManager :: Task () mTaskManager = startupDevices >>| anyTask