0

I have a Raspberry-pi 3 which I am trying to interface with FLIR Lepton thermal camera. While I understand how this interface works, I have a question regarding the SPI read command. Below is the snippet of the code. Full source can be found at github

#define PACKET_SIZE 164
#define PACKET_SIZE_UINT16 (PACKET_SIZE/2)  //82
#define PACKETS_PER_FRAME 60
#define FRAME_SIZE_UINT16 (PACKET_SIZE_UINT16*PACKETS_PER_FRAME)  //4920

uint8_t result[PACKET_SIZE*PACKETS_PER_FRAME];  //9840

for(int j=0;j<PACKETS_PER_FRAME;j++) {
    read(spi_cs0_fd, result+sizeof(uint8_t)*PACKET_SIZE*j, sizeof(uint8_t)*PACKET_SIZE);
}

Since the second parameter of the unix read call is the buffer void *buf, I cannot figure out how the parameter result+sizeof(uint8_t)*PACKET_SIZE*j resolves into a pointer of a location in the array result.

Can someone help explain how this resolves into an array location in result?

Wesley
  • 2,921
  • 6
  • 27
  • 30

2 Answers2

2

result+sizeof(uint8_t)*PACKET_SIZE*j is same as &result[PACKET_SIZE*j], which address of memory location at the index PACKET_SIZE * j in result array.

Read this

P0W
  • 46,614
  • 9
  • 72
  • 119
1

imagine your array is allocated in memory as the following

packet 0:
  [0]
  ..
  [163]
packet 1:
  [164]
  ..
  [227]
packet 2:
  [228]
   ...

so, address of packet 1 is (size of the packet (164) * j(1)), where j is the packet number. sizeof unit8 will resolve in the number of bytes needed, '1' in most cases.

Serge
  • 11,616
  • 3
  • 18
  • 28