Beispiel #1
0
bool lib_aci_set_local_data(aci_state_t *aci_stat, uint8_t pipe, uint8_t *p_value, uint8_t size)
{
  aci_cmd_params_set_local_data_t aci_cmd_params_set_local_data;
  
  if ((p_services_pipe_type_map[pipe-1].location != ACI_STORE_LOCAL)
      ||
      (size > ACI_PIPE_TX_DATA_MAX_LEN))
  {
    return false;
  }

  aci_cmd_params_set_local_data.tx_data.pipe_number = pipe;
  memcpy(&(aci_cmd_params_set_local_data.tx_data.aci_data[0]), p_value, size);
  acil_encode_cmd_set_local_data(&(msg_to_send.buffer[0]), &aci_cmd_params_set_local_data, size);
  return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_close_remote_pipe(aci_state_t *aci_stat, uint8_t pipe)
{
  bool ret_val = false;
  aci_cmd_params_close_remote_pipe_t aci_cmd_params_close_remote_pipe;

  {

    // is_request_operation_pending = true;
    // is_close_remote_pipe_pending = true;
    // request_operation_pipe = pipe;
    aci_cmd_params_close_remote_pipe.pipe_number = pipe;
    acil_encode_cmd_close_remote_pipe(&(msg_to_send.buffer[0]), &aci_cmd_params_close_remote_pipe);
    ret_val = hal_aci_tl_send(&msg_to_send);
  }
  return ret_val;
}
Beispiel #3
0
bool lib_aci_echo_msg(uint8_t msg_size, uint8_t *p_msg_data)
{
  aci_cmd_params_echo_t aci_cmd_params_echo;
  if(msg_size > (ACI_ECHO_DATA_MAX_LEN))
  {
    return false;
  }

  if (msg_size > (ACI_ECHO_DATA_MAX_LEN))
  {
    msg_size = ACI_ECHO_DATA_MAX_LEN;
  }

  memcpy(&(aci_cmd_params_echo.echo_data[0]), p_msg_data, msg_size);
  acil_encode_cmd_echo_msg(&(msg_to_send.buffer[0]), &aci_cmd_params_echo, msg_size);

  return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_send_data(uint8_t pipe, uint8_t *p_value, uint8_t size)
{
  bool ret_val = false;
  aci_cmd_params_send_data_t aci_cmd_params_send_data;

  if (size > ACI_PIPE_TX_DATA_MAX_LEN)
  {
    return false;
  }
  {
      aci_cmd_params_send_data.tx_data.pipe_number = pipe;
      memcpy(&(aci_cmd_params_send_data.tx_data.aci_data[0]), p_value, size);
      acil_encode_cmd_send_data(&(msg_to_send.buffer[0]), &aci_cmd_params_send_data, size);

      ret_val = hal_aci_tl_send(&msg_to_send);
  }
  return ret_val;
}
bool lib_aci_request_data(aci_state_t *aci_stat, uint8_t pipe)
{
  bool ret_val = false;
  aci_cmd_params_request_data_t aci_cmd_params_request_data;

  {

    {



      aci_cmd_params_request_data.pipe_number = pipe;
      acil_encode_cmd_request_data(&(msg_to_send.buffer[0]), &aci_cmd_params_request_data);

      ret_val = hal_aci_tl_send(&msg_to_send);
    }
  }
  return ret_val;
}
Beispiel #6
0
bool lib_aci_broadcast(const uint16_t timeout, const uint16_t adv_interval)
{
  aci_cmd_params_broadcast_t aci_cmd_params_broadcast;
  if (timeout > 16383)
  {
    return false;
  }  
  
  // The adv_interval should be between 160 and 16384 (which translates to the advertisement 
  // interval values 100 ms and 10.24 s.
  if ((160 > adv_interval) || (adv_interval > 16384))
  {
    return false;
  }

  aci_cmd_params_broadcast.timeout = timeout;
  aci_cmd_params_broadcast.adv_interval = adv_interval;
  acil_encode_cmd_broadcast(&(msg_to_send.buffer[0]), &aci_cmd_params_broadcast);
  return hal_aci_tl_send(&msg_to_send);
}
void aci_setup_fill(aci_state_t *aci_stat, uint8_t *num_cmd_offset)
{
    
  while (*num_cmd_offset < aci_stat->aci_setup_info.num_setup_msgs)
  {
    //Copy the setup ACI message from Flash to RAM
    //Add 2 bytes to the length byte for status byte, length for the total number of bytes
    memcpy_P(&msg_to_send, &(aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset]), 
              pgm_read_byte_near(&(aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset].buffer[0]))+2); 
    
    //Put the Setup ACI message in the command queue
    if (!hal_aci_tl_send(&msg_to_send))
    {
		//ACI Command Queue is full
		// *num_cmd_offset is now pointing to the index of the Setup command that did not get sent
		return;
    }
    
    (*num_cmd_offset)++;
  }
 
}
Beispiel #8
0
bool lib_aci_disconnect(aci_state_t *aci_stat, aci_disconnect_reason_t reason)
{
  bool ret_val;
  uint8_t i;
  aci_cmd_params_disconnect_t aci_cmd_params_disconnect;
  aci_cmd_params_disconnect.reason = reason;
  acil_encode_cmd_disconnect(&(msg_to_send.buffer[0]), &aci_cmd_params_disconnect);
  ret_val = hal_aci_tl_send(&msg_to_send);
  // If we have actually sent the disconnect
  if (ret_val)
  {
    // Update pipes immediately so that while the disconnect is happening,
    // the application can't attempt sending another message
    // If the application sends another message before we updated this
    //    a ACI Pipe Error Event will be received from nRF8001
    for (i=0; i < PIPES_ARRAY_SIZE; i++)
    {
      aci_stat->pipes_open_bitmap[i] = 0;
      aci_stat->pipes_closed_bitmap[i] = 0;
    }
  }
  return ret_val;
}
Beispiel #9
0
bool aci_setup_fill(aci_state_t *aci_stat, uint8_t *num_cmd_offset)
{
  bool ret_val = false;

  while (*num_cmd_offset < aci_stat->aci_setup_info.num_setup_msgs)
  {
    //Board dependent defines
    /*#if defined (__AVR__)
        //For Arduino copy the setup ACI message from Flash to RAM.
        memcpy_P(&msg_to_send, &(aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset]),
                  pgm_read_byte_near(&(aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset].buffer[0]))+2);
    #elif defined(__PIC32MX__)
        //In ChipKit we store the setup messages in RAM
        //Add 2 bytes to the length byte for status byte, length for the total number of bytes
        memcpy(&msg_to_send, &(aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset]),
                  (aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset].buffer[0]+2));
    #endif*/

    memcpy(&msg_to_send, &(aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset]),
                  (aci_stat->aci_setup_info.setup_msgs[*num_cmd_offset].buffer[0]+2));

    //Put the Setup ACI message in the command queue
    if (!hal_aci_tl_send(&msg_to_send))
    {
      //ACI Command Queue is full
      // *num_cmd_offset is now pointing to the index of the Setup command that did not get sent
      return ret_val;
   }

    ret_val = true;

    (*num_cmd_offset)++;
  }

  return ret_val;
}
Beispiel #10
0
bool lib_aci_bond_request()
{
  acil_encode_cmd_bond_security_request(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}
Beispiel #11
0
aci_status_code_t aci_setup(aci_state_t *aci_stat, uint8_t num_cmds, uint8_t num_cmd_offset)
{
  uint8_t i = 0;
  uint8_t evt_count = 0;
  aci_evt_t * aci_evt = NULL;
  
  while (i < num_cmds)
  {
    //Copy the setup ACI message from Flash to RAM
    //Add 2 bytes to the length byte for status byte, length for the total number of bytes
    memcpy_P(&aci_cmd, &(aci_stat->aci_setup_info.setup_msgs[num_cmd_offset+i]), 
              pgm_read_byte_near(&(aci_stat->aci_setup_info.setup_msgs[num_cmd_offset+i].buffer[0]))+2); 
    
    //Put the Setup ACI message in the command queue
    if (!hal_aci_tl_send(&aci_cmd))
    {
      Serial.println(F("Cmd Queue Full"));
      return ACI_STATUS_ERROR_INTERNAL;
    }
    else
    {
        //Debug messages:
        //Serial.print(F("Setup msg"));
        //Serial.println(i, DEC);
        #ifdef __arm__
        // This entire setup scheme may have an off-by-one error, where it tries to
        // put 8 commends into the queue which can only hold 7 due to the way the
        // head & tail indexes are managed.  On AVR, the processor is simply too
        // slow to fill the queue before at least one interrupt, but a fast ARM
        // processor can easily do so.  This delay is a workaround to avoid having
        // to restructure a lot of code...
        delayMicroseconds(10);
        #endif
    }
    
    i++;
  }
  while (1)
  {
    //We will sit here if we do not get the same number of command response evts as the commands sent to the ACI
    //
    //@check The setup wil fail in the while(1) below when the 32KHz source for the nRF8001 is in-correct in the setup generated in the nRFgo studio
    if (true == lib_aci_event_get(aci_stat, &aci_data))
    {
      aci_evt = &aci_data.evt;
      
      evt_count++;
  
      if (ACI_EVT_CMD_RSP != aci_evt->evt_opcode )
      {
        //Got something other than a command response evt -> Error
        return ACI_STATUS_ERROR_INTERNAL;
      }
      
      if (!((ACI_STATUS_TRANSACTION_CONTINUE == aci_evt->params.cmd_rsp.cmd_status) || 
           (ACI_STATUS_TRANSACTION_COMPLETE == aci_evt->params.cmd_rsp.cmd_status)))
      {
        return (aci_status_code_t )aci_evt->params.cmd_rsp.cmd_status;
      }
      else
      {
        //Serial.print(F("Cmd Response Evt "));
        //Serial.println(evt_count);
      }
      
      if (num_cmds == evt_count)
      {
        break;
      }                  
    }
  }
  
  return ((aci_status_code_t)aci_evt->params.cmd_rsp.cmd_status);              
}
Beispiel #12
0
bool lib_aci_change_timing_GAP_PPCP()
{
  acil_encode_cmd_change_timing_req_GAP_PPCP(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}
Beispiel #13
0
bool lib_aci_get_battery_level()
{
  acil_encode_cmd_battery_level(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}
Beispiel #14
0
bool lib_aci_get_temperature()
{
  acil_encode_cmd_temparature(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}
Beispiel #15
0
bool lib_aci_radio_reset()
{
  acil_encode_baseband_reset(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}
Beispiel #16
0
bool lib_aci_read_dynamic_data()
{
  acil_encode_cmd_read_dynamic_data(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}
Beispiel #17
0
bool lib_aci_device_version()
{
  acil_encode_cmd_get_device_version(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}
Beispiel #18
0
bool lib_aci_direct_connect()
{
  acil_encode_direct_connect(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}
Beispiel #19
0
bool lib_aci_write_dynamic_data(uint8_t sequence_number, uint8_t* dynamic_data, uint8_t length)
{
  acil_encode_cmd_write_dynamic_data(&(msg_to_send.buffer[0]), sequence_number, dynamic_data, length);
  return hal_aci_tl_send(&msg_to_send);
}
Beispiel #20
0
bool lib_aci_wakeup()
{
  acil_encode_cmd_wakeup(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}
/*
Read the Dymamic data from the EEPROM and send then as ACI Write Dynamic Data to the nRF8001
This will restore the nRF8001 to the situation when the Dynamic Data was Read out
*/
aci_status_code_t bond_data_restore(aci_state_t *aci_stat, uint8_t eeprom_status, bool *bonded_first_time_state)
{
  aci_evt_t *aci_evt; 
  uint8_t eeprom_offset_read = 1;
  uint8_t write_dyn_num_msgs = 0;
  uint8_t len =0;
  
  
  // Get the number of messages to write for the eeprom_status
  write_dyn_num_msgs = eeprom_status & 0x7F;
  
  //Read from the EEPROM
  while(1)
  {
    len = EEPROM.read(eeprom_offset_read);
    eeprom_offset_read++;
    aci_cmd.buffer[0] = len;
    
    for (uint8_t i=1; i<=len; i++)
    {
        aci_cmd.buffer[i] = EEPROM.read(eeprom_offset_read);
        eeprom_offset_read++;
    }
    //Send the ACI Write Dynamic Data
    if (!hal_aci_tl_send(&aci_cmd))
    {
      Serial.println(F("bond_data_restore: Cmd Q Full"));
      return ACI_STATUS_ERROR_INTERNAL;
    }
  
    //Spin in the while loop waiting for an event
    while (1)
    {
      if (lib_aci_event_get(aci_stat, &aci_data))
      {
        aci_evt = &aci_data.evt; 
        
        if (ACI_EVT_CMD_RSP != aci_evt->evt_opcode)
        {
            //Got something other than a command response evt -> Error
            Serial.print(F("bond_data_restore: Expected cmd rsp evt. Got: 0x"));           
            Serial.println(aci_evt->evt_opcode, HEX);
            return ACI_STATUS_ERROR_INTERNAL;
        }
        else
        {
          write_dyn_num_msgs--;
          
          //ACI Evt Command Response
          if (ACI_STATUS_TRANSACTION_COMPLETE == aci_evt->params.cmd_rsp.cmd_status)
          {
            //Set the state variables correctly
            *bonded_first_time_state = false;
            aci_stat->bonded = ACI_BOND_STATUS_SUCCESS;
            
            delay(10);
            
            return ACI_STATUS_TRANSACTION_COMPLETE;
          }
          if (0 >= write_dyn_num_msgs)
          {
            //should have returned earlier
            return ACI_STATUS_ERROR_INTERNAL;
          }
          if (ACI_STATUS_TRANSACTION_CONTINUE == aci_evt->params.cmd_rsp.cmd_status)
          {            
            //break and write the next ACI Write Dynamic Data
            break;
          }
        }
      }
    }    
  }  
}
Beispiel #22
0
bool lib_aci_get_address()
{
  acil_encode_cmd_get_address(&(msg_to_send.buffer[0]));
  return hal_aci_tl_send(&msg_to_send);
}