IRUSER Shared Memory

IRUSER Shared Memory

This is the shared-memory for “ir:USER”, which is provided by the application via InitializeIrnop or InitializeIrnopShared. The size of the shared memory is determined by parameters of the Init functions above.

Overall Structure #

The shared memory consists of 2 or 5 components, depending on which Init function is called. For InitializeIrnopShared, ir service puts more information to the shared memory and applications can read it directly; for InitializeIrnop, ir service puts less information and store the rest in its local storage. All these components are adjacent to each other, without any padding, which means the data can be unaligned if the size specified in Init is unaligned.

SizeDescription
0x10StatusInfo. Only presents when InitializeIrnopShared is called
0x10ReceiveBufferInfo. Only presents when InitializeIrnopShared is called
(specified by Init paramter)ReceiveBuffer
0x10SendBufferInfo. Only presents when InitializeIrnopShared is called
(specified by Init paramter)SendBuffer

StatusInfo #

Relative offsetSizeDescription
0x00x4Latest receive error result. Read by IRUSER:GetLatestReceiveErrorResult
0x40x4Latest Send error result. Read by IRUSER:GetLatestSendErrorResult
0x80x1Connection status. Read by IRUSER:GetConnectionStatus
0x90x1Trying to connect status. Read by IRUSER:GetTryingToConnectStatus
0xA0x1Connection role. Read by IRUSER:GetConnectionRole
0xB0x1Machine ID. Set by IRUSER:SetOwnMachineId
0xC0x1Unknown. Value 1 is observed after connection
0xD0x1Network ID? Seems like a randomly distributed number after connection
0xE0x1Unknown. Value 1 is observed after initialization
0xF0x1Unknown

ReceiveBufferInfo/SendBufferInfo #

The BufferInfo sections store data validity information for the two buffers

Relative offsetSizeDescription
0x00x4Start index of valid packets
0x40x4End index of valid packets
0x80x4Number of valid packets
0xC0x4Unknown/Unused?

ReceiveBuffer/SendBuffer #

Relative offsetSizeDescription
0x00x8 * packet_count (specified in Init parameter)PacketInfo{u32 offset_to_data_buffer, u32 data_length}
0x8 * packet_countbuffer_size - 0x8 * packet_countData buffer

The buffers are two circular buffers. A new packet is added to the end of previous packet in the data buffer, with packet info added to PacketInfo[end_index++]. Note that if an added packet exceeds the end of the buffer, the exceeding data will be wrapped around to the beginning of the data buffer.

Packet structure #

A packet in the data buffer consists of a header, payload and a crc8 checksum

Relative offsetSizeDescription
0x00x1Fixed value 0xA5?
0x10x1Destination network ID?
0x20x1The highest bit is unknown. When second highest bit is clear, the rest bit[0:5] of this byte is the payload length; otherwise bit[0:5] is the higher byte of the payload length
0x30x1When bit[6] of previous byte is set, this byte is the lower byte of the payload length; other wise this byte doesn’t present
0x3 or 0x4payload lengthpayload
0x3 or 0x4 +payload_length0x1CRC-8-CCITT over data above (header + payload)