This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

How the nus mode is automatically subcontracted and sent efficiently?

Hi, there

  1. NRF51822
  2. SDK9.0.0 and S110

How to subcontract in uart nus mode to ensure that each packet does not exceed 20 bytes and is sent as quickly as possible? The official demo must pass the special character to distinguish the last packet. If i do not use special characters to determine the last package, are there other good ways to do this thing ?

  • What do you mean by "subcontract" and "nus mode"? If you want to say that you are using Nordic BLE UART Service (NUS) example and want to be sure that you always pass 20 bytes to it well then simply implement some logic on top of NUS data transfer function to be sure that longer data get fragmented properly. Of course there are plenty ways of making fragmentation, you can get inspiration from any networking protocol. All depends on your priorities: do you need to have the protocol easy to parse (= small code size) or you don't care if it's few bytes bigger FW image but you want to have as minimal overhead? And for what sizes you want to optimize your protocol (= will you be sending mostly small packets <20B or mostly some medium 20-200B or mostly long 200B+)?

    1. Yes, i'm using Nordic BLE UART Service (NUS) ,
    2. Be sending data mostly long 200B+, the maximum packet can be up to 10KB+ sometime. But the master transmitter can set the length of the data to be sent.
    3. The main function is NUS, so the overhead is not high priority, the premise is to ensure fast enough and stable transmission.
    4. Maybe I still need a simple transfer protocol?
    5. If the length of the data to be sent is 128 bytes, then ble should be split into six 20-byte packets and an 8-byte packet, how to do it without any additional protocol ?
  • Well NUS is unstructured serial line without flow control. So the question is: how would you handle the same transfer if that would be wire and not BLE? Minimum is to implement some FIFO mechanism which keeps track about offset in data buffer from where data already went over BLE link. Link Layer in the stack has typically several buffers (6+) so you can stack your 20-byte packets there and once lower layer says that no more Tx buffers are available then you need to wait for Tx completed event and continue in your state machine. This will be pretty easy to implement (many Q&S on this forum and similar things are shown in nRF5 SDK examples) but it will work only if higher layer will be able to interpret such stream of data. If not then you can either add some header to each packet (e.g. one byte which codes if that is start of the packet, middle or the end) or... (1/2)

  • (2/2)

    ... header to each bunch of data which you want to link together (e.g. length of subsequent data which will mean that receiving side should be waiting and buffering data packets as long as it is shorter then this value). And of course many other options, so many protocols solve it in so many ways... (e.g. ASN.1 BER-TLV system is designed exactly for such purposes;)

  • Thanks. Now it's working.

Related