#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)
//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:
//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;
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)
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;
}
}
for(cs = 0; cs<MAXSDSS; cs++){
if(sdss[cs].used && sdss[cs].id == id){
debug("Publish %d=%d", sdss[cs].id, sdss[cs].value);
- write_byte('u');
+ write_byte('p');
write16(sdss[cs].id);
write16(sdss[cs].value);
write_byte('\n');
memset(&tasks, 0, sizeof(struct task)*MAXTASKS);
}
-int task_register(void)
+void task_register(void)
{
uint8_t ct;
uint16_t i;
tasks[ct].used = true;
tasks[ct].lastrun = 0L;
- return ct;
+ write_byte('t');
+ write16(ct);
+ write_byte('\n');
}
void task_delete(void)
{
- tasks[read_byte()].used = false;
+ uint8_t c = read_byte();
+ tasks[c].used = false;
+ write_byte('d');
+ write16(c);
+ write_byte('\n');
}
struct task *task_get(int num)
import Text.Encodings.Base64
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 (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
+++ " 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
= 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])