/// <summary> /// Each Binary message contains the following sections: /// • Header /// • Details /// • Footer /// The format of each section is identical for both data requests and responses; /// the contents of the sections vary according to the command number and the data that is contained by the message. /// </summary> /// <param name="unitId">Destination CANbus network ID and RS485</param> /// <param name="commandNumber">BinaryCommand Number</param> /// <param name="commandDetails">Specific for each Command Number</param> /// <param name="dataRequests">DataRequests</param> public BinaryMessage(byte unitId, BinaryCommand commandNumber, byte[] commandDetails, List <ReadWriteRequest> dataRequests, List <List <byte> > dataRequestsBytes) { List <ReadWriteRequest> query = null; //if (commandNumber == BinaryCommand.ReadWrite) // query = dataRequests.OrderBy(dr => GetOperandSize(dr)).ToList(); m_details = new Details(query == null ? dataRequests : query, dataRequestsBytes); m_header = new Header(unitId, commandNumber, commandDetails, (UInt16)m_details.DetailsBytes.Length); m_footer = new Footer(m_details.CheckSum); m_BinaryMessageBytes = new List <byte>(); m_BinaryMessageBytes.AddRange(m_header.HeaderBytes); m_BinaryMessageBytes.AddRange(m_details.DetailsBytes); m_BinaryMessageBytes.AddRange(m_footer.FooterBytes); }
public Header(byte destination, BinaryCommand commandNumber, byte[] cmdDetails, UInt16 dataLength, byte subCommand) : this() { m_destination = destination; m_commandNumber = (byte)commandNumber; m_cmdDetails = cmdDetails; m_dataLength = dataLength; m_headerBytes[0] = BitConverter.GetBytes('/')[0]; m_headerBytes[1] = BitConverter.GetBytes('_')[0]; m_headerBytes[2] = BitConverter.GetBytes('O')[0]; m_headerBytes[3] = BitConverter.GetBytes('P')[0]; m_headerBytes[4] = BitConverter.GetBytes('L')[0]; m_headerBytes[5] = BitConverter.GetBytes('C')[0]; m_headerBytes[6] = destination; m_headerBytes[7] = 254; //Should always be 254 (FE hex) m_headerBytes[8] = 1; //Should always be 1 m_headerBytes[9] = 0; //Should always be 0 m_headerBytes[10] = 0; m_headerBytes[11] = 0; m_headerBytes[12] = (byte)commandNumber; m_headerBytes[13] = subCommand; if (cmdDetails != null && cmdDetails.Length == 6) { /* * The address of the first element (to read from or to write into) must be arranged as * a 4 byte value and set into bytes 14,15,16,17 of the message header (byte 14 is the least significant byte). */ m_headerBytes[14] = cmdDetails[0]; m_headerBytes[15] = cmdDetails[1]; m_headerBytes[16] = cmdDetails[2]; m_headerBytes[17] = cmdDetails[3]; m_headerBytes[18] = cmdDetails[4]; m_headerBytes[19] = cmdDetails[5]; } m_headerBytes[20] = BitConverter.GetBytes(dataLength)[0]; m_headerBytes[21] = BitConverter.GetBytes(dataLength)[1]; byte[] checkSum = GetCheckSum(); m_headerBytes[22] = checkSum[0]; m_headerBytes[23] = checkSum[1]; }
public override void BuildBinaryCommand(byte unitId, BinaryCommand commandNumber, byte[] cmdDetails, List <ReadWriteRequest> dataRequests, List <List <byte> > dataRequestsBytes, byte subCommand) { m_messageToPLC = new BinaryMessage(unitId, commandNumber, cmdDetails, dataRequests, dataRequestsBytes, subCommand); }
private void SimpleOperations() { if (Tokens.Count < 3) { return; } bool isSuccess = false; Token t1 = Tokens.Pop(); Token t2 = Tokens.Pop(); Token t3 = Tokens.Pop(); //simple operation of two registers if (t1.Type == TokenType.Register && t2.Type == TokenType.Operator && t3.Type == TokenType.Register) { if (Tokens.Peek().Type != TokenType.Semicolon) { Error("No semicolon in operation", t3); } else { Tokens.Pop(); BinaryCommand cmd = null; byte r1 = Convert.ToByte(t1.Value); byte r2 = Convert.ToByte(t3.Value); switch (t2.Value) { case ":=": cmd = new CopyRegisterToRegisterCommand(r1, r2, Format.Int32); break; case "-=": cmd = new SubCommand(r1, r2, Format.Int32); break; case "+=": cmd = new AddCommand(r1, r2, Format.Int32); break; case "?=": cmd = new ArithmeticCompareCommand(r1, r2, Format.Int32); break; case "|=": cmd = new LogicOrCommand(r1, r2, Format.Int32); break; case "&=": cmd = new LogicAndCommand(r1, r2, Format.Int32); break; case "^=": cmd = new LogicXorCommand(r1, r2, Format.Int32); break; case "<<=": cmd = new ArithmeticLeftShiftCommand(r1, r2, Format.Int32); break; case ">>=": cmd = new ArithmeticRightShiftCommand(r1, r2, Format.Int32); break; case ">=": cmd = new LogicRightShiftCommand(r1, r2, Format.Int32); break; case "<=": cmd = new LogicLeftShiftCommand(r1, r2, Format.Int32); break; } if (cmd != null) { Program.Add(cmd); isSuccess = true; } } } if (isSuccess) { return; } Tokens.Push(t3); Tokens.Push(t2); Tokens.Push(t1); }
/// <summary> /// Change the commands that will used by this firmware uploader /// </summary> /// <param name="writeCommand"></param> /// <param name="bootloaderCommand"></param> public void ChangeCommands(BinaryCommand writeCommand, BinaryCommand bootloaderCommand) { _writeCommand = writeCommand; _bootloaderCommand = bootloaderCommand; }
public abstract void BuildBinaryCommand(byte unitId, BinaryCommand commandNumber, byte[] cmdDetails, List <ReadWriteRequest> dataRequests, List <List <byte> > dataRequestsBytes, byte subCommand);
public override void BuildBinaryCommand(byte unitId, BinaryCommand commandNumber, byte[] cmdDetails, List <ReadWriteRequest> dataRequests, List <List <byte> > dataRequestsBytes, byte subCommand) { throw new NotImplementedException(); }