Exemplo n.º 1
0
// Quick way to send a message
int IpcQuickSend( uint tid, uint cmd, uint arg1, uint arg2 )
{
	Message msg;
	RtlZeroMemory( &msg, sizeof(Message) );
	msg.ThreadId = tid;
	msg.Command = cmd;
	msg.Arguments[0] = arg1;
	msg.Arguments[1] = arg2;
	return IpcSend( &msg, 0 );
}
Exemplo n.º 2
0
bool polling_disable()
{
    IPC_IntPayload_t m;

    m.hdr.type   = IPC_CSC_DETECTION_DISABLE;
    m.hdr.source = APP_TASK;
    m.data       = 0;

    if (IpcSend(IpcGetID(APP_TASK), &m, sizeof(m)) == -1)
         return false;

    return true;
}
Exemplo n.º 3
0
// Receive a message
//发送后,等待对方处理完毕,超时返回负值
int	IpcCall( 
	Message*	usermsg, 	//消息正文
	uint		flag,		//发送参数
	int		timeout		//超时值
){
	int ret = IpcSend( usermsg, flag );
	if( ret!=0 || timeout==0 )
		return ret;
	TmSleepThread( TmGetCurrentThread(), timeout );
	//determine if we have got the reply message
	//PERROR("## waring!, not implemented.");
	return 0;
}
Exemplo n.º 4
0
Arquivo: system.c Projeto: Ga-vin/sgos
static int Reply(Message* msg, int code)
{
	msg->Code = (uint)code;
	return IpcSend( msg, 0 );
}
Exemplo n.º 5
0
bool config_setLocation( int argc, const char *argv[], void *data )
{
    #define configSetLocation_RouteId       0
    #define configSetLocation_StopId        1
    #define configSetLocation_EntryPointId  2
    #define configSetLocation_Unavailable   3

    const char             *rtId            = argv[ configSetLocation_RouteId ];
    const char             *stopId          = argv[ configSetLocation_StopId  ];
    const char             *epId            = argc >= ( configSetLocation_EntryPointId + 1 ) ? argv[ configSetLocation_EntryPointId ] : NULL;
    const char             *locUnav         = argc >= ( configSetLocation_Unavailable  + 1 ) ? argv[ configSetLocation_Unavailable  ] : NULL;
    bool                    ret             = false;
    unsigned long           id              = 0;
    char                    waste           = 0;
    MYKI_BR_ContextData_t  *pContextData    = GetCardProcessingThreadContextData();
    IPC_IntPayload_t        ipcSetLocation;
    int                     nLineId         = pContextData->DynamicData.lineId;
    int                     nStopId         = pContextData->DynamicData.stopId;
    int                     nEntryPointId   = pContextData->DynamicData.entryPointId;
    bool                    locAvailable    = true;
    int                     nResult         = 0;
    int                     AppQueueId      = IpcGetID( APP_TASK );

    CsDebug( 9, ( 9, "Set location to %s, %s, %s, %s",
        ( rtId    == NULL ? "(null)" : rtId    ),
        ( stopId  == NULL ? "(null)" : stopId  ),
        ( epId    == NULL ? "(null)" : epId    ),
        ( locUnav == NULL ? "(null)" : locUnav ) ) );

    memset( &ipcSetLocation, 0, sizeof( ipcSetLocation ) );

#define SETVALUE(INPUT, OUTPUT, MAXVALUE, DESC) \
    if ( INPUT != 0 && INPUT[0] != '-' ) \
    { \
        if ( sscanf(INPUT, "%ld%c", &id, &waste) != 1 || id > (unsigned long)(MAXVALUE) ) \
        { \
            CsDebug(9, (9, "Invalid %s '%s'", DESC, INPUT)); \
        } \
        else \
        { \
            OUTPUT = id; \
            CsDebug(9, (9, "Successfully set %s to '%s', %d", DESC, INPUT, int(OUTPUT))); \
            ret = true; \
        } \
    } \
    else \
    { \
        CsDebug(9, (9, "Default %s is %d", DESC, (int)OUTPUT)); \
    }
    SETVALUE( rtId,   nLineId,       0xffff,     "route ID"       );
    SETVALUE( stopId, nStopId,       0xff,       "stop ID"        );
    SETVALUE( epId,   nEntryPointId, 0x7fffffff, "entry point ID" );
#undef SETVALUE

    if ( ret == true )
    {
        pContextData->DynamicData.entryPointId  = nEntryPointId;

        if ( locUnav != NULL )
        {
            locAvailable   =
                ( 
                    locUnav[ 0 ] == 't' || locUnav[ 0 ] == 'T' ||   /*  [Tt]rue */
                    locUnav[ 0 ] == 'y' || locUnav[ 0 ] == 'Y' ||   /*  [Yy]es */
                    locUnav[ 0 ] == '1'
                )   ? false : true;
        }

        ipcSetLocation.hdr.type     = IPC_SET_LOCATION;
        ipcSetLocation.hdr.source   = APP_TASK;
        ipcSetLocation.data         = (   nLineId               & 0x0000ffff ) |
                                      ( ( nStopId << 16 )       & 0x00ff0000 ) |
                                      ( ( locAvailable != false ? 0x80000000 : 0x00000000 ) );

        if ( ( nResult = IpcSend( AppQueueId, &ipcSetLocation, sizeof( ipcSetLocation ) ) ) != 0 )
        {
            CsErrx( "config_setLocation : IpcSend failed (%d)", nResult );
            ret = false;
        }
    }

    return ret;
}
Exemplo n.º 6
0
//#define ____DEBUG_SERIAL_
//#define _DEBUG_SERIAL_
int SerialClass::Read(void)
{
	int	fd;

	if (m_commHandle == INVALID_COMMS_HANDLE)
		OpenPort();

	fd = CommGetDescriptor(m_commHandle);
	if (fd == -1)
	{
        CsErrx("SerialClass::Read: file handle %d is not valid, cannot select/read", m_commHandle);
        return  COMMSERIAL_FAILURE;
	}
    
    // Call timeout
    if(m_timeoutCallback)
        m_timeoutCallback(m_noCommsTimer);

	while (1)
	{
		struct timeval tv;
		fd_set fdset;
    	int ret;

        FD_ZERO(&fdset);
        FD_SET(fd, &fdset);

		tv.tv_sec  = 0;
		tv.tv_usec = 5* 1000 * 1000; // MAGIC 5 seconds

#if defined(____DEBUG_SERIAL_)    
        CsDebug(5, (5, "SerialClass::Read: begin select on h:(%d[%d])", m_commHandle, fd));
#endif
        ret = select(fd + 1, &fdset, NULL, NULL, &tv);

        switch (ret) {
		case -1:
			/* error */
			if (errno != EAGAIN && errno != EINTR)
			{
				CsDebug(1, (1, "SerialClass::Read: error %d on select", errno));
                
                
                CsDebug(1, (1, "SerialClass::Read: closing port and reopen after wait"));
                ClosePort();
				
				usleep(1000000); // Reopen in 1 sec, TODO set in #define 
				
				// re-open it
				CsDebug(1, (1, "SerialClass::Read: re-opening port"));
				OpenPort();
			}
			else
			{
#if defined(_DEBUG_SERIAL_)
				CsDebug(5, (5, "SerialClass::Read: an expected early return %d on select", errno));
#endif
			}
			continue;

		case 0:
			/* no data, timed out */
#if defined(____DEBUG_SERIAL_)
			CsDebug(1, (9, "SerialClass::Read: timeout on select"));
#endif
			continue;

		default:
			/* got data, read it */
            
			break;
        }

		if (FD_ISSET(fd, &fdset))
		{
			int BytesRead;
			#define READBUFFERSIZE	64
			char	buf[ IPC_GENERIC_SIZE(READBUFFERSIZE) ];
			IPC_Generic_t *pMsg = (IPC_Generic_t *)buf;

			BytesRead = read(fd, pMsg->data, READBUFFERSIZE);
			CsDebug(8, (8, "SerialClass::Read(%d):%d", fd, BytesRead));

			if (BytesRead <=0)
			{
                if(BytesRead ==0)
                    CsDebug(7, (7, "SerialClass::Read: EOF returned, closing port;"));
                else
                    CsDebug(7, (7, "SerialClass::Read: fatal error returned, closing port;"));
				ClosePort();
				
                // Report timeout to running application
                if(m_timeoutCallback)
                    m_timeoutCallback(m_noCommsTimer);
                
				usleep(100*1000);
				
				// re-open it
				CsDebug(7, (7, "SerialClass::Read: re-opening port"));
				OpenPort();
				continue;
			}
            else
            {   
                pMsg->hdr.type    = m_reportRecieveCharacter_MessageId;
                pMsg->hdr.source  = m_reportRecieveCharacter_SourceQueueId;
                pMsg->len = BytesRead;

                CsDebug(5, (5, "SerialClass::Read: got %u characters", BytesRead));
                if ((ret = IpcSend(m_queueId, pMsg, IPC_GENERIC_SIZE(BytesRead))) != 0)
                    CsErrx("SerialClass::Read: failed to report rx-data-available to main thread");                 
            }
            
		}
		else // if (FD_ISSET(pipefd, &fdset))
		{
			CsErrx("SerialClass::Read: unexpected unblock of select()");
		}
	}
	/*NOTREACHED*/

	return 0;
}