title: Create and send a bluetooth command frame in Cocoa
body: <p>I'm using the IOBluetooth Cocoa framework to communicate with a bluetooth device. So far I have gotten down the whole process of discovering the device and its services, pairing with it, connecting to it and now I want to send some actual commands, but I'm having some trouble with it. Below is an graphic from the spec for the AVRCP profile that I'm trying to use. You can <a href="http://www.bluetooth.com/nr/rdonlyres/0cd6930c-302e-4bb8-aca8-199066b47ade/922/avrcpspecv10.pdf" rel="nofollow noreferrer">view the pdf here</a>.</p>
  
  <p>I believe I need to write an 5 byte value as shown by the image:</p>
  
  <p><img src="https://imgur.com/K9uUG.png" alt="alt text"></p>
  
  <p>Here is the method I have right now that writes the data:</p>
  
  <pre><code>- (void)l2capChannelOpenComplete:(IOBluetoothL2CAPChannel*)l2capChannel status:(IOReturn)error {
      NSLog(@"Open Complete");
      NSMutableData *playData = [[NSMutableData alloc] initWithCapacity:5];
  
      unsigned char ctype = 0x0;
      unsigned char subunit = 0x90;
      unsigned char opcode = 0x7C;
      unsigned char opid = 0x44;
      unsigned char opdata = 0x0;
  
      [playData appendBytes:&amp;ctype length:8];
      [playData appendBytes:&amp;subunit length:8];
      [playData appendBytes:&amp;opcode length:8];
      [playData appendBytes:&amp;opid length:8];
      [playData appendBytes:&amp;opdata length:8];
  
      usleep(1000);
  
      [l2capChannel writeAsync:[playData mutableBytes] length:40 refcon:nil];
  }
  </code></pre>
  
  <p>When that function runs the devices responds with the following hexadecimal value 0x400010.</p>
  
  <ol>
  <li>I'm not even sure I'm approaching
  this correctly!</li>
  <li>Are the values I'm
  sending correct according the
  example in the image?</li>
  <li>Any help in my
  endeavor to learn here would be much
  appreciated!</li>
  </ol>