Created
December 3, 2014 02:49
-
-
Save ksksue/6e8ec7dfb0d09b992bda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 構造体の例 | |
typedef union _PacketT{ | |
uint8_t byte[10]; | |
struct { | |
uint8_t stx; | |
uint8_t id; | |
uint16_t address; | |
uint32_t data; | |
uint8_t checksum; | |
uint8_t etx; | |
}; | |
}PacketT; | |
//NSDataに変換する | |
-(NSData *)packetToNSData:(PacketT *) packet | |
{ | |
return [NSData dataWithBytes:packet length: sizeof(packet)]; | |
} | |
//NSDataから得る | |
-(PacketT)nsDataToEcoMeganeData:(NSData *)data | |
{ | |
PacketT packet; | |
[data getBytes:&packet length:sizeof(PacketT)]; | |
return packet; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment