Exemple #1
0
//
// included from /usr/include/linux/serial.h
//
//  struct serial_icounter_struct {
//  	int cts, dsr, rng, dcd;
//  	int rx, tx;
//  	int frame, overrun, parity, brk;
//  	int buf_overrun;
//  	int reserved[9];
//  };
//
int wxSerialPort::Ioctl(int cmd, void* args)
{
    int count = 0;
    int err = 0;
   // struct serial_icounter_struct info;
    wxSerialPort_EINFO einfo;

    switch(cmd) {
    case CTB_RESET:
	   return SendBreak(0);
    case CTB_SER_GETEINFO:
/*
	   err = ioctl(fd,TIOCGICOUNT,&info);
	   if(err) return err;
	   einfo.brk = info.brk - save_info.brk;
	   einfo.frame = info.frame - save_info.frame;
	   einfo.overrun = info.overrun - save_info.overrun;
	   einfo.parity = info.parity - save_info.parity;
	   *(wxSerialPort_EINFO*)args = einfo;
*/
	   break;
    case CTB_SER_GETBRK:
/*
	   err = ioctl(fd,TIOCGICOUNT,&info);
	   if(err) return err;
	   if(last_info.brk != info.brk) count = 1;
*/
	   break;
    case CTB_SER_GETFRM:
/*
	   err = ioctl(fd,TIOCGICOUNT,&info);
	   if(err) return err;
	   if(last_info.frame != info.frame) count = 1;
*/
	   break;
    case CTB_SER_GETOVR:
/*
	   err = ioctl(fd,TIOCGICOUNT,&info);
	   if(err) return err;
	   if(last_info.overrun != info.overrun) count = 1;
*/
	   break;
    case CTB_SER_GETPAR:
/*
	   err = ioctl(fd,TIOCGICOUNT,&info);
	   if(err) return err;
	   if(last_info.parity != info.parity) count = 1;
*/
	   break;
    case CTB_SER_GETINQUE:
	   err = ioctl(fd, FIONREAD,&count);
	   if(err) return err;
	   *(int*)args = count;
	   return 0;
    default:
	   return -1;
    }
//    last_info = info;
    return 0;
};
Exemple #2
0
int wxSerialPort::Ioctl(int cmd,void* args)
{
    COMSTAT comstat;
    DWORD errors;
    int result = 0;
    bool brk;
    switch(cmd) {
    case CTB_RESET:
	   return SendBreak(0);
    case CTB_SER_GETEINFO:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  // actualize the last events
		  if(errors & CE_BREAK) einfo.brk++;
		  if(errors & CE_FRAME) einfo.frame++;
		  if(errors & CE_OVERRUN) einfo.overrun++;
		  if(errors & CE_RXPARITY) einfo.parity++;
		  *(wxSerialPort_EINFO*)args = einfo;
		  return 0;
	   }
    case CTB_SER_GETBRK:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  if(errors & CE_BREAK) result = 1;
		  einfo.brk += result;
		  *(int*)args = result;
		  return 0;
	   }
	   break;
    case CTB_SER_GETFRM:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  if(errors & CE_FRAME) result = 1;
		  einfo.frame += result;
		  *(int*)args = result;
		  return 0;
	   }
    case CTB_SER_GETOVR:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  if(errors & CE_OVERRUN) result = 1;
		  einfo.overrun += result;
		  *(int*)args = result;
		  return 0;
	   }
	   break;
    case CTB_SER_GETPAR:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  if(errors & CE_RXPARITY) result = 1;
		  einfo.parity += result;
		  *(int*)args = result;
		  return 0;
	   }
	   break;
    case CTB_SER_GETINQUE:
	   if(ClearCommError(fd,&errors,&comstat)) {
		  *(int*)args = (int)comstat.cbInQue;
		  return 0;
	   }
	   break;
    }
    // error or unknown command
    return -1;
};
Exemple #3
0
//*****************************************************************************
//
// Handles CDC driver notifications related to control and setup of the device.
//
// \param pvCBData is the client-supplied callback pointer for this channel.
// \param ui32Event identifies the event we are being notified about.
// \param ui32MsgValue is an event-specific value.
// \param pvMsgData is an event-specific pointer.
//
// This function is called by the CDC driver to perform control-related
// operations on behalf of the USB host.  These functions include setting
// and querying the serial communication parameters, setting handshake line
// states and sending break conditions.
//
// \return The return value is event-specific.
//
//*****************************************************************************
uint32_t
ControlHandler(void *pvCBData, uint32_t ui32Event,
               uint32_t ui32MsgValue, void *pvMsgData)
{
    uint32_t ui32IntsOff;

    //
    // Which event are we being asked to process?
    //
    switch(ui32Event)
    {
        //
        // We are connected to a host and communication is now possible.
        //
        case USB_EVENT_CONNECTED:
            g_bUSBConfigured = true;

            //
            // Flush our buffers.
            //
            USBBufferFlush(&g_sTxBuffer);
            USBBufferFlush(&g_sRxBuffer);

            //
            // Tell the main loop to update the display.
            //
            ui32IntsOff = ROM_IntMasterDisable();
            g_pcStatus = "Connected";
            g_ui32Flags |= COMMAND_STATUS_UPDATE;
            if(!ui32IntsOff)
            {
                ROM_IntMasterEnable();
            }
            break;

        //
        // The host has disconnected.
        //
        case USB_EVENT_DISCONNECTED:
            g_bUSBConfigured = false;
            ui32IntsOff = ROM_IntMasterDisable();
            g_pcStatus = "Disconnected";
            g_ui32Flags |= COMMAND_STATUS_UPDATE;
            if(!ui32IntsOff)
            {
                ROM_IntMasterEnable();
            }
            break;

        //
        // Return the current serial communication parameters.
        //
        case USBD_CDC_EVENT_GET_LINE_CODING:
            GetLineCoding(pvMsgData);
            break;

        //
        // Set the current serial communication parameters.
        //
        case USBD_CDC_EVENT_SET_LINE_CODING:
            SetLineCoding(pvMsgData);
            break;

        //
        // Set the current serial communication parameters.
        //
        case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE:
            SetControlLineState((uint16_t)ui32MsgValue);
            break;

        //
        // Send a break condition on the serial line.
        //
        case USBD_CDC_EVENT_SEND_BREAK:
            SendBreak(true);
            break;

        //
        // Clear the break condition on the serial line.
        //
        case USBD_CDC_EVENT_CLEAR_BREAK:
            SendBreak(false);
            break;

        //
        // Ignore SUSPEND and RESUME for now.
        //
        case USB_EVENT_SUSPEND:
        case USB_EVENT_RESUME:
            break;

        //
        // We don't expect to receive any other events.  Ignore any that show
        // up in a release build or hang in a debug build.
        //
        default:
#ifdef DEBUG
            while(1);
#else
            break;
#endif

    }

    return(0);
}
//*****************************************************************************
//
// Handles CDC driver notifications related to control and setup of the device.
//
// \param pvCBData is the client-supplied callback pointer for this channel.
// \param ulEvent identifies the event we are being notified about.
// \param ulMsgValue is an event-specific value.
// \param pvMsgData is an event-specific pointer.
//
// This function is called by the CDC driver to perform control-related
// operations on behalf of the USB host.  These functions include setting
// and querying the serial communication parameters, setting handshake line
// states and sending break conditions.
//
// \return The return value is event-specific.
//
//*****************************************************************************
uint32_t
ControlHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,
               void *pvMsgData)
{
    //
    // Which event are we being asked to process?
    //
    switch(ui32Event)
    {
        //
        // We are connected to a host and communication is now possible.
        //
        case USB_EVENT_CONNECTED:
        {
            //
            // Now connected and ready for normal operation.
            //
            HWREGBITW(&g_ui32Flags, FLAG_USB_CONFIGURED) = 1;

            //
            // Flush our buffers.
            //
            USBBufferFlush(&g_sTxBuffer);
            USBBufferFlush(&g_sRxBuffer);

            //
            // Tell the main loop to update the display.
            //
            g_pcStatus = "Host connected.";

            //
            // Set the command status update flag.
            //
            HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE) = 1;

            break;
        }

        //
        // The host has disconnected.
        //
        case USB_EVENT_DISCONNECTED:
        {
            //
            // No longer connected.
            //
            HWREGBITW(&g_ui32Flags, FLAG_USB_CONFIGURED) = 0;

            g_pcStatus = "Host disconnected.";

            //
            // Set the command status update flag.
            //
            HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE) = 1;

            break;
        }

        //
        // Return the current serial communication parameters.
        //
        case USBD_CDC_EVENT_GET_LINE_CODING:
        {
            GetLineCoding(pvMsgData, UART_CLOCK);
            break;
        }

        //
        // Set the current serial communication parameters.
        //
        case USBD_CDC_EVENT_SET_LINE_CODING:
        {
            SetLineCoding(pvMsgData, UART_CLOCK);
            break;
        }

        //
        // Set the current serial communication parameters.
        //
        case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE:
        {
            SetControlLineState((uint16_t)ui32MsgValue);
            break;
        }

        //
        // Send a break condition on the serial line.
        //
        case USBD_CDC_EVENT_SEND_BREAK:
        {
            SendBreak(true);
            break;
        }

        //
        // Clear the break condition on the serial line.
        //
        case USBD_CDC_EVENT_CLEAR_BREAK:
        {
            SendBreak(false);
            break;
        }

        //
        // Ignore SUSPEND and RESUME for now.
        //
        case USB_EVENT_SUSPEND:
        case USB_EVENT_RESUME:
        {
            break;
        }

        //
        // We don't expect to receive any other events.  Ignore any that show
        // up in a release build or hang in a debug build.
        //
        default:
        {
#ifdef DEBUG
            while(1);
#else
            break;
#endif
        }

    }

    return(0);
}
//*****************************************************************************
//
// Handles CDC driver notifications related to control and setup of the device.
//
// \param pvCBData is the client-supplied callback pointer for this channel.
// \param ulEvent identifies the notification event.
// \param ulMsgValue is an event-specific value.
// \param pvMsgData is an event-specific pointer.
//
// This function is called by the CDC driver to perform control-related
// operations on behalf of the USB host.  These functions include setting
// and querying the serial communication parameters, setting handshake line
// states and sending break conditions.
//
// \return The return value is event-specific.
//
//*****************************************************************************
unsigned long
ControlHandler(void *pvCBData, unsigned long ulEvent, unsigned long ulMsgValue,
               void *pvMsgData)
{
    //
    // Which event was sent?
    //
    switch(ulEvent)
    {
        //
        // The host has connected.
        //
        case USB_EVENT_CONNECTED:
        {
            //
            // Turn on the user LED.
            //
            GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_0);

            //
            // Flush the buffers.
            //
            USBBufferFlush(&g_sTxBuffer);
            USBBufferFlush(&g_sRxBuffer);

            break;
        }

        //
        // The host has disconnected.
        //
        case USB_EVENT_DISCONNECTED:
        {
            //
            // Turn off the user LED.
            //
            GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);

            break;
        }

        //
        // Return the current serial communication parameters.
        //
        case USBD_CDC_EVENT_GET_LINE_CODING:
        {
            GetLineCoding(pvMsgData);
            break;
        }

        //
        // Set the current serial communication parameters.
        //
        case USBD_CDC_EVENT_SET_LINE_CODING:
        {
            SetLineCoding(pvMsgData);
            break;
        }

        //
        // Set the current serial communication parameters.
        //
        case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE:
        {
            break;
        }

        //
        // Send a break condition on the serial line.
        //
        case USBD_CDC_EVENT_SEND_BREAK:
        {
            SendBreak(true);
            break;
        }

        //
        // Clear the break condition on the serial line.
        //
        case USBD_CDC_EVENT_CLEAR_BREAK:
        {
            SendBreak(false);
            break;
        }

        //
        // Ignore SUSPEND and RESUME for now.
        //
        case USB_EVENT_SUSPEND:
        case USB_EVENT_RESUME:
        {
            break;
        }

        //
        // Other events can be safely ignored.
        //
        default:
        {
            break;
        }
    }

    return(0);
}
Exemple #6
0
void handleSpecialChars(int iVal, void *pArg1, void *pArg2)
{
   if (iVal == BREAK)
      SendBreak(pDevc->mfd);
}
Exemple #7
0
int GLLegoPIR::set( int addr, int drivemode, int v, int v_max, int fn[] )
{
	//range check
	if ( v > v_max )
		v = v_max;
	if ( v < 0 )
		v = 0;

	//map to 0..7
	v = map( v, 0, v_max, 0, 7 );

	
	if (drivemode == 2) //emergency break
	{
		SendBreak();
		
		//reset speeds
		m_desired_speed = 0;
		m_current_speed = 0;
	}
	else
	{
		//if reverse -> -
		if (drivemode == 0)
			v = -v;
		
		//set desired speed to calculated speed
		m_desired_speed = v;
	
		//if current and desired speed is the same -> send now
		if (m_desired_speed == m_current_speed)
		{
			SendSpeed(m_desired_speed);
		}
		else //different desired/current speed -> check for 0 delay
		{
			if (m_current_speed < m_desired_speed) //we are slower -> accelerate
			{
				if (m_acc == 0) //no delay -> set it now
				{
					m_current_speed = m_desired_speed;
					SendSpeed(m_current_speed);
				}
				else 
				{
#ifdef PIR_SEND_FIRST_STEP_IMMEDIATE //we have delay but want to send first immediately
					++m_current_speed;
					SendSpeed(m_current_speed);
#endif
				}
			}
			else if (m_current_speed > m_desired_speed) //we are faster -> decelerate
			{
				if (m_dec == 0) //no delay -> set it now
				{
					m_current_speed = m_desired_speed;
					SendSpeed(m_current_speed);
				}
				else
				{
#ifdef PIR_SEND_FIRST_STEP_IMMEDIATE //we have delay but want to send first immediatly
					--m_current_speed;
					SendSpeed(m_current_speed);
#endif
				}
			}
			
		}
	}

	m_last_time = millis(); //save time

	return (200);
}
Exemple #8
0
void GLLegoPIR::setPower( int on )
{
	if (on == 0)
		SendBreak();
}
Exemple #9
0
/******************************************************************************
*																			  *
* \brief  Handles CDC driver notifications related to control and setup of    *
*         the device.\n                                                       *
*                                                                             *
* \param pvCBData is the client-supplied callback pointer for this channel.   *
*																		      *
* \param ulEvent identifies the event we are being notified about.            *
*																		      *
* \param ulMsgValue is an event-specific value.                               *
*																		      *
* \param pvMsgData is an event-specific pointer.                              *
*																		      *
* \return The return value is event-specific.                                 *
*                                                                             *
******************************************************************************/
unsigned int ControlHandler(void *pvCBData, unsigned int ulEvent,
                            unsigned int ulMsgValue, void *pvMsgData)
{
    unsigned char ulIntsOff;

    
    /* Which event are we being asked to process? */
    
    switch(ulEvent)
    {
        
        /* We are connected to a host and communication is now possible. */
        
        case USB_EVENT_CONNECTED:
            
            /* Flush our buffers. */
            
            USBBufferFlush(&g_sTxBuffer);
            USBBufferFlush(&g_sRxBuffer);
            ulIntsOff = IntDisable();
            g_pcStatus = "Host connected.";
            g_ulFlags |= COMMAND_STATUS_UPDATE;
			IntEnable(ulIntsOff);
            break;

        
        /* The host has disconnected. */
        
        case USB_EVENT_DISCONNECTED:

            ulIntsOff = IntDisable();
            g_pcStatus = "Host disconnected.";
            g_ulFlags |= COMMAND_STATUS_UPDATE;
         	IntEnable(ulIntsOff);
            break;

        
        /* Return the current serial communication parameters. */
        
        case USBD_CDC_EVENT_GET_LINE_CODING:
            GetLineCoding(pvMsgData);
            break;

        
        /* Set the current serial communication parameters. */
        
        case USBD_CDC_EVENT_SET_LINE_CODING:
            SetLineCoding(pvMsgData);
            break;

        /* Set the current serial communication parameters. */
        
        case USBD_CDC_EVENT_SET_CONTROL_LINE_STATE:
            SetControlLineState((unsigned short)ulMsgValue);
            break;
        
        /* Send a break condition on the serial line.*/
        
        case USBD_CDC_EVENT_SEND_BREAK:
            SendBreak(true);
            break;
        
        /* Clear the break condition on the serial line. */
        
        case USBD_CDC_EVENT_CLEAR_BREAK:
            SendBreak(false);
            break;
       
        /* Ignore SUSPEND and RESUME for now. */
        
        case USB_EVENT_SUSPEND:
        case USB_EVENT_RESUME:
            break;

        /* We don't expect to receive any other events.  Ignore any that show
           up in a release build or hang in a debug build.
        */
        default:
            break;
    }

    return(0);
}