예제 #1
0
 private void BroadcastPosition()
 {
     try
     {
         var enc = new UTF8Encoding();
         var sb  = new StringBuilder();
         sb.Append("\n");
         sb.Append("Po|{");
         sb.Append("\"aZ\":");
         sb.Append(_arrayAzimuth.ToString("f1"));
         sb.Append(",\"hP\":");
         var lh = _horizontalActuator.RelativePosition * Configuration.HorizontalLength;
         sb.Append(lh.ToString("f1"));
         if (DualAxis)
         {
             sb.Append(",\"aE\":");
             sb.Append(_arrayElevation.ToString("f1"));
             sb.Append(",\"vP\":");
             var lv = _verticalActuator.RelativePosition * Configuration.VerticalLength;
             sb.Append(lv.ToString("f1"));
         }
         else
         {
             sb.Append(",\"aE\":0,\"vP\":0");
         }
         sb.Append(",\"dk\":");
         sb.Append(_isDark ? "true" : "false");
         sb.Append(",\"sZ\":");
         sb.Append(_sunAzimuth.ToString("f1"));
         sb.Append(",\"sE\":");
         sb.Append(_sunElevation.ToString("f1"));
         sb.Append(",\"tS\":");
         sb.Append(GetStateCode());
         sb.Append(",\"tE\":");
         sb.Append("0");
         sb.Append("}\r");
         var bytes = enc.GetBytes(sb.ToString());
         _netduinoSerialPort.Write(bytes, 0, bytes.Length);
         _netduinoSerialPort.Flush();
     }
     catch (Exception)
     {
         DebugLogger.TryLog("Worker threw an exception");
     }
 }
예제 #2
0
        /*
         * Commands from android app;
         * "Track"
         *      "Cycle"
         *      "Stop"
         *      "GetConfiguration"
         *      "GetDateTime"
         *      "BroadcastPosition"
         *      "StopBroadcast"
         *      "SetC"
         * "SetL"
         *      "SetO"
         *      "SetDateTime"
         *  "MoveTo"
         */

        private void DoCommand(String command, String data)
        {
            var           json = new JsonFormatter();
            var           enc  = new UTF8Encoding();
            StringBuilder sb;

            byte[] bytes;
            switch (command)
            {
            case "Track":
                Track();
                break;

            case "Cycle":
                Test();
                break;

            case "Stop":
                StopTracking();
                break;

            case "GetConfiguration":
                var txfr    = Configuration.GetConfigTransfer();
                var sconfig = json.ToJson(txfr);
                sb = new StringBuilder();
                sb.Append("\n");
                sb.Append("Cf|");
                sb.Append(sconfig);
                sb.Append("\r");
                bytes = enc.GetBytes(sb.ToString());
                _netduinoSerialPort.Write(bytes, 0, bytes.Length);
                _netduinoSerialPort.Flush();
                break;

            case "GetDateTime":
                sb = new StringBuilder();
                sb.Append("\n");
                sb.Append("Dt|{");
                sb.Append("\"sT\":");     // seconds in unixtime
                sb.Append(GetEpochTime().ToString());
                sb.Append("}");
                bytes = enc.GetBytes(sb.ToString());
                _netduinoSerialPort.Write(bytes, 0, bytes.Length);
                _netduinoSerialPort.Flush();
                break;

            case "BroadcastPosition":
                if (_broadcastTimer == null)
                {
                    _broadcastTimer = new Timer(BroadcastTimerFunction, null, 2000, 2000);
                }
                break;

            case "StopBroadcast":
                if (_broadcastTimer != null)
                {
                    _broadcastTimer.Dispose();
                    _broadcastTimer = null;
                }
                break;

            case "SetA":
                var ca = (Actuator)json.FromJson(enc.GetBytes(data), typeof(Actuator));
                Configuration.SetActuator(ca);
                break;

            case "SetC":
                var cf = (Location)json.FromJson(enc.GetBytes(data), typeof(Location));
                Configuration.SetLocation(cf);
                break;

            case "SetL":
                var limits = (Limits)json.FromJson(enc.GetBytes(data), typeof(Limits));
                Configuration.SetLimits(limits);
                break;

            case "SetO":
                var options = (Options)json.FromJson(enc.GetBytes(data), typeof(Options));
                Configuration.SetOptions(options);
                break;

            case "SetDateTime":
                var dt = UnixTimeStampToDateTime(double.Parse(data));
                Utility.SetLocalTime(dt);
                DS1307.SetRTCTime(dt);
                break;

            case "MoveTo":
                MoveTo(data);
                break;
            }
        }
예제 #3
0
 /*
  * Commands from android app;
 "Track"
 "Cycle"
 "Stop"
 "GetConfiguration"
 "GetDateTime"
 "BroadcastPosition"
 "StopBroadcast"
 "SetC"
 "SetL"
 "SetO"
 "SetDateTime"
 "MoveTo"
 */
 private void DoCommand(String command, String data)
 {
     var json = new JsonFormatter();
     var enc = new UTF8Encoding();
     StringBuilder sb;
     byte[] bytes;
     switch (command)
     {
         case "Track":
             Track();
             break;
         case "Cycle":
             Test();
             break;
         case "Stop":
             StopTracking();
             break;
         case "GetConfiguration":
             var txfr = Configuration.GetConfigTransfer();
             var sconfig = json.ToJson(txfr);
             sb = new StringBuilder();
             sb.Append("\n");
             sb.Append("Cf|");
             sb.Append(sconfig);
             sb.Append("\r");
             bytes = enc.GetBytes(sb.ToString());
             _netduinoSerialPort.Write(bytes, 0, bytes.Length);
             _netduinoSerialPort.Flush();
             break;
         case "GetDateTime":
             sb = new StringBuilder();
             sb.Append("\n");
             sb.Append("Dt|{");
             sb.Append("\"sT\":"); // seconds in unixtime
             sb.Append(GetEpochTime().ToString());
             sb.Append("}");
             bytes = enc.GetBytes(sb.ToString());
             _netduinoSerialPort.Write(bytes, 0, bytes.Length);
             _netduinoSerialPort.Flush();
             break;
         case "BroadcastPosition":
             if (_broadcastTimer == null)
             {
                 _broadcastTimer = new Timer(BroadcastTimerFunction, null, 2000, 2000);
             }
             break;
         case "StopBroadcast":
             if (_broadcastTimer != null)
             {
                 _broadcastTimer.Dispose();
                 _broadcastTimer = null;
             }
             break;
         case "SetA":
             var ca = (Actuator)json.FromJson(enc.GetBytes(data), typeof(Actuator));
             Configuration.SetActuator(ca);
             break;
         case "SetC":
             var cf = (Location)json.FromJson(enc.GetBytes(data), typeof(Location));
             Configuration.SetLocation(cf);
             break;
         case "SetL":
             var limits = (Limits)json.FromJson(enc.GetBytes(data), typeof(Limits));
             Configuration.SetLimits(limits);
             break;
         case "SetO":
             var options = (Options)json.FromJson(enc.GetBytes(data), typeof(Options));
             Configuration.SetOptions(options);
             break;
         case "SetDateTime":
             var dt = UnixTimeStampToDateTime(double.Parse(data));
             Utility.SetLocalTime(dt);
             DS1307.SetRTCTime(dt);
             break;
         case "MoveTo":
             MoveTo(data);
             break;
     }
 }
예제 #4
0
 private void BroadcastPosition()
 {
     try
     {
         var enc = new UTF8Encoding();
         var sb = new StringBuilder();
         sb.Append("\n");
         sb.Append("Po|{");
         sb.Append("\"aZ\":");
         sb.Append(_arrayAzimuth.ToString("f1"));
         sb.Append(",\"hP\":");
         var lh = _horizontalActuator.RelativePosition * Configuration.HorizontalLength;
         sb.Append(lh.ToString("f1"));
         if (DualAxis)
         {
             sb.Append(",\"aE\":");
             sb.Append(_arrayElevation.ToString("f1"));
             sb.Append(",\"vP\":");
             var lv = _verticalActuator.RelativePosition * Configuration.VerticalLength;
             sb.Append(lv.ToString("f1"));
         }
         else
         {
             sb.Append(",\"aE\":0,\"vP\":0");
         }
         sb.Append(",\"dk\":");
         sb.Append(_isDark ? "true" : "false");
         sb.Append(",\"sZ\":");
         sb.Append(_sunAzimuth.ToString("f1"));
         sb.Append(",\"sE\":");
         sb.Append(_sunElevation.ToString("f1"));
         sb.Append(",\"tS\":");
         sb.Append(GetStateCode());
         sb.Append(",\"tE\":");
         sb.Append("0");
         sb.Append("}\r");
         var bytes = enc.GetBytes(sb.ToString());
         _netduinoSerialPort.Write(bytes, 0, bytes.Length);
         _netduinoSerialPort.Flush();
     }
     catch (Exception)
     {
         DebugLogger.TryLog("Worker threw an exception");
     }
 }