private void Awake() { if (instence == null) { instence = this; } }
/// <summary> /// Funkcja tworzy całą tabelkę z licytacją z pojedynczego stołu. Tworzy kolumny na podstawie zmiennej licytacja_szerkosc_kolumny. /// Tworzy wiersz nagłówkowy, oraz z nazwiskami, i jesli licytacja nie jest pusta to tworzy poszczegolne odzywki. Formatuje tabele /// </summary> /// <param name="bidding">licytacja do wypisania</param> /// <param name="dealer">Rozdajacy, zeby wiedziec skad zaczac pisac</param> /// <param name="surnames">Nazwiska do wpisania w strukturze enuma position</param> /// <returns></returns> public Table PrintBiddingTable(List <Bidding> bidding, positions dealer, string[] surnames) { Table table = new Table(); for (int i = 0; i < 4; i++) { table.AddColumn(Unit.FromCentimeter(licytacja_szerokosc_kolumny)); } Row row = table.AddRow(); CreateBiddingFirstRow(ref row); if (linia_z_nazwiskami) { row = table.AddRow(); CreateBiddingSurnameRow(ref row, surnames); } if (bidding.Count > 0) { WriteBids(ref table, bidding, dealer); } table.Format.Alignment = ParagraphAlignment.Center; table.Rows.Height = Unit.FromCentimeter(licytacja_wysokosc_kolumny); table.Borders.Width = licytacja_szerkosc_borders; table.Rows.VerticalAlignment = VerticalAlignment.Center; return(table); }
public positions GetDealer(string boardline, int delay = 3) { string rozklad = FindLine(boardline, Settings.rozklad, 3, '|'); int z = int.Parse(rozklad[0].ToString()); positions pos = (positions)z; return(pos); }
public static Contract FindOptimalContract(int[,] lewy, vulnerabilties vul, positions dealer) { DeefFinesseAnalize df = new DeefFinesseAnalize(lewy, vul, dealer); df.FindOptimalContract(); return(df.optimalContract); }
// Use this for initialization void Start() { m_jars = new List <jar>(); m_position = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <positions>(); foreach (float pos in m_position.position_values) { m_jars.Add(new jar(MAX_NUM_OF_BALLS)); } }
// Use this for initialization void Start() { positions position = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <positions>(); foreach (float pos in position.position_values) { Vector3 pos_vec = new Vector3(pos, y_index, 0.0f); Instantiate(jar_prefab, pos_vec, Quaternion.identity); } }
/// <summary> /// Wypelnia dealera oraz inicjuje karty NSWE wywolujac konstruktor klasy Karty. /// </summary> /// <param name="input">Linia wejscia to "4SA7HJ986DT5CKT972,S92H743DQ743CA843,SJ854HQ2DAKJ92CQ5,SKQT63HAKT5D86CJ6" w kolejności SWNE</param> public RozkladKart(string input) { dealer = (positions)(int.Parse(input[0].ToString())); string[] rozklad = input.Substring(1).Split(','); N = new Karty(rozklad[2]); S = new Karty(rozklad[0]); W = new Karty(rozklad[1]); E = new Karty(rozklad[3]); }
// Use this for initialization void Start() { player = new DefultPlayer(); m_wait_for_next_move = new timer(SPEED); position = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <positions>(); position_index = 0; Vector3 player_pos = transform.position; player_pos.x = position.position_values[position_index]; transform.position = player_pos; }
public SendPosition(NetworkCom network, Movement movement) { NetMove = network; moveData = movement; old.BaseRotation = Convert.ToInt32(Math.Round(moveData.baseMovemend.AngleInPWM)); old.Elb0 = Convert.ToInt32(Math.Round(moveData.elbow0.AngleInPWM)); old.Elb1 = Convert.ToInt32(Math.Round(moveData.elbow1.AngleInPWM)); old.Elb2 = Convert.ToInt32(Math.Round(moveData.elbow2.AngleInPWM)); old.GripperRot = Convert.ToInt32(Math.Round(moveData.griperRotation.AngleInPWM)); old.Gripper = Convert.ToInt32(Math.Round(moveData.griper.AngleInPWM)); actual = old; }
protected void Map(Position position, positions positionsDB) { positionsDB.pos_id = position.PosId; positionsDB.symbol = position.Symbol; positionsDB.side = Convert.ToChar(position.Side).ToString(); positionsDB.pos_status = Convert.ToChar(position.PosStatus).ToString(); positionsDB.exchange = position.Exchange; positionsDB.quantity_type = Convert.ToInt32(position.QuantityType); positionsDB.price_type = Convert.ToInt32(position.PriceType); positionsDB.qty = position.Qty; positionsDB.cash_qty = position.CashQty; positionsDB.percent = position.Percent; positionsDB.cum_qty = position.CumQty; positionsDB.leaves_qty = position.LeavesQty; positionsDB.avg_px = position.AvgPx; positionsDB.last_qty = position.LastQty; positionsDB.last_mkt = position.LastMkt; }
/// <summary> /// Wpisuje do zadanej tabeli licytację. /// </summary> /// <param name="table">Zadana tabela</param> /// <param name="bidding">Lista z licytacja</param> /// <param name="dealer">Rozdający w celu poprawnego miejsca otwarcia licytacji domyslnie N</param> /// <returns></returns> private Table WriteBids(ref Table table, List <Bidding> bidding, positions dealer = positions.N, Font f = null) { int dealer_pos = ((int)dealer + 1) % 4; // N = 0, S = 2 E = 1 int suma = dealer_pos + bidding.Count; Row row = null; if (dealer_pos != 0) { row = table.AddRow(); if (f == null) { row.Format.Font = Czcionki.font_normal; } else { row.Format.Font = f; } } for (int i = 0; i < bidding.Count; i++) { int colNr = (dealer_pos + i) % 4; if (colNr == 0) { row = table.AddRow(); if (f == null) { row.Format.Font = Czcionki.font_normal; } else { row.Format.Font = f; } } if (bidding[i].odzywka != null) { row[colNr].Add(WriteOdzywka(bidding[i].odzywka)); } } return(table); }
// Update is called once per frame void Update() { if (!m_wait_for_next_ball.did_time_passed()) { return; } GetComponent <victory>().update_for_win_next_ball(); positions p = GetComponent <positions>(); int type_ball = (int)Random.Range(0, balls.Count); int place_index = (int)Random.Range(0, p.position_values.Count); Ball ball_to_create = balls[type_ball]; float position_x = p.position_values[place_index]; Vector3 fin_pos = new Vector3(position_x, y_to_drop); GameObject g = (GameObject)Instantiate(ball_to_create.gameObject, fin_pos, Quaternion.identity); g.GetComponent <Ball>().pos_index = place_index; g.GetComponent <Ball>().ball_index = type_ball; }
/// <summary> /// Słuzy do ustalenia czy rozgrywajacy byl po partii. Odbywa się to na podstawie nr rozdania /// </summary> /// <param name="nr">nr rozdania (do zalozen)</param> /// <param name="declarer"> rozgrywający </param> /// <returns></returns> public static bool GetVulnerability(int nr, positions declarer) { if (declarer == positions.N || declarer == positions.S) { if (BridgeInfo.NS_partia[nr % 16] > 0) { return(true); } else { return(false); } } else if (BridgeInfo.WE_partia[nr % 16] > 0) { return(true); } else { return(false); } }
/// <summary> /// Ustawia rozgrywajacego. Dokonuyje konwersji z char do position /// </summary> /// <param name="input">Wielka litera (N,S,W,E) oznaczajaca rozgrywajacego</param> /// <returns>Rozgrywajacy</returns> public positions ConvertPosition(char input) { positions output = 0; if (input == 'N') { output = positions.N; } if (input == 'S') { output = positions.S; } if (input == 'W') { output = positions.W; } if (input == 'E') { output = positions.E; } return(output); }
public void AnalyzeAndSend() { actual.BaseRotation = Convert.ToInt32(moveData.baseMovemend.AngleInPWM); actual.Elb0 = Convert.ToInt32(moveData.elbow0.AngleInPWM); actual.Elb1 = Convert.ToInt32(moveData.elbow1.AngleInPWM); actual.Elb2 = Convert.ToInt32(moveData.elbow2.AngleInPWM); actual.GripperRot = Convert.ToInt32(moveData.griperRotation.AngleInPWM); actual.Gripper = Convert.ToInt32(moveData.griper.AngleInPWM); if (actual.BaseRotation != old.BaseRotation) { NetMove.ACKSend("0" + actual.BaseRotation.ToString()); } if (actual.Elb0 != old.Elb0) { NetMove.ACKSend("1" + actual.Elb0.ToString()); } if (actual.Elb1 != old.Elb1) { NetMove.ACKSend("2" + actual.Elb1.ToString()); } if (actual.Elb2 != old.Elb2) { NetMove.ACKSend("3" + actual.Elb2.ToString()); } if (actual.GripperRot != old.GripperRot) { NetMove.ACKSend("4" + actual.GripperRot.ToString()); } if (actual.Gripper != old.Gripper) { NetMove.ACKSend("5" + actual.Gripper.ToString()); } old = actual; }
} // получение данных public override void ProcessTrade(Trade trade) { // получение данных из таблицы сделок while (working) { } // wait for order will be processed var order = (from o in contextDb.orders where o.OrderNum == trade.OrderNum && o.TradeNum == null select o).FirstOrDefault(); if (order == null) { //MessageBox.Show("В базе данных нет ордеров с номером - " + trade.OrderNum + ".", "Ошибка в программе " + cfg.FullProgName); return; } var posit = (from p in contextDb.positions where p.stocks.ticker == trade.SecCode && p.active == true select p).FirstOrDefault(); // open position if (trade.Op == TradeOp.Buy) { if (posit != null) // position { if (posit.tradetypeid == 1) //bought { posit.priceopen = (posit.priceopen * posit.qty + trade.RawPrice * trade.Quantity) / (posit.qty + trade.Quantity); posit.qty += trade.Quantity; } else if (posit.tradetypeid == 2) //sold { if (posit.qty - trade.Quantity == 0) // close { posit.priceclose = trade.RawPrice; posit.qty = 0; posit.closed = trade.DateTime; posit.active = false; } else // downgrade position qty { posit.priceopen = (posit.priceopen * posit.qty.Value + trade.RawPrice * trade.Quantity) / (posit.qty.Value + trade.Quantity); posit.qty -= trade.Quantity; if (posit.qty < 0) { posit.tradetypeid = 1; // если позиция перевернулась posit.qty = posit.qty * -1; } } } } else // new position { positions positNew = new positions(); var stock = (from s in contextDb.stocks where s.ticker == trade.SecCode select s).FirstOrDefault(); positNew.stock = stock.id; positNew.tradetypeid = 1; positNew.opened = trade.DateTime; positNew.priceopen = trade.RawPrice; positNew.qty = trade.Quantity; positNew.openqty = trade.Quantity; positNew.active = true; contextDb.positions.InsertOnSubmit(positNew); } } else //close position if (trade.Op == TradeOp.Sell) { if (posit != null) // position { if (posit.tradetypeid == 1) //bought { if (posit.qty - trade.Quantity == 0) // close { posit.priceclose = trade.RawPrice; posit.qty = 0; posit.closed = trade.DateTime; posit.active = false; } else // downgrade position qty { posit.priceopen = (posit.priceopen * posit.qty + trade.RawPrice * trade.Quantity) / (posit.qty + trade.Quantity); posit.qty -= trade.Quantity; if (posit.qty < 0) { posit.tradetypeid = 2; // если позиция перевернулась posit.qty = posit.qty * -1; } } } else if (posit.tradetypeid == 2) //sold { posit.priceopen = (posit.priceopen * posit.qty + trade.RawPrice * trade.Quantity) / (posit.qty + trade.Quantity); posit.qty += trade.Quantity; } } else // new position { positions positNew = new positions(); var stock = (from s in contextDb.stocks where s.ticker == trade.SecCode select s).FirstOrDefault(); positNew.stock = stock.id; positNew.tradetypeid = 2; positNew.opened = trade.DateTime; positNew.priceopen = trade.RawPrice; positNew.qty = trade.Quantity; positNew.openqty = trade.Quantity; positNew.active = true; contextDb.positions.InsertOnSubmit(positNew); } } else { MessageBox.Show("Транзакция из QUIK с типом - " + trade.Op.ToString() + " не реализована.", "Ошибка в программе " + cfg.FullProgName); return; } long trdNum = 0; Int64.TryParse(trade.TradeNum.ToString(), out trdNum); order.TradeNum = trdNum; contextDb.SubmitChanges(); }
public static Position Map(this positions source) { return(Mapper.Map <positions, Position>(source)); }
BIHTraverse(colliderIndex, simplexIndex, simplexStart, simplexSize, positions, velocities, radii, simplices, in simplexBounds, 0, contacts, optimizationIterations, optimizationTolerance);
// Use this for initialization void Start() { collied = false; position = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <positions>(); }
public void ThreadReceiveGPS() { db = new gpsEntities(); String DeviceID = ""; try { //Remote ip and remote port String remoteAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString(); String remotePort = ((IPEndPoint)client.Client.RemoteEndPoint).Port.ToString(); // Buffer for reading data Byte[] bytes = new Byte[250]; string hex = ""; String invertedHex = ""; int i; while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) { /* * IMPORTANT: the data sent by the GPS can be ordered in two formats Little-Endian or Big-Endian * (If you have not heard these two terms look for information about Endianness), providers should * tell us in what format they were written the most common is the Big-Endian but for this case I play a * GPS that ordered them in Little-Endian and I had to invert the data so that it has some meaning. * * If your provider has no idea of how this information is sent or for one reason or another you can not communicate * with your provider, you can make trial and error test. It will not take you long just to have the hex in two ways as * you can see below and use the form that gives you meaningful data. * * The way you know that data is correct, is seeing the protocol document that comes with the device or that your provider provides you. * * There are many types of protocols and it is important to make sure that you have the right one so as not to waste your time and think * that you are the one programming the server in an erroneous way. */ // Console.WriteLine("Info: " + message); hex = BitConverter.ToString(bytes, 0, i).Replace("-", " "); invertedHex = Strings.Invert(hex, ' '); //If you want to see the hex before and after being inverted uncomment the two lines below //Console.WriteLine("Received HEX: [ {1}:{2} ] {0} ", hex, remoteAddress, remotePort); //Console.WriteLine("Received HEX: [ {1}:{2} ] {0} ", invertedHex, remoteAddress, remotePort); // messageType = Strings.Right(invertedHex, 8); /* * These are nested if they verify the type of message that the GPS sends to execute the appropriate code for each one (the types of messages are in the gps protocol) * * The process that is carried out with each one of these messages is the following: * * 1.The hex that is sent via TCP / IP is captured. * 2.It is verified in the GPS protocol in which order the variables come and what size each one occupies in bytes. * 3.A place is created where each of these data is stored, the variable is matched to the corresponding bytes and these are eliminated from the main * hex and the corresponding data type is parsed. * 4.The data that interests us is saved in the database. * */ if (messageType == registerType) { Console.WriteLine("Received HEX: [ {1}:{2} ] {0} ", invertedHex, remoteAddress, remotePort); uint uiType = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 8); uint uiLength = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 8); ushort uiVersion = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); ushort uiSequeue = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); var header = new s_NV_Message { uiLength = uiLength, uiType = uiType, uiVersion = uiVersion, uiSequeue = uiSequeue }; String szID = Strings.FromHexLittleEndianToString(invertedHex, 24); invertedHex = Strings.Shorten(invertedHex, 24); DeviceID = szID; int nNetAdpaterType = int.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 8); String szModel = Strings.FromHexLittleEndianToString(invertedHex, 48); invertedHex = Strings.Shorten(invertedHex, 48); int nType = int.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 8); String szSoftware = Strings.FromHexLittleEndianToString(invertedHex, 16); invertedHex = Strings.Shorten(invertedHex, 16); String szHardware = Strings.FromHexLittleEndianToString(invertedHex, 16); invertedHex = Strings.Shorten(invertedHex, 16); var s_NV_Protocol_Device_SignalRegister = new s_NV_Protocol_Device_SignalRegister { header = header, szID = szID, nNetAdpaterType = nNetAdpaterType, szModel = szModel, nType = nType, szSoftware = szSoftware, szHardware = szHardware }; } else if (messageType == gpsType) { Console.WriteLine("Received HEX from Device [{3}]: [ {1}:{2} ] {0} ", invertedHex, remoteAddress, remotePort, DeviceID); uint uiType = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 8); uint uiLength = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 8); ushort uiVersion = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); ushort uiSequeue = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); var header = new s_NV_Message { uiLength = uiLength, uiType = uiType, uiVersion = uiVersion, uiSequeue = uiSequeue }; string szTimeStamp = Strings.FromHexLittleEndianToString(invertedHex, 16); invertedHex = Strings.Shorten(invertedHex, 16); char usDataType = (char)Int16.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); var gpsHeader = new s_NV_Protocol_Device_GPSHeader { szTimeStamp = szTimeStamp, usDataType = usDataType }; ushort usDirect = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); ushort usSpeed = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); decimal ucLongitude_degree = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); decimal ucLongitude_Score = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); ucLongitude_Score /= 60; invertedHex = Strings.Shorten(invertedHex, 2); decimal ucLatitude_degree = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); decimal ucLatitude_Score = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); ucLatitude_Score /= 60; invertedHex = Strings.Shorten(invertedHex, 2); decimal unLongitude_Second = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); unLongitude_Second /= 3600; unLongitude_Second /= 10000000; invertedHex = Strings.Shorten(invertedHex, 8); decimal unLatitude_Second = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); unLatitude_Second /= 3600; unLatitude_Second /= 10000000; invertedHex = Strings.Shorten(invertedHex, 8); string ucStatus = Strings.FromHexToBinary(Strings.Right(invertedHex, 2)); invertedHex = Strings.Shorten(invertedHex, 2); string north = "1"; string west = "1"; decimal latitude = ucLatitude_degree + ucLatitude_Score + unLatitude_Second; decimal longitude = ucLongitude_degree + ucLongitude_Score + unLongitude_Second; if (ucStatus.Substring(1, 1) != north) { latitude *= -1; } if (ucStatus.Substring(2, 1) == west) { longitude *= -1; } var gpsBaseinfo = new s_NV_Protocol_GPS_BaseInfo { usDirect = usDirect, usSpeed = usSpeed, ucLongitude_degree = ucLongitude_degree, ucLongitude_Score = ucLongitude_Score, ucLatitude_degree = ucLatitude_degree, ucLatitude_Score = ucLatitude_Score, unLongitude_Second = unLongitude_Second, unLatitude_Second = unLatitude_Second, latitude_decimal_degree = latitude, longitude_decimal_degree = longitude, ucStatus = ucStatus }; string ucValid = Strings.FromHexToBinary(Strings.Right(invertedHex, 2)); invertedHex = Strings.Shorten(invertedHex, 2); var gpsStatus = new s_NV_Protocol_Device_GPSStatus { ucValid = ucValid }; short sAccelate_X = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); short sAccelate_Y = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); short sAccelate_Z = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); short sAccelate_Unit = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); var gSensor = new s_NV_Protocol_GPS_GSensor { sAccelate_X = sAccelate_X, sAccelate_Y = sAccelate_Y, sAccelate_Z = sAccelate_Z, sAccelate_Unit = sAccelate_Unit }; short sCorner = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); short sUnit = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); var gyroSensor = new s_NV_Protocol_GPS_GyroSensor { sCorner = sCorner, sUnit = sUnit }; short sHigh = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); short sTemperature = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); decimal sOilWear = uint.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); // Oil consumption //(Actual data received *10) invertedHex = Strings.Shorten(invertedHex, 4); string cSatelliteNumber = Strings.FromHexLittleEndianToString(invertedHex, 2); invertedHex = Strings.Shorten(invertedHex, 2); // string ucReserved = Strings.FromHexLittleEndianToString(invertedHex, 2); invertedHex = Strings.Shorten(invertedHex, 2); var gpsExternInfo = new s_NV_Protocol_GPS_ExternInfoEx { sHigh = sHigh, sTemperature = sTemperature, sOilWear = (sOilWear * 10),// Oil consumption //(Actual data received *10) cSatelliteNumber = cSatelliteNumber, // ucReserved = ucReserved }; devices devices = new devices { attributes = "{Tank:{" + gpsExternInfo.sOilWear + "}}" }; uint usYear = uint.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); //year uint ucMonth = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //month uint ucDay = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //day(1~31) uint ucHour = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //hour(0~23) uint ucMinute = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //minute(0~59) uint ucSecond = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //second(0~59) // uint uReserved= uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //reserve var gpsTimeInfo = new s_NV_Protocol_GPS_TimeInfo { usYear = usYear, ucMonth = ucMonth, ucDay = ucDay, ucHour = ucHour, ucMinute = ucMinute, ucSecond = ucSecond, // ucReserved=uReserved }; var gpsData = new GPSData { gpsHeader = gpsHeader, gpsStatus = gpsStatus, gSensor = gSensor, gyroSensor = gyroSensor, baseInfo = gpsBaseinfo, externInfoEx = gpsExternInfo, timeInfo = gpsTimeInfo, header = header }; var devices_id = (from dev in db.devices where dev.uniqueid == DeviceID select dev.id).First(); positions positions = new positions { deviceid = devices_id, servertime = DateTime.Now, devicetime = DateTime.ParseExact(gpsTimeInfo.ucDay.ToString() + "-" + gpsTimeInfo.ucMonth.ToString() + "-" + gpsTimeInfo.usYear.ToString() + " " + gpsTimeInfo.ucHour.ToString() + ":" + gpsTimeInfo.ucMinute.ToString() + ":" + gpsTimeInfo.ucSecond.ToString(), "d-M-yyyy H:m:s", System.Globalization.CultureInfo.InvariantCulture), fixtime = DateTime.Now, latitude = decimal.ToDouble(gpsBaseinfo.latitude_decimal_degree), longitude = decimal.ToDouble(gpsBaseinfo.longitude_decimal_degree), speed = gpsBaseinfo.usSpeed, protocol = "sodimax-mdvr", altitude = 0, valid = true, course = 0, accuracy = 0, address = "", network = "" }; db.positions.Add(positions); db.SaveChanges(); } else if (messageType == counterType) { Console.WriteLine("Received HEX from Device [{3}]: [ {1}:{2} ] {0} ", invertedHex, remoteAddress, remotePort, DeviceID); uint uiType = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 8); uint uiLength = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 8); ushort uiVersion = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); ushort uiSequeue = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); var header = new s_NV_Message { uiLength = uiLength, uiType = uiType, uiVersion = uiVersion, uiSequeue = uiSequeue }; uint usYear = uint.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); //year uint ucMonth = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //month uint ucDay = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //day(1~31) uint ucHour = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //hour(0~23) uint ucMinute = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //minute(0~59) uint ucSecond = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); //second(0~59) // uint uReserved= uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); //invertedHex = Strings.Shorten(invertedHex, 2); //reserve var gpsTimeInfo = new s_NV_Protocol_GPS_TimeInfo { usYear = usYear, ucMonth = ucMonth, ucDay = ucDay, ucHour = ucHour, ucMinute = ucMinute, ucSecond = ucSecond, // ucReserved=uReserved }; DateTime counterDate = DateTime.ParseExact(gpsTimeInfo.ucDay.ToString() + "-" + gpsTimeInfo.ucMonth.ToString() + "-" + gpsTimeInfo.usYear.ToString() + " " + gpsTimeInfo.ucHour.ToString() + ":" + gpsTimeInfo.ucMinute.ToString() + ":" + gpsTimeInfo.ucSecond.ToString(), "d-M-yyyy H:m:s", System.Globalization.CultureInfo.InvariantCulture); string mesType = Strings.FromHexToBinary(Strings.Right(invertedHex, 8)); invertedHex = Strings.Shorten(invertedHex, 8); var MesType = new MesType() { mesType = mesType }; ushort usDirect = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); ushort usSpeed = ushort.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); decimal ucLongitude_degree = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); decimal ucLongitude_Score = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); ucLongitude_Score /= 60; invertedHex = Strings.Shorten(invertedHex, 2); decimal ucLatitude_degree = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 2); decimal ucLatitude_Score = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier); ucLatitude_Score /= 60; invertedHex = Strings.Shorten(invertedHex, 2); decimal unLongitude_Second = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); unLongitude_Second /= 3600; unLongitude_Second /= 10000000; invertedHex = Strings.Shorten(invertedHex, 8); decimal unLatitude_Second = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); unLatitude_Second /= 3600; unLatitude_Second /= 10000000; invertedHex = Strings.Shorten(invertedHex, 8); string ucStatus = Strings.FromHexToBinary(Strings.Right(invertedHex, 2)); invertedHex = Strings.Shorten(invertedHex, 2); string north = "1"; string west = "1"; decimal latitude = ucLatitude_degree + ucLatitude_Score + unLatitude_Second; decimal longitude = ucLongitude_degree + ucLongitude_Score + unLongitude_Second; if (ucStatus.Substring(1, 1) != north) { latitude *= -1; } if (ucStatus.Substring(2, 1) == west) { longitude *= -1; } //invertedHex = Strings.Shorten(invertedHex, 6); //3 bytes de reserva var gpsBaseinfo = new s_NV_Protocol_GPS_BaseInfo { usDirect = usDirect, usSpeed = usSpeed, ucLongitude_degree = ucLongitude_degree, ucLongitude_Score = ucLongitude_Score, ucLatitude_degree = ucLatitude_degree, ucLatitude_Score = ucLatitude_Score, unLongitude_Second = unLongitude_Second, unLatitude_Second = unLatitude_Second, latitude_decimal_degree = latitude, longitude_decimal_degree = longitude, ucStatus = ucStatus }; ushort ucfIn = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); // Number of passengers on board ushort ucfOut = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); // The number of passengers getting off ushort ucbIn = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); // The total number of passengers on board ushort ucbOut = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); //The total number of passengers getting off ushort ucnCunt = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); invertedHex = Strings.Shorten(invertedHex, 4); //Current total number of passengers on //board // string ucReserved = Strings.FromHexToBinary(Strings.Right(invertedHex, 4)); // invertedHex = Strings.Shorten(invertedHex, 4); // reserve ucnum = int.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier); num = Strings.FromHex(Strings.Right(invertedHex, 8)); //Parsing hex to byte to response to the device invertedHex = Strings.Shorten(invertedHex, 8); // identifier—-- The server needs to return this number //to the device by response,if this number is 1, it is void data ,do not need response var peopleCount = new s_NV_PeopleCount() { ucbIn = ucfOut, // How many people entered Up-in down-out ucbOut = ucbOut, ucfIn = (ushort)(ucfOut - ucbIn), // How many people are there ucfOut = ucbIn, // How many people went up-in down-out ucnCunt = ucnCunt, ucnum = ucnum, // Number to send // ucReserved = ucReserved }; var devices_id = (from dev in db.devices where dev.uniqueid == DeviceID select dev.id).First(); var route_id = (from dev in db.devices where dev.uniqueid == DeviceID select dev.routeId).First(); int lastPassengerIn = (from counter in db.passenger_counters orderby counter.servertime descending select counter.totalPassengerIn).First(); int lastPassengerOut = (from counter in db.passenger_counters orderby counter.servertime descending select counter.totalPassengerOut).First(); int invalidData = 1; if (ucnum != invalidData && (peopleCount.ucbIn != lastPassengerIn || peopleCount.ucfOut != lastPassengerOut)) { passenger_counters passenger_Counters = new passenger_counters { deviceid = devices_id, servertime = DateTime.Now, devicetime = counterDate, totalPassengerIn = peopleCount.ucbIn, totalPassengerOut = peopleCount.ucfOut, currentPassengerIn = peopleCount.ucfIn, routeid = (int)route_id //currentPassengerIn= ucfIn }; db.passenger_counters.Add(passenger_Counters); db.SaveChanges(); } } stream.Flush(); // Thread.Sleep(10000); } } catch (SocketException ex) { //If an error occur the client connection will close Console.WriteLine("Error!\n" + ex.Message + "\nClosing connection..."); client.Close(); } catch (Exception ex) { Console.WriteLine("Error!\n" + ex.Message + "\n" + ex.StackTrace); client.Close(); } }
public DeefFinesseAnalize(int[,] lewy_, vulnerabilties vul_, positions dealer_) { lewy = lewy_; vul = vul_; dealer = dealer_; }