/* * public SignalGenerator() * { * this.generator = new Random(); * } */ public static double genSignal(SignalType typeOfSignal) { switch (typeOfSignal) { case SignalType.SBP: { return(generator.NextDouble() * (upperBoundSBP + offset - lowerBoundSBP + offset) + lowerBoundSBP - offset); } case SignalType.DBP: { return(generator.NextDouble() * (upperBoundDBP + offset - lowerBoundDBP + offset) + lowerBoundDBP - offset); } case SignalType.HR: { return(generator.NextDouble() * (upperBoundHR + offset - lowerBoundHR + offset) + lowerBoundHR - offset); } case SignalType.T: { return(generator.NextDouble() * (upperBoundT + offset - lowerBoundT + offset) + lowerBoundT - offset); } default: throw new ArgumentException("Invalid Signal: " + typeOfSignal.ToString()); } }
private async Task CheckSignalWithLast(SignalType signalType, MarketInfo marketInfo) { var table = await GetSignalsTable(); var tableOperation = TableOperation.Retrieve <Signal>("bitmex", ""); await table.ExecuteAsync(tableOperation); var query = new TableQuery <Signal>() .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "bitmex")) .Where(TableQuery.GenerateFilterCondition("Market", QueryComparisons.Equal, marketInfo.Market)); var results = await table.ExecuteQuerySegmentedAsync(query, new TableContinuationToken()); var lastResult = results.Results.OrderBy(o => o.Time).LastOrDefault(); if (lastResult?.SignalType != signalType.ToString().ToLower() && signalType != SignalType.None) { string message; var bitmexClient = new BitmexClient(); if (signalType == SignalType.Bullish) { message = await bitmexClient.GoLong(marketInfo); } else if (signalType == SignalType.Bearish) { message = await bitmexClient.GoShort(marketInfo); } else { return; } Logger.Log(message); await new Mailman().SendMailAsync($"Signal got changed to {signalType} for {marketInfo.Market}.\n {message}"); } }
private void SvcSignalToAddress(CpuThreadState ThreadState) { long Address = (long)ThreadState.X0; SignalType Type = (SignalType)ThreadState.X1; int Value = (int)ThreadState.X2; int Count = (int)ThreadState.X3; Logger.PrintDebug(LogClass.KernelSvc, "Address = 0x" + Address.ToString("x16") + ", " + "Type = " + Type.ToString() + ", " + "Value = 0x" + Value.ToString("x8") + ", " + "Count = 0x" + Count.ToString("x8")); if (IsPointingInsideKernel(Address)) { Logger.PrintWarning(LogClass.KernelSvc, $"Invalid address 0x{Address:x16}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm); return; } if (IsAddressNotWordAligned(Address)) { Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned address 0x{Address:x16}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress); return; } long Result; switch (Type) { case SignalType.Signal: Result = System.AddressArbiter.Signal(Address, Count); break; case SignalType.SignalAndIncrementIfEqual: Result = System.AddressArbiter.SignalAndIncrementIfEqual(Memory, Address, Value, Count); break; case SignalType.SignalAndModifyIfEqual: Result = System.AddressArbiter.SignalAndModifyIfEqual(Memory, Address, Value, Count); break; default: Result = MakeError(ErrorModule.Kernel, KernelErr.InvalidEnumValue); break; } if (Result != 0) { Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!"); } ThreadState.X0 = (ulong)Result; }
private async Task CheckSignalWithLast(SignalType currentSignal, Signal lastSignal, MarketInfo marketInfo) { if (lastSignal == null) { Logger.Info($"First signal for {marketInfo.Market}"); return; } if (lastSignal?.SignalType != currentSignal.ToString().ToLower() && currentSignal != SignalType.None) { if (bool.Parse(Environment.GetEnvironmentVariable("prodIsEnabled"))) { await CreateTrades(currentSignal, marketInfo, "Prod"); } await CreateTrades(currentSignal, marketInfo, "Test"); } }
/// <summary> /// Gets measurement record, creating it if needed. /// </summary> /// <param name="instance">Target <see cref="IIndependentAdapterManager"/> instance.</param> /// <param name="currentDeviceID">Device ID associated with current adapter, or zero if none.</param> /// <param name="pointTag">Point tag of measurement.</param> /// <param name="signalReference">Signal reference of measurement.</param> /// <param name="description">Description of measurement.</param> /// <param name="signalType">Signal type of measurement.</param> /// <param name="targetHistorianAcronym">Acronym of target historian for measurement.</param> /// <returns>Measurement record.</returns> public static MeasurementRecord GetMeasurementRecord(this IIndependentAdapterManager instance, int currentDeviceID, string pointTag, string signalReference, string description, SignalType signalType = SignalType.CALC, string targetHistorianAcronym = "PPA") { // Open database connection as defined in configuration file "systemSettings" category using (AdoDataConnection connection = instance.GetConfiguredConnection()) { TableOperations <DeviceRecord> deviceTable = new TableOperations <DeviceRecord>(connection); TableOperations <MeasurementRecord> measurementTable = new TableOperations <MeasurementRecord>(connection); TableOperations <HistorianRecord> historianTable = new TableOperations <HistorianRecord>(connection); TableOperations <SignalTypeRecord> signalTypeTable = new TableOperations <SignalTypeRecord>(connection); // Lookup target device ID int?deviceID = currentDeviceID > 0 ? currentDeviceID : deviceTable.QueryRecordWhere("Acronym = {0}", instance.Name)?.ID; // Lookup target historian ID int?historianID = historianTable.QueryRecordWhere("Acronym = {0}", targetHistorianAcronym)?.ID; // Lookup signal type ID int signalTypeID = signalTypeTable.QueryRecordWhere("Acronym = {0}", signalType.ToString())?.ID ?? 1; // Lookup measurement record by point tag, creating a new record if one does not exist MeasurementRecord measurement = measurementTable.QueryRecordWhere("PointTag = {0}", pointTag) ?? measurementTable.NewRecord(); // Update record fields measurement.DeviceID = deviceID; measurement.HistorianID = historianID; measurement.PointTag = pointTag; measurement.SignalReference = signalReference; measurement.SignalTypeID = signalTypeID; measurement.Description = description; // Save record updates measurementTable.AddNewOrUpdateRecord(measurement); // Re-query new records to get any database assigned information, e.g., unique Guid-based signal ID if (measurement.PointID == 0) { measurement = measurementTable.QueryRecordWhere("PointTag = {0}", pointTag); } // Notify host system of configuration changes instance.OnConfigurationChanged(); return(measurement); } }
/// <summary> /// 绘制信号. /// </summary> /// <param name="g"></param> /// <param name="r"></param> /// <param name="st"></param> /// <param name="c"></param> private void PaintSignal(Graphics g, Rectangle r, SignalType st, Color c) { int X1 = 0; int Y1 = 0; int X2 = X1 + r.Width; int Y2 = Y1 + r.Height; int Xw = r.Width; int Yh = r.Height; int Xm = X1 + Xw / 2; // X possition of middle point. int Ym = Y1 + Yh / 2; // Y possition of middle point. int Nper = 3; // Number of periodes that schud be shown. int Xpw = Xw / Nper; // One Periode length in pixel. int Yah = 3 * Yh / 8; // Signal amplitude height in picel. g.SmoothingMode = SmoothingMode.HighQuality; // Create a custom pen: Pen myPen = new Pen(Color.LightGray); myPen.DashStyle = DashStyle.Dot; //Draw vertical grid lines: for (int i = 1; i < 2 * Nper; i++) { g.DrawLine(myPen, X1 + (Xpw / 2) * i, Y1, X1 + (Xpw / 2) * i, Y2); } //Draw horisontal grid lines: g.DrawLine(myPen, X1, Ym - Yah, X2, Ym - Yah); g.DrawLine(myPen, X1, Ym, X2, Ym); g.DrawLine(myPen, X1, Ym + Yah, X2, Ym + Yah); // Create requider signal generator: SignalGenerator sg = new SignalGenerator(st); // Adjust aignal generator: sg.Frequency = 1f / Xpw; sg.Phase = 0f; sg.Amplitude = Yah; sg.Offset = 0f; sg.Invert = false; // Generate signal and draw it: float Xold = 0f; float Yold = 0f; float Xnew = 0f; float Ynew = 0f; myPen.Color = c; myPen.DashStyle = DashStyle.Solid; myPen.Width = 2; for (int i = 0; i < Xw; i++) { Xnew = i; Ynew = (float)sg.GetValue(i); // NOTE: Only for debug, not for release configuration! if (i > 0) { g.DrawLine(myPen, X1 + Xold, Ym - Yold, X1 + Xnew, Ym - Ynew); } Xold = Xnew; Yold = Ynew; } // Draw the name of signal form: StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; g.DrawString(st.ToString(), new Font("Times", 8, FontStyle.Bold), new SolidBrush(Color.Black), X2 - Xpw / 4, 10, format); // Draw border rectangle: g.DrawRectangle(new Pen(Color.Tomato, 2), X1 + 1, Y1 + 1, Xw - 2, Yh - 2); }
/// <summary> /// Creates a full signal GameObject for a given SignalType /// </summary> /// <param name="type">The type of the signal</param> public virtual GameObject InstantiateSignal(SignalType type) { if (type == SignalType.Invalid) return null; GameObject signal = Instantiate(signalPrefab); SignalMovement sigObj = signal.GetComponent<SignalMovement>(); signal.transform.SetParent(signalsCont.transform);//put the signals in a container, for a cleaner hierarchy sigObj.signalController = this; sigObj.SigType = type; sigObj.speed = this.signalSpeed; Button infoButton = signal.transform.Find("Canvas/InfoButton").GetComponent<Button>(); infoButton.onClick.AddListener(() => inputManager.SignalClick(signal));//set the click event switch (type) //fill the appropppriate values for each SignalType { case SignalType.LegPain: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Legs", "Parietal", "כאב ברגל", 5, @"תחושה וכאב מעובדים באונה הקודקודית"); break; case SignalType.HandPain: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Arms", "Parietal", "כאב ביד", 5, @"תחושה וכאב מעובדים באונה הקודקודית"); break; case SignalType.ScaryObjectSight: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Eyes", "Occipital", "עצם מפחיד", 20, @"נתונים חזותיים מהעיניים מעובדים באונה העורפית"); break; case SignalType.FamiliarObjectSight: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Eyes", "Occipital", "עצם מוכר", 20, @"נתונים חזותיים מהעיניים מעובדים באונה העורפית"); break; case SignalType.HotObject: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Arms", "Parietal", "מגע חם מאוד", 30, @"על תגובה לטמפרטורות קיצוניות אחראית האונה הקודקודית"); break; case SignalType.ColdObject: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Arms", "Parietal", "מגע קר מאוד", 25, @"על תגובה לטמפרטורות קיצוניות אחראית האונה הקודקודית"); break; case SignalType.SweetTaste: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Tounge", "Parietal", "טעם מתוק", 5, @"טעם מעובד באונה הקודקודית"); break; case SignalType.SourTaste: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Tounge", "Parietal", "טעם חמוץ", 5, @"טעם מעובד באונה הקודקודית"); break; case SignalType.SpokenTo: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Ears", "Frontal", "שיחה", 10, @"עיבוד ותגובה לדיבור מעובדים באונה המצחית"); break; case SignalType.Falling: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Ears", "Cerebellum", "נפילה", 30, @"שיווי משקל ושליטה מוטורית על השרירים הם תפקידיו של המוח הקטן"); break; case SignalType.Running: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Legs", "Cerebellum", "ריצה", 20, @"שיווי משקל ושליטה מוטורית על השרירים הם תפקידיו של המוח הקטן"); break; case SignalType.HotBody: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Blood", "Thalamus", "חום גוף גבוה", 20, @"בקרה על טמפרטורת הגוף היא אחריותו של ההיפותלמוס"); break; case SignalType.ColdBody: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Blood", "Thalamus", "חום גוף נמוך", 20, @"בקרה על טמפרטורת הגוף היא אחריותו של ההיפותלמוס"); break; case SignalType.HighBloodPressure: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Blood", "Stem", "לחץ דם גבוה", 20, @"שמירה על לחץ דם יציב נעשית ע""י גזע המוח"); break; case SignalType.LowBloodPressure: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Blood", "Stem", "לחץ דם נמוך", 20, @"שמירה על לחץ דם יציב נעשית ע""י גזע המוח"); break; case SignalType.LowWater: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Blood", "Thalamus", "ריכוז מים נמוך", 25, @"שמירה על ריכוז נוזלים תקין בדם נעשית ע""י ההיפותלמוס"); break; case SignalType.HighWater: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Blood", "Thalamus", "ריכוז מים גבוה", 25, @"שמירה על ריכוז נוזלים תקין בדם נעשית ע""י ההיפותלמוס"); break; case SignalType.BlockedBreathing: sigObj.FillSignalInfo(SignalMovement.SignalClass.Sensory, "Trachea", "Stem", "חנק", 40, @"אינסטינקטים כגון השתעלות, שנועדה בין השאר להוציא עצמים זרים מקנה הנשימה, נשלטים ע""י גזע המוח"); break; case SignalType.Breath: sigObj.FillSignalInfo(SignalMovement.SignalClass.Motor, "Stem", "Lungs", "נשימה", 20, @"נשימה מתבצעת ע""י הריאות"); break; case SignalType.ReduceHeartRate: sigObj.FillSignalInfo(SignalMovement.SignalClass.Motor, "Stem", "Heart", "הורדת קצב הלב", 10, @"הלב מזרים דם לכל חלקי הגוף, וקצב פעימות מופחת מפחית את לחץ הדם"); break; case SignalType.IncreaseHeartRate: sigObj.FillSignalInfo(SignalMovement.SignalClass.Motor, "Stem", "Heart", "הגברת קצב הלב", 10, @"הלב מזרים דם לכל חלקי הגוף, וקצב פעימות מוגבר מעלה את לחץ הדם"); break; case SignalType.MoveHand: sigObj.FillSignalInfo(SignalMovement.SignalClass.Motor, "Cerebellum", "Arms", "הזזת הידיים", 25, @"הרחקה של הידיים יכולה למנוע פגיעה פיזית"); break; case SignalType.MoveLeg: sigObj.FillSignalInfo(SignalMovement.SignalClass.Motor, "Cerebellum", "Legs", "הזזת הרגליים", 25, @"הרחקה של הרגליים יכולה למנוע פגיעה פיזית"); break; case SignalType.Run: sigObj.FillSignalInfo(SignalMovement.SignalClass.Motor, "Cerebellum", "Legs", "ריצה", 15, @"הפעלת שרירי הרגליים לריצה יכולה להרחיק את הגוף כולו מסכנה"); break; case SignalType.Speak: sigObj.FillSignalInfo(SignalMovement.SignalClass.Motor, "Frontal", "Lungs", "דיבור", 10, @"דיבור, שתלוי, בין השאר, בהוצאת אוויר מהריאות, הוא צורת תקשורת ייחודית לבני אדם, ומשפרת מאוד את יכולת ההישרדות של האדם בקבוצה"); break; case SignalType.Shiver: sigObj.FillSignalInfo(SignalMovement.SignalClass.Motor, "Stem", "Arms", "רעד בידיים", 15, @"רעידות (למשל של הידיים) הן חלק ממנגנוני הגוף לחימום. הרעידות יוצרות חימום ע""י הפעלת השרירים שכחלק מפעולתם פולטים חום"); break; case SignalType.Cough: sigObj.FillSignalInfo(SignalMovement.SignalClass.Motor, "Stem", "Lungs", "שיעול", 35, @"שיעול כולל הוצאת אוויר חזקה ומהירה מהריאות, והוא יכול להוציא עצמים זרים הגורמים לחנק מקנה הנשימה"); break; default: throw new ArgumentException("Unknown SignalType: " + type.ToString(), "type"); } signal.name = type.ToString() + " (" + sigObj.Origin.name + " -> " + sigObj.Target.name + ")"; //set a name, for debugging signal.transform.position = sigObj.Origin.transform.position; return signal; }
/// <summary> /// Paints the signal. /// </summary> /// <param name="g">The g.</param> /// <param name="r">The r.</param> /// <param name="st">The st.</param> /// <param name="c">The c.</param> private void PaintSignal(Graphics g, Rectangle r, SignalType st, Color c) { float X1 = InitialLocation[0]; float Y1 = InitialLocation[1]; float X2 = X1 + r.Width; float Y2 = Y1 + r.Height; float Xw = r.Width; float Yh = r.Height; float Xm = X1 + Xw / 2; // X possition of middle point. float Ym = Y1 + Yh / 2; // Y possition of middle point. float Nper = Periods; // Number of periodes that schud be shown. float Xpw = Xw / Nper; // One Periode length in pixel. float Yah = AmplitudeHeight * Yh / (AmplitudeTension * (GetSum / Maximum)); // Signal amplitude height in picel. // Create a custom pen: if (ShowGridLines) { //Draw vertical grid lines: for (int i = 1; i < GridLines * Nper; i++) { g.DrawLine(GridPen, X1 + (Xpw / GridLines) * i, Y1, X1 + (Xpw / GridLines) * i, Y2); } //Draw horisontal grid lines: g.DrawLine(GridPen, X1, Ym - Yah, X2, Ym - Yah); g.DrawLine(GridPen, X1, Ym, X2, Ym); g.DrawLine(GridPen, X1, Ym + Yah, X2, Ym + Yah); } // Create requider signal generator: SignalGenerate sg = new SignalGenerate(st); // Adjust aignal generator: sg.Frequency = 1 / Xpw; sg.Phase = 0f; sg.Amplitude = Yah; sg.Offset = 0f; sg.Invert = false; // Generate signal and draw it: float Xold = 0f; float Yold = 0f; float Xnew = 0f; float Ynew = 0f; //signalPen.Color = c; //signalPen.DashStyle = DashStyle.Solid; //signalPen.Width = 2; for (int i = 0; i < Xw; i++) { Xnew = i; Ynew = (float)sg.GetValue(i); // NOTE: Only for debug, not for release configuration! if (i > 0) { g.DrawLine(SignalPen, X1 + Xold, Ym - Yold, X1 + Xnew, Ym - Ynew); } Xold = Xnew; Yold = Ynew; } // Draw the name of signal form: StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; if (ShowText) { g.DrawString(st.ToString(), Font, new SolidBrush(ForeColor), X2 - Xpw / 4, 10, format); } if (ShowBorder) { // Draw border rectangle: g.DrawRectangle(BorderColor, X1 + 1, Y1 + 1, Xw - 2, Yh - 2); } }
private void SvcSignalToAddress(CpuThreadState threadState) { long address = (long)threadState.X0; SignalType type = (SignalType)threadState.X1; int value = (int)threadState.X2; int count = (int)threadState.X3; Logger.PrintDebug(LogClass.KernelSvc, "Address = 0x" + address.ToString("x16") + ", " + "Type = " + type.ToString() + ", " + "Value = 0x" + value.ToString("x8") + ", " + "Count = 0x" + count.ToString("x8")); if (IsPointingInsideKernel(address)) { Logger.PrintWarning(LogClass.KernelSvc, $"Invalid address 0x{address:x16}!"); threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm); return; } if (IsAddressNotWordAligned(address)) { Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned address 0x{address:x16}!"); threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress); return; } KProcess currentProcess = _system.Scheduler.GetCurrentProcess(); long result; switch (type) { case SignalType.Signal: result = currentProcess.AddressArbiter.Signal(address, count); break; case SignalType.SignalAndIncrementIfEqual: result = currentProcess.AddressArbiter.SignalAndIncrementIfEqual(address, value, count); break; case SignalType.SignalAndModifyIfEqual: result = currentProcess.AddressArbiter.SignalAndModifyIfEqual(address, value, count); break; default: result = MakeError(ErrorModule.Kernel, KernelErr.InvalidEnumValue); break; } if (result != 0) { Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{result:x}!"); } threadState.X0 = (ulong)result; }
public object DecodeCANMessage(ulong signalValue) { switch (sType) { //连续值解析 case SignalType.Continuous: double value = signalValue; value *= cRatio; value += cOffset; return(value); //离散值解析 case SignalType.Discrete: return(DiscreteDecodeTable.ContainsKey(signalValue) ? DiscreteDecodeTable[signalValue] : string.Format("Undef:{0}", signalValue)); //开关量解析 case SignalType.Switch: return(SwitchMap[signalValue]); //DM1故障码 case SignalType.DM1FaultCode: DM1Value dm1Obj = new DM1Value() { FMI = (uint)(signalValue >> 16 & 0x1F), SPN = (uint)(signalValue >> 21 & 7 << 16 | (signalValue & 0xFFFF)) }; return(dm1Obj); case SignalType.UserDefined: //用匿名函数的形式描述解析器(少用) //JS: function(var_ulong_value){...} return(JavaScriptEngine.runCmd(string.Format("{0}({1})", UDFName, signalValue))); default: throw new Exception("Undefined signal type, please check your code:" + sType.ToString()); } }
public override string ToString() { return(SignalName + " - [Index: " + SignalIndex + "] [Type: " + SignalType.ToString() + "]"); }