<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to synchronize processing of received BLE data to prevent overwrites</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55127/how-to-synchronize-processing-of-received-ble-data-to-prevent-overwrites</link><description>I have a custom BLE characteristic that I want to use to allow an app to send commands to my device. I use an on-write() function that is called whenever a BLE_GATTS_EVT_WRITE event happens to detect the write to the command characteristic and process</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 04 Dec 2019 10:34:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55127/how-to-synchronize-processing-of-received-ble-data-to-prevent-overwrites" /><item><title>RE: How to synchronize processing of received BLE data to prevent overwrites</title><link>https://devzone.nordicsemi.com/thread/223546?ContentTypeID=1</link><pubDate>Wed, 04 Dec 2019 10:34:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a1875d7-969d-4b94-b792-28d7ee94df37</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Dave&lt;/p&gt;
&lt;p&gt;What exactly in your process is it that&amp;#39;s going slowly now? In order to make sure your writing procedure doesn&amp;#39;t get overwritten you&amp;#39;ll have to give some sort of signal in order to let the next command being written.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to synchronize processing of received BLE data to prevent overwrites</title><link>https://devzone.nordicsemi.com/thread/223439?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2019 21:54:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1d6755a-10cd-4176-b3f3-c9298e4749d0</guid><dc:creator>SleepingDog</dc:creator><description>&lt;p&gt;I&amp;#39;ve changed the implementation so that once I&amp;#39;ve parsed and processed the JSON command I write a zero into the first byte of commandJSON. On the app side I read the command characteristic after I&amp;#39;ve written the JSON command to it to look for the zero byte and when I see it I know that the previous command has been processed and I can go ahead and send the next command. This works in that it synchronizes the writing of commands and the processing of them however it is extremely slow.&lt;/p&gt;
&lt;p&gt;I figure there must be a better way.&lt;/p&gt;
&lt;p&gt;I thought about moving data into a circular buffer&amp;nbsp;from the commandJSON buffer so that it is removed quickly but I still would not be guaranteed that it doesn&amp;#39;t get overwritten before I complete the transfer to the circular buffer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to synchronize processing of received BLE data to prevent overwrites</title><link>https://devzone.nordicsemi.com/thread/223417?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2019 17:08:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2aac5238-807d-49ce-bd1d-4f02b9b6d020</guid><dc:creator>SleepingDog</dc:creator><description>&lt;p&gt;Thanks for the reply.&lt;/p&gt;
&lt;p&gt;Are you suggesting I use a second characteristic to allow the App to be notified when it is okay to send another command?&lt;/p&gt;
&lt;p&gt;Dave&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to synchronize processing of received BLE data to prevent overwrites</title><link>https://devzone.nordicsemi.com/thread/223338?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2019 13:17:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:659e9293-e331-41ec-bca6-dd81c9f0cf87</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;It shouldn&amp;#39;t be possible for a command to override &amp;quot;itself&amp;quot; like this. What I think is happening, is that when you are processing the JSONcommand, your application thinks that the on_write function is finished, and sends the next one. You should add a check of some kind that makes sure that you&amp;#39;re finished parsing the first command before calling the on_write(); function again. So add a WAIT_FOR_FINISHED check that confirms that whatever the last function that finishes up processing your command is complete.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>