コード例 #1
0
ファイル: protocol_task.c プロジェクト: Ebeo/flyless
void put_logview()
{
	char roll[10] = "";
	char nick[10] = "";
	char yaw[10]  = "";

	char x[10] = "";
	char y[10] = "";
	char z[10] = "";

	char angle_x[10] = "";
	char angle_y[10] = "";

	UART_Puts((uint8_t* )"$1;1;;");
	sprintf(x,"%0.2f;",  global_data.acc_g.x);
	UART_Puts((uint8_t*)x); //x
	sprintf(y,"%0.2f;",  global_data.acc_g.y);
	UART_Puts((uint8_t*)y); //y
	sprintf(z,"%0.2f;",  global_data.acc_g.z);
	UART_Puts((uint8_t*)z); //z
	sprintf(roll,"%0.2f;",  global_data.gyro_rad.x);
	UART_Puts((uint8_t*)roll); //roll
	sprintf(nick,"%0.2f;",  global_data.gyro_rad.y);
	UART_Puts((uint8_t*)nick); //nick
	sprintf(yaw,"%0.2f;",  global_data.gyro_rad.z);
	UART_Puts((uint8_t*)yaw); //yaw
	sprintf(angle_x,"%0.2f;",  (global_data.attitude.x * 57.295));
	UART_Puts((uint8_t*)angle_x);
	sprintf(angle_y,"%0.2f;",  (global_data.attitude.y * 57.295));
	UART_Puts((uint8_t*)angle_y);
	UART_Puts((uint8_t* )"0\r\n");
}
コード例 #2
0
/**
 * Params:
 *  @AA/BB 数据包头( 1 字节)
 *  @Command 命令码( 1 字节)
 *  @Status 指令调用的结果( 1 字节)
 *  @Len 数据长度( 1 字节)
 *  @Data[I] 数据
 *  @Bcc 异或校验码
 * Return:
 * Limitation:
 */
void RFID_Send(uint8_t cmd, uint8_t* buf1, uint8_t* buf2, uint8_t data)
{
    if(buf1 == NULL){
        uint8_t Send_data[28] = {0};
        buf1 = Send_data;
    }
    uint8_t header = 0xAA;

    uint8_t *ptr = rb[2].tx;
    uint16_t len = 3;
    *ptr++ = header;
    *ptr++ = cmd;
    switch(cmd)
    {
        case Cmd_R_HWVersion://AA 4F 00 E5
            {
                *ptr++ = 0;
                len += 0;
                break;
            }
        case Cmd_Load_Key://aa 4c 12 00 01 14 8a c5 e2 28 28 00 00 ff ff ff ff ff ff 40 f6 fa
            {
                *ptr++ = 18;
                len += 18;
                *ptr++ = 0x00;//_Mode 0

                *ptr++ = data;//_Secnr 扇区号

                *ptr++ = *buf1;*buf1++;//TKey Data[2~9] 传输密码
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;

                *ptr++ = *buf2;*buf2++;//Nkey Data[10~17] 要下载到RAM中的卡密码
                *ptr++ = *buf2;*buf2++;
                *ptr++ = *buf2;*buf2++;
                *ptr++ = *buf2;*buf2++;
                *ptr++ = *buf2;*buf2++;
                *ptr++ = *buf2;*buf2++;
                *ptr++ = *buf2;*buf2++;
                *ptr++ = *buf2;
                break;
            }
        case Cmd_Request://aa 41 01 01 eb
            {
                *ptr++ = 1;
                len += 1;
                *ptr++ = 0x01;//_Mode
                break;
            }
        case Cmd_Anticoll://aa 42 05 00 00 00 00 00 ed
            {
                *ptr++ = 5;
                len += 5;
                *ptr++ = 0;// 卡片系列号
                *ptr++ = 0;
                *ptr++ = 0;
                *ptr++ = 0;
                *ptr++ = 0;
                break;
            }
        case Cmd_Select://aa 43 04 82 8a 8d 5d 35
            {
                *ptr++ = 4;
                len += 4;
                *ptr++ = *buf1;*buf1++;// 卡片系列号
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;
                break;
            }
        case Cmd_Authentic://aa 44 02 00 01 ed
            {
                *ptr++ = 2;
                len += 2;
                *ptr++ = 0x00;// _Mode 0
                *ptr++ = data;// _SecNr 扇区号
                break;
            }
        case Cmd_Halt://aa 45 00 ef
            {
                *ptr++ = 0;
                len += 0;            
                break;
            }
        case Cmd_R_Block://aa 46 01 04 e9 //读 4 块  即1扇区0块的数据/////////////////
            {
                *ptr++ = 1;
                len += 1;
                *ptr++ = data;
                break;
            }
        case Cmd_W_Block://aa 47 11 04 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff f8//写 16 字节数据
            {
                *ptr++ = 17;
                len += 17;
                *ptr++ = data;// 要写入数据的块地址
                *ptr++ = *buf1;*buf1++;// 数据块的第一个字节
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;
                break;
            }
        case Cmd_A_Money://aa 48 05 04 0a 00 00 00 e9//对 4 块加值 10
            {
                *ptr++ = 5;
                len += 5;
                *ptr++ = *buf1;*buf1++;// 值
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;
                break;
            }
        case Cmd_L_Money://aa 49 05 04 0a 00 00 00 e9//对 4 块减值 10
            {
                *ptr++ = 5;
                len += 5;
                *ptr++ = *buf1;*buf1++;// 值
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;*buf1++;
                *ptr++ = *buf1;
                break;
            }
        default:
            {
                break;
            }
    }
    *ptr = CrcCheck_8(rb[2].tx,len);
    len += 1;
    UART_Puts (LPC_UART3, rb[2].tx, len);
    //UART_Send(LPC_UART3, Send_data, len, BLOCKING);
}