public int SendGetSwitchStatusMethod() { if (sensorPort != null && sensorPortCapability == null) { sensorPortCapability = GetCapability(sensorPort, Globals.UserSystem); } if (sensorPort != null && sensorPortCapability != null) { IList<View.VParamType> retVals = null; try { IList<View.VParamType> parameters = new List<View.VParamType>(); //retVals = sensorPort.Invoke(RoleSwitchBinary.RoleName, RoleSwitchBinary.OpGetName, parameters, ControlPort, sensorPortCapability, ControlPortCapability); retVals = sensorPort.Invoke(RoleSensor.RoleName, RoleSensor.OpGetName, parameters, ControlPort, sensorPortCapability, ControlPortCapability); } catch (Exception e) { logger.Log("Error while calling {0} request: {1}", RoleSensor.OpGetName, e.ToString()); } int result = 0; string message = ""; if (retVals[0].Maintype() != (int)ParamType.SimpleType.error) { result = Convert.ToInt32(retVals[0].Value()); message = String.Format("{0} success to {1} result = {2}", RoleSensor.OpGetName, sensorPort.ToString(), result); } else { message = String.Format("{0} failure to {1}", RoleSensor.OpGetName, sensorPort.ToString()); } LogMessageToWindow(message); return result; } return -1; }
public void SendGetDevicePresenceMethod() { if (fitbitPort != null && fitbitPortCapability == null) { fitbitPortCapability = GetCapability(fitbitPort, Globals.UserSystem); } if (fitbitPort != null && fitbitPortCapability != null) { IList<View.VParamType> retVals; try { IList<View.VParamType> parameters = new List<View.VParamType>(); parameters.Add(new ParamType(ParamType.SimpleType.binary, "", DateTime.Today, "activityDate")); retVals = fitbitPort.Invoke(RoleFitbitUltra.RoleName, RoleFitbitUltra.OpGetDevicePresence, parameters, ControlPort, fitbitPortCapability, ControlPortCapability); } catch (Exception e) { logger.Log("Error while calling {0} request: {1}", RoleFitbitUltra.OpGetDevicePresence, e.ToString()); return; } bool result; string message = ""; if (retVals[0].Maintype() != (int)ParamType.SimpleType.error) { result = Convert.ToBoolean(retVals[0].Value()); if (result == true) { message = String.Format("User is home, and the home security system is {0}", homeSecurityActivated); if (homeSecurityActivated) { message = String.Format("{0}\nDeactivating Home security system", message); homeSecurityActivated = false; } } else { message = String.Format("User is Away and the home security system is {0}", homeSecurityActivated); if (!homeSecurityActivated) { message = String.Format("{0}\nActivating Home security system", message); homeSecurityActivated = true; } } } else { message = String.Format("{0} failure to {1}", RoleFitbitUltra.OpGetDevicePresence, fitbitPort.ToString()); return; } LogMessageToWindow(message); } }
public void SendGetDevicePresenceMethod(int counter) { if (fitbitPort != null && fitbitPortCapability == null) { fitbitPortCapability = GetCapability(fitbitPort, Globals.UserSystem); } if (fitbitPort != null && fitbitPortCapability != null) { IList<View.VParamType> retVals; try { IList<View.VParamType> parameters = new List<View.VParamType>(); retVals = fitbitPort.Invoke(RoleFitbitUltra.RoleName, RoleFitbitUltra.OpGetDevicePresence, parameters, ControlPort, fitbitPortCapability, ControlPortCapability); } catch (Exception e) { logger.Log("Error while calling {0} request: {1}", RoleFitbitUltra.OpGetDevicePresence, e.ToString()); return; } bool result = false; string message = ""; if (retVals[0].Maintype() != (int)ParamType.SimpleType.error) { result = Convert.ToBoolean(retVals[0].Value()); message = String.Format("{0} success to {1} result = {2}", RoleFitbitUltra.OpGetDevicePresence, fitbitPort.ToString(), result); } else { message = String.Format("{0} failure to {1}", RoleFitbitUltra.OpGetDevicePresence, fitbitPort.ToString()); return; } LogMessageToWindow(message); currentPresence = result; } }
public void SendTurnOnSwitchMethod(int counter) { if (switchPort != null && switchPortCapability == null) { switchPortCapability = GetCapability(switchPort, Globals.UserSystem); } if (switchPort != null && switchPortCapability != null) { IList<View.VParamType> retVals = null; try { IList<View.VParamType> parameters = new List<View.VParamType>(); parameters.Add(new ParamType(ParamType.SimpleType.integer, "8", (byte)255, "level")); retVals = switchPort.Invoke(RoleSwitchBinary.RoleName, RoleSwitchBinary.OpSetName, parameters, ControlPort, switchPortCapability, ControlPortCapability); } catch (Exception e) { logger.Log("Error while calling {0} request: {1}", RoleSwitchBinary.OpSetName, e.ToString()); } int result = 0; string message = ""; if (retVals[0].Maintype() != (int)ParamType.SimpleType.error) { result = Convert.ToInt32(retVals[0].Value()); message = String.Format("{0} success to {1} result = {2}", RoleSwitchBinary.OpSetName, switchPort.ToString(), result); } else { message = String.Format("{0} failure to {1}", RoleSwitchBinary.OpSetName, switchPort.ToString()); } LogMessageToWindow(message); } }
public void SendGetHasRecentActivityMethod(int counter) { if (fitbitPort != null && fitbitPortCapability == null) { fitbitPortCapability = GetCapability(fitbitPort, Globals.UserSystem); } if (fitbitPort != null && fitbitPortCapability != null) { IList<View.VParamType> retVals; try { IList<View.VParamType> parameters = new List<View.VParamType>(); retVals = fitbitPort.Invoke(RoleFitbitUltra.RoleName, RoleFitbitUltra.OpGetHasRecentActivity, parameters, ControlPort, fitbitPortCapability, ControlPortCapability); } catch (Exception e) { logger.Log("Error while calling {0} request: {1}", RoleFitbitUltra.OpGetHasRecentActivity, e.ToString()); return; } bool result = false; string message = ""; if (retVals[0].Maintype() != (int)ParamType.SimpleType.error) { result = Convert.ToBoolean(retVals[0].Value()); message = String.Format("{0} success to {1} result = {2}", RoleFitbitUltra.OpGetHasRecentActivity, fitbitPort.ToString(), result); } else { message = String.Format("{0} failure to {1}", RoleFitbitUltra.OpGetHasRecentActivity, fitbitPort.ToString()); return; } LogMessageToWindow(message); if (currentPresence == true && result == true) { // lower thermostat temperature // turn on fans counter++; if (SendGetSwitchStatusMethod(counter) == 0) { counter++; SendTurnOnSwitchMethod(counter); } LogMessageToWindow("User has returned from a run, thermostat has been lowered and fans have been turned on."); } } }
public void SendGetDeviceCurrentStepsGoalMethod(int counter) { if (fitbitPort != null && fitbitPortCapability == null) { fitbitPortCapability = GetCapability(fitbitPort, Globals.UserSystem); } if (fitbitPort != null && fitbitPortCapability != null) { IList<View.VParamType> retVals; try { IList<View.VParamType> parameters = new List<View.VParamType>(); parameters.Add(new ParamType(ParamType.SimpleType.binary, "", DateTime.Today, "activityDate")); retVals = fitbitPort.Invoke(RoleFitbitUltra.RoleName, RoleFitbitUltra.OpGetStepsGoal, parameters, ControlPort, fitbitPortCapability, ControlPortCapability); } catch (Exception e) { logger.Log("Error while calling {0} request: {1}", RoleFitbitUltra.OpGetStepsGoal, e.ToString()); return; } int result = 0; string message = ""; if (retVals[0].Maintype() != (int)ParamType.SimpleType.error) { result = Convert.ToInt32(retVals[0].Value()); message = String.Format("{0} success to {1} result = {2}", RoleFitbitUltra.OpGetStepsGoal, fitbitPort.ToString(), result); } else { message = String.Format("{0} failure to {1}", RoleFitbitUltra.OpGetStepsGoal, fitbitPort.ToString()); return; } LogMessageToWindow(message); if (currentSteps >= result) { // enable TV counter++; if (SendGetSwitchStatusMethod(counter) == 0) { counter++; SendTurnOnSwitchMethod(counter); } LogMessageToWindow("User has met their steps goal for today, TV has been enabled."); } else { // disable TV counter++; if (SendGetSwitchStatusMethod(counter) != 0) { counter++; SendTurnOffSwitchMethod(counter); } LogMessageToWindow("User has not met their steps goal for today, TV has been disabled."); } } }
public void SendGetDeviceCurrentStepsMethod(int counter) { if (fitbitPort != null && fitbitPortCapability == null) { fitbitPortCapability = GetCapability(fitbitPort, Globals.UserSystem); } if (fitbitPort != null && fitbitPortCapability != null) { IList<View.VParamType> retVals; try { IList<View.VParamType> parameters = new List<View.VParamType>(); parameters.Add(new ParamType(ParamType.SimpleType.binary, "", DateTime.Today, "activityDate")); retVals = fitbitPort.Invoke(RoleFitbitUltra.RoleName, RoleFitbitUltra.OpGetSteps, parameters, ControlPort, fitbitPortCapability, ControlPortCapability); } catch (Exception e) { logger.Log("Error while calling {0} request: {1}", RoleFitbitUltra.OpGetSteps, e.ToString()); return; } int result = 0; string message = ""; if (retVals[0].Maintype() != (int)ParamType.SimpleType.error) { result = Convert.ToInt32(retVals[0].Value()); message = String.Format("{0} success to {1} result = {2}", RoleFitbitUltra.OpGetSteps, fitbitPort.ToString(), result); } else { message = String.Format("{0} failure to {1}", RoleFitbitUltra.OpGetSteps, fitbitPort.ToString()); return; } LogMessageToWindow(message); currentSteps = result; } }