Esempio n. 1
0
        public async Task Test_gettime()
        {
            GetTimeResponse timeresponse = await deribit.Supporting.GetTime();

            var timedifferencemillis = Math.Abs((DateTime.UtcNow - timeresponse.server_time).TotalMilliseconds);

            Assert.That(timedifferencemillis, Is.LessThan(1000));
        }
Esempio n. 2
0
 /// <summary> Setter constructor. </summary>
 public GetTime(GetTimeRequest request)
 {
     Request  = request;
     Response = new GetTimeResponse();
 }
Esempio n. 3
0
 /// <summary> Empty constructor. </summary>
 public GetTime()
 {
     Request  = GetTimeRequest.Singleton;
     Response = new GetTimeResponse();
 }
Esempio n. 4
0
        /// <summary>
        /// Checks for new messages from the LiveView and responds accordingly.
        /// </summary>
        protected void Listen()
        {
            if (client.Available == 0)
            {
                return;
            }

            byte[] data = new byte[client.Available];
            this.client.GetStream().Read(data, 0, data.Length);

            LiveViewMessage[] messages = LiveViewMessage.Decode(data);

            foreach (LiveViewMessage message in messages)
            {
                Console.WriteLine("<-- Recieved message:\n" + message.ToString() + "\n");
                Send(new AckMessage(message.messageId));

                switch (message.messageId)
                {
                case LiveViewMessage.MSG_GETCAPS_RESP:
                    Capabilities = message as GetCapsResponse;
                    Send(new SetMenuSizeMessage((byte)MenuItems.Length));
                    Send(new SetMenuSettingsMessage(MenuVibrationTime, 0));
                    break;

                case LiveViewMessage.MSG_GETMENUITEMS:
                    byte i = 0;
                    foreach (MenuItem menuItem in this.MenuItems)
                    {
                        Send(new GetMenuItemResponse(i, menuItem.isAlert, menuItem.unreadCount, menuItem.text, menuItem.bitmap));
                        i++;
                    }
                    break;

                case LiveViewMessage.MSG_GETMENUITEM:
                    byte     index = ((GetMenuItemMessage)(message)).index;
                    MenuItem item  = MenuItems.ElementAt(index);
                    this.Send(new GetMenuItemResponse(index, item.isAlert, item.unreadCount, item.text, item.bitmap));
                    break;

                case LiveViewMessage.MSG_GETTIME:
                    Send(new GetTimeResponse(GetTimeResponse.GetLocalTime(), Use24HourClock));
                    break;

                case LiveViewMessage.MSG_DEVICESTATUS:
                    Send(new DeviceStatusAck());
                    if (deviceStatusListener != null)
                    {
                        deviceStatusListener(this, message as DeviceStatusMessage);
                    }
                    break;

                case LiveViewMessage.MSG_NAVIGATION:
                    if (navigationListener != null)
                    {
                        navigationListener(this, message as NavigationMessage);
                    }
                    break;

                case LiveViewMessage.MSG_GETALERT:
                    if (alertListener != null)
                    {
                        alertListener(this, message as GetAlertMessage);
                    }
                    break;

                case LiveViewMessage.MSG_SETVIBRATE_ACK:
                    break;

                case LiveViewMessage.MSG_SETLED_ACK:
                    break;

                case LiveViewMessage.MSG_DISPLAYPANEL_ACK:
                    break;

                case LiveViewMessage.MSG_SETSTATUSBAR_ACK:
                    break;

                case LiveViewMessage.MSG_GETSCREENMODE_RESP:
                    //EVENT
                    break;

                case LiveViewMessage.MSG_SETSCREENMODE_ACK:
                    break;

                case LiveViewMessage.MSG_DISPLAYBITMAP_ACK:
                    break;

                case LiveViewMessage.MSG_CLEARDISPLAY_ACK:
                    break;

                case LiveViewMessage.MSG_DISPLAYTEXT_ACK:
                    break;

                default:
                    throw new Exception("Unknown message: " + message.messageId);
                }
            }
        }