~ubuntu-branches/ubuntu/intrepid/comedilib/intrepid

« back to all changes in this revision

Viewing changes to lib/get.c

  • Committer: Bazaar Package Importer
  • Author(s): David Schleef
  • Date: 2003-09-23 18:11:12 UTC
  • Revision ID: james.westby@ubuntu.com-20030923181112-sat05jyh702rb1at
Tags: upstream-0.7.21
ImportĀ upstreamĀ versionĀ 0.7.21

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    lib/get.c
 
3
    functions to return information about comedi devices
 
4
 
 
5
    COMEDILIB - Linux Control and Measurement Device Interface Library
 
6
    Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
 
7
 
 
8
    This library is free software; you can redistribute it and/or
 
9
    modify it under the terms of the GNU Lesser General Public
 
10
    License as published by the Free Software Foundation, version 2.1
 
11
    of the License.
 
12
 
 
13
    This library is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
    Lesser General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU Lesser General Public
 
19
    License along with this library; if not, write to the Free Software
 
20
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 
21
    USA.
 
22
*/
 
23
 
 
24
#include <stdio.h>
 
25
#include <math.h>
 
26
#include <stdlib.h>
 
27
#include <sys/types.h>
 
28
#include <sys/stat.h>
 
29
#include <fcntl.h>
 
30
#include <unistd.h>
 
31
#include <sys/ioctl.h>
 
32
#include <errno.h>
 
33
#include <string.h>
 
34
 
 
35
#include "libinternal.h"
 
36
 
 
37
 
 
38
EXPORT_ALIAS_DEFAULT(_comedi_get_n_subdevices,comedi_get_n_subdevices,0.7.18);
 
39
int _comedi_get_n_subdevices(comedi_t *it)
 
40
{
 
41
        if(!valid_dev(it))
 
42
                return -1;
 
43
 
 
44
        return it->n_subdevices;
 
45
}
 
46
 
 
47
EXPORT_ALIAS_DEFAULT(_comedi_get_version_code,comedi_get_version_code,0.7.18);
 
48
int _comedi_get_version_code(comedi_t *it)
 
49
{
 
50
        if(!valid_dev(it))
 
51
                return -1;
 
52
 
 
53
        return it->devinfo.version_code;
 
54
}
 
55
 
 
56
EXPORT_ALIAS_DEFAULT(_comedi_get_driver_name,comedi_get_driver_name,0.7.18);
 
57
char* _comedi_get_driver_name(comedi_t *it)
 
58
{
 
59
        if(!valid_dev(it))
 
60
                return NULL;
 
61
 
 
62
        return it->devinfo.driver_name;
 
63
}
 
64
 
 
65
EXPORT_ALIAS_DEFAULT(_comedi_get_board_name,comedi_get_board_name,0.7.18);
 
66
char* _comedi_get_board_name(comedi_t *it)
 
67
{
 
68
        if(!valid_dev(it))
 
69
                return NULL;
 
70
 
 
71
        return it->devinfo.board_name;
 
72
}
 
73
 
 
74
EXPORT_ALIAS_DEFAULT(_comedi_get_subdevice_flags,comedi_get_subdevice_flags,0.7.18);
 
75
int _comedi_get_subdevice_flags(comedi_t *it,unsigned int subd)
 
76
{
 
77
        if(!valid_dev(it))
 
78
                return 0;
 
79
 
 
80
        return it->subdevices[subd].subd_flags;
 
81
}
 
82
 
 
83
EXPORT_ALIAS_DEFAULT(_comedi_get_subdevice_type,comedi_get_subdevice_type,0.7.18);
 
84
int _comedi_get_subdevice_type(comedi_t *it,unsigned int subd)
 
85
{
 
86
        if(!valid_dev(it))
 
87
                return -1;
 
88
 
 
89
        return it->subdevices[subd].type;
 
90
}
 
91
 
 
92
EXPORT_ALIAS_DEFAULT(_comedi_find_subdevice_by_type,comedi_find_subdevice_by_type,0.7.18);
 
93
int _comedi_find_subdevice_by_type(comedi_t *it,int type,unsigned int subd)
 
94
{
 
95
        if(!valid_subd(it,subd))
 
96
                return -1;
 
97
 
 
98
        for(;subd<it->n_subdevices;subd++){
 
99
                if(it->subdevices[subd].type==type)
 
100
                        return subd;
 
101
        }
 
102
        return -1;
 
103
}
 
104
 
 
105
EXPORT_ALIAS_DEFAULT(_comedi_get_read_subdevice,comedi_get_read_subdevice,0.7.19);
 
106
int _comedi_get_read_subdevice(comedi_t *dev)
 
107
{
 
108
        if(!valid_dev(dev))
 
109
                return -1;
 
110
 
 
111
        return dev->devinfo.read_subdevice;
 
112
}
 
113
 
 
114
EXPORT_ALIAS_DEFAULT(_comedi_get_write_subdevice,comedi_get_write_subdevice,0.7.19);
 
115
int _comedi_get_write_subdevice(comedi_t *dev)
 
116
{
 
117
        if(!valid_dev(dev))
 
118
                return -1;
 
119
 
 
120
        return dev->devinfo.write_subdevice;
 
121
}
 
122
 
 
123
EXPORT_ALIAS_DEFAULT(_comedi_get_n_channels,comedi_get_n_channels,0.7.18);
 
124
int _comedi_get_n_channels(comedi_t *it,unsigned int subd)
 
125
{
 
126
        if(!valid_subd(it,subd))
 
127
                return -1;
 
128
 
 
129
        return it->subdevices[subd].n_chan;
 
130
}
 
131
 
 
132
 
 
133
/* */
 
134
 
 
135
EXPORT_ALIAS_DEFAULT(_comedi_get_maxdata,comedi_get_maxdata,0.7.18);
 
136
lsampl_t _comedi_get_maxdata(comedi_t *it,unsigned int subdevice,unsigned int chan)
 
137
{
 
138
        if(!valid_chan(it,subdevice,chan))
 
139
                return 0;
 
140
 
 
141
        if(it->subdevices[subdevice].maxdata_list)
 
142
                return it->subdevices[subdevice].maxdata_list[chan];
 
143
 
 
144
        return it->subdevices[subdevice].maxdata;
 
145
}
 
146
 
 
147
EXPORT_ALIAS_DEFAULT(_comedi_maxdata_is_chan_specific,comedi_maxdata_is_chan_specific,0.7.18);
 
148
int _comedi_maxdata_is_chan_specific(comedi_t *it,unsigned int subdevice)
 
149
{
 
150
        if(it->subdevices[subdevice].maxdata_list)
 
151
                return 1;
 
152
        return 0;
 
153
}
 
154
 
 
155
EXPORT_ALIAS_DEFAULT(_comedi_get_rangetype,comedi_get_rangetype,0.7.18);
 
156
int _comedi_get_rangetype(comedi_t *it,unsigned int subdevice,unsigned int chan)
 
157
{
 
158
        if(!valid_chan(it,subdevice,chan))
 
159
                return -1;
 
160
 
 
161
        if(it->subdevices[subdevice].range_type_list)
 
162
                return it->subdevices[subdevice].range_type_list[chan];
 
163
 
 
164
        return it->subdevices[subdevice].range_type;
 
165
}
 
166
 
 
167
 
 
168
EXPORT_ALIAS_DEFAULT(_comedi_get_range,comedi_get_range,0.7.18);
 
169
comedi_range * _comedi_get_range(comedi_t *it,unsigned int subdevice,unsigned int chan,unsigned int range)
 
170
{
 
171
        int range_type;
 
172
 
 
173
        if(!valid_chan(it,subdevice,chan))
 
174
                return NULL;
 
175
 
 
176
        range_type=comedi_get_rangetype(it,subdevice,chan);
 
177
 
 
178
        if(range>=RANGE_LENGTH(range_type))
 
179
                return NULL;
 
180
 
 
181
        if(it->subdevices[subdevice].rangeinfo_list)
 
182
                return it->subdevices[subdevice].rangeinfo_list[chan]+range;
 
183
 
 
184
        return it->subdevices[subdevice].rangeinfo+range;
 
185
}
 
186
 
 
187