#include "r12ds.h"
#include "cmsis_os.h"
#include "user_task.h"
#include <string.h>


#ifdef r12ds_t

#ifdef DEBUG

CMD_RC_t cmd_rc;

uint8_t sbus_rx_buf[2][RC_FRAME_LENGTH];

#else 

static CMD_RC_t cmd_rc;

#endif



CMD_RC_t *R12ds_DataGet(){
	return &cmd_rc; 
}


//void R12ds_HandleOffline(void) {
//	 CMD_RC_t *rc;
//	 rc = R12ds_DataGet();

//  memset(rc, 0, sizeof(*rc));
//  rc->offline  = 1;//用作遥控器断电后急停使用
//}

#endif
	
void Task_r12ds(void *argument)
{
   (void)argument;
	
#ifdef r12ds_t

  const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_R12DS;
    R12ds_DMA_Init(sbus_rx_buf[0],sbus_rx_buf[1],50);
	
      uint32_t tick = osKernelGetTickCount();
   while (1)
   {
#ifdef DEBUG
		 
    task_runtime.stack_water_mark.r12ds =
        osThreadGetStackSpace(osThreadGetId());
		 
#endif
		 
//      if(R12Buf0_WaitDmaCplt(1))
//			{
			 sbus_to_rc(sbus_rx_buf[0],&cmd_rc);
//		   R12ds_HandleOffline();
//			}
//		  else if(R12Buf1_WaitDmaCplt(1))	
//			{
//				sbus_to_rc(sbus_rx_buf[1],&cmd_rc);
//			}
      osMessageQueueReset(task_runtime.msgq.cmd.raw.rc);
	    osMessageQueuePut(task_runtime.msgq.cmd.raw.rc,(&cmd_rc),0,0);
	 
	 	tick += delay_tick; /* 计算下一个唤醒时刄1ķ*/
		 osDelay(10);
   }


#endif

    
 }
