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?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.