From: Mart Lubbers Date: Wed, 8 Feb 2017 17:39:44 +0000 (+0100) Subject: update message spec X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=55afb005ced3bba3813163596cdc7288a318a3c2;p=mTask.git update message spec --- diff --git a/client/main.c b/client/main.c index 3388f21..90f6e5f 100644 --- a/client/main.c +++ b/client/main.c @@ -17,6 +17,7 @@ #define MSG_GET_TASK 't' #define MSG_DEL_TASK 'd' #define MSG_SDS_SPEC 's' +#define MSG_SDS_DEL 'a' #define MSG_SDS_UPD 'u' void read_message(void) @@ -24,7 +25,6 @@ void read_message(void) //Find next task if(input_available()){ uint8_t c = read_byte(); - uint8_t ct; debug("Receiving input: %c %02x\n", c, c); switch(c){ case MSG_SDS_SPEC: @@ -36,16 +36,17 @@ void read_message(void) //TODO do something with the return value sds_update(); break; + case MSG_SDS_DEL: + debug("Receiving a delete SDS request"); + sds_delete(); + break; case MSG_DEL_TASK: debug("Receiving a delete task request"); task_delete(); break; case MSG_GET_TASK: debug("Receiving a task"); - ct = task_register(); - write_byte('t'); - write16(ct); - write_byte('\n'); + task_register(); break; case '\0': break; diff --git a/client/sds.c b/client/sds.c index c5f69b6..c2fdbde 100644 --- a/client/sds.c +++ b/client/sds.c @@ -36,6 +36,20 @@ void sds_register(void) debug("Received sds %d: %d", sdss[cs].id, sdss[cs].value); sdss[cs].used = true; + + write_byte('s'); + write16(sdss[cs].id); + write_byte('\n'); +} + +void sds_delete(void) +{ + uint8_t cs; + cs = read16(); + sdss[cs].used = false; + write_byte('a'); + write16(sdss[cs].id); + write_byte('\n'); } bool sds_update(void) @@ -52,6 +66,9 @@ bool sds_update(void) sdss[cs].value = read16(); debug("Received sds update %d: %d", sdss[cs].id, sdss[cs].value); + write_byte('u'); + write16(sdss[cs].id); + write_byte('\n'); return true; } } @@ -64,7 +81,7 @@ void sds_publish(int id) for(cs = 0; cs String -encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n" encode (MTTask to data) = "t" +++ to16bit to +++ to16bit (size data) +++ data +++ "\n" +encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n" encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n" decode :: String -> MTaskMSGRecv decode x | size x == 0 = MTEmpty = case x.[0] of + 't' = MTTaskAck (from16bit (x % (1,3))) + 'd' = MTTaskDelAck (from16bit (x % (1,3))) + 'm' = MTMessage x + 's' = MTSDSAck (from16bit (x % (1,3))) + 'a' = MTSDSDelAck (from16bit (x % (1,3))) + 'p' = MTPub (from16bit (x % (1,3))) (x % (3,5)) '\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") safePrint :== toString o toJSON @@ -49,9 +52,13 @@ instance toString MTaskMSGSend where +++ " value " +++ safePrint v instance toString MTaskMSGRecv where + toString (MTTaskAck i) = "Task added with id: " +++ toString i + toString (MTTaskDelAck i) = "Task deleted with id: " +++ toString i + toString (MTSDSAck i) = "SDS added with id: " +++ toString i + toString (MTSDSDelAck i) = "SDS deleted with id: " +++ toString i toString (MTPub i v) = "Publish id: " +++ toString i +++ " value " +++ safePrint v - toString (MTTaskAdded i) = "Task added with id: " +++ toString i + toString (MTMessage m) = m toString MTEmpty = "Empty message" bclength :: BC -> Int diff --git a/miTask.icl b/miTask.icl index 5436ffe..767cd98 100644 --- a/miTask.icl +++ b/miTask.icl @@ -113,7 +113,8 @@ mTaskTask = let (msgs, sdsShares) = makeMsgs 1000 bc in = updateSDSs xs m n updateSDSs _ m mtm = case mtm of MTMessage s = upd (\l->take 5 [s:l]) m @! () - mta=:(MTTaskAdded _) = upd (\l->take 5 [toString mta:l]) m @! () + mta=:(MTTaskAck _) = upd (\l->take 5 [toString mta:l]) m @! () + //TODO other recv msgs _ = return () lens :: ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> ([String], [String])