~ubuntu-branches/debian/jessie/rtai/jessie

« back to all changes in this revision

Viewing changes to rtai-lab/scilab5/devices/rtai_led.c

  • Committer: Bazaar Package Importer
  • Author(s): Roland Stigge
  • Date: 2009-07-04 11:47:08 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090704114708-0ivbkccfaawz2pby
Tags: 3.7.1-1
* New upstream release
* debian/control: Standards-Version: 3.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
COPYRIGHT (C) 2006  Roberto Bucher (roberto.bucher@supsi.ch)
 
3
 
 
4
This library is free software; you can redistribute it and/or
 
5
modify it under the terms of the GNU Lesser General Public
 
6
License as published by the Free Software Foundation; either
 
7
version 2 of the License, or (at your option) any later version.
 
8
 
 
9
This library is distributed in the hope that it will be useful,
 
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
Lesser General Public License for more details.
 
13
 
 
14
You should have received a copy of the GNU Lesser General Public
 
15
License along with this library; if not, write to the Free Software
 
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 
17
*/
 
18
 
 
19
#include <machine.h>
 
20
#include <scicos_block4.h>
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
#include <rtai_netrpc.h>
 
24
#include <rtai_msg.h>
 
25
#include <rtai_mbx.h>
 
26
#include <string.h>
 
27
#include "rtmain.h"
 
28
 
 
29
#define MAX_RTAI_LEDS               1000
 
30
#define MBX_RTAI_LED_SIZE           5000
 
31
 
 
32
extern char *TargetLedMbxID;
 
33
 
 
34
void par_getstr(char * str, int par[], int init, int len);
 
35
 
 
36
static void init(scicos_block *block)
 
37
{
 
38
  char ledName[20];
 
39
  char name[7];
 
40
  int nch  = GetNin(block);
 
41
  int * ipar = GetIparPtrs(block);
 
42
  MBX *mbx;
 
43
 
 
44
  par_getstr(ledName,ipar,1,ipar[0]);
 
45
  rtRegisterLed(ledName,nch);
 
46
  get_a_name(TargetLedMbxID,name);
 
47
 
 
48
  mbx = (MBX *) RT_typed_named_mbx_init(0,0,name,MBX_RTAI_LED_SIZE/sizeof(unsigned int)*sizeof(unsigned int),FIFO_Q);
 
49
  if(mbx == NULL) {
 
50
    fprintf(stderr, "Cannot init mailbox\n");
 
51
    exit_on_error();
 
52
  }
 
53
 
 
54
  *(block->work) = mbx;
 
55
 
 
56
}
 
57
 
 
58
static void inout(scicos_block *block)
 
59
{
 
60
  MBX * mbx = *(block->work);
 
61
  int i;
 
62
  unsigned int led_mask = 0;
 
63
  int nleds  = GetNin(block);
 
64
 
 
65
  double *u;
 
66
  for (i = 0; i < nleds; i++) {
 
67
    u = block->inptr[i];
 
68
    if (u[0] > 0.1) {
 
69
      led_mask += (1 << i);
 
70
    } else {
 
71
      led_mask += (0 << i);
 
72
    }
 
73
  }
 
74
  RT_mbx_send_if(0, 0, mbx, &led_mask, sizeof(led_mask));
 
75
 
 
76
}
 
77
 
 
78
static void end(scicos_block *block)
 
79
{
 
80
  int * ipar = GetIparPtrs(block);
 
81
 
 
82
  char ledName[10];
 
83
  MBX * mbx = *(block->work);
 
84
  RT_named_mbx_delete(0, 0, mbx);
 
85
  par_getstr(ledName,ipar,1,ipar[0]);
 
86
  printf("Led %s closed\n",ledName);
 
87
 
 
88
}
 
89
 
 
90
void rtled(scicos_block *block,int flag)
 
91
{
 
92
  if (flag==1){          /* set output */
 
93
    inout(block);
 
94
  }
 
95
  else if (flag==5){     /* termination */ 
 
96
    end(block);
 
97
  }
 
98
  else if (flag ==4){    /* initialisation */
 
99
    init(block);
 
100
  }
 
101
}
 
102
 
 
103