예제 #1
0
        public override void MainMethod()
        {
            Ensure.Init();
            CPU.DisableInts();
            GDT.Init();
            IDT.Init();
            ISR.Init();
            Console.Clear();
            ACPI.Init();
            ACPI.Enable();
            PageManager.Init();
            Heap.Init();
            GC.Init();
            Paging.Init();
            PIT.Init();
            RTC.Init();
            Scheduler.Init();
            CPU.EnableInts();
            DiskDrive.Init();
            //FatFileSystem.Init();
            PCI.Init();
            Driver.Init();
            AudioMixer.Init();

            new Thread(Event.Init, "Events").Start();
            new Thread(new SCI().Main, "Shell").Start();

            Scheduler.Idle();
        }
예제 #2
0
        /// <summary>
        /// WARNING: may produce inacurate results (specially in emulators).
        /// Get the frequency of the processor without using interrupts.
        /// Notes: needs bochs: "clock: sync=slowdown, time0=local\n" line to work (well, seems to).
        /// </summary>
        /// <remarks>Credit to: http://wiki.osdev.org/Detecting_CPU_Speed#Without_Interrupts . In emulators the PIT
        /// can go much more quicker than expected giving absurdly big values.
        /// </remarks>
        /// <returns>Frequency in MHz</returns>
        public static double GetFrequency()
        {
            uint   eaxPrev, edxPrev, eaxNext, edxNext;
            byte   countNextLo, countNextHi;
            ulong  ciclesPrev, ciclesNext;
            int    pitNext;
            double ticks = 0;

            //This variables take account of wasted cicles
            PIT pit = new PIT();

            //Tell the pit to decrease the counter at its top speed until it reaches 0
            pit.Command.Byte = 0x34;
            //Load the number first msb and next lsb
            //The counter will be 0x10000 (as 0 doesnt exist in pit, the counter will be 65536)
            pit.Data0.Byte = 0;
            pit.Data0.Byte = 0;

            //Get the cicles used in the next loop
            GetCurrentTimeStampCounter(&edxPrev, &eaxPrev);

            //Wait a Little
            //This avoids errors produced by cicles wasted trying to get the cicles and loading the pit
            //Putting much delay gets incorrect speed
            for (int i = 1; i < 2000; i++)
            {
            }

            GetCurrentTimeStampCounter(&edxNext, &eaxNext);

            //Get the current timer
            //Read using a latch in channel 0 (mode software triggered strobe)
            pit.Command.Byte = 0x4;
            //Read the lowest part
            countNextLo = pit.Data0.Byte;
            //Read the highest part
            countNextHi = pit.Data0.Byte;

            //Since we finished getting the values, now we calculate the cicles and time
            ciclesPrev = (edxPrev << 32) + eaxPrev;
            ciclesNext = (edxNext << 32) + eaxNext;
            pitNext    = (countNextHi << 8) + countNextLo;

            //The cicles will be the substraction of the two read values
            ulong totalCicles = ciclesNext - ciclesPrev;

            //The elapsed ticks will be the stating counter minus the read pit.
            //0x10000 is the starting counter (which we arbitrarily put)
            ticks += (0x10000 - pitNext);

            //Since we know that a tic will happen every 1 / 1193180 sec, its easy to get the freq (cicles per second)
            //We use 1.19 to get mhz directly
            double frequency = (totalCicles) * 1.193180 / ticks;

            Debugger.DoSend("Frequency: " + frequency + " mhz");

            return(frequency);
        }
예제 #3
0
        private void Cost_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.SalaryGrossText.IsEnabled = false;
            double SalaryGross, PIT;

            try
            {
                SalaryGross = Double.Parse(this.SalaryGrossText.Text);
                double pension_contribution = Math.Round(SalaryGross * 0.0976, 2);
                double renta_contribution   = Math.Round(SalaryGross * 0.015, 2);
                double disease_contribution = Math.Round(SalaryGross * 0.0245, 2);
                this.PensionBox.Text = pension_contribution.ToString();
                this.RentaBox.Text   = renta_contribution.ToString();
                this.DiseaseBox.Text = disease_contribution.ToString();
                SalaryGross         -= pension_contribution + renta_contribution + disease_contribution;
                double health_contribution        = Math.Round(SalaryGross * 0.09, 2);
                double health_contribution_income = Math.Round(SalaryGross * 0.0775, 2); // 7,75%
                this.HealthCareBox.Text = health_contribution.ToString();
                SalaryGross            -= cost_of_getting_income;
                SalaryGross             = Math.Round(SalaryGross, 0);
                if (SalaryGross * 12 < 85528)
                {
                    PIT = Math.Round(Math.Round((SalaryGross) * 0.18, 2) - pit_2 - health_contribution_income, 0);
                    if (PIT < 0)
                    {
                        PIT = 0;
                    }
                    this.Tax_1Box.Text = PIT.ToString();
                }
                else
                {
                    PIT = SalaryGross; //TODO 32% podatku
                }
                SalaryGross             = Double.Parse(this.SalaryGrossText.Text);
                this.SalaryNetText.Text = (SalaryGross - pension_contribution - renta_contribution - disease_contribution - health_contribution - PIT).ToString();
            }
            catch (FormatException)
            {
                MessageBox.Show("Popraw dane");
            }
            this.SalaryGrossText.IsEnabled = true;
        }
예제 #4
0
        public static void AcpiOsStall(uint Milliseconds)
        {
            uint divisor = PIT.PrepareSleep(Milliseconds * 1000);

            PIT.Sleep(divisor);
        }
예제 #5
0
        //protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
        //{

        //}

        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            //  DeviceId = turnContext.Activity.From.Id;


            RecognizerResult re = new RecognizerResult();


            EmployeeModel ems = new EmptyBot().GiveEmployee();

            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                DeviceId = turnContext.Activity.From.Id.Substring(0, 36);
                // await turnContext.SendActivityAsync(DeviceId);
                var recognizerResult = await this.Recognizer.RecognizeAsync(turnContext, cancellationToken);

                var    topIntent      = recognizerResult?.GetTopScoringIntent();
                string strIntent      = (topIntent != null) ? topIntent.Value.intent : "";
                double dblIntentScore = (topIntent != null) ? topIntent.Value.score : 0.0;
                re = recognizerResult;
                if (turnContext.Activity.Value != null)
                {
                    JObject data = turnContext.Activity.Value as JObject;
                    if (data.GetValue("code1") != null)
                    {
                        string[] codes = data.GetValue("code1").ToString().Split(",");

                        // await turnContext.SendActivityAsync(data.GetValue("code1").ToString());



                        if (ems.Allow_ticketing == "FALSE")
                        {
                            await turnContext.SendActivityAsync("You are not able to create booking");
                        }
                        else
                        {
                            await turnContext.SendActivityAsync(new RequestToBookApi().BookFlight(recognizerResult.Entities, codes));
                        }
                    }
                    else if (data.GetValue("LoginID", StringComparison.CurrentCulture) != null)
                    {
                        //JObject login = turnContext.Activity.Value as JObject;


                        await turnContext.SendActivityAsync(new LoginIntent().Login(data.GetValue("LoginID", StringComparison.CurrentCulture).ToString(), data.GetValue("Password", StringComparison.CurrentCulture).ToString(), DeviceId, ""));
                    }
                }

                else
                {
                    string LoginId  = turnContext.Activity.From.Id.Substring(turnContext.Activity.From.Id.IndexOf("|") + 1, turnContext.Activity.From.Id.LastIndexOf("|") - (turnContext.Activity.From.Id.IndexOf("|") + 1));
                    string Password = turnContext.Activity.From.Id.Substring(turnContext.Activity.From.Id.LastIndexOf("|") + 1);
                    new LoginIntent().Login(LoginId, Password, DeviceId, "");
                    List <CustomFlightDetailModel> cfdm = new EmptyBot().GetIteneraries();

                    switch (strIntent)
                    {
                    case "Welcome":
                        Random        rm  = new Random();
                        int           num = rm.Next(1, 8);
                        EmployeeModel e   = new EmptyBot().GiveEmployee();
                        switch (num)
                        {
                        case 1:
                            await turnContext.SendActivityAsync(" How can I help you today?");

                            break;

                        case 2:
                            await turnContext.SendActivityAsync("Hello");

                            break;

                        case 8:
                            await turnContext.SendActivityAsync(DateTime.Now.Hour < 12 && DateTime.Now.Hour > 5? "Good morning" : DateTime.Now.Hour > 16? "Good evening" : "Good afternoon");

                            break;

                        case 7:
                            await turnContext.SendActivityAsync("Welcome " + e.FirstName);

                            break;

                        case 4:
                            await turnContext.SendActivityAsync("Namaste!! What can I assist you with today?");

                            break;

                        case 3:
                            await turnContext.SendActivityAsync("How can I assist you today?");

                            break;

                        case 5:
                            await turnContext.SendActivityAsync("Hi " + e.FirstName);

                            break;

                        case 6:
                            await turnContext.SendActivityAsync("Hello " + e.FirstName);

                            break;

                        default:
                            await turnContext.SendActivityAsync("hope you are having a great day? How can I assist you today?");

                            break;
                        }



                        break;

                    case "Flight_availability":

                        //await turnContext.SendActivityAsync(DeviceId);
                        //await turnContext.SendActivityAsync(LoginId);
                        //await turnContext.SendActivityAsync(Password);
                        EmployeeModel em = GiveEmployee();
                        if (em.Email == null)
                        {
                            var inputcard = turnContext.Activity.CreateReply();
                            var inputjson = new LoginIntent().InputCard();
                            //var inputjson = File.ReadAllText(System.IO.Directory.GetCurrentDirectory() + @"/simplecard.json");
                            Attachment attachment = new Attachment
                            {
                                ContentType = AdaptiveCard.ContentType,
                                Content     = AdaptiveCard.FromJson(inputjson).Card
                            };
                            inputcard.Attachments = new List <Attachment>()
                            {
                                attachment
                            };
                            await turnContext.SendActivityAsync("please login to proceed..");

                            await turnContext.SendActivityAsync(inputcard);
                        }
                        else
                        {
                            await turnContext.SendActivityAsync("Search is in progress...");

                            var response = turnContext.Activity.CreateReply();
                            var x        = new GiveJson().CreateAdaptiveCardFromJsonModified(recognizerResult.Entities);
                            response.Attachments = x;
                            if (x != null)
                            {
                                Random rm1  = new Random();
                                int    num1 = rm1.Next(1, 6);
                                switch (num1)
                                {
                                case 1:
                                    await turnContext.SendActivityAsync("Here is the snapshot");

                                    break;

                                case 2:
                                    await turnContext.SendActivityAsync("Hi " + em.FirstName + ", as per policy the lowest fare is available");

                                    break;

                                case 3:
                                    await turnContext.SendActivityAsync("Certainly " + em.FirstName + ", Here are the details");

                                    break;

                                case 4:
                                    await turnContext.SendActivityAsync("Sharing results for flights ");

                                    break;

                                case 5:
                                    await turnContext.SendActivityAsync("Sure, Here you are!!Please select the flight to book");

                                    break;

                                case 6:
                                    await turnContext.SendActivityAsync("Hi" + em.FirstName + ", you have booked for " + recognizerResult.Entities.GetValue("City").First + " to " + recognizerResult.Entities.GetValue("City").Last + ". Here are the flight details");

                                    break;
                                }


                                await turnContext.SendActivityAsync(response);

                                //await turnContext.SendActivityAsync("would you like to search for other flights??");
                                var myitem = new UtteranceLog();



                                myitem.UtteranceList.AddRange(PIT.GiveItenerary());


                                IDictionary <string, object> changes = new Dictionary <string, object>();
                                {
                                    changes.Add(DeviceId + "pricedIteneraries", myitem);
                                }
                                await _myStorage.WriteAsync(changes, cancellationToken);

                                //  await turnContext.SendActivityAsync(DeviceId);
                            }
                            else
                            {
                                await turnContext.SendActivityAsync("Sorry no flights are available");
                            }
                        }
                        break;

                    case "Flight_details":


                        if (cfdm.Count > 0)
                        {
                            await turnContext.SendActivityAsync(new FlightDetails().GetFlightDetails(recognizerResult.Entities));
                        }
                        else
                        {
                            await turnContext.SendActivityAsync("Please seacrh for available flights to see details");
                        }
                        break;

                    case "mail":

                        if (cfdm.Count > 0)
                        {
                            await turnContext.SendActivityAsync(new SendMail().Mail(recognizerResult.Entities));
                        }
                        else
                        {
                            await turnContext.SendActivityAsync("Please seacrh for available flights to see details");
                        }

                        break;

                    case "Fares":

                        if (cfdm.Count > 0)
                        {
                            await turnContext.SendActivityAsync(new SendMail().FareDetail(recognizerResult.Entities));
                        }
                        else
                        {
                            await turnContext.SendActivityAsync("Please seacrh for available flights to see fares");
                        }
                        break;

                    case "Queries":
                        EmployeeModel em2 = GiveEmployee();
                        if (em2.Email == null)
                        {
                            var        inputcard  = turnContext.Activity.CreateReply();
                            var        inputjson  = new LoginIntent().InputCard();
                            Attachment attachment = new Attachment
                            {
                                ContentType = AdaptiveCard.ContentType,
                                Content     = AdaptiveCard.FromJson(inputjson).Card
                            };
                            inputcard.Attachments = new List <Attachment>()
                            {
                                attachment
                            };
                            await turnContext.SendActivityAsync("please login to proceed..");

                            await turnContext.SendActivityAsync(inputcard);
                        }
                        else
                        {
                            Query    Query = new Query();
                            string[] str1  = new string[] { DeviceId + "query" };
                            var      temp1 = _myStorage.ReadAsync <UtteranceLog>(str1);
                            if (temp1.Result.Count > 0)
                            {
                                Query = temp1.Result[DeviceId + "query"].query;
                            }
                            var qresponse = turnContext.Activity.CreateReply();
                            var r         = new QueryResponse().CreateAdaptiveCardFromJson(recognizerResult.Entities, Query);

                            if (r != null && !(r is List <Attachment>))
                            {
                                await turnContext.SendActivityAsync(r);
                            }

                            if (r != null && (r is List <Attachment>))
                            {
                                qresponse.Attachments = r;

                                Random rm1  = new Random();
                                int    num1 = rm1.Next(1, 6);
                                switch (num1)
                                {
                                case 1:
                                    await turnContext.SendActivityAsync("Here is the snapshot");

                                    break;

                                case 2:
                                    await turnContext.SendActivityAsync("Hi " + ems.FirstName + ", as per policy the lowest fare is available");

                                    break;

                                case 3:
                                    await turnContext.SendActivityAsync("Certainly " + ems.FirstName + ", Here are the details");

                                    break;

                                case 4:
                                    await turnContext.SendActivityAsync("Sharing results for flights ");

                                    break;

                                case 5:
                                    await turnContext.SendActivityAsync("Sure, Here you are!!Please select the flight to book");

                                    break;

                                case 6:
                                    await turnContext.SendActivityAsync("Hi" + ems.FirstName + ", you have booked for " + recognizerResult.Entities.GetValue("City").First + " to " + recognizerResult.Entities.GetValue("City").Last + ". Here are the flight details");

                                    break;
                                }
                                await turnContext.SendActivityAsync(qresponse);

                                //await turnContext.SendActivityAsync("would you like to search for other flights??");
                                var myitem = new UtteranceLog();



                                myitem.UtteranceList.AddRange(PIT.GiveItenerary());


                                IDictionary <string, object> changes = new Dictionary <string, object>();
                                {
                                    changes.Add(DeviceId + "pricedIteneraries", myitem);
                                }
                                await _myStorage.WriteAsync(changes, cancellationToken);
                            }

                            if (r == null)
                            {
                                await turnContext.SendActivityAsync("Sorry no flights are available");
                            }
                        }
                        break;

                    case "BookFlight":

                        if (cfdm.Count > 0)
                        {
                            EmployeeModel em1 = GiveEmployee();

                            if (em1.Allow_ticketing == "FALSE")
                            {
                                await turnContext.SendActivityAsync("You are not able to create booking");
                            }
                            else
                            {
                                if (recognizerResult.Entities.GetValue("FlightNumber") != null)
                                {
                                    await turnContext.SendActivityAsync(new RequestToBookApi().BookFlight(recognizerResult.Entities, new string[] { }));
                                }
                                else
                                {
                                    await turnContext.SendActivityAsync("Please select flight");
                                }
                            }
                        }
                        else
                        {
                            await turnContext.SendActivityAsync("Please seacrh for available flights to book flights");
                        }

                        break;

                    case "CustomFlights":

                        var res = turnContext.Activity.CreateReply();
                        res.Attachments = new List <Attachment> {
                            new FlightDetails().Customflights(recognizerResult.Entities)
                        };
                        await turnContext.SendActivityAsync(res);

                        break;

                    default:
                        await turnContext.SendActivityAsync("Sorry i did not understand");

                        break;
                    }
                }
            }
            //else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate&& turnContext.Activity.MembersAdded.Count==1)
            //{
            //    await turnContext.SendActivityAsync("Hello!! I am SPARROW, a virtual travel assistant. How can I help you today?"+ DeviceId);


            //    //try
            //    //{
            //    //    await turnContext.SendActivityAsync("Hello!! I am SPARROW, a virtual travel assistant. How can I help you today?");
            //    //    WebRequest request = WebRequest.Create("http://online-corporate-traveller.amadeus.com/live/V17_2_0/webapi/api/SBTMobile/FlightSearch");
            //    //    request.Method = "POST";
            //    //    request.ContentType = "application/json";
            //    //    Stream dataStream = request.GetRequestStream();

            //    //    // getJson(date, direct, type, quantity, origin, desti);
            //    //    // JObject abc = new SearchRequest().GetJson();
            //    //    new LoginIntent().Login(re.Entities);
            //    //    EmployeeModel em = new EmptyBot().GiveEmployee();
            //    //    byte[] byteArray = Encoding.UTF8.GetBytes(new SearchRequest().GetJson("DEL", "BOM", DateTime.Now.AddDays(3), "0", "1",em.TokenID, "AI"));
            //    //    request.ContentLength = byteArray.Length;
            //    //    dataStream.Write(byteArray, 0, byteArray.Length);
            //    //    dataStream.Close();
            //    //    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            //    //    using (Stream receiveStream = Flight_Availability.GetStreamForResponse(response))
            //    //    {
            //    //        StreamReader sr = new StreamReader(receiveStream);
            //    //        string responseFromServer = sr.ReadToEnd();
            //    //        await turnContext.SendActivityAsync(responseFromServer);
            //    //    }

            //    //    dataStream.Close();
            //    //    response.Close();
            //    //}
            //    //catch (Exception ex)
            //    //{
            //    //    throw ex;
            //    //}

            //}

            else if (turnContext.Activity.Type == ActivityTypes.Event)
            {
                await turnContext.SendActivityAsync("Hello!! I am SPARROW, a virtual travel assistant.");
            }
        }
예제 #6
0
        public event writecsvdelegate writecsvEvent;                                                                                                                           //写入数据事件

        public void DataAnalysis(byte[] data, int num)                                                                                                                         //从数据报中解析出有用信息
        {
            if (data[0] == 0xAA && data[1] == 0xAA)                                                                                                                            //帧头
            {
                if (data[2] == 0X01)
                {
                    Rol = (short)(((0 ^ data[4]) << 8) ^ data[5]);  //将b1赋给s的低8位
                    Pit = (short)(((0 ^ data[6]) << 8) ^ data[7]);  //将b1赋给s的低8位
                    Yaw = (short)(((0 ^ data[8]) << 8) ^ data[9]);  //将b1赋给s的低8位
                    //WaverolpityawEvent((int)(Rol / 100), (int)(Pit / 100), (int)(Yaw / 100));
                }
                if (data[2] == 0X02)
                {
                    a_x = (short)(((0 ^ data[4]) << 8) ^ data[5]);
                    a_y = (short)(((0 ^ data[6]) << 8) ^ data[7]);
                    a_z = (short)(((0 ^ data[8]) << 8) ^ data[9]);
                    g_x = (short)(((0 ^ data[10]) << 8) ^ data[11]);
                    g_y = (short)(((0 ^ data[12]) << 8) ^ data[13]);
                    g_z = (short)(((0 ^ data[14]) << 8) ^ data[15]);
                    m_x = (short)(((0 ^ data[16]) << 8) ^ data[17]);
                    m_y = (short)(((0 ^ data[18]) << 8) ^ data[19]);
                    m_z = (short)(((0 ^ data[20]) << 8) ^ data[21]);
                }
                if (data[2] == 0X03)
                {
                    THR  = (short)(((0 ^ data[4]) << 8) ^ data[5]);
                    YAW  = (short)(((0 ^ data[6]) << 8) ^ data[7]);
                    ROL  = (short)(((0 ^ data[8]) << 8) ^ data[9]);
                    PIT  = (short)(((0 ^ data[10]) << 8) ^ data[11]);
                    AUX1 = (short)(((0 ^ data[12]) << 8) ^ data[13]);
                    AUX2 = (short)(((0 ^ data[14]) << 8) ^ data[15]);
                    AUX3 = (short)(((0 ^ data[16]) << 8) ^ data[17]);
                    AUX4 = (short)(((0 ^ data[18]) << 8) ^ data[19]);
                    AUX5 = (short)(((0 ^ data[20]) << 8) ^ data[21]);
                    AUX6 = (short)(((0 ^ data[22]) << 8) ^ data[23]);
                }
                if (data[2] == 0X07)
                {
                    Hei = (short)(((0 ^ data[8]) << 8) ^ data[9]);
                    //WaveheightEvent(Hei);
                }

                statusshowEvent(Rol, Pit, Yaw);
                showsensorshowEvent((int)a_x, (int)a_y, (int)a_z, (int)g_x, (int)g_y, (int)g_z, (int)m_x, (int)m_y, (int)m_z);
                heightshowEvent(Hei);
                showrecvdataEvent(THR, YAW, ROL, PIT, AUX1, AUX2, AUX3, AUX4, AUX5, AUX6);

                //WaveAllEvent((int)(Rol / 100), (int)(Pit / 100), (int)(Yaw / 100), Hei, (ROL-1500)/3, (PIT - 1500) / 3, (YAW - 1500) / 3, (THR - 1500) / 3);
                WaveAllEvent1((int)(Rol / 100), (int)(Pit / 100), (int)(Yaw / 100), Hei, (ROL - 1500) / 3, (PIT - 1500) / 3, (YAW - 1500) / 3, (THR - 1500) / 3);

                if (writecsvflag == true)
                {
                    i++;
                    // string fileName = "C:\\Users\\Administrator\\Desktop\\1.csv";   //指定文件保存在 当前项目文件夹中的bin/debug/文件夹中
                    //// if (!System.IO.File.Exists("C:\\Users\\Administrator\\Desktop\\1.csv"))
                    // StreamWriter sw = new StreamWriter(fileName, true, Encoding.Default);


                    if (i == 1)
                    {
                        ////向文件中输出一行记录  csv文件为逗号分隔符格式文件  同一行中单元格之间用逗号分开
                        //sw.WriteLine("高度,姓名,年龄");
                        if (writecsvEvent != null)
                        {
                            writecsvEvent("Rol", "Pit", "Yaw", "Hei", "RCrol", "RCpit", "RCyaw", "RCthr", "TargetHeight");
                        }
                    }
                    //sw.WriteLine("{0},张三,20", Hei.ToString());
                    if (writecsvEvent != null)
                    {
                        writecsvEvent(Rol.ToString(), Pit.ToString(), Yaw.ToString(), Hei.ToString(), ROL.ToString(), PIT.ToString(), YAW.ToString(), THR.ToString(), (TargetHeight / 10).ToString());
                    }
                }
            }
        }
예제 #7
0
 public static void PITSleep(uint ms)
 {
     PIT.SleepMilliseconds(ms);
 }