private static void PostMessage(MailUser user, string subject, string msg) { TRACE("PostMessage", "[" + ThreadName + " Posts " + MailBox.GetMailUserName(user) + ": " + MailBox.Limit(msg, 8) + "...]"); try { MailBox.Post(user, subject + ';' + msg); } catch (Exception e) { TRACE("PostMessage", "HANDELED EXCEPTION: could not post message. " + e.Message); } }
private static string HandleDevelopmentCommand(string cmd) { string reply = "OK."; if (cmd.IndexOf("GetOnTime") == 0) { reply = "Class not operated."; //reply = ACControl.GetOnTime(); } else if (cmd.IndexOf("LogTemperatures") == 0) { reply = SetBoolParameter(ref LogTemperatures, cmd); } else if (cmd.IndexOf("SetAlpha=") == 0) { try { double alpha = ExtractDouble(cmd); if (!TempSensor.SetAlpha(alpha)) { reply = "ERROR: could not set Alpha to " + alpha.ToString(); } } catch (Exception e) { reply = "Exception: " + e.Message; } } else if (cmd.IndexOf("MailBoxStatus") == 0) { reply = "MainThread {" + MailBox.MsgCount(MailUser.MainThread) + "}. WifiThread {" + MailBox.MsgCount(MailUser.WifiThread) + "}"; } else { reply = "Unknown message."; } return(reply); }
private static void HandleMessage(string msg) { TRACE("HandleMessage", "[" + ThreadName + " handling: " + MailBox.Limit(msg, 8) + "...]"); string[] Mail = msg.Split(';'); if (Mail.Length != 2) { throw new Exception("Unrecognized messsage format"); } string Subject = Mail[0]; string Content = Mail[1]; switch (Subject) { case "Post": if (WifiState != State.Associated) { TRACE("HandleMessage", " Rejecting POST request: In Session."); RejectedAttempts++; break; } Debug.Print("----------------------------[ POST: START ]----------------------------------"); HttpPost(Content); RejectedAttempts = 0; Debug.Print("----------------------------[ POST: END ]------------------------------------"); break; case "Get": if (WifiState != State.Associated) { TRACE("HandleMessage", " Rejecting GET request: In Session."); RejectedAttempts++; break; } Debug.Print("----------------------------[ GET: START ]-----------------------------------"); HttpGet(Content); RejectedAttempts = 0; Debug.Print("----------------------------[ GET: END ]-------------------------------------"); break; case "Control": if (Content == "Associate") { Debug.Print("----------------------------[ ASSOCIATE: START ]-----------------------------"); AssociateToNetwork(); Debug.Print("----------------------------[ ASSOCIATE: END ]-------------------------------"); } else if (Content == "Reset") { HandleConnectionFail(); } break; case "Debug": string reply = SendToGS(Content); PostMessage(MailUser.MainThread, "Debug", reply); break; default: throw new Exception("Unrecognized mail subject"); } }
private static void HandleMessage(string msg) { TRACE("HandleMessage", "[" + ThreadName + " handling: " + MailBox.Limit(msg, 16) + "...]"); string[] Mail = msg.Split(';'); if (Mail.Length != 2) { TRACE("HandleMessage", "* Message Discarded: Unrecognized messsage format *"); return; } string Subject = Mail[0]; string Content = Mail[1]; switch (Subject) { case "TempSensor": // --- TEMP SENSOR -------------------------- // if (Content.Equals("GetTemp")) { PostMessage(MailUser.WifiThread, "Post", TempSensor.StringValue() + " degC"); } break; case "OnboardLed": // --- ONBOARD LED -------------------------- // if (Content.Equals("TurnOn")) { StatusLed.SetState(Led.LedState.On); //OnboardLed.Write(true); TRACE("HandleMessage", "OnboardLed turned on."); } else if (Content.Equals("TurnOff")) { StatusLed.SetState(Led.LedState.Off); //OnboardLed.Write(false); TRACE("HandleMessage", "OnboardLed turned off."); } break; case "ACRemote": // --- AC REMOTE ---------------------------- // if (Content.IndexOf("SetAcTemp") >= 0) { try { int val = ExtractParameter(Content); RemoteControl.SetTemperatureTo(val); TRACE("HandleMessage", "AC Temp set to {" + val.ToString() + "degC}"); } catch { TRACE("HandleMessage", "Could not extract parameter in message: " + Content); } } else if (Content.Equals("TurnAcOff")) { RemoteControl.PushOff(); TRACE("HandleMessage", "AC turned off."); } else if (Content.IndexOf("SetFanState=") == 0) { int val = ExtractParameter(Content); RemoteControl.SetFanTo((ACRemote.ACFanState)val); } break; case "WifiModule": // --- WIFI MODULE -------------------------- // if (Content.Equals("Reset GainSpan")) { StatusLed.SetState(Led.LedState.BlinkFast); GainSpanReset(); } break; case "Debug": // message addressed to PC DebugUart.Write(Content); break; default: throw new Exception("Unrecognized mail subject"); } }