- (void)setSensorTextField:(UInt8)port value:(NSString*)value
{
…
[self sendToScratchWithPort:port value:value];
}
- (void)sendToScratchWithPort:(UInt8)port
value:(NSString *)value
{
NSString *message= [NSString stringWithFormat:@"sensor-update NXT_Sensor_%u \"%@\"", port, value];
//NSLog(@"NXT: %@", message);
NSData *data= [message dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *writeData= [NSMutableData data];
char *c= malloc(4);
unsigned n= [data length];
c[0]= (char)((n>>24) & 0xFF);
c[1]= (char)((n>>16) & 0xFF);
c[2]= (char)((n>>8) & 0xFF);
c[3]= (char)(n & 0xFF);
[writeData appendBytes:c length:4];
[writeData appendData:data];
[socket writeData:writeData withTimeout:-1 tag:0];
free(c);
}
0 件のコメント:
コメントを投稿