/// <summary> /// Reads product information from a file. /// </summary> /// <param name="path">Path to product file.</param> /// <param name="mask">The device mask to set.</param> /// <param name="state">The device states for the masked devices.</param> /// <remarks> /// The file should be a text file with seperate lines containing the product Id and the version. /// The lines should be space seperated key value pairs as below. /// PRODUCT_ID 2 /// VERSION 4 /// </remarks> public static CANFrame PopulateProductFrameFromFile(string path, DeviceCatalogueInfo.EquipmentFlages mask, DeviceCatalogueInfo.EquipmentFlages state) { byte prodId; byte ver; ProductInfoFromFile(path, out prodId, out ver); CANFrame frame = CNXCANMsgHelper.PackProductId(prodId, ver, (uint)mask, (uint)state); CNXLog.WarnFormat("Product Frame {0}", frame.ToString()); return(frame); }
private CANFrame BuildQueryResponce() { byte[] data; CANFrame frame = new CANFrame(); try { frame.MailboxId = 0x500 + (uint)mBlockId; // decide what the offset value should be uint offset = mLastIndexWritten; ushort crc = 0; // no active or downloading block if (mLastIndexWritten == 0 && mCRC == 0) { offset = 0; } else if (BlockStatus == BlockState.COMPLETE) { offset = 0xffffffff; crc = mCRC; } data = new byte[7]; // populate the offset BitConverter.GetBytes(offset).CopyTo(data, 0); if (!BitConverter.IsLittleEndian) { Array.Reverse(data, 0, 4); } // populate the crc BitConverter.GetBytes(crc).CopyTo(data, 4); if (!BitConverter.IsLittleEndian) { Array.Reverse(data, 4, 2); } // populate the current version data[6] = mProdVersion; frame.Data = data; CNXLog.InfoFormat("BuildQueryResponce {0} {1}", BlockStatus, frame.ToString()); } catch (Exception e) { CNXLog.ErrorFormat("BuildQueryResponce {0} {1}", (Block)mBlockId, e.ToString()); } return(frame); }
/// <summary> /// Processes the CAN frame and writes any valid data to the block. /// </summary> /// <param name="frame"> /// Block frame. /// If the frame was a block query the responce is provided. /// Where no responce is required the frame mailbox will be set to 0. /// </param> /// <returns>The lowest complete data offset.</returns> public uint ProcessChunk(CANFrame frame) { if (mBlockId != (byte)(frame.MailboxId & 0xff)) { return(0); } try { // make sure we have a file if (mMemStream == null) { CreateMemoryStream(); } if (mMemStream == null) { return(0); } // save the current state BlockState state = BlockStatus; // process block type switch (frame.MailboxId & 0xf00) { // Chunk 1 case 0x600: lock (mBlockLock) { ProcessChunk1(frame.Data); } break; // Chunk N case 0x700: BlockState newState = state; lock (mBlockLock) { ProcessChunkN(frame.Data); newState = BlockStatus; } if (newState != state) { OnRaiseBlockStatusEvent(new BlockStatusEventArgs(mBlockId, newState)); } break; // Block Query case 0x400: SendBlockQueryResponce(); break; default: break; } //BlockState newState = BlockStatus; //if (newState != state) // OnRaiseBlockStatusEvent(new BlockStatusEventArgs(newState)); } catch (Exception e) { CNXLog.ErrorFormat("ProcessChunk frame {0} failed {1}.", frame.ToString(), e.ToString()); } return(mLastIndexWritten); }
public override string ToString() { return(mCatalogueFrame.ToString()); }