Ejemplo n.º 1
0
int
_cdk_filter_text( void * opaque, int ctl, FILE * in, FILE * out )
{
    if( ctl == STREAMCTL_READ )
        return text_encode( opaque, in, out );
    else if( ctl == STREAMCTL_WRITE )
        return text_decode( opaque, in, out );
    else if( ctl == STREAMCTL_FREE ) {
        text_filter_t * tfx = opaque;
        if( tfx ) {
            _cdk_log_debug( "free text filter\n" );
            tfx->lf = NULL;
        }
    }
    return CDK_Inv_Mode;
}
Ejemplo n.º 2
0
int16_t cmd_decode (void)
{

 uint8_t  cmd_no =0;
 uint8_t  *cmd_argument;
 uint8_t  *buffer_ptr;
 uint8_t   i;
 
// Should repeat until end of buffer
 
// Loop until end of text

   buffer_ptr   = g_rcv_buff;
   cmd_argument = g_rcv_buff;
     
   while ( cmd_no !=  CMD_LINE_END)     // Until end of line which mean g_motor will change
   {
 		cmd_no =  text_decode (buffer_ptr,cmd_argument);
#ifdef DEBUG		
		uart_puts("Command :");
		uart_putc(0x30+cmd_no);
		uart_putc('*');
		uart_puts(cmd_argument);
#endif        
 		switch (cmd_no)
		{
			case MOTOR_CMD: 
				g_motor = (uint8_t)atoi(cmd_argument);
				if (g_motor > 0)
				   g_motor--;                //  > 0 Start from 0 need -1
				else
				   g_motor = 0;
 
 				break;
			case  SPEED_CMD:	
				i = (uint8_t)atoi(cmd_argument);
				if ( i >=  MOTOR_MAX)
						i = MOTOR_MAX-1;    // Start from 0
				g_speed[g_motor] =  g_speed_table[i];
  				break;
			case  ANGLE_CMD:   // Can be - 
				g_angle[g_motor] = atoi(cmd_argument);
				if (g_angle[g_motor] < 0)
				{   
						g_mode[g_motor] = MOTOR_BACKWARD;
// Set g_angle to positive value by invert all bit and +1                
                        g_angle[g_motor] = (~(g_angle[g_motor])+1);
                        if  (g_angle[g_motor] > 1)
						{
 						   g_angle[g_motor] *= MOTOR_ANGLE_COEF;
						   g_speed[g_motor] = g_speed_table[MOTOR_ANGLE_SPEED] ;
						}		
				}	
				else  if (g_angle[g_motor] == 0)
				        g_mode[g_motor] = MOTOR_STOP;
				else	  
				{
					if ((g_angle[g_motor] > 0))   //  +
						g_mode[g_motor] = MOTOR_FORWARD;
					if  (g_angle[g_motor] > 1)
					{
 						g_angle[g_motor] *=  MOTOR_ANGLE_COEF;	
						   g_speed[g_motor] = g_speed_table[MOTOR_ANGLE_SPEED] ;
					}
 				}
				break;	
 			default:
			    uart_puts("Command not found ");
 		        break;	  
		}		
    }
 return 0; 
}
Ejemplo n.º 3
0
int16_t cmd_decode (uint8_t *buffer_ptr)
{

 uint8_t  cmd_no =0;
 uint8_t  *cmd_argument;
 uint8_t   i,j ;
 
// Should repeat until end of buffer
 
// Loop until end of text

   cmd_argument = buffer_ptr;
     
   while ( cmd_no !=  CMD_LINE_END)     // Until end of line which mean g_motor will change
   {
 		cmd_no =  text_decode (buffer_ptr,cmd_argument);
#ifdef DEBUG		
		uart_puts("Command :");
 		uart_putc(0x30+cmd_no);
 		uart_putc('*');
 		uart_puts(cmd_argument);
#endif        
 		switch (cmd_no)
		{
			case MOTOR_CMD: 
				g_motor = (uint8_t)atoi(cmd_argument);
				if (g_motor > 0)
				   g_motor--;                //  > 0 Start from 0 need -1
				else
				   g_motor = 0;
 				break;
			case  SPEED_CMD:	
				i = (uint8_t)atoi(cmd_argument);
				if ( i >=  MOTOR_MAX_SPEED)
						i = MOTOR_MAX_SPEED;    // Start from 0
				if (i)   // i > 0; 		
					i--;   //Start from 0;		
				g_speed[g_motor] =  g_speed_table[i];
				if (g_speed[g_motor] == 0)
				        g_mode[g_motor] = MOTOR_STOP;
  				break;
			case  ANGLE_CMD:   // Can be - 	             			 
     			g_angle[g_motor] = atoi(cmd_argument);
				if (g_angle[g_motor] < 0)
				{   
						g_mode[g_motor] = MOTOR_BACKWARD;
 
// Set g_angle to positive value by invert all bit and +1                
                        g_angle[g_motor] = (~(g_angle[g_motor])+1);
                        if  (g_angle[g_motor] > 1)
						{
 						   g_angle[g_motor] *= MOTOR_ANGLE_COEF;
						   g_status[g_motor] = 1;
 						   g_speed[g_motor] = g_speed_table[MOTOR_ANGLE_SPEED] ;
						}		
				}	
				else  if (g_angle[g_motor] == 0)
				       {  	
							g_mode[g_motor] = MOTOR_STOP;
 					   }
				else	  
				{
					if ((g_angle[g_motor] > 0))   //  +
					{
						g_mode[g_motor] = MOTOR_FORWARD;
 					}
					if  (g_angle[g_motor] > 1)
					{
 						g_angle[g_motor] *=  MOTOR_ANGLE_COEF;	
						g_status[g_motor] = 1;
  						g_speed[g_motor]  = g_speed_table[MOTOR_ANGLE_SPEED] ;
					}
 				}
                g_pos[g_motor] = 0;
				break;	
			case PROGRAM_CMD:
				g_program_flag = (uint8_t)atoi(cmd_argument);
				if (g_program_flag)   // Start  program save in buffer
				{
					uart_puts ("Program Start to save : ");
				     g_program_index = 0;
				}
				else
				{  
					uart_puts ("Program End : ");
				}
				break;
 			case SAVE_CMD:
				j = (uint8_t)atoi(cmd_argument);
				if ( j > 0)    // Save commmand to eeprom
                {
					g_program_buff[g_program_index] = 0x00 ;  // Put null at the end
                    g_program_index++;   
                    for ( i =0; i < g_program_index; i++)
                    {
						while (!eeprom_is_ready());
							eeprom_write_byte(&g_program_eeprom[i],g_program_buff[i]);
					}
					debug_value( g_program_index,10);
					uart_puts ("Save complete ");
					g_program_index = 0;	
				}
				break;
		    case RUN_CMD:
			    program_run();
			    break;
 			default:
			    uart_putc(0x0D);
				uart_putc(0x0A);
 		        break;	  
		}		
    }
 
 return 0; 
}
Ejemplo n.º 4
0
int16_t cmd_decode (void)
{

    uint8_t  cmd_no =0;
    uint8_t  *cmd_argument;
    uint8_t  *buffer_ptr;


// Should repeat until end of buffer

// Loop until end of text

    buffer_ptr   = g_rcv_buff;
    cmd_argument = g_rcv_buff;

    while ( cmd_no !=  CMD_LINE_END)
    {
        cmd_no =  text_decode (buffer_ptr,cmd_argument);
//		debug_value (cmd_no,10);
        uart_puts("Command :");
        uart_putc(0x30+cmd_no);
        uart_putc('*');
        uart_puts(cmd_argument);

        switch (cmd_no)
        {
        case MOTOR_CMD:
            g_motor = (uint8_t)atoi(cmd_argument);
            if (g_motor > 0)
                g_motor--;                //  > 0 Start from 0 need -1
            else
                g_motor = 0;
            g_motor_change[g_motor] =1;
            break;
        case  SPEED_CMD:
            g_speed[g_motor] = (uint8_t)atoi(cmd_argument);
            g_motor_change[g_motor] = 1;
            break;
        case  ANGLE_CMD:   // Can be -
            g_angle[g_motor] = atoi(cmd_argument);
            if (g_angle[g_motor] < 0)
            {
                g_mode[g_motor] = MOTOR_BACKWARD;
// Set g_angle to positive value by invert all bit and +1
                g_angle[g_motor] = (~(g_angle[g_motor])+1);

            }
            else  if (g_angle[g_motor] == 0)
                g_mode[g_motor] = MOTOR_STOP;
            else
            {
                if ((g_angle[g_motor] > 0))   //  +
                    g_mode[g_motor] = MOTOR_FORWARD;
            }
            g_motor_change[g_motor] = 1;
            break;
        default:
            uart_puts("Command not found ");
            break;
        }
    }
    return 0;
}