pub struct BlockData {
pub block_type: u16,
pub block_number: u16,
pub format: u16,
pub total_length: u32,
pub flags: u16,
pub crc1: u16,
pub crc2: u16,
pub payload: Vec<u8>,
}Expand description
A raw PLC block in the Siemens Diagra upload/download format.
The wire format starts with a 20-byte header:
[blk_type:2][blk_number:2][format:2][length:4][flags:2][crc1:2][crc2:2][??:4]followed by the MC7 code / data payload, and optionally trailer strings.
Fields§
§block_type: u16Block type identifier (see BlockType discriminants).
block_number: u16Block number.
format: u16Block format/encoding version.
total_length: u32Total block length (including header).
flags: u16Block flags.
crc1: u16First CRC value.
crc2: u16Second CRC value.
payload: Vec<u8>Raw MC7 code / data payload (everything after the 20-byte header).
Implementations§
Source§impl BlockData
impl BlockData
Sourcepub fn from_bytes(data: &[u8]) -> Option<Self>
pub fn from_bytes(data: &[u8]) -> Option<Self>
Parse raw uploaded bytes into a BlockData.
Sourcepub fn new_db(db_number: u16, size_bytes: u16) -> Self
pub fn new_db(db_number: u16, size_bytes: u16) -> Self
Build a minimal empty DB block ready for download.
Creates a Diagra-format block with the S7 DB header structure.
size_bytes is the desired DB size in bytes (must be even).
Sourcepub fn crc32(&self) -> u32
pub fn crc32(&self) -> u32
Compute a CRC-32 checksum of the serialized block bytes.
Suitable for comparing a locally stored block against one uploaded
from the PLC: local.crc32() == plc_block.crc32().
Sourcepub fn set_attributes(&mut self, attrs: &BlockAttributes)
pub fn set_attributes(&mut self, attrs: &BlockAttributes)
Apply BlockAttributes to this block in-place.
The S7 block footer is at payload[payload.len()-48..] (when payload
is large enough). Author/Family/Name each occupy 8 bytes at fixed
offsets within the footer.