예제 #1
0
파일: hu_aap.c 프로젝트: kovrov/headunit
 int aa_pro_sen_b01 (int chan, byte * buf, int len) {                  // Sensor Start Request...
   logd ("Sensor Start Request chan: %d", chan);
   byte rsp [] = {0x80, 0x02, 0x08, 0};
   int ret = hu_aap_enc_send (chan, rsp, sizeof (rsp));               // Respond with Sensor Response
   if (ret)
     return (ret);
   ms_sleep (20);                                                      // Else if success and channel = video...
   byte rsp2 [] = {0x80, 0x03, 106, /*4, 0x0a,*/ 2, 8, 1}; // Driving Status = Stopped
   return (hu_aap_enc_send (chan, rsp2, sizeof (rsp2)));              // Respond with Sensor Batch
 }
예제 #2
0
파일: hu_aap.c 프로젝트: kovrov/headunit
 int aa_pro_all_b00 (int chan, byte * buf, int len) {
   logd ("Video/Media Setup Request all chan: %d", chan);
   byte rsp [] = {0x80, 0x03, 0x08, 2, 0x10, 1, 0x18, 0};//0x1a, 4, 0x08, 1, 0x10, 2};      // 1/2, MaxUnack, int[] 1        2, 0x08, 1};//
   int ret = hu_aap_enc_send (chan, rsp, sizeof (rsp));               // Respond with Config Response
   if (ret || chan != AA_CH_VID)
     return (ret);
   ms_sleep (20);                                                      // Else if success and channel = video...
   byte rsp2 [] = {0x80, 0x08, 0x08, 1, 0x10, 1};                      // 1, 1     VideoFocus gained focusState=0 unsolicited=true
   return (hu_aap_enc_send (chan, rsp2, sizeof (rsp2)));              // Respond with VideoFocus gained/notif focusState=0 unsolicited=true
 }
예제 #3
0
파일: hu_aap.c 프로젝트: kovrov/headunit
 int aa_pro_all_a07 (int chan, byte * buf, int len) {
   logd ("Channel Open all chan: %d", chan);
   byte rsp [] = {0, 8, 8, 0};                                         // Status 0 = OK
   int ret = hu_aap_enc_send (chan, rsp, sizeof (rsp));               // Respond with Channel Open OK
   if (ret || chan != AA_CH_SEN)
     return (ret);
   ms_sleep (20);                                                      // Else if success and channel = sensor...
   byte rspds [] = {0x80, 0x03, 0x6a, 2, 8, 0};                        // Driving Status = 0 = Parked (1 = Moving)
   return (hu_aap_enc_send (chan, rspds, sizeof (rspds)));            // Respond with response
 }
예제 #4
0
파일: hu_aap.c 프로젝트: kovrov/headunit
 int aa_pro_ctr_a12 (int chan, byte * buf, int len) {                  // Audio Focus Request
   loge ("Audio Focus Request: %d", buf [3]);
   buf [1] = 19;                                                       // Use request buffer for response
   buf [3] = 2;  // Focus granted ?
   int ret = hu_aap_enc_send (chan, buf, len);                        // Respond
   return (0);
 }
예제 #5
0
파일: hu_aap.c 프로젝트: kovrov/headunit
  int aa_pro_all_a0f (int chan, byte * buf, int len) {
    logd ("Byebye all chan: %d", chan);
    int ret = hu_aap_enc_send (chan, bye_rsp, sizeof (bye_rsp));       // Respond with Byebye rsp

    ms_sleep (100);                                                     // Wait for response
    //terminate = 1;

    hu_aap_stop ();

    return (-1);
  }
예제 #6
0
  int jni_aa_cmd (int cmd_len, char * cmd_buf, int res_max, char * res_buf) {
    if (ena_log_extra || cmd_len >= 1)
      logd ("cmd_len: %d  cmd_buf %p  res_max: %d  res_buf: %p", cmd_len, cmd_buf, res_max, res_buf);
    int res_len = 0;
    int ret = 0;

    if (cmd_buf != NULL && cmd_len == 3 && cmd_buf [0] == 121) {        // If onCreate() hu_tra:transport_start()
      byte ep_in_addr  = cmd_buf [1];
      byte ep_out_addr = cmd_buf [2];
      ret = hu_aap_start (ep_in_addr, ep_out_addr);                    // Start USB/ACC/OAP, AA Protocol
      aap_state_starts ++;  // Count error starts too
      if (ret == 0) {
        logd ("hu_aap_start() success aap_state_starts: %d", aap_state_starts);
      }
      else {
        loge ("hu_aap_start() error aap_state_starts: %d", aap_state_starts);
        aap_state_start_error = 1;
        return (-1);
      }
    }

    if (cmd_buf != NULL && cmd_len >= 4) {                              // If encrypted command to send...
      int chan = cmd_buf [0];
      ret = hu_aap_enc_send (chan, & cmd_buf [4], cmd_len - 4);        // Send

      if (cmd_buf != NULL && cmd_len  >= 8 && cmd_buf [5] == 15) {  // If byebye...
        loge ("Byebye");
        ms_sleep (100);
        ret = hu_aap_stop ();
      }

    }
    else {
      ret = hu_aap_recv_process ();                                    // Process 1 message
    }
    if (ret < 0) {
      return (ret);
    }

    byte * dq_buf = read_head_buffer_get (& res_len);
    if (ena_log_extra || (ena_log_verbo && dq_buf != NULL))
      logd ("dq_buf: %p", dq_buf);
    if (dq_buf == NULL || res_len <= 0) {
      if (ena_log_extra)
        logd ("No data dq_buf: %p  res_len: %d", dq_buf, res_len);
      return (0);
    }
    memcpy (res_buf, dq_buf, res_len);

    if (ena_log_verbo)
      logd ("res_len: %d", res_len);
    return (res_len);
  }
예제 #7
0
파일: main.c 프로젝트: 4hmedSamir/headunit
gboolean myMainLoop(gpointer app)
{
	if (shouldRead)
	{
		read_data(app);
	}

	send_arg* cmd;
 
	if (cmd = g_async_queue_try_pop(sendqueue))
	{
		hu_aap_enc_send(cmd->retry, cmd->chan, cmd->cmd_buf, cmd->cmd_len);
		if(cmd->shouldFree)
			free(cmd->cmd_buf);
		free(cmd);
	}

	return TRUE; 
}
예제 #8
0
파일: hu_aap.cpp 프로젝트: mishaaq/headunit
  int HUServer::hu_aap_enc_send_media_packet(int retry, int chan, uint16_t messageCode, uint64_t timeStamp, const byte* buffer, int bufferLen, int overrideTimeout)
  {
    const int requiredSize = bufferLen + 2 + 8;
    if (temp_assembly_buffer.size() < requiredSize)
    {
      temp_assembly_buffer.resize(requiredSize);
    }

    uint16_t* destMessageCode = reinterpret_cast<uint16_t*>(temp_assembly_buffer.data());
    *destMessageCode++ = htobe16(messageCode);

    uint64_t* destTimestamp = reinterpret_cast<uint64_t*>(destMessageCode);
    *destTimestamp++ = htobe64(timeStamp);

    memcpy(destTimestamp, buffer, bufferLen);

    //logd ("Send %s on channel %i %s", message.GetTypeName().c_str(), chan, chan_get(chan));
    //hex_dump("PB:", 80, temp_assembly_buffer.data(), requiredSize);
    return hu_aap_enc_send(retry, chan, temp_assembly_buffer.data(), requiredSize, overrideTimeout);
  }
예제 #9
0
파일: hu_aap.c 프로젝트: kovrov/headunit
  int iaap_video_process (int type, int flag, byte * buf, int len) {    // Process video packet
// MaxUnack
//loge ("????????????????????? !!!!!!!!!!!!!!!!!!!!!!!!!   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   ack_ctr: %d  len: %d", ack_ctr ++, len);
int ret = hu_aap_enc_send (AA_CH_VID, vid_ack, sizeof (vid_ack));      // Respond with ACK (for all fragments ?)
/*
    int ret = 0;
    //if (ack_ctr ++ % 17 == 16)
    if (ack_ctr ++ % 2 == 1)
      loge ("Drop ack to test !!!!!!!!!!!!!!!!!!!!!!!!!   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   ack_ctr: %d  len: %d", ack_ctr, len);
    else
      ret = hu_aap_enc_send (AA_CH_VID, vid_ack, sizeof (vid_ack));      // Respond with ACK (for all fragments ?)
//*/
    if (0) {
    }
    else if (flag == 11 && (type == 0 || type == 1) && (buf [10] == 0 && buf [11] == 0 && buf [12] == 0 && buf [13] == 1)) {  // If Not fragmented Video
      iaap_video_decode (& buf [10], len - 10);                                                                               // Decode H264 video
    }
    else if (flag == 9 && (type == 0 || type == 1) && (buf [10] == 0 && buf [11] == 0 && buf [12] == 0 && buf [13] == 1)) {   // If First fragment Video
      memcpy (assy, & buf [10], len - 10);                                                                                    // Len in bytes 2,3 doesn't include total len 4 bytes at 4,5,6,7
      assy_size = len - 10;                                                                                                   // Add to re-assembly in progress
    }
    else if (flag == 11 && type == 1 && (buf [2] == 0 && buf [3] == 0 && buf [4] == 0 && buf [5] == 1)) {                     // If Not fragmented First video config packet
      iaap_video_decode (& buf [2], len - 2);                                                                                 // Decode H264 video
    }
    else if (flag == 8) {                                                                                                     // If Middle fragment Video
      memcpy (& assy [assy_size], buf, len);
      assy_size += len;                                                                                                       // Add to re-assembly in progress
    }
    else if (flag == 10) {                                                                                                    // If Last fragment Video
      memcpy (& assy [assy_size], buf, len);
      assy_size += len;                                                                                                       // Add to re-assembly in progress
      iaap_video_decode (assy, assy_size);                                                                                    // Decode H264 video fully re-assembled
    }
    else
      loge ("Video error type: %d  flag: %d  buf: %p  len: %d", type, flag, buf, len);

    return (0);
  }
예제 #10
0
파일: hu_aap.cpp 프로젝트: mishaaq/headunit
  int HUServer::hu_aap_enc_send_message(int retry, int chan, uint16_t messageCode, const google::protobuf::MessageLite& message, int overrideTimeout)
  {
    const int messageSize = message.ByteSize();
    const int requiredSize = messageSize + 2;
    if (temp_assembly_buffer.size() < requiredSize)
    {
      temp_assembly_buffer.resize(requiredSize);
    }

    uint16_t* destMessageCode = reinterpret_cast<uint16_t*>(temp_assembly_buffer.data());
    *destMessageCode++ = htobe16(messageCode);

    if (!message.SerializeToArray(destMessageCode, messageSize))
    {
      loge("AppendToString failed for %s", message.GetTypeName().c_str());
      return -1;
    }

    logd ("Send %s on channel %i %s", message.GetTypeName().c_str(), chan, chan_get(chan));
    //hex_dump("PB:", 80, temp_assembly_buffer.data(), requiredSize);
    return hu_aap_enc_send(retry, chan, temp_assembly_buffer.data(), requiredSize, overrideTimeout);

  }
예제 #11
0
파일: hu_jni.c 프로젝트: FrankZZ/headunit
  int jni_aa_cmd (int cmd_len, char * cmd_buf, int res_max, char * res_buf) {
    if (ena_log_extra || cmd_len >= 1)
      logd ("cmd_len: %d  cmd_buf %p  res_max: %d  res_buf: %p", cmd_len, cmd_buf, res_max, res_buf);
    int res_len = 0;
    int ret = 0;


    int vid_bufs = vid_buf_buf_tail - vid_buf_buf_head;
    int aud_bufs = vid_buf_buf_tail - vid_buf_buf_head;


    if (cmd_buf != NULL && cmd_len == 3 && cmd_buf [0] == 121) {        // If onCreate() hu_tra:transport_start()
      byte ep_in_addr  = cmd_buf [1];
      byte ep_out_addr = cmd_buf [2];                                   // Get endpoints passed

      ret = hu_aap_start (ep_in_addr, ep_out_addr);                     // Start USB/ACC/OAP, AA Protocol

      aap_state_starts ++;                                              // Count error starts too
      if (ret == 0) {
        logd ("hu_aap_start() success aap_state_starts: %d", aap_state_starts);
      }
      else {
        loge ("hu_aap_start() error aap_state_starts: %d", aap_state_starts);
        aap_state_start_error = 1;
        return (-1);
      }
    }

/* Functions                code                            Params:
    Transport Start         hu_aap_start()                  USB EPs
    Poll/Handle 1 Rcv Msg   hu_aap_recv_process()           -
    Send:
      Send Mic              hu_aap_enc_send()               mic data
      Send Touch            hu_aap_enc_send()               touch data
      Send Ctrl             hu_aap_enc_send()/hu_aap_stop() ctrl data

  Returns:
    Audio Mic Start/Stop
    Audio Out Start/Stop
    Video
    Audio
*/
    else if (cmd_buf != NULL && cmd_len >= 4) {                         // If encrypted command to send...
      int chan = 0;//cmd_buf [0];

      if (cmd_len > 63)                                                 // If Microphone audio...
        chan = AA_CH_MIC;
      else if (cmd_len > 6 && cmd_buf [4] == 0x80 && cmd_buf [5] == 1)  // If Touch event...
        chan = AA_CH_TOU;
      else                                                              // If Byebye or other control packet...
        chan = AA_CH_CTR;
      if (chan != cmd_buf [0]) {
        loge ("chan: %d != cmd_buf[0]: %d", chan, cmd_buf [0]);
        chan = cmd_buf [0];
      }

      //hex_dump ("JNITX: ", 16, cmd_buf, cmd_len);

      ret = hu_aap_enc_send (chan, & cmd_buf [4], cmd_len - 4);         // Send

      if (cmd_buf != NULL && cmd_len  >= 8 && cmd_buf [5] == 15) {      // If byebye...
        logd ("Byebye");
        ms_sleep (100);
        ret = hu_aap_stop ();
      }

    }
    else {
      if (vid_bufs > 0 || aud_bufs > 0)                                 // If any queue audio or video...
        ret = 0;                                                        // Do nothing (don't wait for recv iaap_tra_recv_tmo)
      else
        ret = hu_aap_recv_process ();                                   // Else Process 1 message w/ iaap_tra_recv_tmo
    }
    if (ret < 0) {
      return (ret);                                                     // If error then done w/ error
    }

    if (vid_bufs <= 0 && aud_bufs <= 0) {                               // If no queued audio or video...
      ret = hu_aap_mic_get ();
      if (ret >= 1) {// && ret <= 2) {                                  // If microphone start (2) or stop (1)...
        return (ret);                                                   // Done w/ mic notification: start (2) or stop (1)
      }
                                                                        // Else if no microphone state change...
      
      if (hu_aap_out_get (AA_CH_AUD) >= 0)                              // If audio out stop...
        return (3);                                                     // Done w/ audio out notification 0
      if (hu_aap_out_get (AA_CH_AU1) >= 0)                              // If audio out stop...
        return (4);                                                     // Done w/ audio out notification 1
      if (hu_aap_out_get (AA_CH_AU2) >= 0)                              // If audio out stop...
        return (5);                                                     // Done w/ audio out notification 2
    }

    byte * dq_buf = NULL;
    dq_buf = aud_read_head_buf_get (& res_len);                         // Get audio if ready

    if (dq_buf == NULL)                                                 // If no audio... (Audio has priority over video)
      dq_buf = vid_read_head_buf_get (& res_len);                       // Get video if ready

    else {                                                              // If audio
      if (dq_buf [0] == 0 && dq_buf [1] == 0 && dq_buf [2] == 0 && dq_buf [3] == 1) {
        dq_buf [3] = 0;                                                   // If audio happened to have magic video signature... (rare), then 0 the 1
        loge ("magic video signature in audio");
      }

      //hu_uti.c:  #define aud_buf_BUFS_SIZE    65536 * 4      // Up to 256 Kbytes
    }

    if (ena_log_extra || (ena_log_verbo && dq_buf != NULL))
      logd ("dq_buf: %p", dq_buf);
    if (dq_buf == NULL || res_len <= 0) {
      if (ena_log_extra)
        logd ("No data dq_buf: %p  res_len: %d", dq_buf, res_len);
      return (0);
    }
    memcpy (res_buf, dq_buf, res_len);

    if (ena_log_verbo)
      logd ("res_len: %d", res_len);
    return (res_len);
  }
예제 #12
0
파일: hu_aap.c 프로젝트: kovrov/headunit
 int aa_pro_tou_b02 (int chan, byte * buf, int len) {                  // TouchScreen/Input Start Request...    Or "send setup, ch:X" for channel X
   logd ("TouchScreen/Input Start Request tou chan: %d", chan);
   byte rsp [] = {0x80, 0x03, 0x08, 0};
   int ret = hu_aap_enc_send (chan, rsp, sizeof (rsp));               // Respond with Key Binding Response = OK
   return (ret);
 }
예제 #13
0
파일: hu_aap.c 프로젝트: kovrov/headunit
 int aa_pro_all_a0b (int chan, byte * buf, int len) {
   logd ("Ping all chan: %d", chan);
   buf [1] = 12;                                                       // Use request buffer for response
   int ret = hu_aap_enc_send (chan, buf, len);                        // Respond with Channel Open OK
   return (ret);
 }
예제 #14
0
파일: hu_aap.c 프로젝트: kovrov/headunit
 int aa_pro_ctr_a05 (int chan, byte * buf, int len) {
   logd ("Service Disc req");
   return (hu_aap_enc_send (chan, sd_buf, sizeof (sd_buf)));
 }