示例#1
0
文件: mpris.c 项目: rcatolino/remote
static void sendTrackStatus(int property_list) {
  if (HAS_TITLE(property_list) && mpris_data->title != NULL) {
    debug("sending title\n");
    transmitMsg(client_socket, pathFromUrl(mpris_data->title),
                strlen(pathFromUrl(mpris_data->title)),
                TRACK_TITLE, TRACK_TITLE_SZ);
  }
  if (HAS_ARTIST(property_list) && mpris_data->artist != NULL) {
    debug("sending artist\n");
    transmitMsg(client_socket, mpris_data->artist, strlen(mpris_data->artist),
                TRACK_ARTIST, TRACK_ARTIST_SZ);
  }
  if (HAS_ALBUM(property_list) && mpris_data->album != NULL) {
    debug("sending album\n");
    transmitMsg(client_socket, mpris_data->album, strlen(mpris_data->album),
                TRACK_ALBUM, TRACK_ALBUM_SZ);
  }
  if (HAS_LENGTH(property_list)) {
    int64_t length = htobe64(mpris_data->length);
    debug("sending length : %ld\n", mpris_data->length);
    transmitMsg(client_socket, (char *)&length, sizeof(int64_t),
                TRACK_LENGTH, TRACK_LENGTH_SZ);
  }
  if (HAS_TRACKID(property_list) && mpris_data->trackid != NULL) {
    debug("sending trackid : %s\n", mpris_data->trackid);
    transmitMsg(client_socket, mpris_data->trackid, strlen(mpris_data->trackid),
                TRACK_ID, TRACK_ID_SZ);
  }
  if (HAS_ARTURL(property_list) && mpris_data->artUrl != NULL) {
    debug("sending arturl\n");
    transmit(client_socket, TRACK_ARTURL, TRACK_ARTURL_SZ);
    transmitFile(client_socket, pathFromUrl(mpris_data->artUrl));
  }
}
示例#2
0
文件: bot.c 项目: Beirdo/beirdobot
void ProcOnRegistered(BN_PInfo I)
{
    bool                found;
    LinkedListItem_t   *item;
    IRCServer_t        *server;
    IRCChannel_t       *channel;

    server = (IRCServer_t *)I->User;

    if( verbose ) {
        LogPrintNoArg( LOG_DEBUG, "Event Registered");
    }

    if( strcmp(server->nickserv, "") ) {
        /* We need to register with nickserv */
        transmitMsg( server, TX_PRIVMSG, server->nickserv, 
                     server->nickservmsg );
    }

    if( server->channels ) {
        LinkedListLock( server->channels );
        for( found = false, item = server->channels->head; 
             item && !found; item = item->next ) {
            channel = (IRCChannel_t *)item;
            if( channel->joined || !channel->enabled ) {
                continue;
            }

            transmitMsg( server, TX_JOIN, channel->channel, NULL );
            found = true;
        }
        LinkedListUnlock( server->channels );
    }
}
示例#3
0
文件: bot.c 项目: Beirdo/beirdobot
void ProcOnJoinChannel(BN_PInfo I, const char Chan[])
{
    bool                found;
    LinkedListItem_t   *item;
    IRCServer_t        *server;
    IRCChannel_t       *channel;

    server = (IRCServer_t *)I->User;
    LogPrint( LOG_NOTICE, "Joined channel %s on server %s", Chan, 
              server->server);

    if( server->channels ) {
        LinkedListLock( server->channels );
        for( found = false, item = server->channels->head; 
             item && !found; item = item->next ) {
            channel = (IRCChannel_t *)item;
            if( channel->joined || !channel->enabled ) {
                continue;
            }

            if( !strcasecmp(Chan, channel->channel) ) {
                channel->joined = TRUE;
                channel->newChannel = FALSE;
                db_flush_nicks( channel );
                continue;
            }

            transmitMsg( server, TX_JOIN, channel->channel, NULL );
            found = true;
        }
        LinkedListUnlock( server->channels );
    }
}
示例#4
0
文件: bot.c 项目: Beirdo/beirdobot
void ProcOnKick(BN_PInfo I, const char Chan[], const char Who[],
                const char Whom[], const char Msg[])
{
    char           *string;
    IRCChannel_t   *channel;
    IRCServer_t    *server;
    char            nick[256];

    string = (char *)malloc(MAX_STRING_LENGTH);
    BN_ExtractNick(Whom, nick, 256);
    sprintf(string, "%s has been kicked from %s by %s (%s)\n", Whom, Chan, Who,
                    Msg);

    server = (IRCServer_t *)I->User;
    channel = FindChannel(server, Chan);
    db_add_logentry( channel, (char *)Who, TYPE_KICK, string, true );
    db_update_nick( channel, nick, false, false );
    db_nick_history( channel, nick, HIST_LEAVE );
    free( string );

    if( !strcasecmp( Whom, server->nick ) ) {
#ifdef REJOIN_ON_KICK
        /*
         * We just got kicked.  The NERVE!  Join again.
         */
        channel->joined = FALSE;
        transmitMsg( server, TX_JOIN, channel->channel, NULL );
#endif
        LogPrint( LOG_NOTICE, "Kicked from channel %s on server %s by %s (%s)", 
                  channel->channel, server->server, Who, Msg);
    }
}
示例#5
0
文件: bot.c 项目: Beirdo/beirdobot
void LoggedActionMessage( IRCServer_t *server, IRCChannel_t *channel,
                          char *message )
{
    transmitMsg( server, TX_ACTION, channel->channel, message );
    db_add_logentry( channel, server->nick, TYPE_ACTION, message, false );
    db_update_nick( channel, server->nick, true, false );
}
示例#6
0
bool SerialManagerView::eventFilter(QObject *object, QEvent *event)
{
    if (object == message && event->type() == QEvent::KeyPress)
    {
        QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
        if (keyEvent->key() == Qt::Key_Return)
        {
            // Special tab handling
            //qDebug("Enter Key Pressed...");

            /// transmission
            if (message->text().length() > 0) {
                appendEndCmd();
                transmitMsg();
            }
            return true;
        }
        else
        {
            return QWidget::eventFilter(object, event);
        }
    }
    else
    {
        return QWidget::eventFilter(object, event);
    }
}
示例#7
0
文件: mpris.c 项目: rcatolino/remote
static void sendLoopStatus() {
  if (mpris_data->loop == NULL) {
    return;
  }
  transmitMsg(client_socket, mpris_data->loop, strlen(mpris_data->loop),
              LOOP_HEAD, LOOP_HEAD_SZ);
}
示例#8
0
文件: bot.c 项目: Beirdo/beirdobot
void ProcOnInvite(BN_PInfo I, const char Chan[], const char Who[],
                  const char Whom[])
{
    IRCChannel_t   *channel;
    IRCServer_t    *server;

    if( verbose ) {
        LogPrint( LOG_DEBUG, "You (%s) have been invited to %s by %s", Whom, 
                  Chan, Who);
    }

    server = (IRCServer_t *)I->User;
    channel = FindChannel(server, Chan);
    if( !channel || !channel->enabled ) {
        return;
    }

    /*
     * We are configured for this channel, rejoin
     */
    LogPrint( LOG_NOTICE, "Invited to channel %s on server %s by %s", 
              channel->channel, server->server, Who);
    channel->joined = FALSE;
    transmitMsg( server, TX_JOIN, channel->channel, NULL );
}
示例#9
0
QespTest::QespTest(QWidget *parent)
    : QWidget(parent)

{
    //modify the port settings on your own
#ifdef Q_OS_UNIX
    port = new QextSerialPort(QLatin1String("/dev/ttyS0"), QextSerialPort::Polling);
#else
    port = new QextSerialPort(QLatin1String("COM1"), QextSerialPort::Polling);
#endif /*Q_OS_UNIX*/
    port->setBaudRate(BAUD19200);
    port->setFlowControl(FLOW_OFF);
    port->setParity(PAR_NONE);
    port->setDataBits(DATA_8);
    port->setStopBits(STOP_2);
    //set timeouts to 500 ms
    port->setTimeout(500);

    message = new QLineEdit(this);

    // transmit receive
    QPushButton *transmitButton = new QPushButton(tr("Transmit"));
    connect(transmitButton, SIGNAL(clicked()), SLOT(transmitMsg()));
    QPushButton *receiveButton = new QPushButton(tr("Receive"));
    connect(receiveButton, SIGNAL(clicked()), SLOT(receiveMsg()));
    QHBoxLayout *trLayout = new QHBoxLayout;
    trLayout->addWidget(transmitButton);
    trLayout->addWidget(receiveButton);

    //CR LF
    QPushButton *CRButton = new QPushButton(tr("CR"));
    connect(CRButton, SIGNAL(clicked()), SLOT(appendCR()));
    QPushButton *LFButton = new QPushButton(tr("LF"));
    connect(LFButton, SIGNAL(clicked()), SLOT(appendLF()));
    QHBoxLayout *crlfLayout = new QHBoxLayout;
    crlfLayout->addWidget(CRButton);
    crlfLayout->addWidget(LFButton);

    //open close
    QPushButton *openButton = new QPushButton(tr("Open"));
    connect(openButton, SIGNAL(clicked()), SLOT(openPort()));
    QPushButton *closeButton = new QPushButton(tr("Close"));
    connect(closeButton, SIGNAL(clicked()), SLOT(closePort()));
    QHBoxLayout *ocLayout = new QHBoxLayout;
    ocLayout->addWidget(openButton);
    ocLayout->addWidget(closeButton);

    received_msg = new QTextEdit();

    QVBoxLayout *myVBox = new QVBoxLayout;
    myVBox->addWidget(message);
    myVBox->addLayout(crlfLayout);
    myVBox->addLayout(trLayout);
    myVBox->addLayout(ocLayout);
    myVBox->addWidget(received_msg);
    setLayout(myVBox);

    qDebug("isOpen : %d", port->isOpen());
}
示例#10
0
文件: bot.c 项目: Beirdo/beirdobot
void channelLeave( IRCServer_t *server, IRCChannel_t *channel, 
                   char *oldChannel )
{
    transmitMsg( server, TX_PART, oldChannel, 
                 "Leaving due to reconfiguration" );
    db_nick_history( channel, "", HIST_END );
    channel->joined = FALSE;
}
示例#11
0
文件: mpris.c 项目: rcatolino/remote
static void sendPlaybackStatus() {
  if (mpris_data->playback == NULL) {
    return;
  }
  debug("client socket : %d\n", client_socket);
  transmitMsg(client_socket, mpris_data->playback, strlen(mpris_data->playback),
              PLAYBACK_HEAD, PLAYBACK_HEAD_SZ);
}
示例#12
0
文件: bot.c 项目: Beirdo/beirdobot
void ProcOnConnected(BN_PInfo I, const char HostName[])
{
    IRCServer_t *server;

    server = (IRCServer_t *)I->User;
    LogPrint( LOG_NOTICE, "Connected to %s:%d as %s...", server->server, 
              server->port, server->nick);

    if( verbose ) {
        LogPrint( LOG_DEBUG, "Event Connected : (%s)", HostName);
    }

    /* We are doing our own, thanks! */
    BN_DisableFloodProtection(I);

    if( strcmp( server->password, "" ) ) {
        transmitMsg( server, TX_PASSWORD, NULL, server->password );
    }
    transmitMsg( server, TX_NICK, NULL, server->nick );
    transmitMsg( server, TX_REGISTER, server->username, server->realname );
}
示例#13
0
void SerialManagerView::setupGUI() {






    // transmit receive
    QPushButton *transmitButton = new QPushButton(tr("Transmit"));
    connect(transmitButton, SIGNAL(clicked()), SLOT(transmitMsg()));
    QPushButton *receiveButton = new QPushButton(tr("Receive"));
    connect(receiveButton, SIGNAL(clicked()), SLOT(receiveMsg()));
    QHBoxLayout *trLayout = new QHBoxLayout;
    trLayout->addWidget(transmitButton);
    trLayout->addWidget(receiveButton);

    //CR LF
    QPushButton *CRButton = new QPushButton(tr("CR"));
    connect(CRButton, SIGNAL(clicked()), SLOT(appendCR()));
    QPushButton *LFButton = new QPushButton(tr("LF"));
    connect(LFButton, SIGNAL(clicked()), SLOT(appendLF()));
    QHBoxLayout *crlfLayout = new QHBoxLayout;
    crlfLayout->addWidget(CRButton);
    crlfLayout->addWidget(LFButton);

    //open close
    QPushButton *openButton = new QPushButton(tr("Open"));
    connect(openButton, SIGNAL(clicked()), SLOT(openPort()));
    QPushButton *closeButton = new QPushButton(tr("Close"));
    connect(closeButton, SIGNAL(clicked()), SLOT(closePort()));
    QHBoxLayout *ocLayout = new QHBoxLayout;
    ocLayout->addWidget(openButton);
    ocLayout->addWidget(closeButton);

    received_msg = new QTextEdit();

    QVBoxLayout *myVBox = new QVBoxLayout;
    myVBox->addWidget(message);
    myVBox->addLayout(crlfLayout);
    myVBox->addLayout(trLayout);
    myVBox->addLayout(ocLayout);
    myVBox->addWidget(received_msg);
    setLayout(myVBox);

    qDebug("isOpen : %d", port->isOpen());

    /// configure textEdit
    message->installEventFilter(this);
}
示例#14
0
文件: bot.c 项目: Beirdo/beirdobot
void ProcOnNames(BN_PInfo I, const char Channel[], const char *Names[],
                 int Count)
{
    int             i;
    IRCServer_t    *server;

    server = (IRCServer_t *)I->User;

    if( verbose ) {
        LogPrint( LOG_DEBUG, "Names for channel (%s) :", Channel);
        for (i = 0; i < Count; i++) {
            LogPrint( LOG_DEBUG, "\t(%s)", Names[i]);
        }
        LogPrint( LOG_DEBUG, "End of names for (%s)", Channel);
    }

    transmitMsg( server, TX_WHO, (char *)Channel, NULL );
}
示例#15
0
文件: mpris.c 项目: rcatolino/remote
void sendPosition() {
  int64_t pos = htobe64(mpris_data->position);
  transmitMsg(client_socket, (char*)&pos, sizeof(int64_t),
              POSITION, POSITION_SZ);
}
示例#16
0
void botCmdPlugin( IRCServer_t *server, IRCChannel_t *channel, char *who, 
                   char *msg, void *tag )
{
    int             len;
    char           *line;
    char           *command;
    char           *message;
    bool            ret;
    static char    *notauth = "You are not authorized, you can't do that!";

    if( !server || channel ) {
        return;
    }

    if( !authenticate_check( server, who ) ) {
        transmitMsg( server, TX_PRIVMSG, who, notauth );
        return;
    }

    line = strstr( msg, " " );
    if( line ) {
        /* Command has trailing text, skip the space */
        len = line - msg;
        line++;

        command = (char *)malloc( len + 2 );
        strncpy( command, msg, len );
        command[len] = '\0';
    } else {
        /* Command is the whole line */
        command = strdup( msg );
    }

    /* Strip trailing spaces */
    if( line ) {
        for( len = strlen(line); len && line[len-1] == ' ';
             len = strlen(line) ) {
            line[len-1] = '\0';
        }

        if( *line == '\0' ) {
            line = NULL;
        }
    }

    if( !strcmp( command, "list" ) ) {
        BalancedBTreeLock( pluginTree );
        if( line && !strcmp( line, "all" ) ) {
            message = botCmdDepthFirst( pluginTree->root, false );
        } else {
            message = botCmdDepthFirst( pluginTree->root, true );
        }
        BalancedBTreeUnlock( pluginTree );
    } else if( !strcmp( command, "load" ) && line ) {
        ret = pluginLoad( line );
        message = (char *)malloc(strlen(line) + 32);
        if( ret ) {
            sprintf( message, "Loaded module %s", line );
        } else {
            sprintf( message, "Module %s already loaded", line );
        }
    } else if( !strcmp( command, "unload" ) && line ) {
        ret = pluginUnload( line );
        message = (char *)malloc(strlen(line) + 32);
        if( ret ) {
            sprintf( message, "Unloaded module %s", line );
        } else {
            sprintf( message, "Module %s already unloaded", line );
        }
    } else {
        message = NULL;
        free( command );
        return;
    }

    transmitMsg( server, TX_MESSAGE, who, message );

    free( message );
    free( command );
}
示例#17
0
文件: bot.c 项目: Beirdo/beirdobot
void botSighup( int signum, void *arg )
{
    IRCServer_t            *server;
    LinkedListItem_t       *listItem, *next;
    BalancedBTreeItem_t    *item;
    IRCChannel_t           *channel;
    bool                    newChannel = FALSE;

    server = (IRCServer_t *)arg;
    if( !server ) {
        return;
    }

    /*
     * Check each channel on the server, leave those no longer needed
     */
    if( server->channels ) {
        LinkedListLock( server->channels );
        BalancedBTreeLock( server->channelName );
        BalancedBTreeLock( server->channelNum );

        for( listItem = server->channels->head; listItem; listItem = next ) {
            next = listItem->next;
            channel = (IRCChannel_t *)listItem;

            if( !channel->visited ) {
                channelLeave( server, channel, channel->channel );
                regexpBotCmdRemove( server, channel );
                LinkedListRemove( server->channels, listItem, LOCKED );

                item = BalancedBTreeFind( server->channelName, 
                                          &channel->channel, LOCKED );
                if( item ) {
                    BalancedBTreeRemove( server->channelName, item, LOCKED,
                                         FALSE );
                }

                item = BalancedBTreeFind( server->channelNum,
                                          &channel->channelId, LOCKED );
                if( item ) {
                    BalancedBTreeRemove( server->channelNum, item, LOCKED,
                                         FALSE );
                }

                ThreadAllNotifyChannel( channel );

                cursesMenuItemRemove( 2, MENU_CHANNELS, channel->menuText );
                free( channel->menuText );
                free( channel->channel );
                free( channel->fullspec );
                free( channel->url );
                free( channel );
            } else if( channel->newChannel && channel->enabled && 
                       !channel->joined && !newChannel ) {
                newChannel = TRUE;
                transmitMsg( server, TX_JOIN, channel->channel, NULL );
            } else if( channel->newChannel && !channel->enabled ) {
                channel->newChannel = FALSE;
            }
        }
        BalancedBTreeUnlock( server->channelNum );
        BalancedBTreeUnlock( server->channelName );
        LinkedListUnlock( server->channels );
    }
}
示例#18
0
//-----------------------------------------------
//local functions
//-----------------------------------------------
void execEvent(struct Event event)
{
	int i, iPara, iCmd;
	int iSynchVal, iSynchValMeasNorm, iDeltaSynchMeas;
	
	static enum STATE_Connection s_StConnection = ST_ConnReset;
	static enum STATE_Motor s_StMotor = ST_BrakeClosed;

	iCmd = event.ucData[0];

	switch(s_StConnection)
	{
	case ST_ConnReset:
		//-------------------
		switch(iCmd)
		{
		//-------------------
		case CMD_MOTCTRL_CONNECT:
			transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
			s_StConnection = ST_ConnConnected;
			break;
		//-------------------
		case CMD_MOTCTRL_DISCONNECT:
			_trap_(0x00);
			break;
		//-------------------
		default:
			if(event.iSource != EVSOURCE_INTERN)
				transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept);
			break;
		}

		break;	//case ST_ConnReset

	case ST_ConnConnected:
		
		//---------------------------------------
		//commands always executed
		switch(iCmd)
		{
		//-------------------
		case CMD_MOTCTRL_DISCONNECT:
			_trap_(0x00);
			return;
		//-------------------
		//io
		case CMD_MOTCTRL_SETDIGOUT:
			setOutputPort8(event.ucData[1], event.ucData[2]);
			return;
		//-------------------
		case CMD_MOTCTRL_GETDIGIN:
			transmitMsg(event.iSource, P1H, P1L, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
			return;
		//-------------------
		case CMD_MOTCTRL_GETANALOGIN:
			iPara = g_iAnIn[event.ucData[1]];
			transmitMsg(event.iSource, iPara >> 8, iPara, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
			return;
		//-------------------
		//debug
		case CMD_MOTCTRL_SETCTRLPARA:
			g_iIn1 = (event.ucData[1] << 8) | event.ucData[2];
			g_iIn2 = (event.ucData[3] << 8) | event.ucData[4];
			g_iIn3 = (event.ucData[5] << 8) | event.ucData[6];

			//synch pos fine tuning
			//gc_iFieldPosSynchNorm = g_iIn1;

			return;
		//-------------------
		case CMD_MOTCTRL_GETCTRLPARA:
			transmitMsg(event.iSource, g_iOut1 >> 8, g_iOut1, g_iOut2 >> 8, g_iOut2, g_iOut3 >> 8, g_iOut3, 0, (iCmd << 2) | Msg_OK);
			return;
		//-------------------
		//get data
		case CMD_MOTCTRL_GETPOSVEL:
			transmitMsg(event.iSource, g_lPosMeas >> 24, g_lPosMeas >> 16, g_lPosMeas >> 8, g_lPosMeas, g_iVelMeas >> 8, g_iVelMeas, 0, (iCmd << 2) | Msg_OK);
			return;
		//-------------------
		case CMD_MOTCTRL_GETSTATUS:
			transmitMsg(event.iSource, g_iStateCtrl >> 8, g_iStateCtrl, g_iTempMeas >> 8, g_iTempMeas, 0, 0, 0, (iCmd << 2) | Msg_OK);
			return;
		}
		
		//---------------------------------------
		//motor control commands state machine
		switch(s_StMotor)
		{
		//-------------------
		case ST_BrakeClosed:
			switch(iCmd)
			{
			case CMD_MOTCTRL_DISABLEBRAKE:
				if(event.ucData[1] == 1)
				{
					openBrake(gc_iBrakeHasRelais);
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
					s_StMotor = ST_BrakeOpen;
				}
				break;	//CMD_MOTCTRL_DISABLEBRAKE

			default:
				if(event.iSource != EVSOURCE_INTERN)
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept);
			}	//switch(iCmd)

			break;	//ST_BrakeClosed

		//-------------------
		case ST_BrakeOpen:
			switch(iCmd)
			{
			case CMD_MOTCTRL_DISABLEBRAKE:
				if(event.ucData[1] == 0)
				{
					closeBrake(gc_iBrakeHasRelais);
					s_StMotor = ST_BrakeClosed;
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
				}
				break;	//CMD_MOTCTRL_DISABLEBRAKE

			case CMD_MOTCTRL_ENABLEMOTOR: 
				if(event.ucData[1] == 1)
				{
					enableMotor(gc_iSineZero);
	
					g_iPosVelCtrlRun = 0;
					g_iTorqueCmd = 0;
					g_iTorqueCtrlRun = 1;
					g_iFieldPos = 0;
					g_iCommRun = 0;
					g_iSynchRun = 1;
	
					//increase torque slowly
					do
					{
						g_iTorqueCmd++;
						Delay(5000);
					}
					while(g_iTorqueCmd < gc_iSynchTorque);
	
					s_StMotor = ST_MotorEnabled;
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
				}
				break;	//CMD_MOTCTRL_ENABLEMOTOR

			default:
				if(event.iSource != EVSOURCE_INTERN)
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept);
			}	//switch(iCmd)

			break;	//ST_BrakeOpen

		//-------------------
		case ST_MotorEnabled:
			switch(iCmd)
			{
			case CMD_MOTCTRL_ENABLEMOTOR:
				if(event.ucData[1] == 0)
				{
					disableMotorCtrl();
					s_StMotor = ST_BrakeOpen;
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
				}
				break;	//CMD_MOTCTRL_ENABLEMOTOR
	
			case CMD_MOTCTRL_SYNCHMOTOR:
				//exec single rot to snap in rotor
				for(i=0; i<gc_iEncPulsePerRev; i++)
				{
					g_iFieldPos++;
					Delay(gc_iSynchVelDelay);
				}

				g_iFieldPos = 0;
				g_lPosOffset = g_lPosOffset + T2;	//g_lPosOffset used to move back to 0 after synch
				T2 = 0;

				//enable synch int
				g_iSynchIntCaptured = 0;
				EXICON = 0x0008 | 0x0001;			//EXIN0 interrupt on pos edge, EXIN1 interrupt on neg edge

				//wait for synch interrupt, communication blocking
				while(g_iSynchIntCaptured == 0)
				{
					_atomic_(3);
					//if no synch interrupt captured, update iSynchVal
					if(g_iSynchIntCaptured == 0)
						iSynchVal = T2;

					g_iFieldPos++;
					Delay(gc_iSynchVelDelay);
				}

				g_lPosOffset = g_lPosOffset + iSynchVal;

				//shift back iSynchVal
				while(iSynchVal > gc_iEncPulsePerPhase)
					iSynchVal = iSynchVal - gc_iEncPulsePerPhase;

				//reset T2, g_iT2RevCnt -> EncPosAbs = 0
				T2 = 0;
				g_iT2RevCnt = 0;
				if(gc_iMotorType == MotorType_6Pol)
					iSynchValMeasNorm = toFieldPosNorm_Mot6Pol_Enc4096(iSynchVal);
				if(gc_iMotorType == MotorType_4Pol)
					iSynchValMeasNorm = toFieldPosNorm_Mot4Pol_Enc4096(iSynchVal);

				iDeltaSynchMeas = iSynchValMeasNorm - gc_iFieldPosSynchNorm;
				if(iDeltaSynchMeas < -255)
					iDeltaSynchMeas = iDeltaSynchMeas + 512;
				if(iDeltaSynchMeas > 255)
					iDeltaSynchMeas = iDeltaSynchMeas - 512;
				
				//test for correct SynchVal
				if((iDeltaSynchMeas > -30) && (iDeltaSynchMeas < 90))
				{
					transmitMsg(event.iSource, iSynchValMeasNorm >> 8, iSynchValMeasNorm, gc_iFieldPosSynchNorm >> 8, gc_iFieldPosSynchNorm, 0, 0, 0, (iCmd << 2) | Msg_OK);
					s_StMotor = ST_MotorSynch;
				}
				else
				{
					disableMotorCtrl();
					transmitMsg(event.iSource, iSynchValMeasNorm >> 8, iSynchValMeasNorm, gc_iFieldPosSynchNorm >> 8, gc_iFieldPosSynchNorm, 0, 0, 0, (iCmd << 2) | Msg_Error);
					s_StMotor = ST_BrakeOpen;
				}
				break;	//CMD_MOTCTRL_SYNCHMOTOR

			default:
				if(event.iSource != EVSOURCE_INTERN)
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept);
			}	//switch(iCmd)

			break;	//ST_MotorEnabled

		//-------------------
		case ST_MotorSynch:
			switch(iCmd)
			{
			case CMD_MOTCTRL_ENABLECOMM:
				g_iTorqueCmd = 0;
				while(g_lTorqueCmd != 0)
					;
				g_iT2Overflow = 0;
				g_lPosCmd = getEncPosAbsAsLong();
				g_iSynchRun = 0;
				g_iCommRun = 1;
				g_iPosVelCtrlRun = 1;
				s_StMotor = ST_MotorRunning;

				setVoltDownBrake(gc_iBrakeHasRelais);

				transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
				break;	//CMD_MOTCTRL_ENABLECOMM

			default:
				if(event.iSource != EVSOURCE_INTERN)
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept);
			}	//switch

			break;	//ST_MotorSynch

		//-------------------
		case ST_MotorRunning:
			switch(iCmd)
			{
			case CMD_MOTCTRL_SETCMDVAL:
				g_lPosCmd = (((long int)event.ucData[1]) << 24 | ((long int)event.ucData[2]) << 16 | ((long int)event.ucData[3]) << 8 | (long int)event.ucData[4]);
				g_iVelCmd = event.ucData[5] << 8 | event.ucData[6];

				transmitMsg(event.iSource, g_iStateCtrl >> 8, g_iStateCtrl, g_iTempMeas >> 8, g_iTempMeas, 0, 0, 0, (CMD_MOTCTRL_GETSTATUS << 2) | Msg_OK);
				transmitMsg(event.iSource, g_lPosMeas >> 24, g_lPosMeas >> 16, g_lPosMeas >> 8, g_lPosMeas, g_iVelMeas >> 8, g_iVelMeas, 0, (CMD_MOTCTRL_GETPOSVEL << 2) | Msg_OK);

				break;	//CMD_MOTCTRL_SETCMDVAL
			
			case CMD_MOTCTRL_SETMOTIONTYPE:
				g_iStMotionType = event.ucData[1];
				transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
				break;	//CMD_MOTCTRL_SETMOTIONTYPE
	
			case CMD_MOTCTRL_SETEMSTOP:
				g_iPosVelCtrlRun = 0;
				g_iVelCmd = 0;
				g_iTorqueCmd = 0;
				//decrease torque slowly
				/*
				while(g_iTorqueCmd > 0)
				{
					g_iTorqueCmd--;
					Delay(3000);
				}
				*/
				closeBrake(gc_iBrakeHasRelais);
				s_StMotor = ST_MotorEMStop;
				if(event.iSource != EVSOURCE_INTERN)
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
				break;	//CMD_MOTCTRL_SETEMSTOP

			case CMD_MOTCTRL_ENABLEMOTOR:
				if(event.ucData[1] == 0)
				{
					disableMotorCtrl();
					s_StMotor = ST_BrakeOpen;
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
				}
				break;	//CMD_MOTCTRL_ENABLEMOTOR

			default:
				if(event.iSource != EVSOURCE_INTERN)
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept);
			}	//switch(iCmd)

			break;	//ST_MotorRunning

		//-------------------
		case ST_MotorEMStop:
			switch(iCmd)
			{
			case CMD_MOTCTRL_SETCMDVAL:
				transmitMsg(event.iSource, g_iStateCtrl >> 8, g_iStateCtrl, g_iTempMeas >> 8, g_iTempMeas, 0, 0, 0, (CMD_MOTCTRL_GETSTATUS << 2) | Msg_OK);
				transmitMsg(event.iSource, g_lPosMeas >> 24, g_lPosMeas >> 16, g_lPosMeas >> 8, g_lPosMeas, g_iVelMeas >> 8, g_iVelMeas, 0, (CMD_MOTCTRL_GETPOSVEL << 2) | Msg_OK);
				break;	//CMD_MOTCTRL_SETCMDVAL

			case CMD_MOTCTRL_RESETEMSTOP:
				openBrake(gc_iBrakeHasRelais);
				g_iPosVelCtrlRun = 1;
				s_StMotor = ST_MotorRunning;
				transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
				break;
			
			case CMD_MOTCTRL_ENABLEMOTOR:
				if(event.ucData[1] == 0)
				{
					disableMotorCtrl();
					s_StMotor = ST_BrakeOpen;
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_OK);
				}
				break;	//CMD_MOTCTRL_ENABLEMOTOR

			default:
				if(event.iSource != EVSOURCE_INTERN)
					transmitMsg(event.iSource, 0, 0, 0, 0, 0, 0, 0, (iCmd << 2) | Msg_NotAccept);
			}	//switch(iCmd)

			break;	//ST_MotorEMStop

		}	//switch(StMotor)
示例#19
0
int transmit(int socketd, char * buff, size_t size) {
    return transmitMsg(socketd, buff, size, NULL, 0);
}