How to get a Pulse in Photon

Hi all,

I have the problem that I can’t recognise a Pulse sent by MsgSendPulse into
my Photon application.

The problem: I have a library in which I setup “callbacks” by submitting
Connection ID’s to the lib. When an event occurs, it sends a Pulse via
MsgSndPulse to this Connection ID.
Everything works fine, as long as I don’t use Photon.

I tried to use PtAppAddInput with a 0 rcvid, but if the pulse is sent, the
handler is not called.

Has anyone a hint how to do it? I don’t want to make the lib Photon
dependant, which I had to do if I follow the “Interprocess Communication”
part of the Photon documentation.

Anx help is appreciated.

Greetings,
Sven

Hello Sven,

Take a look at the following link. I think this may answer your questions.
http://qdn.qnx.com/support/docs/photon_2.0_en/prog_guide/ipc.html

Regards,
Dave B.

Sven Fischer wrote:

Hi all,

I have the problem that I can’t recognise a Pulse sent by MsgSendPulse into
my Photon application.

The problem: I have a library in which I setup “callbacks” by submitting
Connection ID’s to the lib. When an event occurs, it sends a Pulse via
MsgSndPulse to this Connection ID.
Everything works fine, as long as I don’t use Photon.

I tried to use PtAppAddInput with a 0 rcvid, but if the pulse is sent, the
handler is not called.

Has anyone a hint how to do it? I don’t want to make the lib Photon
dependant, which I had to do if I follow the “Interprocess Communication”
part of the Photon documentation.

Anx help is appreciated.

Greetings,
Sven

Apps wrote:

Hello Sven,

Take a look at the following link. I think this may answer your
questions.
http://qdn.qnx.com/support/docs/photon_2.0_en/prog_guide/ipc.html

Great. I have gone through this a lot of times, and then I decided to ask
in the newsgroup, because I didn’t get any results. For my problems, read
my original posting.

Yes, I could do it the way you propose, e.g. with a Pt* function, but I
just want to use plain MsgSendPulse in my library, and that gives the
problems 'cause my Photon app doesn’t recognize them.

Sven

Hi Sven,

I have spoken with one of the developers and the preferred way is to use PtPulseArm()
and pass the sigevent rather than just the connection ID.

Hand-made pulses with non-negative codes should work with an input proc
attached to pid 0, but they didn’t in 6.0.

hope this helps
Regards
Brenda


Sven Fischer <fischer@deutaeit.de> wrote:

Apps wrote:

Hello Sven,

Take a look at the following link. I think this may answer your
questions.
http://qdn.qnx.com/support/docs/photon_2.0_en/prog_guide/ipc.html

Great. I have gone through this a lot of times, and then I decided to ask
in the newsgroup, because I didn’t get any results. For my problems, read
my original posting.

Yes, I could do it the way you propose, e.g. with a Pt* function, but I
just want to use plain MsgSendPulse in my library, and that gives the
problems 'cause my Photon app doesn’t recognize them.

Sven

Gui Group wrote:

I have spoken with one of the developers and the preferred way is to use
PtPulseArm() and pass the sigevent rather than just the connection ID.

Maybe you could ask them if I am able to use the sigev_code and/or the
sigev_value.sival_ptr fields of the sigevent structure, or if they have to
be kept fixed. I am using these fields right now in my pulses.

Hand-made pulses with non-negative codes should work with an input proc
attached to pid 0, but they didn’t in 6.0.

…and obviously not in 6.1 likewise.

Thanks for your help,
Sven

Hi Sven,

I received more information from the developer:

Sven Fischer <fischer@deutaeit.de> wrote:

Gui Group wrote:

I have spoken with one of the developers and the preferred way is to use
PtPulseArm() and pass the sigevent rather than just the connection ID.

Maybe you could ask them if I am able to use the sigev_code and/or the
sigev_value.sival_ptr fields of the sigevent structure, or if they have to
be kept fixed. I am using these fields right now in my pulses.

Hand-made pulses with non-negative codes should work with an input proc
attached to pid 0, but they didn’t in 6.0.

…and obviously not in 6.1 likewise.

Thanks for your help,
Sven

The preferred way is to use PtAppCreatePulse() to allocate a pulse
code and value, and PtPulseArm() to get them in the form of a
sigevent structure. Since the Photon library uses the code and the
value to distinguish between different Photon pulses, the pulse you
send must match the Photon-generated code and value exactly (except
the top three bits of the value – see docs); otherwise the library
will ignore the pulse.

Another way to use pulses it is to use a pulse code in the “user
range” (non-negative) and any value you want. These pulses will be
only given to input procs attached to pid zero. This method gives
you the freedom to use all the 32 bits of the value, but it makes it
your responsibility to keep track of the codes and values that each
part of your application uses, which can be inconvenient if your
application has many such parts. As I said, this method did not
work in 6.0, but it does work in 6.1.

The following sample program works under 6.1 and demonstrates how
to set up the pulses:

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

void fail( const char *msg ) {
perror( msg );
exit( 1 );
}

void be_child( int chid, struct sigevent *sev ) {
pid_t parent = getppid();
int coid;
if ( ( coid = ConnectAttach( 0, parent, chid, _NTO_SIDE_CHANNEL, 0 ) ) < 0 )
fail( “ConnectAttach” );
printf( “Sending the Photon pulse…\n” );
if ( MsgSendPulse( coid, 10, sev->sigev_code, sev->sigev_value.sival_int ) == -1 )
fail( “MsgSendPulse” );
sleep( 1 );
printf( “Sending the user pulse…\n” );
if ( MsgSendPulse( coid, 10, 3, 0x12345678 ) == -1 )
fail( “MsgSendPulse” );
sleep( 1 );
kill( parent, SIGINT );
}

int ptinput( void *data, int rcvid, void *message, size_t size ) {
printf( “Got Photon pulse\n” );
return Pt_HALT;
}

int userinput( void *data, int rcvid, void *message, size_t size ) {
struct _pulse *pulse = message;
printf( “Got user pulse (%d.%X)\n”, pulse->code, pulse->value.sival_int );
return Pt_HALT;
}

void main( void ) {
int chid;
struct sigevent sev;
pid_t ptpulse, child;
if ( PtInit( NULL ) )
fail( “PtInit” );
if ( ( chid = PtChannelCreate() ) < 0 )
fail( “PtChannelCreate” );
if ( ( ptpulse = PtAppCreatePulse( NULL, -1 ) ) == 0 )
fail( “PtAppCreatePulse” );
if ( PtPulseArm( NULL, ptpulse, &sev ) )
fail( “PtPulseArm” );
if ( PtAppAddInput( NULL, ptpulse, ptinput, NULL ) == NULL
|| PtAppAddInput( NULL, 0, userinput, NULL ) == NULL
)
fail( “PtAppAddInput” );
if ( ( child = fork() ) < 0 )
fail( “fork” );
if ( child == 0 )
be_child( chid, &sev );
else
PtMainLoop();
}

Hope this helps
Regards
Brenda

Hi Sven,

Sorry I did a typo …

it should be the top four bits of the value instead of the three
that I wrote…

Sorry
Brenda

Gui Group <gui@qnx.com> wrote:

Hi Sven,

I received more information from the developer:

Sven Fischer <> fischer@deutaeit.de> > wrote:
Gui Group wrote:

I have spoken with one of the developers and the preferred way is to use
PtPulseArm() and pass the sigevent rather than just the connection ID.

Maybe you could ask them if I am able to use the sigev_code and/or the
sigev_value.sival_ptr fields of the sigevent structure, or if they have to
be kept fixed. I am using these fields right now in my pulses.

Hand-made pulses with non-negative codes should work with an input proc
attached to pid 0, but they didn’t in 6.0.

…and obviously not in 6.1 likewise.

Thanks for your help,
Sven

The preferred way is to use PtAppCreatePulse() to allocate a pulse
code and value, and PtPulseArm() to get them in the form of a
sigevent structure. Since the Photon library uses the code and the
value to distinguish between different Photon pulses, the pulse you
send must match the Photon-generated code and value exactly (except
the top three bits of the value – see docs); otherwise the library
will ignore the pulse.

Another way to use pulses it is to use a pulse code in the “user
range” (non-negative) and any value you want. These pulses will be
only given to input procs attached to pid zero. This method gives
you the freedom to use all the 32 bits of the value, but it makes it
your responsibility to keep track of the codes and values that each
part of your application uses, which can be inconvenient if your
application has many such parts. As I said, this method did not
work in 6.0, but it does work in 6.1.

The following sample program works under 6.1 and demonstrates how
to set up the pulses:

#include <stdio.h
#include <stdlib.h
#include <sys/neutrino.h
#include <Pt.h

void fail( const char *msg ) {
perror( msg );
exit( 1 );
}

void be_child( int chid, struct sigevent *sev ) {
pid_t parent = getppid();
int coid;
if ( ( coid = ConnectAttach( 0, parent, chid, _NTO_SIDE_CHANNEL, 0 ) ) < 0 )
fail( “ConnectAttach” );
printf( “Sending the Photon pulse…\n” );
if ( MsgSendPulse( coid, 10, sev->sigev_code, sev->sigev_value.sival_int ) == -1 )
fail( “MsgSendPulse” );
sleep( 1 );
printf( “Sending the user pulse…\n” );
if ( MsgSendPulse( coid, 10, 3, 0x12345678 ) == -1 )
fail( “MsgSendPulse” );
sleep( 1 );
kill( parent, SIGINT );
}

int ptinput( void *data, int rcvid, void *message, size_t size ) {
printf( “Got Photon pulse\n” );
return Pt_HALT;
}

int userinput( void *data, int rcvid, void *message, size_t size ) {
struct _pulse *pulse = message;
printf( “Got user pulse (%d.%X)\n”, pulse->code, pulse->value.sival_int );
return Pt_HALT;
}

void main( void ) {
int chid;
struct sigevent sev;
pid_t ptpulse, child;
if ( PtInit( NULL ) )
fail( “PtInit” );
if ( ( chid = PtChannelCreate() ) < 0 )
fail( “PtChannelCreate” );
if ( ( ptpulse = PtAppCreatePulse( NULL, -1 ) ) == 0 )
fail( “PtAppCreatePulse” );
if ( PtPulseArm( NULL, ptpulse, &sev ) )
fail( “PtPulseArm” );
if ( PtAppAddInput( NULL, ptpulse, ptinput, NULL ) == NULL
|| PtAppAddInput( NULL, 0, userinput, NULL ) == NULL
)
fail( “PtAppAddInput” );
if ( ( child = fork() ) < 0 )
fail( “fork” );
if ( child == 0 )
be_child( chid, &sev );
else
PtMainLoop();
}

Hope this helps
Regards
Brenda