#include "Cyton_DataPkg.h"
#include "usart.h"	
#include <string.h>
#include "delay.h"       
#include "led.h"       
#include "key.h"
#include "Timer.h"
#include "ADS129x.h"

#include "myQueue.h"

#define CYTON__DATA_PKG_BUF_LEN    (33)


static uint8_t aucSampNumber = 0;

void Cyton_DataPkg_ClearSampNum()
{
    aucSampNumber = 0;
}

int Cyton_DataFormat2Package(uint8_t *pszData, uint32_t pszDataChannel[], uint8_t aucChannelCnt)
{
    uint8_t *pszIndex = pszData;
    int iChannelIndex = 0;
    static uint8_t test = 0;

    *pszIndex++ = 0xA0;
    *pszIndex++ = aucSampNumber++;

    /* Channel 0 - 8 */
    while (iChannelIndex < aucChannelCnt) {
        *pszIndex++ = test++;
        *pszIndex++ = test++;
        *pszIndex++ = test++;
        iChannelIndex ++;
    }

    *pszIndex++ = 0x00;
    *pszIndex++ = 0x00;
    *pszIndex++ = 0x00;
    *pszIndex++ = 0x00;
    *pszIndex++ = 0x00;
    *pszIndex++ = 0x00;
    *pszIndex++ = 0xC0;
    
    return (pszIndex - pszData);
}

int Cyton_GetDataPkg_Len()
{
    return CYTON__DATA_PKG_BUF_LEN;
}