Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Timer based program problem: (3 Items)
   
Timer based program problem  
Hello

First of all: sorry for my English - it isn't as good as I want it to be :). Secondly: I'm supposed to write program in 
which server receives messages and is stimulated via impulses which are being sent from the timer. 

Unfortunately I completely don't know how to write this program as I've never taken up with QNX before to much and 
what's more I don't have possibility to check whatever it works. 

Please help - I need to have this program by the end of this week. Any help would be nice.

Thank in advance. Regards.



RE: Timer based program problem  
In the Help, you can find the book of "Getting Started with QNX
Neutrino: A Guide for Realtime Programmer". In the "Sample Programs" in
this book, there is an sample code "time1.c" which shows how the server
gets the pulse when timer expires. You can start from there. 

Thanks
Weijie
 

-----Original Message-----
From: Rafal B [mailto:community-noreply@qnx.com] 
Sent: June 9, 2009 2:53 AM
To: general-community
Subject: Timer based program problem

Hello

First of all: sorry for my English - it isn't as good as I want it to be
:). Secondly: I'm supposed to write program in which server receives
messages and is stimulated via impulses which are being sent from the
timer. 

Unfortunately I completely don't know how to write this program as I've
never taken up with QNX before to much and what's more I don't have
possibility to check whatever it works. 

Please help - I need to have this program by the end of this week. Any
help would be nice.

Thank in advance. Regards.





_______________________________________________
General
http://community.qnx.com/sf/go/post31180
Re: RE: Timer based program problem  
Weijie Zhang ---> thank you, I found it and it looks like this is the program I've been looking for. Unfortunately, it's
 quite complicated ;) like for me, at the class we haven't written such complex programs. For example, this is a program
 which send messages from client to server:


#include <stdlib.h>
#include <sys/neutrino.h>

#define SIZE 32

struct {
	int type; 				
	char text[SIZE]; 		
	} 

msg, rmsg;

main() {

	int child, res,i,pid, status;
	int chid,con;
	
	//Utworzenie kanalu
	chid = ChannelCreate(_NTO_CHF_DISCONNECT);

	//Tworzenie procesu potomnego
	if ((child = fork()) == 0) { 	
	// Kod klienta ------------------------------------
	printf("Proces potomny utworzony\n");
    pid = getppid();
    
    //Klient dolacza sie do kanalu chid procesu pid
    con = ConnectAttach(0,pid,chid,0,0);
    if(con>=0) {
    	printf("Proces potomny - polaczenie %d\n",con);
    } 
    else {
    perror("Polaczenie"); exit(1);
    }

    for(i=0; i<10; i++) {
    
    sprintf(msg.text,"K - %d",i);
    printf("Klient - wyslane: %s \n", msg.text);
    MsgSend(con,&msg,sizeof(msg),&rmsg,sizeof(rmsg));
    printf("Klient - odebrane: %s \n",rmsg.text);
    sleep(1);
    };
    exit(0);
	}
	
	//Kod serwera ---------------------------------------
	printf("Serwer startuje \n");
	for(i=0; i<11; i++) {
	pid = MsgReceive(chid,&msg,sizeof(msg),NULL);
	printf("Serwer - odebrane %s \n", msg.text);
	sprintf(msg.text,"potwierdzenie %d",i+1);
	res = MsgReply(pid,0,&msg,sizeof(msg));
	}
	pid = wait(&status);
}

Anyway ;) - I need to modify time1.c program a little bit. 

Once again, thanks.

Regards