Question

I'm new to the entire IOKit stuff, so there might be some trivial solutions for my problems. I'm playing around with a Smartpen that does OBEX over USB. So far I got a subclass of OBEXSession to Successfully connect to the Device.

OBEXAddTargetHeader("LivescribeService", 
                    strlen("LivescribeService"), 
                    header);
CFMutableDataRef headerData = OBEXHeadersToBytes(header);
OBEXError error = [session OBEXConnect:kOBEXConnectFlagNone
                       maxPacketLength:maxPacketLength
                       optionalHeaders:(void *)CFDataGetBytePtr(headerData)
                 optionalHeadersLength:CFDataGetLength(headerData)
                         eventSelector:@selector(openedConnection) 
                        selectorTarget:target
                                refCon:NULL];

After that error is 0 and the openedConnection message is sent to the target. The data that gets written and read to/from my USB pipe looks ok. Now I'd like to send a GET, but that somehow fails.

UInt32 connectionIDInt = 0x1;
const char *connectionID[4] = {0x0,0x0,0x0,0x0};
memcpy(connectionID, &connectionIDInt, 4);

OBEXAddConnectionIDHeader(connectionID, 4, header);
OBEXAddNameHeader(CFSTR("ppdata?key=pp0000"), header);
headerData = OBEXHeadersToBytes(header);
error = [session OBEXGet:YES
                 headers:(void *)CFDataGetBytePtr(headerData)
           headersLength:CFDataGetLength(headerData)
           eventSelector:@selector(OBEXGetHandler:) 
          selectorTarget:target
                  refCon:nil];

But that always results in a kOBEXBadArgumentError and I have absolutely no idea what I'm doing wrong. I tried to play around with different headers, it's always the same, and as far as I know, this should be the correct header. Or what other argument could probably be wrong?

Might this have something to do with the maxPacketLength I used for connecting? I used 1024 because I had no idea what to use. I tried to call -getMaxPacketLength but that returns just 0. Do I have to override that method? Or how do I have to deal with that packet length?

Était-ce utile?

La solution

Finally I figured it out. The problem consisted of two parts. First problem was OBEXAddTargetHeader("LivescribeService", strlen("LivescribeService"), header);. Because strlen is the length of the string and not how many bytes are used (+1 for the 0x00 string terminator) the device responded with an error because it expects the string to be terminated. Sadly the OBEXSession just ignored the error that came back from the device.

Second problem was that I sent the received data with kOBEXTransportEventTypeStatus instead of kOBEXTransportEventTypeDataReceived to the clientHandleIncomingData: method.

Now the connection to the device works as expected.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top