<?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>Assign an array to an ESB Payload ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108244/assign-an-array-to-an-esb-payload</link><description>Hi, 
 Currently tinkering with ESB comms, everything is fine but I was wondering whether there is a simple way to assign an array to a payload. For now, I have 2 int variables, say 301 and 257 and I assign each digits to the payload: tx_payload.data[0</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 13 Feb 2024 06:15:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108244/assign-an-array-to-an-esb-payload" /><item><title>RE: Assign an array to an ESB Payload ?</title><link>https://devzone.nordicsemi.com/thread/468509?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2024 06:15:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de029663-df91-43e1-a1a7-4e0a6fec8eb4</guid><dc:creator>Steve Jordi</dc:creator><description>&lt;p&gt;Hi Mike&lt;/p&gt;
&lt;p&gt;Thanks for this reminder and solution. It&amp;#39;s exactly what I need.&amp;nbsp;&lt;br /&gt;And guess what, I already used that in a C++ app back in... 1999. I was a bit rusted (no pun intended with Rust).&lt;/p&gt;
&lt;p&gt;I knew it was something like that but was struggling with the data[4] offset for the 2nd value. I worked around using a string but avoid unless conversions back and forth is always slimmer, faster and nicer.&lt;/p&gt;
&lt;p&gt;Perfect, you made my day.&lt;/p&gt;
&lt;p&gt;Steve&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assign an array to an ESB Payload ?</title><link>https://devzone.nordicsemi.com/thread/468499?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2024 02:26:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:870ecfbc-c57c-474b-bdc5-5ed5a4a4c9df</guid><dc:creator>Mike Thompson</dc:creator><description>&lt;p&gt;Hi Steve, the payload data&amp;nbsp;is itself an array of unsigned 8-bit values (uint8_t).&amp;nbsp; There are many ways to do what you describe, but one way would be to dereference the array elements as pointers to 32-bit values and assign them directly.&lt;br /&gt;&lt;br /&gt;It might look something as follows (putty the values into variables is optional).&lt;br /&gt;&lt;br /&gt;uint32_t num1 = 301;&lt;br /&gt;uint32_t num2 = 257;&lt;br /&gt;*((uint32_t *) &amp;amp;tx_payload.data[0]) = num1;&lt;br /&gt;&lt;span&gt;*((uint32_t *) &amp;amp;tx_payload.data[4]) = num2;&lt;br /&gt;&lt;/span&gt;tx_payload.length = sizeof(uint32_t) * 2;&lt;br /&gt;&lt;br /&gt;Then on the receiving side, do the opposite dereference the values from the received payload data.&lt;br /&gt;&lt;br /&gt;uint32_t num1, num2;&lt;br /&gt;&lt;span&gt;num1 = *((uint32_t *) &amp;amp;rx_payload.data[0]);&lt;/span&gt;&lt;br /&gt;&lt;span&gt;num2 = *((uint32_t *) &amp;amp;rx_payload.data[4]);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;You will probably want to familiarize yourself with how C handles pointers into arrays and type conversion.&amp;nbsp; It&amp;#39;s quite a bit different than other languages that you may be more familiar with.&lt;br /&gt;&lt;br /&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>