Пример #1
0
int main() {
    int i;
    int id1, id2;
    struct _pulse pulse;

    // Request I/O privileges
    ThreadCtl( _NTO_TCTL_IO, 0 );

    chid = ChannelCreate( 0 );
	coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0 );

	SIGEV_PULSE_INIT( &event1, coid, getprio(0), MY_PULSE_CODE1, 0 );
    id1=InterruptAttach( SYSPAGE_ENTRY(qtime)->intr, &handler1,
                        NULL, 0, 0 );

	SIGEV_PULSE_INIT( &event2, coid, getprio(0), MY_PULSE_CODE2, 0 );
    id2=InterruptAttach( SYSPAGE_ENTRY(qtime)->intr, &handler2,
                        NULL, 0, 0 );

    for( i = 0; i < 10; ++i ) {
        // Wait for ISR to wake us up
    	MsgReceivePulse( chid, &pulse, sizeof( pulse ), NULL );
    	if(pulse.code == MY_PULSE_CODE1) {
            printf( "1000 events\n" );
    	} else if(pulse.code == MY_PULSE_CODE2) {
    		printf( "2500 events\n" );
    	}
    }

    // Disconnect the ISR handler
    InterruptDetach(id1);
    InterruptDetach(id2);
    return 0;
}
Пример #2
0
//Communication with the server
//Using buffers: buffer, receive
void* message_client(void* arg){

	//Define thread priority
	if(((struct thread_args*)arg)->which_thread == 0){
		set_priority(22);
		printf("I HAVE PRIORITY 22\n");
	}
	else if(((struct thread_args*)arg)->which_thread == 1){
		set_priority(21);
		printf("I HAVE PRIORITY 21\n");
	}
	else if(((struct thread_args*)arg)->which_thread == 2){
		set_priority(19);
		printf("I HAVE PRIORITY 19\n");
	}
	else{
		set_priority(18);
		printf("I HAVE PRIORITY 18\n");
	}

	//Perform communication
	int channelID, status;

	channelID = ConnectAttach(0, ((struct thread_args*)arg)->pid, 1, 0, 0);

	//Sends data in buffer. Puts returned data in receive buffer
	status = MsgSend(channelID, &buffer, sizeof buffer, &receive, sizeof receive);

	printf("SERVER REPLY: %c\n", receive[0]);

	//Detach from server
	ConnectDetach(channelID);

	return 0;
}
Пример #3
0
/*
 *  Given a process id, iterate through all open files of that process
 *  looking for a match to the target file, and then determine how it
 *  is being used by that process.  This is quite different in QNX to
 *  UNIX, as chroot and chdir do not hold open a reference to the file.
 *  The iteration process attempts to dup each file descriptor into
 *  this process, so it can then be queried; attempt to skip things which
 *  aren't files (heuristic guess) and use a timeout as self-defence.
 */
int howused(pid_t pid, match_t *match)
{
struct _server_info	sinfo;
struct _fdinfo		finfo;
struct stat			st;
io_dup_t			msg;
uint64_t			to;
int					fd, coid, usage;

	usage = 0;
	for (fd = 0; (fd = ConnectServerInfo(pid, fd, &sinfo)) != -1; ++fd) {
		if ((pid != sinfo.pid || !(fd & _NTO_SIDE_CHANNEL)) && (coid = ConnectAttach(sinfo.nd, sinfo.pid, sinfo.chid, 0, _NTO_COF_CLOEXEC)) != -1) {
			msg.i.type = _IO_DUP;
			msg.i.combine_len = sizeof(msg.i);
			msg.i.info.nd = netmgr_remote_nd(sinfo.nd, ND_LOCAL_NODE);
			msg.i.info.pid = pid;
			msg.i.info.chid = sinfo.chid;
			msg.i.info.scoid = sinfo.scoid;
			msg.i.info.coid = fd;
			TimerTimeout(CLOCK_MONOTONIC, _NTO_TIMEOUT_SEND | _NTO_TIMEOUT_REPLY, NULL, (to = 1000000000LL, &to), NULL);
			if (MsgSend(coid, &msg.i, sizeof(msg.i), NULL, 0) == -1) {
				ConnectDetach(coid);
			}
			else {
				if (fstat(coid, &st) != -1 && ismatch(match, st.st_dev, st.st_ino)) {
					if (iofdinfo(coid, 0, &finfo, NULL, 0) == -1 || sinfo.pid != PATHMGR_PID || finfo.mode != 0)
						usage |= USED_OPEN;
				}
				close(coid);
			}
		}
	}
	return(usage);
}
void PeriodicThreadImplQNX::makePeriodic()
{
  if (m_chid == -1)
  {
    LOGGING_ERROR_C(Thread, PeriodicThreadImplQNX,
                    "No timer channel available! Cannot make this thread periodic!" << endl);
    return;
  }

  struct sigevent event;
  int coid;

  coid = ConnectAttach(0, 0, m_chid, 0, 0);
  if (coid == -1)
  {
    LOGGING_ERROR_C(Thread, PeriodicThreadImplQNX,
                    "Could not attach to the timer channel! Cannot make this thread periodic!" << endl);
    return;
  }

  SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, ePT_PULSE_TIMER, 0);

  int res = timer_create(CLOCK_REALTIME, &event, &m_timerid);
  if (res == -1)
  {
    LOGGING_ERROR_C(Thread, PeriodicThreadImplQNX,
                    "Could not create timer! Cannot make this thread periodic!" << endl);
    return;
  }

  m_made_periodic = true;

  setPeriod(m_period);
}
Пример #5
0
void B1S02_Seg1::timerSeg1Max() {
	PuckHandler::getInstance()->printQueueStatus();
	if(controller->isFirstElementInSegment()) {

		puckHandler->removePuckFromSeg1();
		puckHandler->removePuckFromBand(controller);
		if(puckHandler->isBandEmpty()){
			actorHAL->engineStop();
		}
		controller->resetController();

		printf("Debug State <B1S02_Seg1>: ERROR<ERR_STATE_ERROR_MAX> called by puck%d\n", controller->getID());

		int errorfsmChid = errfsm->getErrorFSMChid();
		int errorfsmCoid;
		int rc;

		if ((errorfsmCoid = ConnectAttach(0, 0, errorfsmChid, _NTO_SIDE_CHANNEL, 0)) == -1) {
			printf("B1S02_Seg1: Error in ConnectAttach\n");
		}

		//rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_CRITICAL_ERROR);
		rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_ERROR_MAX);
		if (rc < 0) {
			printf("B1S02_Seg1: Error in MsgSendPulse");
		}

		if (ConnectDetach(errorfsmCoid) == -1) {
			printf("B1S02_Seg1: Error in ConnectDetach\n");
		}
	}
}
Пример #6
0
void * pi_a() {
	int coid;
	int rcvid;

	char send[50] = "PI_A";
	char receive[50];

	int from;
	int to;
	double result;

	int status = 0;

	coid = ConnectAttach(0, pid, chid, 0, NULL);
	checkresult(coid, "\nConnect Attach failed in PI_A: ");

	printf("PI_A: connected to channel (Connect ID = %i) \n", coid);

	while (status == 0){
		status = MsgSend(coid, &send, sizeof(send), &from, sizeof(double));
		status = MsgSend(coid, &send, sizeof(send), &to, sizeof(double));

		k = 0, pi_old = 0, pi = 0;

		for(k = from; k <= to;k++){
			pi = pi_old + 4 * (pow(-1, k+1)) / (2*k -1);
			pi_old = pi;
		}

		status = MsgSend(coid, &pi, sizeof(double), &receive, sizeof(receive));
	}

	return(NULL);
}//end pi
Пример #7
0
void B1S02_Seg1::sbHeightcontrolOpen() {
	if(controller->isFirstElementInSegment()) {
		if(this->controller->isSegTimerMinCalled()){
			controller->resetSegTimers();

			puckHandler->removePuckFromSeg1();
			new (this) B1S03_Height(controller);
		} else {

			printf("Debug State <B1S02_Seg1>: ERROR<ERR_STATE_ERROR_MIN> called by puck%d\n", controller->getID());

			int errorfsmChid = errfsm->getErrorFSMChid();
			int errorfsmCoid;
			int rc;

			if ((errorfsmCoid = ConnectAttach(0, 0, errorfsmChid, _NTO_SIDE_CHANNEL, 0)) == -1) {
				printf("B1S02_Seg1: Error in ConnectAttach\n");
			}

			rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_ERROR_MIN);
			if (rc < 0) {
				printf("B1S02_Seg1: Error in MsgSendPulse");
			}

			if (ConnectDetach(errorfsmCoid) == -1) {
				printf("B1S02_Seg1: Error in ConnectDetach\n");
			}
		}
	} else {
		new (this) B1S02_Seg1(controller);
	}
}
Пример #8
0
static void* client(void* arg) {
	int nodeId = 0; // 0 = local
	pid_t pid = 0; // 0 = same process
	int connectionId = 0;
	int number = 0;
	int res = 0;

	connectionId = ConnectAttach(nodeId, pid, channelId, 0, 0);
	if(connectionId == -1) {
		printf("msgSendReceivePulse: client: error attaching to channel!\n");fflush(stdout);
		exit(EXIT_FAILURE);
	}

	while(run) {
		sleep(WAIT_SHORT);

		number++;
		printf("Client: sending pulse message #%d\n", number);fflush(stdout);

		res = MsgSendPulse(connectionId, SIGEV_PULSE_PRIO_INHERIT, 1, 0);
		if(res == -1) {
			printf("msgSendReceivePulse: client: error sending pulse!\n");fflush(stdout);
			exit(EXIT_FAILURE);
		}
	}

	ConnectDetach(connectionId);
	if(res == -1) {
		printf("msgSendReceiveReply: client: error detaching from channel!\n");fflush(stdout);
		exit(EXIT_FAILURE);
	}

	pthread_exit(NULL);
}
Пример #9
0
int omap3_attach_intr(omap3_spi_t *omap3)
{
    if ((omap3->chid = ChannelCreate(_NTO_CHF_DISCONNECT | _NTO_CHF_UNBLOCK)) == -1)
        return -1;

    if ((omap3->coid = ConnectAttach(0, 0, omap3->chid, _NTO_SIDE_CHANNEL, 0)) == -1)
        goto fail0;

    omap3->spievent.sigev_notify   = SIGEV_PULSE;
    omap3->spievent.sigev_coid	 = omap3->coid;
    omap3->spievent.sigev_code	 = OMAP3_SPI_EVENT;
    omap3->spievent.sigev_priority = omap3->prio;

    /*
     * Attach SPI interrupt
     */
    omap3->iid_spi = InterruptAttach(omap3->irq_spi, spi_intr, omap3, 0, _NTO_INTR_FLAGS_TRK_MSK);

    if (omap3->iid_spi != -1)
        return 0;

    ConnectDetach(omap3->coid);
fail0:
    ChannelDestroy(omap3->chid);

    return -1;
}
Пример #10
0
std::string IDSEXT::RegisterProvider(const std::string& providerName)
{
    Json::FastWriter writer;
    Json::Value resultJSON;

    ids_provider_mapping *registeredItem = reinterpret_cast<ids_provider_mapping *>(malloc(sizeof(ids_provider_mapping)));
    if (!registeredItem) {
        fprintf(stderr, "Unable to register IDS provider - malloc error\n");
        return "";
    }

    registeredItem->providerName = strdup(providerName.c_str());
    resultJSON["result"] = ids_register_provider(registeredItem->providerName, &registeredItem->provider, &registeredItem->providerFd);
    if ( (ids_result_t) resultJSON["result"].asInt() == IDS_SUCCESS ) {
        registeredItem->next = providers;
        providers = registeredItem;

        registeredItem->sigEvent = new sigevent;
        registeredItem->sigEvent->sigev_notify = SIGEV_PULSE;
        registeredItem->sigEvent->sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0, eventCHID, _NTO_SIDE_CHANNEL, 0);
        registeredItem->sigEvent->sigev_priority = getprio(0);
        registeredItem->sigEvent->sigev_code = registeredItem->providerFd;
        registeredItem->sigEvent->sigev_value.sival_int = registeredItem->providerFd;

        if (ionotify(registeredItem->providerFd, _NOTIFY_ACTION_POLLARM, _NOTIFY_COND_INPUT, registeredItem->sigEvent) & _NOTIFY_COND_INPUT) {
            MsgDeliverEvent(0, registeredItem->sigEvent);
        }
    } else {
        resultJSON["errno"] = strerror(errno);
    }

    std::string resultStr = writer.write(resultJSON);
    return( resultStr.c_str() );
}
Пример #11
0
static void init_pulse_and_timer(void) {
	timer_t timerid;			// timer ID for timer
	struct sigevent event;		// event to deliver
	struct itimerspec timer;	// timer data structure
	int	coid;					// connection back to myself
	int ctrid;

	// create a connection back to myself
	coid = ConnectAttach(0, 0, chid, 0, 0);
	if(coid == -1) {
		fprintf(stderr, "%s: couldn't create connection!\n", progname);
		perror(NULL);
		exit(EXIT_FAILURE);
	}

	// set up the kind of event that we want to deliver - a pulse
	SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, CODE_TIMER, 0);

	// create the timer, binding it to the event
	ctrid = timer_create(CLOCK_REALTIME, &event, &timerid);
	if(ctrid == -1) {
		fprintf(stderr, "%s: couldn't create a timer, errno %d\n", progname, errno);
		perror(NULL);
		exit(EXIT_FAILURE);
	}
	setup_timer(1, 0, 1, 0, &timer);
	timer_settime(timerid, 0, &timer, NULL);
}
int main(int argc, char *argv[]) {
	if(argc < 2) {
		printf("use with channel_id\n");
		return 1;
	}
	int chid = atoi(argv[1]);
	sleep(1);
	coid = ConnectAttach(getppid(), chid, 0);
	if(coid < 0) {
		printf("kernel not responsible\n");
		return 2;
	}

	pthread_t tid;
	pthread_create(&tid, NULL, ping, NULL);

	printf("console\n");
	MESSAGE *pmsg = (MESSAGE *) malloc(MAXMSGSIZE);
	pmsg->type = MSGCMD;
	for(;;) {
		printf("%% "); fflush(stdout);
		if(!fgets(pmsg->body, MAXMSGSIZE - sizeof(MESSAGE) - 1, stdin)) break;
		pmsg->len = strlen(pmsg->body);
		MsgSend(coid, pmsg, sizeof(MESSAGE) + pmsg->len, pmsg, MAXMSGSIZE);
		if(pmsg->len < 1 || (pmsg->len == 1 && pmsg->body[0] == '\n')) continue;
		pmsg->body[pmsg->len] = 0;
		printf("kernel said:\n");
		printf("%s", pmsg->body);
	}
	printf("console closed\n");
	return EXIT_SUCCESS;
}
Пример #13
0
void SensorHAL::initInterrupt() {
	//Create channel for pulse notification
	if ((chid = ChannelCreate(0)) == -1) {
		printf("SensorHAL: Error in ChannelCreate\n");
	}

	//Connect to channel
	if ((coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0)) == -1) {
		printf("SensorHAL: Error in ConnectAttach\n");
	}

	//Initialisiere ein sigevent als Pulse
	SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_ISR, 0);

	//Get rights
	if (-1 == ThreadCtl(_NTO_TCTL_IO, 0)) {
		printf("ThreadCtl access failed\n");
		exit(EXIT_FAILURE);
	}

	//Init Port A, B, C, if HAl doesnt already
	out8(PORT_CTRL, DIO_INIT);

	//Enable IRQs for PortB and PortC
	out8(DIO_INTERRUPT_ENABLE_REG, DIO_INTERRUPT_ENABLE_BC);

	//Reset IRQs
	out8(DIO_INTERRUPT_CLEAR_REG, 0x00);

	//Registriere die Interrupt Service Routine
	if ((interruptId = InterruptAttach(DIO_IRQ, ISR, &event, sizeof(event), 0))
			== -1) {
		printf("SensorHAL: Error in InterruptAttach\n");
	}
}
int YARPNativeEndpointManager::CreateOutputEndpoint(YARPUniqueNameID& name)
{
#ifndef __QNX6__
	ACE_UNUSED_ARG(name);
	return YARP_FAIL;
#else
	YARPUniqueNameQnx& nameq = (YARPUniqueNameQnx&)name;

	int coid = ConnectAttach( 
						netmgr_strtond (nameq.getNode().c_str(),NULL),
						nameq.getPid(),
						nameq.getChannelID(),
						0,
						0);

	ACE_DEBUG ((LM_DEBUG, "ConnectAttach: %s(%d), %d %d, returned %d\n",
		nameq.getNode().c_str(),
		netmgr_strtond (nameq.getNode().c_str(), NULL),
		nameq.getPid(), nameq.getChannelID(),
		coid));

	if (coid != -1)
	{
		nameq.setRawIdentifier(coid);
		return YARP_OK; ///name.getNameID();
	}

	/// failed.
	///return YARPNameID();
	return YARP_OK;
#endif
}
Пример #15
0
Timer::Timer(long sec, long nsec)
{
	event = (struct sigevent*) calloc(1, sizeof(struct sigevent));
	channel_id = ChannelCreate(_NTO_CHF_FIXED_PRIORITY);
	connection_id = ConnectAttach(0, 0, channel_id, 0, 0);
	SIGEV_PULSE_INIT(event, connection_id, SIGEV_PULSE_PRIO_INHERIT, PulseCode++, NULL);
	timer_create(CLOCK_REALTIME, event, &timer_id);
	SetTime(sec, nsec);
}
Пример #16
0
int main3(int argc, char **argv) {
	struct sigevent event_frame;
	struct itimerspec itime_frame;
	timer_t frame_timer_id;
	int chid;
	int rcvid;
	int srv_coid;
	my_message_t msg;

	if(argc != 3) {
		printf("proper usage: ./lab5 hyperperiod_duration_in_sec frames_count\n");
		return 0;
	}

	int duration = atoi(argv[1]);
	int frames_count = atoi(argv[2]);

	float frame_duration = (float)duration / (float)frames_count;

	int frame_duration_seconds = (int) frame_duration;
	int frame_duration_ns = (int) ((frame_duration - frame_duration_seconds) * 1000000000);

	chid = ChannelCreate(0);
	srv_coid = ConnectAttach(ND_LOCAL_NODE, 0, chid, _NTO_SIDE_CHANNEL, 0);


	event_frame.sigev_notify = SIGEV_PULSE;
	event_frame.sigev_coid = srv_coid;
	event_frame.sigev_priority = getprio(0);
	event_frame.sigev_code = FRAME_PULSE_CODE;
	timer_create(CLOCK_REALTIME, &event_frame, &frame_timer_id);
	itime_frame.it_value.tv_sec = frame_duration_seconds;
	itime_frame.it_value.tv_nsec = frame_duration_ns;
	itime_frame.it_interval.tv_sec = frame_duration_seconds;
	itime_frame.it_interval.tv_nsec = frame_duration_ns;
	timer_settime(frame_timer_id, 0, &itime_frame, NULL);


	int tid;
	int i = 0;
	pthread_create(&tid, NULL, print_functions, (void *)i);
	for (;;) {
		rcvid = MsgReceivePulse(chid, &msg, sizeof(msg), NULL);
		if (rcvid == 0) {
			if (msg.pulse.code == FRAME_PULSE_CODE) {
				i++;
				pthread_cancel(tid);
				pthread_create(&tid, NULL, print_functions, (void *)i);
				printf("\n\n\tKoniec ramki %d\n\n", i);
				if(i == frames_count) {
					printf("\n\n\t\tKoniec hiper-okresu\n\n");
					i = -1;
				}
			}
		}
	}
}
Пример #17
0
int main(int argc, char *argv[]) {
	pid_t pid_2 = getpid();
	pid_t pid_1 = getppid();
	char *msg = (char*)malloc(BUFFER_LENGTH*sizeof(char));
	char *rmsg = (char*)malloc(BUFFER_LENGTH*sizeof(char));
	printf(" P2>\n");
	printf(" P2> Parent pid: %i\n", pid_1);
	int chidP1 = atoi(argv[0]);

	// Step 3 Creating channel - chidP2.
	int chidP2 = ChannelCreate(0);
	printf(" P2> pid: %i, P1 chid: %i, P2 chid: %i\n", pid_2, chidP1, chidP2);

	// Step 4 Spawning P3 process - pid_3.
	char argv0[12];
	sprintf(argv0, "%i", chidP2);
	int pid_3 = spawnl(P_NOWAITO, "/tmp/M3", argv0, NULL);

	// Step 6 Sending chidP2 to P1.
	int coid_1 = ConnectAttach(ND_LOCAL_NODE, pid_1, chidP1, _NTO_SIDE_CHANNEL, 0);
	if (coid_1==-1) {
		fprintf(stderr, "Connection error.\n");
		exit(EXIT_FAILURE);
	}
	printf(" P2> P2 coid: %i\n", coid_1);
	int msg_res = MsgSend(coid_1, &chidP2, sizeof(int), rmsg, BUFFER_LENGTH*sizeof(char)); //sizeof(bytes)
	if (msg_res < 0) {
		msg_res = errno;
		fprintf(stderr, " P2> Error MsgSend\n");
		fprintf(stderr, " P2> Error code:%i\n", msg_res);
		exit(EXIT_FAILURE);
	}
	printf(" P2> Server replied \n%s\n", rmsg);

	// Step 8 Receiving query from P3.
	int rcvid = MsgReceive(chidP2, msg, sizeof(msg), NULL);
	printf(" P2> Received, rcvid: %i\n", rcvid);
	printf(" P2> Message: %s\n", msg);

	// Step 9 Replying to P3. Sending pid_1 and chidP1.
	*(int*)((int)msg) = pid_1;
	*(int*)((int)msg + 4) = chidP1;
	MsgReply(rcvid, EOK, msg, 8);

	// Step 12 Receiving message from P1. Reply.
	rcvid = MsgReceive(chidP2, msg, sizeof(msg), NULL);
	printf(" P2> Received, rcvid: %i\n", rcvid);
	printf(" P2> Message: %s\n", msg);
	strcpy(msg, "P2 OK");
	MsgReply(rcvid, EOK, msg, strlen(msg) + 1);

	printf(" P2> Good luck!\n");
	return EXIT_SUCCESS;
}
Пример #18
0
//Communication with the server
//Using buffers: buffer, receive
int message_client(pid_t pid){
	int channelID, status;
	channelID = ConnectAttach(0, pid, 1, 0, 0);

	//Sends data in buffer. Puts returned data in receive buffer
	status = MsgSend(channelID, &buffer, sizeof buffer, &receive, sizeof receive);

	//Detach from server
	ConnectDetach(channelID);

	//Unnecessary return
	return channelID;
}
Пример #19
0
void CreateInterrupt(Interrupt *ret, long periodMicros, long sec)
{
	//declare variables
	struct sigevent event;
	struct itimerspec timer;
	struct _clockperiod clkper;
	struct sched_param param;
	timer_t timer_id;

	/* Give this thread root permissions to access the hardware */
	ThreadCtl( _NTO_TCTL_IO, NULL );

	int chid = ChannelCreate( 0 ); //create event channel

	/* Set our priority to the maximum, so we won’t get disrupted by anything other than interrupts. */
	param.sched_priority = sched_get_priority_max( SCHED_RR );

	//set the clock from 10ns to 1microsecond ticks
	clkper.nsec = 100000;
	clkper.fract = 0;
	ClockPeriod ( CLOCK_REALTIME, &clkper, NULL, 0 ); // 1ms

	//Set up the pulse width modulation event
	event.sigev_notify = SIGEV_PULSE;		// most basic message we can send -- just a pulse number
	event.sigev_coid = ConnectAttach ( ND_LOCAL_NODE, 0, chid, 0, 0 );  // Get ID that allows me to communicate on the channel
	assert ( event.sigev_coid != -1 );		// stop with error if cannot attach to channel
	event.sigev_priority = getprio(0);
	event.sigev_code = 1023;				// arbitrary number assigned to this pulse
	event.sigev_value.sival_ptr = (void*)0;		// ?? TBD

	// Now create the timer and get back the timer_id value for the timer we created.
	if ( timer_create( CLOCK_REALTIME, &event, &timer_id ) == -1)
	{
		perror ( "can’t create timer" );
		exit( EXIT_FAILURE );
	}

	/* Change the timer request to alter the behavior. */
	timer.it_value.tv_sec = sec;
	timer.it_value.tv_nsec = periodMicros * 1000;
	timer.it_interval.tv_sec = sec;
	timer.it_interval.tv_nsec = periodMicros * 1000;


	//ret = (Interrupt){timer_id, timer, chid, periodMicros};
	ret->timer_id = timer_id;
	ret->timer = timer;
	ret->chid = chid;
	ret->period = periodMicros;
}
Пример #20
0
int main(int argc, char* argv[]) 
{
	int coid;         //Connection ID to server
	cksum_msg_t msg;
	int incoming_checksum;  //space for server's reply
	int status;       //status return value used for ConnectAttach and MsgSend
	int server_pid;   //server's process ID
	int server_chid;  //server's channel ID

    setvbuf (stdout, NULL, _IOLBF, 0);

	if(4 != argc) {
		printf("This program must be started with commandline arguments, for example:\n\n");
		printf("   cli 482834 1 abcdefghi    \n\n");
		printf(" 1st arg(482834): server's pid\n");
		printf(" 2nd arg(1): server's chid\n");
		printf(" 3rd arg(abcdefghi): string to send to server\n"); //to make it 
		                                //easy, let's not bother handling spaces
		exit(EXIT_FAILURE);
	}
	
	server_pid = atoi(argv[1]);
	server_chid = atoi(argv[2]);
	
	printf("attempting to establish connection with server pid: %d, chid %d\n", server_pid, server_chid);
	
	//PUT CODE HERE to establish a connection to the server's channel, store the
	//connection id in the variable 'coid'
	coid = ConnectAttach(ND_LOCAL_NODE, server_pid, server_chid, _NTO_SIDE_CHANNEL, NULL);
	if(-1 == coid) {   //was there an error attaching to server?
		perror("ConnectAttach"); //look up error code and print
		exit(EXIT_FAILURE);
	}
	
	msg.msg_type = CKSUM_MSG_TYPE;
	strcpy(msg.string_to_cksum, argv[3]);
	printf("Sending string: %s\n", msg.string_to_cksum);
	
	//PUT CODE HERE to send message to server and get the reply
	status = MsgSend(coid, &msg, sizeof(msg), &incoming_checksum, sizeof(incoming_checksum));
	if(-1 == status) {   //was there an error sending to server?
		perror("MsgSend");
		exit(EXIT_FAILURE);
	}
	
	printf("received checksum=%d from server\n", incoming_checksum);
	printf("MsgSend return status: %d\n", status);
	
	return EXIT_SUCCESS;
}
Пример #21
0
int main(int argc, char *argv[])
{
	int server_pid;   // PID serwera
	int server_chid;  // CHID serwera
	int coid;	// COID
	int value1;	// wysylana liczba1
	int value2 = 38; // wyslana liczba2
	int status; // status z funkcji MsgSend()

	if(argc != 4) {
		printf("K: Program musi byc wywolany z 3 argumentami, np:\n\n");
		printf("K: client 482834 1 abcdefghi    \n\n");
		printf("K: - pierwszy arg(482834): pid serwera\n");
		printf("K: - drugi arg(1): chid serwera\n");
		printf("K: - trzeci arg(5): int wysylany do serwera\n");
		exit(EXIT_FAILURE);
	}
	server_pid = atoi(argv[1]);
	server_chid = atoi(argv[2]);

	printf("K: Probuje nawiazac polaczenie z serwerem pid: %d, chid %d\n", server_pid, server_chid);
	/* Tworzenie polaczenia */
	coid = ConnectAttach(ND_LOCAL_NODE, server_pid, server_chid,_NTO_SIDE_CHANNEL,0);
	if (coid == -1)
	{
		printf("K: Nie moge utworzyc polaczenia: %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}

	value1 = atoi(argv[3]);
	printf("K: Wysylam wiadomosc: %d\n", value1);
	//	getprio(0) pobiera priorytet biezacego procesu.
	status = MsgSendPulse(coid, getprio(0),_PULSE_CODE_MINAVAIL,value1);

	if (status == -1)
	{
		printf("K: Nie moge wyslac impulsu 1: %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}
	printf("K: Wysylam wiadomosc: %d\n", value2);
	status = MsgSendPulse(coid, getprio(0), _PULSE_CODE_MINAVAIL+5, value2);
	if (status == -1)
	{
		printf("K: Nie moge wyslac impulsu 2: %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}

	return EXIT_SUCCESS;
}
Пример #22
0
//Communication with the server
//Using buffers: buffer, receive
void* message_client(pid_t pid){
	int channelID, status;
	printf("RECEIVED ARGUMENT FROM DUMB PROCESS: %d\n", pid);
	channelID = ConnectAttach(0, pid, 1, 0, 0);

	//Sends data in buffer. Puts returned data in receive buffer
	status = MsgSend(channelID, &buffer, sizeof buffer, &receive, sizeof receive);

	printf("SERVER REPLY: %c\n", receive[0]);

	//Detach from server
	ConnectDetach(channelID);

	return 0;
}
Пример #23
0
int main(int argc, char* argv[])
{
	int coid;         //Connection ID to server
	int status;       //status return value used for ConnectAttach and MsgSend
	int server_pid;   //server's process ID
	int server_chid;  //server's channel ID
	kom_t msg;
	kom_t reply;

	if(3 != argc) {
		printf("This program must be started with commandline arguments, for example:\n\n");
		printf("   cli 482834 1   \n\n");
		printf(" 1st arg(482834): server's pid\n");
		printf(" 2nd arg(1): server's chid\n");
		exit(EXIT_FAILURE);
	}

	server_pid = atoi(argv[1]);
	server_chid = atoi(argv[2]);

	printf("attempting to establish connection with server pid: %d, chid %d\n", server_pid, server_chid);

	coid = ConnectAttach(ND_LOCAL_NODE, server_pid, server_chid, _NTO_SIDE_CHANNEL, 0);
	if(-1 == coid) {
		perror("ConnectAttach");
		exit(EXIT_FAILURE);
	}

	int i = 0;
	while(i++ < 10) {
		msg.type = 1;
		msg.from = getpid();
		sprintf(msg.text, "Proces %d, krok petli %d\n", getpid(), i);

		status = MsgSend(coid, &msg, sizeof(msg), &reply, sizeof(reply) );
		if(-1 == status) {
			perror("MsgSend");
			exit(EXIT_FAILURE);
		}
		sleep(1);
	}

	msg.type = 0;
	status = MsgSend(coid, &msg, sizeof(msg), &reply, sizeof(reply) );


	exit(EXIT_SUCCESS);
}
Пример #24
0
/*
 * Function     - __pwm_setup()
 *
 * Arguments    - None
 *
 * Return Value - None
 */
static __inline void __pwm_setup(void)
{
   timer_t  timer_id;
   struct sigevent event;
   struct itimerspec interval_time;

   // Set-up signal handler for handling __SIG_SETUP_OP
   action.sa_handler = __pwm_signal_handler;
   action.sa_flags = SA_SIGINFO;
   sigaction(__SIG_SETUP_OP, &action, NULL);

#if defined (__ARM__)
   // Map GPIO address into virtual memory
   gpio_base = (sint32_t)mmap_device_memory(0,
                                            GPIO_MEM_SIZE,
                                            (PROT_READ | PROT_WRITE | PROT_NOCACHE),
                                            0,
                                            (uint32_t)GPIO_BASE_ADDR);

   if(gpio_base == MAP_DEVICE_FAILED)
   {
      perror("Mapping GPIO base address\n");
      exit(0);
   }
#endif   // #if defined (__ARM__)

   // Create channel for timer pulses
   channel_id = ChannelCreate(0);

   // Setup timer pulse event
   event.sigev_notify = SIGEV_PULSE;
   event.sigev_priority = getprio(0);
   event.sigev_code = __TIMER_PULSE_CODE;
   event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0, channel_id, _NTO_SIDE_CHANNEL, 0);

   // Create the timer
   timer_create(CLOCK_REALTIME, &event, &timer_id);

   // Set timer interval
   interval_time.it_value.tv_sec = 0;
   interval_time.it_value.tv_nsec = __TIMER_TICK_NS;
   interval_time.it_interval.tv_sec = 0;
   interval_time.it_interval.tv_nsec = __TIMER_TICK_NS;

   // Timer will start after this call
   timer_settime(timer_id, 0, &interval_time, NULL);
}
Пример #25
0
void nagger(void *arg){
	set_priority(*(int*)arg);

	// Creating shared memory
	int skynetDesc = shm_open("/skynetcore", O_RDWR, S_IRWXU);
	struct skynetCore_t* skynetCore = mmap(0, sizeof(struct skynetCore_t), PROT_READ|PROT_WRITE, MAP_SHARED, skynetDesc, 0);

	pthread_mutex_lock(&skynetCore->protector);
	int corePid = skynetCore->pid;
	pthread_mutex_unlock(&skynetCore->protector);

	int message = *(int*)arg;
	int skynetChannelId = ConnectAttach(0, corePid, 1, 0, 0);
	MsgSend(skynetChannelId, &message, sizeof(int), &message, sizeof(int));
	printf("I sent %i and got %i back!\n", *(int*)arg, message);
	ConnectDetach(skynetChannelId);
}
Пример #26
0
Sensorik::Sensorik() {
	initInterrupts();

	// create channel for dispatcher
	sensorik_Chid = ChannelCreate(0);
	if (sensorik_Chid == -1) {
		perror("Dispatcher: ChannelCreate sensorik_Chid failed");
		exit(EXIT_FAILURE);
	}

	// attach to signal channel(stellt die verbindung zu dem channel des Prozesses PID)
	sensorik_Coid = ConnectAttach(0, 0, sensorik_Chid, _NTO_SIDE_CHANNEL, 0);
	if (sensorik_Coid == -1) {
		perror("SensorCtrl: ConnectAttach sensorik_Coid failed");
		exit(EXIT_FAILURE);
	}
}
Пример #27
0
void B2S02_Seg1::timerSeg1Max() {

	puckHandler->removePuckFromBand(controller);
	actorHAL->engineStop();

	printf("Debug State <B2S02_Seg1>: ERROR<ERR_STATE_ERROR_MAX> called by puck%d\n", controller->getID());

	int replyChid = errfsm->getReplyChid();
	int errorfsmChid = errfsm->getErrorFSMChid();
	int errorfsmCoid;
	int rc;

	struct _pulse pulse;

	if ((errorfsmCoid = ConnectAttach(0, 0, errorfsmChid, _NTO_SIDE_CHANNEL, 0)) == -1) {
		printf("B2S02_Seg1: Error in ConnectAttach\n");
	}

	//rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_CRITICAL_ERROR);
	rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_ERROR_MAX);
	if (rc < 0) {
		printf("B2S02_Seg1: Error in MsgSendPulse");
	}

	rc = MsgReceivePulse(replyChid, &pulse, sizeof(pulse), NULL);
	if (rc < 0) {
		printf("B2S02_Seg1: Error in recv pulse\n");
	}

	if (ConnectDetach(errorfsmCoid) == -1) {
		printf("B2S02_Seg1: Error in ConnectDetach\n");
	}

	bool tmpBand1Waiting = controller->isBand1Waiting();

	controller->resetController();

	if(tmpBand1Waiting){
		rs232_1->sendMsg(RS232_BAND2_READY);
		ActorHAL::getInstance()->engineRight(false);
		ActorHAL::getInstance()->engineUnstop();

		controller->handOverTimer = timerHandler->createTimer(puckHandler->getDispChid(), TIME_VALUE_HAND_OVER_SEC, TIME_VALUE_HAND_OVER_MSEC, TIMER_HAND_OVER);
		timerHandler->startTimer(controller->handOverTimer);
	}
}
Пример #28
0
void *count_primes2(void *arg) {
	int status;
	int coid;
	par_t reply;

	coid = ConnectAttach(ND_LOCAL_NODE, pid, chid, _NTO_SIDE_CHANNEL, 0);
	while (1) {
		par_t args;
		args.typ = 10;
		args.numer = pthread_self();

		status = MsgSend(coid, &args, sizeof(args), &reply, sizeof(reply));
		if (reply.typ == 1) {
			sleep(1);

			int primes_count = 0;

			printf("Proces: %d, watek: %d\n", getpid(), pthread_self());
			int i;
			for (i = reply.pocz; i < reply.kon; i++) {
				int c;
				int prime = 1;
				for (c = 2; c <= i / 2; c++) {
					if (i % c == 0) {
						prime = 0;
						break;
					}
				}
				if (prime && i != 0 && i != 1)
					primes_count++;
			}

			//sleep(15 - args->numer);

			printf("\twatek: %d, poczatek %d, koniec %d, primes %d\n",
					pthread_self(), reply.pocz, reply.kon, primes_count);

			pthread_mutex_lock(&primes_mutex);
			p_count += primes_count;
			pthread_mutex_unlock(&primes_mutex);
		} else if (reply.typ == 0) {
			return 0;
		}

	}
}
Пример #29
0
/**
 * Do some initialization work :
 * Get HALSensoric instance
 * Create a channel and attach to it
 */
void Demultiplexer::init(){
	hal_sensoric_ = HALSensoric::getInstance();

	channel_id_ = ChannelCreate(0);
		if(channel_id_ == -1) {
			perror ("Demultiplexer: ChannelCreat failed : ");
			exit(EXIT_FAILURE);
		}

		con_id_ = ConnectAttach(0, 0, channel_id_, _NTO_SIDE_CHANNEL, 0);
		if (con_id_ == -1) {
			perror("Demultiplexer : ConnectAttach failed : ");
			exit(EXIT_FAILURE);
		}
#ifdef DEBUG_
		cout << "Demultiplexer attached to channelId: " << channel_id_ << endl;
#endif
}
Пример #30
0
void *t2()
{
	int coid, sending_status;

	struct _msg_info client_info;
	client_info.tid = 2;
	client_info.priority = 13;
	coid = ConnectAttach(0, pid, chid, _NTO_SIDE_CHANNEL, &client_info);

	sending_status = MsgSend(coid, NULL, 0, NULL, 0);
	if(-1 == sending_status) {   //was there an error sending to server?
		perror("MsgSend");
		exit(EXIT_FAILURE);
	}

	return EXIT_SUCCESS;

}