/// <summary> /// For creating outgoing frames /// </summary> /// <param name="sendCounter"></param> /// <param name="receiveCounter"></param> /// <param name="payload"></param> public FrameTcp(uint sendCounter, uint receiveCounter, ushort keyNumber, InformationId informationId, params FrameVdS[] payload) { // AES frames must be blocks of 16 bytes //var tmpLen = (payload.Sum(p => p.GetByteCount()) + 13) / 16.0; //var aesLength = (int)(Math.Ceiling(tmpLen) * 16); var aesLength = 160; this.FillByteCount = aesLength - payload.Sum(p => p.GetByteCount() + 13); // K + SL + aesBuffer this.buffer = new byte[2 + 2 + aesLength]; // copy payload into buffer var payloadBytes = payload.SelectMany(p => p.Serialize()).ToArray(); Array.Copy(payloadBytes, 0, this.buffer, 0 + 2 + 2 + 4 + 2 + 4 + 1 + 1 + 1, payloadBytes.Length); this.KeyNumber = keyNumber; this.FrameLength = (ushort)(this.buffer.Length - 4); this.SendCounter = sendCounter; this.ReceiveCounter = receiveCounter; this.InformationId = informationId; this.ProtocolId = ProtocolId.VdS2465; this.PayloadLength = (byte)payloadBytes.Length; // set CRC this.Checksum = this.CalculateCrc(); }
public ActionResult DeleteConfirmed(int id) { InformationId informationid = db.InformationIds.Find(id); db.InformationIds.Remove(informationid); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /InformationIdAdmin/Details/5 public ActionResult Details(int id = 0) { InformationId informationid = db.InformationIds.Find(id); if (informationid == null) { return(HttpNotFound()); } return(View(informationid)); }
public ActionResult Edit(InformationId informationid) { if (ModelState.IsValid) { db.Entry(informationid).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(informationid)); }
public static FrameVdS CreateEmpty(InformationId informationId) { if (informationId != InformationId.PollReqRes) { throw new ArgumentException("informationId"); } var buff = new byte[0]; return(new FrameVdS(buff, 0, informationId)); }
public ActionResult Create(InformationId informationid) { if (ModelState.IsValid) { db.InformationIds.Add(informationid); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(informationid)); }
public static FrameVdS CreateSyncRequestResponse(InformationId informationId) { if (informationId != InformationId.SyncReq && informationId != InformationId.SyncRes) { throw new ArgumentException("informationId"); } // Window size var buff = new byte[] { 0x01 }; return(new FrameVdS(buff, 0, informationId)); }
public void SendRequest(InformationId informationId) { switch (informationId) { case InformationId.SyncReq: var syncReq = new FrameTcp( this.MySendCounter, this.OtherSendCounter, this.KeyNumber, informationId, FrameVdS.CreateSyncRequestResponse(InformationId.SyncReq)); Log.Info("{0} >> {1}", this.Type, syncReq); var syncReqbuff = syncReq.Serialize(); this.stream.Write(syncReqbuff, 0, syncReqbuff.Length); this.IncrementMySendCounter(); break; case InformationId.SyncRes: break; case InformationId.PollReqRes: var pollReq = new FrameTcp( this.MySendCounter, this.OtherSendCounter, this.KeyNumber, informationId, FrameVdS.CreateEmpty(InformationId.PollReqRes)); Log.Info("{0} >> {1}", this.Type, pollReq); var polReqBuff = pollReq.Serialize(); this.stream.Write(polReqBuff, 0, polReqBuff.Length); this.IncrementMySendCounter(); break; case InformationId.Payload: break; case InformationId.ErrorInformationIdUnknown: break; case InformationId.ErrorProtocolIdUnknown: break; default: throw new ArgumentOutOfRangeException("intInformationId"); } }
public FrameVdS(byte[] bytes, int start, InformationId informationId = InformationId.Payload) { this.InformationId = informationId; if (this.InformationId == InformationId.Payload) { var vdsLength = bytes[start]; this.buffer = new byte[vdsLength + 1 + 1]; Array.Copy(bytes, start, this.buffer, 0, this.buffer.Length); } else if (informationId == InformationId.SyncReq || informationId == InformationId.SyncRes) { this.buffer = new byte[1]; this.buffer[0] = bytes[start]; } else { this.buffer = new byte[0]; } }
public FrameVdS_04(byte[] bytes, int start, InformationId informationId = InformationId.Payload) : base(bytes, start, informationId) { }