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