This file is indexed.

/usr/share/doc/libcomedi-dev/demo/sender.c is in libcomedi-dev 0.10.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Digital I/O example
 * Part of Comedilib
 *
 * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
 *
 * This file may be freely modified, distributed, and combined with
 * other software, as long as proper attribution is given in the
 * source code.
 */
/*
 * Requirements:  A board with a digital I/O subdevice.  Not just
 *    a 'digital input' or 'digital output' subdevice, but one in
 *    which the channels can be configured between input and output.
 */

#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "examples.h"


int chan_dat = 1;
int chan_clk = 0;

int wait1 = usec_to_nsec(0);
int wait2 = usec_to_nsec(0);

comedi_t *device;

void write_bits(int subdevice, int bits);


int main(int argc, char *argv[])
{
	int ret;
	int stype;
	int i;
	struct parsed_options options;

	init_parsed_options(&options);
	options.subdevice = -1;
	parse_options(&options, argc, argv);

	device = comedi_open(options.filename);
	if(!device){
		comedi_perror(options.filename);
		exit(-1);
	}
	if(options.subdevice < 0)
	{
		options.subdevice = comedi_find_subdevice_by_type(device, COMEDI_SUBD_DIO, 0);
		if(options.subdevice < 0){
			fprintf(stderr,"No dio subdevice found.\n");
			exit(-1);
		}
	}
	stype = comedi_get_subdevice_type(device, options.subdevice);
	if(stype != COMEDI_SUBD_DIO){
		printf("%d is not a digital I/O subdevice\n", options.subdevice);
		exit(-1);
	}

	printf("configuring pin %d for output...\n", chan_dat);
	ret = comedi_dio_config(device, options.subdevice, chan_dat, COMEDI_OUTPUT);
	if(ret < 0){
		comedi_perror("comedi_dio_config");
		exit(-1);
	}

	printf("configuring pin %d for output...\n", chan_clk);
	ret = comedi_dio_config(device, options.subdevice, chan_clk, COMEDI_OUTPUT);
	if(ret < 0){
		comedi_perror("comedi_dio_config");
		exit(-1);
	}

	for(i = 0; i < 0x100; i++){
		write_bits(options.subdevice, i);
	}
	//write_bits(0xa5);

	return 0;
}


void write_bits(int subdevice, int bits)
{
	comedi_insnlist il;
	comedi_insn insn[5];
	lsampl_t data[10];
	int mask = (1<<chan_dat)|(1<<chan_clk);
	int i;
	int bit;
	int ret;

	il.n_insns = 5;
	il.insns = insn;

	memset(insn,0,sizeof(insn));

	/* clock low, set data */
	insn[0].insn = INSN_BITS;
	insn[0].n = 2;
	insn[0].data = data + 0;
	insn[0].subdev = subdevice;

	/* wait 1 */
	insn[1].insn = INSN_WAIT;
	insn[1].n = 1;
	insn[1].data = data + 2;

	/* clock high, same data */
	insn[2].insn = INSN_BITS;
	insn[2].n = 2;
	insn[2].data = data + 4;
	insn[2].subdev = subdevice;

	/* wait 1 */
	insn[3].insn = INSN_WAIT;
	insn[3].n = 1;
	insn[3].data = data + 6;

	/* clock low, same data */
	insn[4].insn = INSN_BITS;
	insn[4].n = 2;
	insn[4].data = data + 8;
	insn[4].subdev = subdevice;


	for(i=0;i<8;i++){
		bit=1<<(7-i);
//printf("writing %d\n",bit&bits);

		data[0] = mask;
		data[1] = (bits&bit)?(1<<chan_dat):0;

		data[2] = wait1;
		data[3] = 0;

		data[4] = mask;
		data[5] = ((bits&bit)?(1<<chan_dat):0)|(1<<chan_clk);

		data[6] = wait2;
		data[7] = 0;

		data[8] = mask;
		data[9] = (bits&bit)?(1<<chan_dat):0;

		ret = comedi_do_insnlist(device,&il);
		if(ret < 0)
			comedi_perror("comedi_do_insnlist");
	}

}