Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- //#pragma pack(1)
- typedef union sSetOnChangeFIFO
- {
- uint8_t raw_data[8];
- struct __attribute__((packed)) {
- uint32_t event;
- uint8_t gpioValue;
- uint16_t gpioInstance;
- uint8_t gpioController;
- };
- }sSetOnChangeFIFO;
- sSetOnChangeFIFO setonchange;
- void foo(uint8_t *pData)
- {
- int i;
- for (i=0;i<8;i++)
- {
- printf("%d, ", pData[i]);
- }
- printf("\n");
- }
- int main()
- {
- //foo(&setonchange.raw_data[0]);
- uint8_t eventWithDataBuffer[12];
- uint32_t data, event = 67;
- //setonchange.ptr_s = &setonchange.raw_data[1];
- setonchange.event = 67;
- setonchange.gpioValue = 1;
- setonchange.gpioInstance = 160;
- setonchange.gpioController = 0;
- printf("size is: %lu\n", sizeof(setonchange));
- data = ((0 & 0x000000FF) << 24) | ((160 & 0x0000FFFF) << 8) | (1 & 0x000000FF);
- memcpy(&eventWithDataBuffer[0], &event, 4);
- memcpy(&eventWithDataBuffer[4], &data, 4);
- //printf("%d", *(setonchange.raw_data));
- /*memcpy(&eventWithDataBuffer[0], &setonchange.event, 7);*/
- foo(&setonchange.raw_data[0]);
- foo(&eventWithDataBuffer[0]);
- //printf("length is: %lu", sizeof(setonchange.fields));
- //printf("instance is: %lu", setonchange.s.gpioInstance);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement