#include "User_Dri_main.h"

extern unsigned char xdata sg_ucUartDbgData[128];
MCUART_watch xdata Uartwatch;

void uart_boxing(uint8 ChNum, int32 CH0, int32 CH1, int32 CH2, int32 CH3, int32 CH4, int32 CH5, int32 CH6, int32 CH7)
{
    uint8 i = 0, tt = 0;
    static float  CH[20] = 0;
    static uint16 cmdTFT_CH1[4] = {0x00, 0x00, 0x80, 0x7F};
    typedef union
    {
        float            fdata;
        unsigned long    ldata;
    } datetype;
    datetype  Ddate;
    Wait_DMA(1);
    CH[0] = CH0; CH[1] = CH1; CH[2] = CH2; CH[3] = CH3; CH[4] = CH4; CH[5] = CH5; CH[6] = CH6; CH[7] = CH7;
    
    for (tt = 0; tt < ChNum; tt++)
    {
        Ddate.fdata = CH[tt];
        sg_ucUartDbgData[0 + tt * 4] = Ddate.ldata;
        sg_ucUartDbgData[1 + tt * 4] = (Ddate.ldata >> 8 & 0xFF);
        sg_ucUartDbgData[2 + tt * 4] = (Ddate.ldata >> 16 & 0xFF);
        sg_ucUartDbgData[3 + tt * 4] = (Ddate.ldata >> 24 & 0xFF);
    }
    
    if (ChNum != 0)
    {
        for (i = 0; i < 4; i++)
        {
            sg_ucUartDbgData[4 + (tt - 1) * 4 + i] = cmdTFT_CH1[i];
        }
    }
    
    DMA1_LEN = 4 + (tt - 1) * 4 + (i - 1);
    Switch_DMA(1);
}


void UART1RCE()
{
    Uartwatch.uarttimejishu = 0;
    Uartwatch.uartre[Uartwatch.uartjia++] = UT_DR;
}

void UART1deal()
{
    static uint8 aa[6] = 0;
    uint8 ii = 0;
    
    if (Uartwatch.uarttimejishu >= 30 && Uartwatch.uartjia != 0)
    {
        if ((Uartwatch.uartre[0] == 'T') && (Uartwatch.uartre[1] == ':') && (Uartwatch.uartre[Uartwatch.uartjia - 1] == 0x0A))
        {
            if (Uartwatch.uartre[2] == '1')
            {
                Uartwatch.fast = 1;
            }
            else if (Uartwatch.uartre[2] == '0')
            {
                Uartwatch.fast = 0;
            }
        }
        else if ((Uartwatch.uartre[0] == 'S') && (Uartwatch.uartre[1] == ':') && (Uartwatch.uartre[Uartwatch.uartjia - 1] == 0x0A))
        {
            for (ii = 0; ii <= 5; ii++)
            {
                aa[ii] = 0;
            }
            
            for (ii = 0; ii <= (Uartwatch.uartjia - 4); ii++)
            {
                aa[ii] = 1;
            }
            
            ConTrolCmd.yajispeed = ((Uartwatch.uartre[Uartwatch.uartjia - 6] & 0x0f) * 10000 * aa[4]) + ((Uartwatch.uartre[Uartwatch.uartjia - 5] & 0x0f) * 1000 * aa[3])
                + ((Uartwatch.uartre[Uartwatch.uartjia - 4] & 0x0f) * 100 * aa[2]) + ((Uartwatch.uartre[Uartwatch.uartjia - 3] & 0x0f) * 10 * aa[1]) + (Uartwatch.uartre[Uartwatch.uartjia - 2] & 0x0f) * aa[0];
        }
        
        Uartwatch.uartjia = 0;
    }
}


void trace1()
{
    static uint8 ii = 0;
    
    if (Uartwatch.cunflag == 1)
    {
        ii++;
        Uartwatch.jiajia++;
        Uartwatch.buff1[ii] = VoltageComp.testUq4; //Uartwatch.jiajia;
        Uartwatch.buff2[ii] = VoltageComp.mcDcbus;
        Uartwatch.buff3[ii] = FOC__ID;
    }
    
    if (ii >= (Buge - 1))
    {
        ii = 0;
        Uartwatch.jiajia = 0;
        Uartwatch.faflag = 1;
        Uartwatch.cunflag = 0;
    }
}
extern uint16 AimFrequencyMaxVAC;



