/// <summary> /// Creates a DeviceCatalogueInfo object from the frame data. /// </summary> /// <returns>A DeviceCatalogueInfo representation of the frame.</returns> /// <remarks>If the frame isnt a CNXMsgIds.ProductId type frame null is returned.</remarks> public DeviceCatalogueInfo ToDeviceCatalogueInfo() { if ((CNXMsgIds)MailboxId != CNXMsgIds.ProductId || mData.Length < 2) { return(null); } DeviceCatalogueInfo dci = new DeviceCatalogueInfo() { ProductId = (DeviceCatalogueInfo.Product)mData[0], BuildNo = mData[1] }; if (mData.Length > 3) { dci.Mask = (DeviceCatalogueInfo.EquipmentFlages)mData[2]; dci.Status = (DeviceCatalogueInfo.EquipmentFlages)mData[3]; } if (mData.Length > 5) { dci.Mask |= (DeviceCatalogueInfo.EquipmentFlages)((uint)mData[4] << 8); dci.Status |= (DeviceCatalogueInfo.EquipmentFlages)((uint)mData[5] << 8); } if (mData.Length > 7) { dci.Mask |= (DeviceCatalogueInfo.EquipmentFlages)((uint)mData[6] << 16); dci.Status |= (DeviceCatalogueInfo.EquipmentFlages)((uint)mData[7] << 16); } return(dci); }
/// <summary> /// Updates the device catalogue to include the new item or update the details of an existing item. /// </summary> /// <param name="info">Device details to be used to update the catalogue.</param> /// <returns>The type of change that occured</returns> public CatalogueChangeType UpdateDeviceCatalogue(DeviceCatalogueInfo info) { CatalogueChangeType catalogueUpdated = CatalogueChangeType.NONE; try { if (info.ProductId > 0 && info.BuildNo > 0) { DeviceCatalogueInfo existing = FindDevice(info.ProductId); if (existing == null) { mDeviceCatalogue.Add(info); catalogueUpdated = CatalogueChangeType.EQUIPMENT; } else { // update entry catalogueUpdated = existing.Update(info); } // update the equipment mask and status if (catalogueUpdated != CatalogueChangeType.NONE) { RefreshEquipmentFlags(); } } } catch (Exception e) { CNXLog.Error("UpdateDeviceCatalogue", e); } return(catalogueUpdated); }
/// <summary> /// Initialises the frame from DeviceCatalogueInfo /// </summary> /// <param name="dci">The cateloge information to initialise the frame from.</param> public void FromDeviceCatalogueInfo(DeviceCatalogueInfo dci) { MailboxId = (uint)CNXMsgIds.ProductId; // allocate the data payload if ((uint)dci.Mask > 0x0000ffff) { mData = new byte[8]; } else if ((uint)dci.Mask > 0x000000ff) { mData = new byte[6]; } else if ((uint)dci.Mask > 0) { mData = new byte[4]; } else { mData = new byte[2]; } mData[0] = (byte)dci.ProductId; mData[1] = dci.BuildNo; if (mData.Length > 3) { mData[2] = (byte)dci.Mask; mData[3] = (byte)dci.Status; } if (mData.Length > 5) { mData[4] = (byte)(((uint)dci.Mask >> 8) & 0xff); mData[5] = (byte)(((uint)dci.Status >> 8) & 0xff); } if (mData.Length > 7) { mData[6] = (byte)(((uint)dci.Mask >> 16) & 0xff); mData[7] = (byte)(((uint)dci.Status >> 16) & 0xff); } }
public override string ToString() { string message = null; StringBuilder strData = new StringBuilder(); try { if ((mMailboxId & 0xffffff00) == (uint)CNXMsgIds.BlockQueryResponse) { Block block; uint offset; ushort crc; byte version; if (CNXCANMsgHelper.UnpackBlockQueryResponce(this, out block, out offset, out crc, out version)) { object[] arg = new object[] { block, offset, crc, version }; message = String.Format("Block {0}, offset 0x{1:x} ({1}), CRC 0x{2:x}, version {3}.", arg); return(message); } } switch ((CNXMsgIds)mMailboxId) { case CNXMsgIds.PassengerCountEvent: foreach (PassengerCountEventMask mask in Enum.GetValues(typeof(PassengerCountEventMask))) { if ((mData[1] & (byte)mask) != 0) { if ((byte)mask > (byte)PassengerCountEventMask.Forth) { strData.AppendFormat("{0} {1} ", mask, ((mData[0] & (byte)mask) == 0) ? "retracted," : "extended,"); } else { strData.AppendFormat("{0} door {1} ", mask, ((mData[0] & (byte)mask) == 0) ? "open," : "closed,"); } } //if (mask == PassengerCountEventMask.Bike) // break; } message = strData.ToString(); break; case CNXMsgIds.PassengerLoad: message = String.Format("{0} door {1} boarding, {2} alighting.", (DoorCountType)mData[0], mData[1], mData[2]); break; case CNXMsgIds.PassengerBoardings: strData.Append("Pasenger Loading: "); for (int i = 0; i < DataLength; i += 2) { strData.AppendFormat("Door {0} on {1}, off {2}. ", (i / 2), mData[i], mData[i + 1]); } message = strData.ToString(); break; case CNXMsgIds.DateTime: message = String.Format("{0} {1}", (CNXMsgIds)mMailboxId, CNXCANMsgHelper.UnpackDateTimeFrame(this).ToString()); break; case CNXMsgIds.GPS: message = String.Format("GPS {0}", CNXCANMsgHelper.UnpackGPSState(this).ToString()); break; case CNXMsgIds.DuressState: message = String.Format("Duress state {0}.", (DuressStateType)mData[0]); break; case CNXMsgIds.TripOnRoute: short pathId; int position; int? tripNo; ushort? serviceStart; RunningStateType runningState; CNXCANMsgHelper.UnpackTripOnRoute(this, out pathId, out position, out tripNo, out serviceStart, out runningState); object[] TripArgs = { pathId, position, tripNo, serviceStart, runningState }; message = String.Format("TripOnRoute pathId:{0} Poistion:{1} TripNo:{2} Service:{3} Running:{4}", TripArgs); break; case CNXMsgIds.ProductId: DeviceCatalogueInfo dci = ToDeviceCatalogueInfo(); message = dci.ToString(); break; case CNXMsgIds.BlockChunk1: case CNXMsgIds.BlockChunkN: case CNXMsgIds.BlockQuery: case CNXMsgIds.BlockQueryResponse: case CNXMsgIds.Destination: case CNXMsgIds.DeviceCatalogue: case CNXMsgIds.DigitalInputState: case CNXMsgIds.Fareset: case CNXMsgIds.ManufacturingTest: case CNXMsgIds.RouteTrip: case CNXMsgIds.TripProgress: case CNXMsgIds.TripOffRoute: case CNXMsgIds.TripNone: message = string.Format("{0} {1}", (CNXMsgIds)mMailboxId, DefaultToString()); break; default: message = DefaultToString(); break; } } catch (Exception e) { Console.WriteLine(e.ToString()); } return(message); }