Пример #1
0
void SendPack_Camera(int father, int child, uint8 *camerabuff, int camera_size)
{
    char buffer[DATA_PACKET];
    char buff_end[DATA_PACKET];
    char tmpbuff[10];
    int count_i = 0;
    
    //============================================
    buffer[count_i++]='0';
    
    buffer[count_i++]='#';
    
    buffer[count_i++]='|';
    buffer[count_i++]=48 + father;
    buffer[count_i++]='|';
    buffer[count_i++]=48 + child;
    buffer[count_i++]='|';
    
    //CCD发送格式    
    sprintf(tmpbuff, "(80+60)");
    strcat(buffer, tmpbuff);
    count_i += strlen(tmpbuff);
    
    buffer[count_i++]='\0';
    buffer[0]=strlen(buffer) - 1;
    
    //NRF send buffer
    if(buffer[0] < 31)
    {
        if(nrf_tx((uint8*)buffer, DATA_PACKET)==1)
        {
            while(nrf_tx_state() == NRF_TXING);         //等待发送完成
        }
    }
    else
    {
        printf("in NRF_DIY.c of \"SendPack_Short\" is overflow!!");
    }
    
    //Camera数据的发送
    SendPack_Long(camerabuff, camera_size, 31);
    
    count_i = 0;
    buff_end[count_i++]=1;
    buff_end[count_i++]='|';
    buff_end[count_i++]='$';
    buff_end[count_i++]='\0';
    buff_end[0]=strlen(buff_end) - 1;
    
    if(nrf_tx((uint8*)buff_end, DATA_PACKET)==1)
    {
      while(nrf_tx_state() == NRF_TXING);         //等待发送完成
    }
}
Пример #2
0
//data--要发送的数据 ;actualLen--需要发送数据的长度;sendlen,一次性发送的长度 (定值):DATA_PACKET - 1 = 31
void SendPack_Long(unsigned char *data, int actualLen, int sendlen)
{
  //test
  //int count = 0;
  //=====

  uint8 buffer[DATA_PACKET] = {0};
  
  if (data != NULL && sendlen < DATA_PACKET)
  {
    //int send_length = strlen((char*)data);

    for (int i = 0; i < actualLen; i++)
    {
      buffer[i % sendlen + 1] = data[i];

      if ((i% sendlen + 1== sendlen))
      {
        buffer[0] = sendlen;
        if(nrf_tx(buffer, DATA_PACKET)==1)
        {
          while(nrf_tx_state() == NRF_TXING);         //等待发送完成
        }
        memset(buffer, 0, sizeof(buffer) / sizeof(char));
      }
      if ((i == actualLen - 1) && actualLen%sendlen != 0)
      {
        //添加结束符?
        buffer[0] = i % sendlen + 1;
        if(nrf_tx(buffer, DATA_PACKET)==1)
        {
          while(nrf_tx_state() == NRF_TXING);         //等待发送完成
        }
        memset(buffer, 0, sizeof(buffer) / sizeof(char));
      }

      //Do your job here
      //Dosomething();
    }
  }
  else
  {
    //reporte an error
  }
}
Пример #3
0
//value全部放大1000倍后回发电脑;(float报错也是醉了————万恶的IAR)
void SendPack_Short(int father, int child, float value, int hasHead, int hasEnd)
{
    char buffer[DATA_PACKET];
    char value_string[20];
    int count_i = 0;
    
    sprintf(value_string, "%4d|", (int)(1000*value));
    buffer[count_i++]='0';
    
    if(hasHead) //设置是否需要加数据头
      buffer[count_i++]='#';
    
    buffer[count_i++]='|';
    if(father > 10)
    {
        buffer[count_i++]=48 + father/10;
        buffer[count_i++]=48 + father%10;
    }
    else
    {
        buffer[count_i++]=48 + father;
    }
    buffer[count_i++]='|';
    
    //child 为两位,分情况进行添加
    if(child > 10)
    {
        buffer[count_i++]=48 + child/10;
        buffer[count_i++]=48 + child%10;
    }
    else
    {
        buffer[count_i++]=48 + child;
    }
    buffer[count_i++]='|';
    buffer[count_i++]='\0';
    strcat(buffer, value_string);
    if(hasEnd)  //添加结束符
      strcat(buffer, "$");
    buffer[0]=strlen(buffer)-1;
    
    //printf("%d---%s", (int)buffer[0], buffer);
    if(buffer[0] < 31)
    {
        if(nrf_tx((uint8*)buffer, DATA_PACKET)==1)
        {
            while(nrf_tx_state() == NRF_TXING);         //等待发送完成
        }
    }
    else
    {
        printf("in NRF_DIY.c of \"SendPack_Short\" is overflow!!");
    }
}
NrfErrorType_e NrfSendStr(uint8 * str,uint32 len)
{
	if (nrf_tx(str, DATA_PACKET) == 1)         //发送一个数据包:buff(包为32字节)
	{
		//等待发送过程中,此处可以加入处理任务

		while (nrf_tx_state() == NRF_TXING);         //等待发送完成

		if (NRF_TX_OK == nrf_tx_state())
		{
			return Nrf_AllGreen;
		}
		else
		{
			return Nrf_SendFail;
		}
	}
	else
	{
		return Nrf_SendFail;
	}
}
Пример #5
0
//value全部放大1000倍后回发电脑;(float报错也是醉了————万恶的IAR)
void SendPack_Echo(int father, int child, char *sendACK)
{
    char buffer[DATA_PACKET];
    int count_i = 0;
    
    buffer[count_i++]='0';
    
    buffer[count_i++]='#';
    
    buffer[count_i++]='|';
    if(father > 10)
    {
        buffer[count_i++]=48 + father/10;
        buffer[count_i++]=48 + father%10;
    }
    else
    {
        buffer[count_i++]=48 + father;
    }
    buffer[count_i++]='|';
    
    //child 为两位,分情况进行添加
    if(child > 10)
    {
        buffer[count_i++]=48 + child/10;
        buffer[count_i++]=48 + child%10;
    }
    else
    {
        buffer[count_i++]=48 + child;
    }
    buffer[count_i++]='|';
    buffer[count_i++]='\0';
    strcat(buffer, sendACK);
      strcat(buffer, "|$");
    buffer[0]=strlen(buffer)-1;
    
    //printf("%d---%s", (int)buffer[0], buffer);
    if(buffer[0] < 31)
    {
        if(nrf_tx((uint8*)buffer, DATA_PACKET)==1)
        {
            while(nrf_tx_state() == NRF_TXING);         //等待发送完成
        }
    }
    else
    {
        printf("in NRF_DIY.c of \"SendPack_Short\" is overflow!!");
    }
}
Пример #6
0
void SendPack_CCD(int father, int child, uint8 *ccdbuff, int ccdwidth, int hasHead, int hasEnd)//一次发送只能小于32为的数组
{
    char buffer[DATA_PACKET];
    char buff_end[DATA_PACKET];
    int count_i = 0;
    
    //============================================
    buffer[count_i++]='0';
    
    if(hasHead) //设置是否需要加数据头
      buffer[count_i++]='#';
    
    buffer[count_i++]='|';
    //数字大于10时候的单独处理
    if(father > 10)
    {
        buffer[count_i++]=48 + father/10;
        buffer[count_i++]=48 + father%10;
    }
    else
    {
        buffer[count_i++]=48 + father;
    }
    buffer[count_i++]='|';
    
    //child 为两位,分情况进行添加
    if(child > 10)
    {
        buffer[count_i++]=48 + child/10;
        buffer[count_i++]=48 + child%10;
    }
    else
    {
        buffer[count_i++]=48 + child;
    }
    buffer[count_i++]='|';
    
    //CCD发送格式
    buffer[count_i++]='(';
    //child 为两位,分情况进行添加
    if(ccdwidth > 100)
    {
        buffer[count_i++]=48 + ccdwidth/100;
        buffer[count_i++]=48 + ccdwidth/10%10;
        buffer[count_i++]=48 + ccdwidth%10;
    }
    else if(ccdwidth >10)
    {
        buffer[count_i++]=48 + ccdwidth/10;
        buffer[count_i++]=48 + ccdwidth%10;
    }
    else{}
    buffer[count_i++]=')';
    buffer[count_i++]='\0';
    buffer[0]=strlen(buffer) - 1;
    
    //NRF send buffer
    if(buffer[0] < 31)
    {
        if(nrf_tx((uint8*)buffer, DATA_PACKET)==1)
        {
            while(nrf_tx_state() == NRF_TXING);         //等待发送完成
        }
    }
    else
    {
        printf("in NRF_DIY.c of \"SendPack_Short\" is overflow!!");
    }
    
    //CCD数据的发送
    SendPack_Long(ccdbuff, ccdwidth, 31);
    
    count_i = 0;
    buff_end[count_i++]=1;
    buff_end[count_i++]='|';
    buff_end[count_i++]='\0';
    buff_end[0]=strlen(buff_end) - 1;
    
    //NRF send buffer
    if(buff_end[0] < 31)
    {
        if(nrf_tx((uint8*)buff_end, DATA_PACKET)==1)
        {
            while(nrf_tx_state() == NRF_TXING);         //等待发送完成
        }
    }
    
    count_i = 0;
    buff_end[count_i++]=1;
    buff_end[count_i++]='$';
    buff_end[count_i++]='\0';
    
    if(hasEnd)  //添加结束符
    {
        if(nrf_tx((uint8*)buff_end, DATA_PACKET)==1)
          {
              while(nrf_tx_state() == NRF_TXING);         //等待发送完成
          }
    }
    
    //printf("%d---%s", (int)buffer[0], buffer);
}
Пример #7
0
void SendPack_PID(int father, int child, float P, float I, float D, int hasHead, int hasEnd)//一次发送只能小于32为的数组
{
    char buffer[DATA_PACKET];
    char value_string[20];
    int count_i = 0;
    
    //============================================
    buffer[count_i++]='0';
    
    if(hasHead) //设置是否需要加数据头
      buffer[count_i++]='#';
    
    buffer[count_i++]='|';
    //数字大于10时候的单独处理
    if(father > 10)
    {
        buffer[count_i++]=48 + father/10;
        buffer[count_i++]=48 + father%10;
    }
    else
    {
        buffer[count_i++]=48 + father;
    }
    buffer[count_i++]='|';
    
    //child 为两位,分情况进行添加
    if(child > 10)
    {
        buffer[count_i++]=48 + child/10;
        buffer[count_i++]=48 + child%10;
    }
    else
    {
        buffer[count_i++]=48 + child;
    }
    buffer[count_i++]='|';
    buffer[count_i++]='\0';
    //添加P
    sprintf(value_string, "P%4d", (int)(1000*P));
    strcat(buffer, value_string);
    //添加I
    sprintf(value_string, "I%4d", (int)(1000*I));
    strcat(buffer, value_string);
    //添加D
    sprintf(value_string, "D%4d|", (int)(1000*D));
    strcat(buffer, value_string);
    
    if(hasEnd)  //添加结束符
      strcat(buffer, "$");
    
    buffer[0]=strlen(buffer)-1;
    
    //printf("%d---%s", (int)buffer[0], buffer);
    if(buffer[0] < 31)
    {
        if(nrf_tx((uint8*)buffer, DATA_PACKET)==1)
        {
            while(nrf_tx_state() == NRF_TXING);         //等待发送完成
        }
    }
    else
    {
        printf("in NRF_DIY.c of \"SendPack_Short\" is overflow!!");
    }
}