/usr/share/doc/libcomedi-dev/demo/eeprom_dump.c is in libcomedi-dev 0.10.2-4+b3.
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 | /*
Dumps eeproms
*/
#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include <stdlib.h>
#include "examples.h"
int read_eeprom(comedi_t *it,unsigned int **eeprom, struct parsed_options options);
void dump_eeprom(unsigned int *eeprom,int len);
comedi_t *device;
int main(int argc, char *argv[])
{
int len;
unsigned int *eeprom;
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);
}
len = read_eeprom(device, &eeprom, options);
dump_eeprom(eeprom,len);
return 0;
}
int read_eeprom(comedi_t *it, unsigned int **eeprom, struct parsed_options options)
{
int n,i,ret;
lsampl_t data;
unsigned int *ptr;
lsampl_t maxdata;
if(options.subdevice < 0)
{
options.subdevice = comedi_find_subdevice_by_type(it, COMEDI_SUBD_MEMORY, 0);
if(options.subdevice < 0){
fprintf(stderr,"No memory subdevice\n");
return 0;
}
}
n = comedi_get_n_channels(it, options.subdevice);
maxdata = comedi_get_maxdata(it, options.subdevice, 0);
if(maxdata != 0xff){
fprintf(stderr,"Demo only supports 8-bit memory subdevice has strange maxdata, aborting\n");
exit(-1);
}
ptr = malloc(sizeof(unsigned int) * n);
for(i = 0; i < n; i++){
ret = comedi_data_read(it, options.subdevice, i, 0, 0, &data);
ptr[i] = data;
if(ret < 0){
comedi_perror("comedi_data_read");
return 0;
}
}
*eeprom=ptr;
return n;
}
void dump_eeprom(unsigned int *eeprom,int len)
{
int i, j, c;
for (i = 0; i < len - 16; i+=16) {
printf("%04x: ",i);
for (j = 0; j < 16; j++) {
printf("%02x", eeprom[i + j] & 0xff);
}
printf(" ");
for (j = 0; j < 16; j++) {
c = eeprom[i + j] & 0xff;
printf("%c", isprint(c) ? c : '.');
}
printf("\n");
}
if(i==len)return;
printf("%04x: ",i);
for (j = 0; j < len-i; j++) {
printf("%02x", eeprom[i + j] & 0xff);
}
for(;j<16;j++){
printf(" ");
}
printf(" ");
for (j = 0; j < len-i; j++) {
c = eeprom[i + j] & 0xff;
printf("%c", isprint(c) ? c : '.');
}
for(;j<16;j++){
printf(" ");
}
printf("\n");
}
|