<?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>Offset while sending data</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/7012/offset-while-sending-data</link><description>I have a project which will send the temperature from the nRF51DK to host. 
 The value of the temperature is an integer. As example Value:0x00000A2B -&amp;gt; 2603 -&amp;gt;26.03&amp;#176;C 
 But on the Host side I will recieve only Value:2B 
 The same if I change the length</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 May 2015 13:17:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/7012/offset-while-sending-data" /><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24735?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 13:17:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4ca8ddf-5020-460d-93ed-d5aea95f934d</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;oh and of course if this is working now but your reading is really only actually two bytes, you can change everything back to uin16_t and length to 2, we only changed it to 4 so it was easier to test.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24734?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 13:16:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85f6f700-9b72-48fe-9f60-c0c6ce57ab21</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;it just casts the pointer to uint32_t to a pointer to uint8_t, not the value, the pointer.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s misleading that function takes a uint8_t* because it makes people think that it wants only uint8_t, a single byte or single character. In some ways it would be better if it were a void* to indicate that it&amp;#39;s just &amp;#39;the first byte in a sequence of bytes&amp;#39;. Anyway what that function really takes is a buffer of bytes, the pointer to the first byte is p_value, len is the number of bytes. Doesn&amp;#39;t have to be an actual array, doesn&amp;#39;t have to be anything related to uint8_t, just needs to be a block of bytes starting at p_value and of length bytes.&lt;/p&gt;
&lt;p&gt;In this case your value is a uint32_t, which is 4 bytes one after another. &amp;amp;(temp_value) is a pointer to the first byte, which is what you want, it&amp;#39;s the right pointer, just the wrong &lt;em&gt;type&lt;/em&gt; of pointer. (uint8_t*) just says &amp;#39;treat it like a byte pointer&amp;quot;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24733?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 12:56:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e46516f-dd4a-455c-814d-ffbaf07aa0aa</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;Now it works! What will (uint8_t*) exactly do?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24736?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 12:06:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5559430-1b91-43d0-8eba-3e4db75c8fed</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;just cast it&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(uint8_t*)&amp;amp;temp_value
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24732?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 12:02:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1444ff1f-20af-486a-8fc3-0c05507fc657</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;And p_value is defined in ble_gatts.h file. This file cannot be edited...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24731?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 12:00:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02afccf2-03a5-4782-ace3-fb46e625a553</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;If I define temp_value as uint32_t will get an error:&lt;/p&gt;
&lt;p&gt;gatts_value.p_value	= &amp;amp;temp_value;&lt;/p&gt;
&lt;p&gt;Because p_value is an uint8_t and temp_value is an uint32_t&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24730?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 11:49:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28a8c013-f3e7-4fdc-ae31-567f736fe59c</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Yes - in that function header. I&amp;#39;m assuming it&amp;#39;s already a uint32_t when you send it over to the function, declaring it as uint8_t there truncates it into just the last byte. But check the place you call the function too.&lt;/p&gt;
&lt;p&gt;You&amp;#39;ll see it come in in the master control panel &amp;#39;backwards&amp;#39;, ie lowest byte first. That&amp;#39;s ok depending on what you are going to use to read it the other end, you either just read the bytes as they are or you flip them around. Worry about that when you get them all sent over properly.&lt;/p&gt;
&lt;p&gt;Pretty sure at this point you have this probem&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t fridge_temperature = ...; 
ble_fridge_send_temp( fridge, fridge_temperature );
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but fridge_temperature starts as 0x00002710, then gets truncated to 0x10, the final byte. But all those variables are still 32 bits long internally, so you get zeros.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24729?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 11:39:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:029f3f0b-f49b-4641-8841-f235ee8b4923</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;@RK Your solution would be to define temp_value as uint32_t?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24728?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 10:10:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aeafbfee-6187-4492-b35e-4d84bd35f00a</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;No you don&amp;#39;t need to do that. An int32_t is 4 consecutive bytes in memory, just like a uint8_t array. He just needs to get it all the way to the function without truncation which specifying the parameter as uint8_t does.&lt;/p&gt;
&lt;p&gt;At the other end it needs to be turned back into an uint32_t but that&amp;#39;s easy, if the endienness of the host is the same you can just read it right out of the buffer, else you flip the bytes around.&lt;/p&gt;
&lt;p&gt;Or, if you remember your old Unix networking code you call&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;htonl( value to send )
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;on the value before you send it, as a uint32_t and then&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ntohl( value received )
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;on the value (as a uint32_t) after you receive it. That works on any and every platform because it&amp;#39;s guaranteed to turn the value into network order on the way out and back to host order on the way back.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24727?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 09:59:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e6864ce3-3ca3-41c6-8cc1-2cd7a4bb1404</guid><dc:creator>muhkuhns</dc:creator><description>&lt;p&gt;Googling int32 to 4 uint8 may help you if I get your problem right. Check this Link:
&lt;a href="http://stackoverflow.com/questions/6499183/converting-a-uint32-value-into-a-uint8-array4"&gt;stackoverflow.com/.../converting-a-uint32-value-into-a-uint8-array4&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Your measured value is int32? You then need to split this into an uint8 array before you send it. And the other way around when you want the original value back. Sadly I am not at home and don&amp;#39;t have access to my application where is implemented this&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Offset while sending data</title><link>https://devzone.nordicsemi.com/thread/24726?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 09:46:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1cf95dfc-766c-47c0-abe1-e59d7bc90a6a</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Your problem here is that temp_value is a uint8_t, so it gets truncated to a single byte on the way into the function (probably the utxb ARM instruction), hence you&amp;#39;re just going to get the lowest byte and lose the rest.&lt;/p&gt;
&lt;p&gt;Sorry I missed this in your last post.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>