SHARE
TWEET

Untitled

a guest Oct 16th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4.  
  5. //#pragma pack(1)
  6.  
  7. typedef union sSetOnChangeFIFO
  8. {
  9. uint8_t raw_data[8];
  10.     struct __attribute__((packed)) {
  11.    uint32_t event;
  12.    uint8_t gpioValue;
  13. uint16_t gpioInstance;
  14. uint8_t gpioController;
  15.     };
  16. }sSetOnChangeFIFO;
  17.  
  18. sSetOnChangeFIFO setonchange;
  19.  
  20. void foo(uint8_t *pData)
  21. {
  22.     int i;
  23.     for (i=0;i<8;i++)
  24.     {
  25.         printf("%d, ", pData[i]);  
  26.     }
  27.     printf("\n");
  28. }
  29.  
  30. int main()
  31. {
  32.     //foo(&setonchange.raw_data[0]);
  33.     uint8_t eventWithDataBuffer[12];
  34.     uint32_t data, event = 67;
  35.     //setonchange.ptr_s = &setonchange.raw_data[1];
  36.    
  37.     setonchange.event = 67;
  38.     setonchange.gpioValue = 1;
  39.     setonchange.gpioInstance = 160;
  40.     setonchange.gpioController = 0;
  41.    
  42.     printf("size is: %lu\n", sizeof(setonchange));
  43.    
  44.    
  45.     data = ((0 & 0x000000FF) << 24) | ((160 & 0x0000FFFF) << 8) | (1 & 0x000000FF);
  46. memcpy(&eventWithDataBuffer[0], &event, 4);
  47.     memcpy(&eventWithDataBuffer[4], &data, 4);
  48.     //printf("%d", *(setonchange.raw_data));
  49.    
  50.     /*memcpy(&eventWithDataBuffer[0], &setonchange.event, 7);*/
  51.     foo(&setonchange.raw_data[0]);
  52.     foo(&eventWithDataBuffer[0]);
  53.     //printf("length is: %lu", sizeof(setonchange.fields));
  54.     //printf("instance is: %lu", setonchange.s.gpioInstance);
  55.  
  56.     return 0;
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top