This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sensor status message. Property length (NCS 1.6)

Good day!

I have a question about length in MPID. In current implementation size measures in uint16 size and this brings lot's of troubles when you try to decode values: 8 bit and 16 bit have same size, 24 bit and 32 bit does also.

Is it a bug and size should be calculated in bytes or I missed something in Mesh model specification?

Parents
  • Hey again Ivan! Sorry about the delay.

    The length field should give a number of bytes, or octets. Where in our code are you seeing this? 

    Best regards,

    Elfving

  • I think I've found where it comes from. Check out this line:

    https://github.com/nrfconnect/sdk-nrf/blob/7f9018b11836b3c4d2049fce626a8ffa9770ad4c/subsys/bluetooth/mesh/sensor.c#L84

    int sensor_status_id_encode(struct net_buf_simple *buf, uint8_t len, uint16_t id)
    {
    	if ((len > 0 && len <= 16) && id < 2048) {
    		if (net_buf_simple_tailroom(buf) < 2 + len) {
    			return -ENOMEM;
    		}
    
    		net_buf_simple_add_le16(buf, ((len - 1) << 1) | (id << 5));
    	} else {
    		if (net_buf_simple_tailroom(buf) < 3 + len) {
    			return -ENOMEM;
    		}
    
    		net_buf_simple_add_u8(buf, BIT(0) | (((len - 1) & BIT_MASK(7))
    						     << 1));
    		net_buf_simple_add_le16(buf, id);
    	}
    
    	return 0;
    }
    

    To header goes (len - 1)

  • Hey Ivan,

    It seems to me that our implementation here is correct. However there seems to be somewhat of an off-by-one mistake in MshMDLv1.0.1, section 4.2.14. It should say that "Property values longer than 127 octets are not supported by the Sensor Status message." It will be fixed in newer versions.

    When length <=16 and Property ID < 2048: The Length field is a 1-based uint4 value (valid range 0x0–0xF, representing range of 1–16).
    When length <=127 and Property ID < 65535: The Length field is a 1-based uint7 value (valid range 0x0–0x7F, representing range of 1–127). The value 0x7F represents a length of zero.

    Best regards,

    Elfving

  • Thanks a lot for clarification. My mistake, missed part with valid range.

Reply Children
No Data
Related