fixed bug with USB buffer lost

This commit is contained in:
eddyem 2014-09-23 16:16:52 +04:00
parent 4f7419c715
commit 518a4b12f2
10 changed files with 429 additions and 363 deletions

View File

@ -1,22 +0,0 @@
PROGRAM = client
LDFLAGS =
SRCS = client.c
CC = gcc
DEFINES = -D_XOPEN_SOURCE=501
CXX = gcc
CFLAGS = -Wall -Werror $(DEFINES)
OBJS = $(SRCS:.c=.o)
all : $(PROGRAM) clean
$(PROGRAM) : $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM)
# some addition dependencies
# %.o: %.c
# $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@
#$(SRCS) : %.c : %.h $(INDEPENDENT_HEADERS)
# @touch $@
clean:
/bin/rm -f *.o *~
depend:
$(CXX) -MM $(CXX.SRCS)

View File

@ -1,261 +0,0 @@
/*
* client.c - simple terminal client
*
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <termios.h> // tcsetattr
#include <unistd.h> // tcsetattr, close, read, write
#include <sys/ioctl.h> // ioctl
#include <stdio.h> // printf, getchar, fopen, perror
#include <stdlib.h> // exit
#include <sys/stat.h> // read
#include <fcntl.h> // read
#include <signal.h> // signal
#include <time.h> // time
#include <string.h> // memcpy
#include <stdint.h> // int types
#include <sys/time.h> // gettimeofday
#define BUFLEN 1024
double t0; // start time
FILE *fout = NULL; // file for messages duplicating
char *comdev = "/dev/ttyACM0";
int BAUD_RATE = B115200;
struct termio oldtty, tty; // TTY flags
struct termios oldt, newt; // terminal flags
int comfd; // TTY fd
/**
* function for different purposes that need to know time intervals
* @return double value: time in seconds
*/
double dtime(){
double t;
struct timeval tv;
gettimeofday(&tv, NULL);
t = tv.tv_sec + ((double)tv.tv_usec)/1e6;
return t;
}
/**
* Exit & return terminal to old state
* @param ex_stat - status (return code)
*/
void quit(int ex_stat){
tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // return terminal to previous state
ioctl(comfd, TCSANOW, &oldtty ); // return TTY to previous state
close(comfd);
if(fout) fclose(fout);
printf("Exit! (%d)\n", ex_stat);
exit(ex_stat);
}
/**
* Open & setup TTY, terminal
*/
void tty_init(){
// terminal without echo
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
if(tcsetattr(STDIN_FILENO, TCSANOW, &newt) < 0) quit(-2);
printf("\nOpen port...\n");
if ((comfd = open(comdev,O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0){
fprintf(stderr,"Can't use port %s\n",comdev);
quit(1);
}
printf(" OK\nGet current settings...\n");
if(ioctl(comfd,TCGETA,&oldtty) < 0) exit(-1); // Get settings
tty = oldtty;
tty.c_lflag = 0; // ~(ICANON | ECHO | ECHOE | ISIG)
tty.c_oflag = 0;
tty.c_cflag = BAUD_RATE|CS8|CREAD|CLOCAL; // 9.6k, 8N1, RW, ignore line ctrl
tty.c_cc[VMIN] = 0; // non-canonical mode
tty.c_cc[VTIME] = 5;
if(ioctl(comfd,TCSETA,&tty) < 0) exit(-1); // set new mode
printf(" OK\n");
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
}
/**
* getchar() without echo
* wait until at least one character pressed
* @return character readed
*
int mygetchar(){
int ret;
do ret = read_console();
while(ret == 0);
return ret;
}*/
/**
* read both tty & console
* @param buff (o) - buffer for messages readed from tty
* @param length (io) - buff's length (return readed len or 0)
* @param rb (o) - byte readed from console or -1
* @return 1 if something was readed here or there
*/
int read_tty_and_console(char *buff, size_t *length, int *rb){
ssize_t L;
struct timeval tv;
int sel, retval = 0;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(STDIN_FILENO, &rfds);
FD_SET(comfd, &rfds);
tv.tv_sec = 0; tv.tv_usec = 10000;
sel = select(comfd + 1, &rfds, NULL, NULL, &tv);
if(sel > 0){
if(FD_ISSET(STDIN_FILENO, &rfds)){
*rb = getchar();
retval = 1;
}else{
*rb = -1;
}
if(FD_ISSET(comfd, &rfds)){
if((L = read(comfd, buff, *length)) < 1){ // disconnect or other troubles
fprintf(stderr, "USB error or disconnected!\n");
quit(1);
}else{
if(L == 0){ // USB disconnected
fprintf(stderr, "USB disconnected!\n");
quit(1);
}
*length = (size_t) L;
retval = 1;
}
}else{
*length = 0;
}
}
return retval;
}
void help(){
printf("Use this commands:\n"
"h\tShow this help\n"
"q\tQuit\n"
);
}
void con_sig(int rb){
char cmd;
if(rb < 1) return;
if(rb == 'q') quit(0); // q == exit
cmd = (char) rb;
write(comfd, &cmd, 1);
/*switch(rb){
case 'h':
help();
break;
default:
cmd = (uint8_t) rb;
write(comfd, &cmd, 1);
}*/
}
/**
* Get integer value from buffer
* @param buff (i) - buffer with int
* @param len - length of data in buffer (could be 2 or 4)
* @return
*/
uint32_t get_int(char *buff, size_t len){
if(len != 2 && len != 4){
fprintf(stdout, "Bad data length!\n");
return 0xffffffff;
}
uint32_t data = 0;
uint8_t *i8 = (uint8_t*) &data;
if(len == 2) memcpy(i8, buff, 2);
else memcpy(i8, buff, 4);
return data;
}
/**
* Copy line by line buffer buff to file removing cmd starting from newline
* @param buffer - data to put into file
* @param cmd - symbol to remove from line startint (if found, change *cmd to (-1)
* or NULL, (-1) if no command to remove
*/
void copy_buf_to_file(char *buffer, int *cmd){
char *buff, *line, *ptr;
if(!cmd || *cmd < 0){
fprintf(fout, "%s", buffer);
return;
}
buff = strdup(buffer), ptr = buff;
do{
if(!*ptr) break;
if(ptr[0] == (char)*cmd){
*cmd = -1;
ptr++;
if(ptr[0] == '\n') ptr++;
if(!*ptr) break;
}
line = ptr;
ptr = strchr(buff, '\n');
if(ptr){
*ptr++ = 0;
//fprintf(fout, "%s\n", line);
}//else
//fprintf(fout, "%s", line); // no newline found in buffer
fprintf(fout, "%s\n", line);
}while(ptr);
free(buff);
}
int main(int argc, char *argv[]){
int rb, oldcmd = -1;
char buff[BUFLEN+1];
size_t L;
if(argc == 2){
fout = fopen(argv[1], "a");
if(!fout){
perror("Can't open output file");
exit(-1);
}
setbuf(fout, NULL);
}
tty_init();
signal(SIGTERM, quit); // kill (-15)
signal(SIGINT, quit); // ctrl+C
signal(SIGQUIT, SIG_IGN); // ctrl+\ .
signal(SIGTSTP, SIG_IGN); // ctrl+Z
setbuf(stdout, NULL);
t0 = dtime();
while(1){
L = BUFLEN;
if(read_tty_and_console(buff, &L, &rb)){
if(rb > 0){
con_sig(rb);
oldcmd = rb;
}
if(L){
buff[L] = 0;
printf("%s", buff);
if(fout){
copy_buf_to_file(buff, &oldcmd);
}
}
}
}
}

View File

@ -317,7 +317,8 @@ void usb_send_buffer(){
send_block = 1; send_block = 1;
if(USB_Tx_ptr){ if(USB_Tx_ptr){
if(current_usb && USB_connected){ if(current_usb && USB_connected){
usbd_ep_write_packet(current_usb, 0x82, USB_Tx_Buffer, USB_Tx_ptr); // usbd_ep_write_packet return 0 if previous packet isn't transmit yet
while(USB_Tx_ptr != usbd_ep_write_packet(current_usb, 0x82, USB_Tx_Buffer, USB_Tx_ptr));
usbd_poll(current_usb); usbd_poll(current_usb);
} }
USB_Tx_ptr = 0; USB_Tx_ptr = 0;

View File

@ -4,12 +4,12 @@ function Tout = H705(Rin)
_alpha = 0.00375; _alpha = 0.00375;
_beta = 0.16; _beta = 0.16;
_delta = 1.605; _delta = 1.605;
T = [-200:0.1:50]; T = [-300:0.1:300];
_A = _alpha + _alpha*_delta/100.; _A = _alpha + _alpha*_delta/100.;
_B = -_alpha*_delta/1e4; _B = -_alpha*_delta/1e4;
_C = zeros(size(T)); _C = zeros(size(T));
_C(find(T<0.)) = -_alpha*_beta/1e8; _C(find(T<0.)) = -_alpha*_beta/1e8;
rT = 1000.*(1 + _A*T + _B*T.^2 - _C.*T.^3*100. + _C.*T.^4); rT = 1000.*(1 + _A*T + _B*T.^2 - _C.*T.^3*100. + _C.*T.^4);
%plot(T, rT); %plot(T, rT);
Tout = interp1(rT, T, Rin, 'spline') Tout = interp1(rT, T, Rin, 'spline');
endfunction endfunction

View File

@ -0,0 +1,182 @@
0 4030000 1950 2158 3 1241 1813 2066 1957 2142 831842 834237 829938 831237 837140 839963 837795 835370
0 4040000 1992 2152 2 1233 1798 2065 1958 2140 831451 834116 829908 831100 837022 839812 837645 835276
0 4110000 2007 2156 2 1237 1804 2076 1978 2155 831147 833584 829457 830553 836564 839470 837275 834922
0 4120000 2016 2160 4 1237 1808 2072 1960 2143 831160 833585 829380 830643 836541 839417 837195 834896
0 4190000 2010 2159 4 1233 1804 2068 1956 2145 944245 946269 942208 943118 949283 952112 949942 947836
0 4200000 1965 2167 0 1234 1804 2064 1957 2142 943980 946124 941858 942899 948925 951724 949644 947656
0 4210000 1995 2158 4 1236 1805 2068 1962 2141 943854 945934 941679 942910 948767 951754 949492 947428
0 4220000 1991 2163 0 1238 1804 2074 1964 2146 943716 945795 941504 942707 948657 951586 949432 947243
0 4230000 2008 2170 1 1236 1806 2064 1955 2140 943545 945720 941548 942565 948515 951515 949278 947220
0 4240000 1945 2149 2 1232 1799 2066 1958 2141 943460 945683 941417 942467 948403 951362 949248 947034
0 4250000 1992 2151 3 1232 1795 2059 1950 2138 943343 945537 941346 942462 948372 951288 949138 947082
0 4310000 1993 2158 3 1237 1807 2066 1959 2140 1020838 1022715 1018379 1019515 1025257 1028189 1026121 1024100
0 4320000 1995 2153 2 1238 1806 2073 1962 2143 1020553 1022458 1018151 1019149 1025203 1028162 1026032 1024140
0 4330000 2009 2162 5 1236 1807 2067 1962 2147 1020486 1022174 1017976 1019128 1025063 1028060 1025752 1024045
0 4460000 1990 2153 4 1237 1804 2068 1958 2144 1182496 1183725 1179656 1180533 1186405 1189477 1187228 1185755
0 4470000 2009 2170 4 1235 1802 2072 1959 2152 1182111 1183506 1179135 1179983 1186111 1189087 1186944 1185496
0 4480000 2009 2170 0 1238 1805 2063 1957 2140 1182042 1183267 1178928 1179945 1185878 1188797 1186833 1185302
0 4490000 2006 2167 4 1230 1799 2070 1984 2154 1181872 1183127 1178845 1179732 1185656 1188669 1186503 1185019
0 4500000 1994 2165 0 1243 1814 2083 1968 2141 1181589 1182886 1178552 1179593 1185587 1188506 1186396 1184883
0 4510000 1957 2135 1 1241 1810 2073 1964 2144 1181506 1182838 1178436 1179472 1185319 1188484 1186316 1184826
0 4520000 1996 2150 3 1232 1797 2069 1963 2144 1181502 1182765 1178388 1179346 1185269 1188228 1186105 1184646
0 4530000 1992 2159 2 1235 1803 2071 1964 2148 1181335 1182639 1178379 1179264 1185254 1188168 1185947 1184545
0 4590000 2150 2140 2 1247 1810 2081 1981 2163 1328006 1328720 1324254 1325017 1330980 1334057 1332001 1331029
0 4600000 1998 2153 3 1239 1808 2074 1957 2144 1327672 1328547 1324143 1324987 1330868 1333893 1331847 1330721
0 4610000 2006 2168 4 1234 1802 2073 1960 2151 1327550 1328322 1324003 1324734 1330742 1333785 1331718 1330647
0 4620000 1967 2167 0 1234 1803 2064 1956 2141 1327436 1328215 1323864 1324686 1330566 1333665 1331740 1330505
0 4630000 2006 2157 4 1233 1802 2075 1981 2153 1327319 1328117 1323740 1324559 1330458 1333584 1331466 1330326
0 4690000 1965 2160 0 1229 1796 2068 1961 2145 1327006 1327958 1323503 1324285 1330221 1333220 1331139 1330091
0 4750000 2012 2161 4 1233 1810 2074 1960 2145 1663850 1663596 1658970 1659810 1665682 1668801 1666709 1666428
0 4760000 1964 2164 0 1233 1803 2062 1956 2141 1663656 1663383 1658813 1659433 1665299 1668343 1666575 1666262
0 4770000 1990 2155 3 1234 1801 2063 1967 2146 1663481 1663248 1658683 1659281 1665414 1668263 1666291 1665862
0 4780000 2011 2161 2 1238 1806 2073 1973 2144 1663253 1663040 1658521 1659126 1664983 1668144 1666158 1665780
0 4790000 1967 2143 3 1245 1809 2069 1954 2141 1663086 1662854 1658367 1658974 1664888 1668054 1666020 1665791
0 4800000 1995 2149 3 1235 1803 2068 1961 2142 1662978 1662773 1658261 1658802 1664773 1667860 1665920 1665616
0 4810000 1990 2151 4 1235 1802 2065 1955 2141 1662806 1662731 1658154 1658694 1664646 1667754 1665663 1665357
0 4820000 2000 2147 3 1239 1805 2069 1960 2141 1662740 1662446 1657928 1658703 1664595 1667633 1665698 1665421
0 4980000 1988 2151 4 1238 1806 2066 1964 2144 1838285 1837507 1832933 1833417 1839217 1842434 1840536 1840648
0 4990000 1991 2162 0 1236 1806 2075 1963 2143 1838128 1837412 1832442 1833042 1839119 1842335 1840463 1840450
0 5000000 1961 2133 1 1238 1814 2077 1967 2147 1838066 1837371 1832722 1833256 1839151 1842354 1840370 1840462
0 5010000 1992 2158 2 1241 1810 2063 1959 2141 1838042 1837305 1832789 1833201 1839127 1842323 1840388 1840415
0 5020000 1996 2153 3 1240 1806 2072 1959 2145 1838015 1837258 1832772 1833217 1839103 1842279 1840250 1840355
0 5030000 2023 2175 3 1241 1799 2076 1993 2160 1837994 1837310 1832686 1833175 1839043 1842205 1840200 1840384
0 5040000 2019 2165 0 1236 1799 2074 1965 2150 1837957 1837247 1832605 1833147 1839033 1842235 1840246 1840366
0 5110000 1963 2161 0 1231 1798 2064 1956 2142 2057261 2055860 2051222 2051466 2057416 2060736 2058756 2059287
0 5120000 1986 2147 4 1240 1807 2068 1963 2142 2057174 2055709 2051058 2051422 2057282 2060511 2058651 2059210
0 5130000 1999 2157 3 1239 1807 2073 1956 2144 2056962 2055584 2051052 2051374 2057196 2060479 2058595 2059076
0 5140000 1967 2140 2 1242 1810 2073 1966 2145 2056893 2055474 2050788 2051214 2057143 2060344 2058444 2058929
0 5150000 1998 2151 3 1236 1805 2069 1963 2145 2056901 2055472 2050790 2051114 2057028 2060200 2058450 2058972
0 5160000 1991 2162 2 1240 1807 2073 1960 2143 2056800 2055573 2050682 2051077 2056711 2060156 2058323 2058844
0 5170000 2001 2147 3 1239 1810 2076 1964 2142 2056628 2055260 2050790 2051144 2056936 2060125 2058417 2058800
0 5260000 2001 2153 5 1236 1806 2069 1951 2139 2207156 2205412 2200700 2200888 2206708 2210079 2208106 2209095
0 5270000 2021 2174 4 1241 1810 2079 1994 2153 2206980 2205233 2200521 2200760 2206658 2209925 2208023 2208880
0 5280000 2016 2161 1 1239 1808 2070 1955 2144 2206980 2205136 2200388 2200722 2206676 2209847 2208031 2208835
0 5290000 1995 2150 2 1234 1801 2062 1956 2137 2206886 2205115 2200388 2200671 2206506 2209711 2207875 2208789
0 5300000 1985 2149 4 1234 1800 2064 1956 2142 2206752 2205060 2200352 2200526 2206383 2209667 2207764 2208593
0 5310000 2005 2154 4 1242 1798 2065 1957 2140 2206590 2204880 2200247 2200491 2206339 2209648 2207692 2208478
0 5320000 1963 2171 0 1236 1805 2061 1955 2141 2206561 2204764 2200057 2200369 2206215 2209492 2207641 2208470
0 5330000 1995 2152 4 1237 1806 2069 1959 2142 2206497 2204762 2199985 2200281 2206123 2209370 2207506 2208369
0 5340000 2005 2160 3 1237 1807 2074 1957 2141 2206361 2204579 2199957 2200293 2205989 2209326 2207413 2208319
0 5350000 1968 2110 0 1239 1810 2074 1962 2149 2206401 2204619 2199922 2200228 2206003 2209230 2207498 2208262
0 5450000 2012 2171 4 1235 1805 2075 1962 2149 2347731 2345591 2341043 2341229 2347004 2350352 2348529 2349393
0 5460000 1991 2152 0 1233 1799 2065 1956 2143 2347809 2345584 2340806 2340867 2346840 2350146 2348268 2349382
0 5470000 2016 2162 4 1239 1810 2084 1978 2153 2347465 2345524 2340677 2340832 2346782 2350112 2348154 2349395
0 5480000 1992 2163 0 1236 1804 2073 1960 2144 2347546 2345336 2340536 2340710 2346533 2349896 2348092 2349216
0 5490000 1966 2112 1 1243 1806 2068 1961 2145 2347487 2345326 2340523 2340785 2346508 2349818 2347912 2349270
0 5560000 1954 2132 2 1239 1809 2070 1960 2141 2347042 2344698 2340006 2340323 2346184 2349442 2347543 2348701
0 5610000 1997 2147 3 1233 1801 2064 1956 2139 2491200 2488663 2483889 2483964 2489782 2493053 2491412 2492885
0 5620000 2011 2166 3 1239 1811 2080 1959 2140 2491085 2488543 2483704 2483905 2489725 2492976 2491276 2492578
0 5630000 1967 2142 1 1243 1807 2069 1961 2141 2490851 2488410 2483451 2483795 2489651 2492803 2491124 2492433
0 5640000 1997 2156 3 1242 1814 2070 1961 2144 2490809 2488154 2483410 2483538 2489385 2492752 2490897 2492364
0 5650000 1997 2154 2 1235 1804 2071 1959 2145 2490666 2488048 2483378 2483405 2489273 2492615 2490817 2492229
0 5660000 2010 2170 4 1236 1808 2076 1962 2153 2490614 2488059 2483152 2483430 2489259 2492540 2490682 2492148
0 5670000 1968 2170 0 1236 1806 2057 1952 2135 2490529 2488000 2483249 2483288 2489189 2492487 2490722 2492088
0 5680000 1993 2156 4 1236 1803 2064 1959 2139 2490458 2487911 2483161 2483207 2489071 2492263 2490689 2492001
0 5850000 1999 2149 3 1235 1804 2068 1960 2142 2663770 2660848 2656142 2656342 2661983 2665257 2663425 2665142
0 5860000 1986 2150 4 1234 1799 2064 1959 2144 2663790 2660793 2656236 2656303 2661964 2665244 2663523 2665222
0 5870000 1990 2152 5 1237 1807 2072 1960 2146 2663800 2660821 2656126 2656256 2661833 2665217 2663466 2665240
0 5880000 1951 2161 0 1230 1801 2070 1961 2145 2663774 2660767 2656186 2656157 2661864 2665273 2663300 2665160
0 5890000 1993 2153 4 1237 1807 2071 1962 2144 2663773 2660787 2656052 2656062 2661793 2665058 2663288 2665091
0 5900000 1991 2152 2 1240 1808 2074 1965 2144 2663768 2660713 2656141 2656215 2661844 2665110 2663351 2665182
0 5910000 2016 2159 2 1236 1806 2067 1954 2140 2663601 2660680 2656151 2656137 2661779 2665021 2663322 2664989
0 6000000 1988 2151 3 1232 1797 2062 1957 2142 2735938 2732721 2727861 2727905 2733683 2736932 2735178 2737184
0 6010000 1999 2150 3 1237 1809 2072 1962 2150 2735653 2732627 2727778 2727692 2733470 2736849 2735047 2736970
0 6020000 1944 2165 0 1239 1809 2064 1958 2145 2735517 2732421 2727526 2727671 2733450 2736721 2734982 2736859
0 6030000 1990 2153 4 1233 1802 2065 1957 2140 2735382 2732336 2727473 2727461 2733261 2736669 2734827 2736778
0 6040000 1990 2164 0 1232 1799 2068 1956 2148 2735438 2732172 2727436 2727429 2733184 2736469 2734691 2736550
0 6050000 1964 2137 2 1241 1815 2078 1968 2144 2735260 2732129 2727375 2727329 2733140 2736493 2734670 2736643
0 6060000 1987 2149 1 1233 1804 2064 1957 2139 2735236 2732032 2727163 2727124 2733101 2736398 2734608 2736469
0 6070000 1983 2155 3 1241 1807 2074 1964 2151 2735144 2732006 2727181 2727174 2732900 2736215 2734547 2736431
0 6130000 1942 2152 2 1234 1802 2069 1959 2143 2885792 2882254 2877412 2877372 2883254 2886561 2884807 2886933
0 6140000 1995 2154 2 1238 1808 2075 1959 2146 2885631 2882117 2877279 2877122 2882935 2886280 2884676 2886806
0 6150000 2004 2165 4 1232 1810 2079 1965 2150 2885371 2882021 2877227 2877075 2882739 2886109 2884411 2886560
0 6160000 1958 2167 0 1233 1800 2066 1959 2142 2885304 2881818 2876981 2876873 2882784 2886073 2884380 2886485
0 6170000 1994 2148 4 1236 1806 2068 1958 2141 2885266 2881771 2876899 2876822 2882554 2886022 2884210 2886419
0 6180000 2006 2162 3 1237 1808 2073 1958 2144 2885184 2881693 2876896 2876790 2882574 2885799 2884120 2886374
0 6190000 1965 2138 2 1241 1809 2069 1962 2143 2885022 2881573 2876769 2876689 2882381 2885746 2884103 2886167
0 6200000 1995 2151 2 1235 1803 2069 1962 2142 2885005 2881492 2876690 2876610 2882369 2885696 2883985 2886102
0 6290000 1988 2149 4 1235 1798 2063 1953 2140 3133056 3128916 3123927 3123618 3129170 3132504 3130845 3133407
0 6300000 1963 2166 0 1233 1801 2066 1961 2144 3132200 3128137 3123182 3123295 3128908 3132227 3130503 3132968
0 6310000 1996 2154 4 1243 1815 2077 1963 2147 3131898 3127748 3122839 3122659 3128375 3132000 3130309 3132843
0 6320000 2007 2166 3 1237 1803 2069 1953 2145 3131987 3127852 3122911 3122703 3128243 3131686 3130014 3132746
0 6330000 1968 2141 1 1243 1809 2071 1957 2144 3131567 3127581 3122643 3122489 3128139 3131490 3129802 3132514
0 6340000 1994 2149 3 1235 1804 2071 1964 2145 3131536 3127427 3122559 3122374 3128091 3131469 3129868 3132308
0 6350000 1995 2156 4 1234 1801 2066 1955 2141 3131388 3127332 3122415 3122101 3127927 3131188 3129729 3132265
0 6360000 2008 2172 4 1237 1801 2065 1960 2141 3131373 3127465 3122338 3121999 3127962 3131212 3129522 3132113
0 6450000 1997 2154 5 1238 1808 2070 1953 2137 3247722 3243406 3238531 3238265 3243888 3247458 3245716 3248543
0 6460000 2002 2165 3 1233 1798 2062 1961 2145 3247636 3243293 3238392 3238124 3243804 3247149 3245594 3248419
0 6470000 2007 2173 1 1241 1803 2059 1950 2138 3247420 3243252 3238324 3238038 3243747 3247161 3245421 3248263
0 6480000 1997 2148 2 1233 1803 2067 1960 2141 3247386 3243066 3238222 3237914 3243724 3246997 3245372 3248089
0 6490000 1993 2154 4 1235 1805 2073 1953 2138 3247288 3243016 3238133 3237873 3243480 3246914 3245325 3248120
0 6500000 2010 2172 3 1239 1802 2071 1958 2150 3247229 3242900 3238035 3237785 3243466 3246828 3245202 3247926
0 6510000 1989 2151 0 1235 1804 2064 1955 2145 3247138 3242788 3237969 3237700 3243413 3246728 3245077 3247829
0 6520000 1995 2152 4 1236 1804 2065 1961 2147 3247077 3242896 3237923 3237637 3243312 3246735 3245120 3247776
0 6530000 1997 2168 0 1237 1808 2075 1964 2139 3247037 3242725 3237806 3237540 3243219 3246652 3244988 3247793
0 6540000 1962 2106 2 1243 1811 2074 1962 2150 3246923 3242705 3237847 3237539 3243251 3246580 3244915 3247681
0 6600000 1998 2167 0 1240 1812 2084 1968 2139 3381653 3376988 3372076 3371827 3377442 3380822 3379168 3382324
0 6610000 1979 2117 3 1251 1815 2080 1995 2165 3381411 3376940 3371965 3371724 3377342 3380773 3379100 3382063
0 6620000 1949 2150 2 1233 1803 2068 1958 2140 3381299 3376674 3371849 3371564 3377238 3380582 3378991 3381908
0 6630000 1995 2166 2 1244 1810 2078 1957 2142 3381251 3376637 3371732 3371447 3377027 3380501 3378935 3381836
0 6640000 1994 2147 3 1237 1813 2075 1963 2155 3381134 3376558 3371650 3371346 3376956 3380321 3378747 3381726
0 6730000 1994 2151 4 1237 1806 2072 1962 2144 3380533 3375946 3371052 3370795 3376378 3379833 3378152 3381127
0 6740000 2004 2163 3 1235 1801 2061 1947 2155 3380470 3375815 3371018 3370727 3376318 3379700 3378176 3381189
0 6790000 1939 2162 0 1234 1805 2067 1961 2145 3524739 3519922 3515186 3514846 3520375 3523665 3522147 3525339
0 6800000 1998 2156 4 1236 1805 2069 1959 2142 3524379 3519586 3514603 3514164 3520084 3523475 3521848 3524987
0 6810000 2009 2161 3 1233 1800 2065 1964 2146 3524271 3519376 3514420 3514038 3519595 3522963 3521570 3524751
0 6820000 1963 2108 1 1242 1814 2074 1964 2148 3523878 3519178 3514274 3513781 3519423 3522870 3521254 3524367
0 6830000 1996 2150 3 1235 1803 2066 1959 2140 3523837 3518963 3514058 3513716 3519286 3522699 3521191 3524293
0 6840000 2001 2156 2 1239 1806 2072 1956 2142 3523714 3518833 3513906 3513554 3519097 3522604 3521036 3524154
0 6850000 1995 2147 4 1238 1813 2075 1963 2153 3523695 3518789 3513894 3513479 3518981 3522392 3520839 3524150
0 6860000 1965 2167 0 1234 1801 2064 1957 2142 3523468 3518624 3513775 3513331 3518909 3522413 3520806 3523985
0 6870000 1995 2153 4 1236 1807 2070 1961 2143 3523520 3518621 3513718 3513347 3518981 3522333 3520819 3523988
0 6880000 2017 2171 4 1241 1808 2074 1958 2139 3523510 3518672 3513707 3513324 3518890 3522345 3520730 3523953
0 6940000 1992 2152 2 1232 1799 2061 1957 2141 3655906 3650801 3645782 3645495 3651026 3654420 3652866 3656218
0 6950000 1996 2158 0 1238 1807 2076 1964 2137 3655812 3650788 3645853 3645332 3650939 3654357 3652840 3656136
0 7010000 2000 2156 4 1240 1812 2076 1958 2141 3655407 3650128 3645344 3644865 3650479 3653903 3652374 3655707
0 7020000 1992 2163 0 1236 1806 2076 1964 2142 3655353 3650258 3645258 3644859 3650456 3653766 3652324 3655742
0 7030000 1958 2124 0 1234 1807 2071 1963 2142 3655286 3650249 3645254 3644883 3650465 3653866 3652260 3655646
0 7040000 1985 2152 1 1235 1807 2068 1962 2143 3655292 3650193 3645263 3644806 3650362 3653788 3652282 3655657
0 7100000 2009 2174 1 1238 1810 2066 1957 2142 3715467 3710202 3705258 3704748 3710237 3713667 3712171 3715607
0 7110000 1943 2150 3 1232 1801 2070 1962 2145 3715247 3710034 3705133 3704690 3710167 3713652 3712133 3715532
0 7120000 1989 2152 2 1233 1801 2070 1960 2145 3715197 3709948 3704944 3704578 3710121 3713541 3712041 3715473
0 7130000 2011 2171 3 1236 1803 2073 1961 2152 3715162 3709952 3704989 3704486 3710075 3713455 3711930 3715460
0 7140000 2016 2162 0 1240 1805 2066 1957 2143 3714913 3709846 3704992 3704416 3709992 3713370 3711896 3715245
0 7150000 1988 2150 4 1235 1804 2064 1961 2142 3714948 3709745 3704832 3704433 3709937 3713308 3711776 3715350
0 7160000 1989 2162 0 1232 1798 2066 1956 2142 3714876 3709806 3704767 3704338 3710004 3713444 3711790 3715203
0 7170000 1965 2140 2 1242 1804 2066 1958 2140 3714926 3709768 3704724 3704339 3709870 3713278 3711712 3715239
0 7180000 1991 2149 1 1233 1803 2066 1959 2143 3714731 3709731 3704718 3704288 3709826 3713271 3711649 3715158
0 7300000 2005 2165 3 1234 1798 2061 1947 2151 3773682 3768356 3763384 3762943 3768411 3771910 3770373 3773962
0 7310000 2016 2161 1 1236 1810 2070 1956 2143 3773676 3768410 3763476 3762900 3768507 3771947 3770400 3773904
0 7320000 1990 2149 3 1233 1799 2073 1966 2147 3773666 3768394 3763416 3762983 3768535 3771942 3770403 3773919
0 7330000 1993 2150 1 1239 1804 2070 1957 2143 3773614 3768410 3763347 3762921 3768397 3771873 3770337 3773955
0 7340000 2012 2161 4 1233 1806 2070 1957 2145 3774004 3768779 3763772 3763310 3768810 3772235 3770754 3774287
0 7350000 1954 2175 0 1238 1808 2063 1959 2145 3774094 3768713 3763789 3763304 3768903 3772383 3770805 3774337
0 7360000 1988 2147 4 1240 1808 2068 1961 2145 3774270 3768927 3764022 3763405 3769061 3772479 3770955 3774483
0 7370000 2009 2161 3 1235 1802 2068 1968 2150 3774262 3768998 3764055 3763635 3769175 3772489 3771023 3774452
0 7420000 2016 2157 0 1235 1802 2066 1957 2141 3867191 3861882 3856896 3856353 3861839 3865223 3863792 3867422
0 7430000 1994 2150 4 1237 1807 2070 1960 2142 3866825 3861387 3856375 3856085 3861522 3864910 3863425 3866998
0 7440000 2005 2157 3 1235 1801 2065 1965 2149 3866760 3861181 3856238 3855730 3861241 3864766 3863258 3866831
0 7450000 1952 2121 1 1234 1811 2072 1963 2144 3866623 3861055 3856151 3855694 3861041 3864580 3862965 3866727
0 7460000 2000 2150 2 1235 1804 2070 1963 2144 3866434 3861003 3856012 3855568 3861034 3864493 3862915 3866645
0 7470000 1993 2155 3 1234 1800 2064 1952 2136 3866417 3860887 3855967 3855367 3861020 3864431 3862899 3866546
0 7480000 2007 2170 4 1236 1797 2066 1960 2142 3866340 3860863 3855889 3855388 3860819 3864335 3862779 3866480
0 7490000 1959 2173 0 1237 1806 2059 1954 2138 3866277 3860827 3855838 3855377 3860767 3864259 3862753 3866406
0 7500000 1996 2154 4 1235 1804 2067 1959 2141 3866163 3860799 3855852 3855327 3860886 3864106 3862715 3866286
0 7510000 1991 2163 0 1233 1801 2071 1959 2142 3866181 3860706 3855774 3855265 3860781 3864087 3862752 3866288
0 7590000 1992 2154 2 1235 1801 2065 1952 2136 4002329 3996645 3991573 3991033 3996536 3999969 3998456 4002372
0 7600000 1994 2152 2 1236 1807 2070 1964 2146 4002207 3996603 3991609 3991001 3996554 3999889 3998391 4002307
0 7610000 1997 2156 3 1233 1799 2064 1950 2139 4002212 3996555 3991486 3990970 3996399 4000040 3998445 4002320
0 7620000 2004 2165 3 1231 1812 2082 1965 2149 4002274 3996499 3991469 3990966 3996378 3999790 3998422 4002191
0 7630000 1962 2170 0 1234 1803 2061 1954 2139 4002145 3996454 3991488 3990995 3996454 3999818 3998335 4002257
0 7640000 1995 2155 4 1234 1800 2068 1964 2144 4002005 3996384 3991448 3990854 3996371 3999786 3998232 4002100
0 7650000 1994 2165 0 1236 1804 2074 1962 2143 4002019 3996321 3991300 3990760 3996273 3999729 3998226 4002033
0 7660000 1968 2141 2 1244 1812 2076 1967 2148 4001925 3996309 3991335 3990829 3996230 3999636 3998174 4002032
0 7710000 2013 2166 6 1231 1798 2071 1984 2151 4075828 4070056 4065339 4064656 4070029 4073472 4072044 4075903
0 7720000 1994 2165 0 1238 1808 2076 1964 2146 4075727 4069803 4064880 4064208 4069700 4073247 4071762 4075624
0 7730000 2005 2158 1 1234 1814 2075 1984 2124 4075472 4069567 4064691 4064110 4069487 4072926 4071408 4075368
0 7740000 1989 2156 1 1238 1809 2064 1957 2141 4075272 4069521 4064553 4063917 4069416 4072843 4071323 4075207
0 7750000 1994 2160 3 1239 1809 2076 1962 2146 4075208 4069376 4064302 4063932 4069320 4072736 4071247 4075170
0 7760000 2007 2168 4 1234 1807 2077 1963 2149 4075108 4069278 4064324 4063770 4069197 4072619 4071237 4075141
0 7770000 1970 2165 0 1234 1803 2062 1955 2141 4075014 4069245 4064318 4063709 4069141 4072504 4071117 4075063
0 7780000 1994 2158 4 1237 1807 2073 1962 2147 4074939 4069317 4064230 4063650 4069100 4072526 4071090 4074986
0 7790000 1986 2147 4 1235 1803 2068 1960 2146 4074954 4069045 4064167 4063617 4069079 4072452 4070962 4074895

View File

@ -31,6 +31,8 @@
#include <stdint.h> // int types #include <stdint.h> // int types
#include <sys/time.h> // gettimeofday #include <sys/time.h> // gettimeofday
#define BUFLEN 1024
double t0; // start time double t0; // start time
FILE *fout = NULL; // file for messages duplicating FILE *fout = NULL; // file for messages duplicating
@ -40,6 +42,8 @@ struct termio oldtty, tty; // TTY flags
struct termios oldt, newt; // terminal flags struct termios oldt, newt; // terminal flags
int comfd; // TTY fd int comfd; // TTY fd
#define DBG(...) do{fprintf(stderr, __VA_ARGS__);}while(0)
/** /**
* function for different purposes that need to know time intervals * function for different purposes that need to know time intervals
* @return double value: time in seconds * @return double value: time in seconds
@ -92,59 +96,69 @@ void tty_init(){
tcsetattr(STDIN_FILENO, TCSANOW, &newt); tcsetattr(STDIN_FILENO, TCSANOW, &newt);
} }
/**
* Read character from console without echo
* @return char readed
*/
int read_console(){
int rb;
struct timeval tv;
int retval;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(STDIN_FILENO, &rfds);
tv.tv_sec = 0; tv.tv_usec = 10000;
retval = select(1, &rfds, NULL, NULL, &tv);
if(!retval) rb = 0;
else {
if(FD_ISSET(STDIN_FILENO, &rfds)) rb = getchar();
else rb = 0;
}
return rb;
}
/** /**
* getchar() without echo * getchar() without echo
* wait until at least one character pressed * wait until at least one character pressed
* @return character readed * @return character readed
*/ *
int mygetchar(){ // ÁÎÁÌÏÇ getchar() ÂÅÚ ÎÅÏÂÈÏÄÉÍÏÓÔÉ ÖÁÔØ Enter int mygetchar(){
int ret; int ret;
do ret = read_console(); do ret = read_console();
while(ret == 0); while(ret == 0);
return ret; return ret;
} }*/
/** /**
* Read data from TTY * read both tty & console
* @param buff (o) - buffer for data read * @param buff (o) - buffer for messages readed from tty
* @param length - buffer len * @param length (io) - buff's length (return readed len or 0)
* @return amount of readed bytes * @param rb (o) - byte readed from console or -1
* @return 1 if something was readed here or there
*/ */
size_t read_tty(uint8_t *buff, size_t length){ int read_tty_and_console(char *buff, size_t *length, int *rb){
ssize_t L = 0; ssize_t L;
fd_set rfds; // ssize_t l;
size_t buffsz = *length;
struct timeval tv; struct timeval tv;
int retval; int sel, retval = 0;
fd_set rfds;
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(STDIN_FILENO, &rfds);
FD_SET(comfd, &rfds); FD_SET(comfd, &rfds);
tv.tv_sec = 0; tv.tv_usec = 10000; // wait for 10ms tv.tv_sec = 0; tv.tv_usec = 10000;
retval = select(comfd + 1, &rfds, NULL, NULL, &tv); sel = select(comfd + 1, &rfds, NULL, NULL, &tv);
if (!retval) return 0; if(sel > 0){
if(FD_ISSET(comfd, &rfds)){ if(FD_ISSET(STDIN_FILENO, &rfds)){
if((L = read(comfd, buff, length)) < 1) return 0; *rb = getchar();
retval = 1;
}else{
*rb = -1;
}
if(FD_ISSET(comfd, &rfds)){
if((L = read(comfd, buff, buffsz)) < 1){ // disconnect or other troubles
fprintf(stderr, "USB error or disconnected!\n");
quit(1);
}else{
if(L == 0){ // USB disconnected
fprintf(stderr, "USB disconnected!\n");
quit(1);
}
// all OK continue reading
/* DBG("readed %zd bytes, try more.. ", L);
buffsz -= L;
while(buffsz > 0 && (l = read(comfd, buff+L, buffsz)) > 0){
L += l;
buffsz -= l;
}
DBG("full len: %zd\n", L); */
*length = (size_t) L;
retval = 1;
}
}else{
*length = 0;
}
} }
return (size_t)L; return retval;
} }
void help(){ void help(){
@ -154,13 +168,11 @@ void help(){
); );
} }
#define dup_pr(...) do{printf(__VA_ARGS__); if(fout) fprintf(fout, __VA_ARGS__);}while(0)
void con_sig(int rb){ void con_sig(int rb){
uint8_t cmd; char cmd;
if(rb < 1) return; if(rb < 1) return;
if(rb == 'q') quit(0); // q == exit if(rb == 'q') quit(0); // q == exit
cmd = (uint8_t) rb; cmd = (char) rb;
write(comfd, &cmd, 1); write(comfd, &cmd, 1);
/*switch(rb){ /*switch(rb){
case 'h': case 'h':
@ -178,7 +190,7 @@ void con_sig(int rb){
* @param len - length of data in buffer (could be 2 or 4) * @param len - length of data in buffer (could be 2 or 4)
* @return * @return
*/ */
uint32_t get_int(uint8_t *buff, size_t len){ uint32_t get_int(char *buff, size_t len){
if(len != 2 && len != 4){ if(len != 2 && len != 4){
fprintf(stdout, "Bad data length!\n"); fprintf(stdout, "Bad data length!\n");
return 0xffffffff; return 0xffffffff;
@ -190,9 +202,42 @@ uint32_t get_int(uint8_t *buff, size_t len){
return data; return data;
} }
/**
* Copy line by line buffer buff to file removing cmd starting from newline
* @param buffer - data to put into file
* @param cmd - symbol to remove from line startint (if found, change *cmd to (-1)
* or NULL, (-1) if no command to remove
*/
void copy_buf_to_file(char *buffer, int *cmd){
char *buff, *line, *ptr;
if(!cmd || *cmd < 0){
fprintf(fout, "%s", buffer);
return;
}
buff = strdup(buffer), ptr = buff;
do{
if(!*ptr) break;
if(ptr[0] == (char)*cmd){
*cmd = -1;
ptr++;
if(ptr[0] == '\n') ptr++;
if(!*ptr) break;
}
line = ptr;
ptr = strchr(buff, '\n');
if(ptr){
*ptr++ = 0;
//fprintf(fout, "%s\n", line);
}//else
//fprintf(fout, "%s", line); // no newline found in buffer
fprintf(fout, "%s\n", line);
}while(ptr);
free(buff);
}
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
int rb; int rb, oldcmd = -1;
uint8_t buff[256]; char buff[BUFLEN+1];
size_t L; size_t L;
if(argc == 2){ if(argc == 2){
fout = fopen(argv[1], "a"); fout = fopen(argv[1], "a");
@ -210,14 +255,19 @@ int main(int argc, char *argv[]){
setbuf(stdout, NULL); setbuf(stdout, NULL);
t0 = dtime(); t0 = dtime();
while(1){ while(1){
rb = read_console(); L = BUFLEN;
if(rb > 0) con_sig(rb); if(read_tty_and_console(buff, &L, &rb)){
L = read_tty(buff, 255); if(rb > 0){
if(L){ con_sig(rb);
buff[L] = 0; oldcmd = rb;
printf("%s", buff); }
//if(fout) fprintf(fout, "%zd\t%s", time(NULL), buff); if(L){
if(fout) fprintf(fout, "%s", buff); buff[L] = 0;
printf("%s", buff);
if(fout){
copy_buf_to_file(buff, &oldcmd);
}
}
} }
} }
} }

View File

@ -7,8 +7,8 @@ function data_stat(filename, msrd)
if(nargin == 2) MF = 1; endif; if(nargin == 2) MF = 1; endif;
D = dlmread(filename); D = dlmread(filename);
if(isempty(D)) return; endif; if(isempty(D)) return; endif;
[r c] = ind2sub(size(D), find(D(:,[3:18]) == 0)); % find bad data % [r c] = ind2sub(size(D), find(D(:,[3:18]) == 0)); % find bad data
D(r,:) = []; % and delete it % D(r,:) = []; % and delete it
% [r c] = ind2sub(size(D), (D(:,[11:18]) < 2000000)); % [r c] = ind2sub(size(D), (D(:,[11:18]) < 2000000));
% D(r,:) = []; % D(r,:) = [];
printf("Some statistics:\n\n\trelative error for inner ADC:\n"); printf("Some statistics:\n\n\trelative error for inner ADC:\n");
@ -27,12 +27,6 @@ function data_stat(filename, msrd)
Rr = R(:,2); Rr = R(:,2);
T = R(:,1)/1000; T = R(:,1)/1000;
addlabels(Time, D(:,[3 4 6:10]), T, Rr); addlabels(Time, D(:,[3 4 6:10]), T, Rr);
%~ M = mean(mean(D(:,[3 4 6:10]))) / mean(Rr);
%~ Y = Rr * M;
%~ T = R(:,1)/1000;
%~ hold on; plot(T, Y, '.');
%~ text(T+10, Y, num2str(Rr));
%~ hold off;
endif; endif;
Tit = sprintf("Internal 12-bit ADC, err=%f%%", avrg); Tit = sprintf("Internal 12-bit ADC, err=%f%%", avrg);
xlabel("Time, s"); ylabel("R, ADU"); title(Tit); xlabel("Time, s"); ylabel("R, ADU"); title(Tit);
@ -47,11 +41,6 @@ function data_stat(filename, msrd)
plot(Time, D(:,[11:18])); plot(Time, D(:,[11:18]));
if(MF) if(MF)
addlabels(Time, D(:,[11:18]), T, Rr); addlabels(Time, D(:,[11:18]), T, Rr);
%~ M = mean(mean(D(:,[11:18]))) / mean(Rr);
%~ Y = Rr * M;
%~ hold on; plot(T, Y, '.');
%~ text(T+10, Y, num2str(Rr));
%~ hold off;
endif; endif;
Tit = sprintf("External 24-bit ADC, err=%f%%", avrg); Tit = sprintf("External 24-bit ADC, err=%f%%", avrg);
xlabel("Time, s"); ylabel("R, ADU"); title(Tit); xlabel("Time, s"); ylabel("R, ADU"); title(Tit);
@ -64,13 +53,6 @@ function data_stat(filename, msrd)
plot(Time, newD); plot(Time, newD);
if(MF) if(MF)
addlabels(Time, newD, T, Rr); addlabels(Time, newD, T, Rr);
%~ newDr = interp1(Time, meanline, T);
%~ N = [ ones(size(Rr)) Rr ];
%~ K = N \ newDr
%~ Y = Rr * K(2) + K(1);
%~ hold on; plot(T, Y, '.');
%~ text(T+10, Y, num2str(Rr));
%~ hold off;
endif; endif;
Tit = sprintf("External 24-bit ADC, corrected"); Tit = sprintf("External 24-bit ADC, corrected");
xlabel("Time, s"); ylabel("R, ADU"); title(Tit); xlabel("Time, s"); ylabel("R, ADU"); title(Tit);
@ -78,18 +60,23 @@ function data_stat(filename, msrd)
close close
if(MF) if(MF)
% R = K*ADU -> K = ADU \ R % R = K*ADU -> K = ADU \ R
Kmul = []; Kadd = []; Kmul = []; Kadd = []; Kmul2 = [];
for i = 11:18 for i = 11:18
dat = interp1(Time, D(:,i), T); dat = interp1(Time, D(:,i), T);
N = [ ones(size(dat)) dat ]; N = [ ones(size(dat)) dat dat.^2];
K = N \ Rr; K = N \ Rr;
Kadd = [Kadd K(1)]; Kadd = [Kadd K(1)];
Kmul = [Kmul K(2)]; Kmul = [Kmul K(2)];
Kmul2= [Kmul2 K(3)];
endfor endfor
%Kmul = median(Kmul); %Kmul = median(Kmul);
%Kadd = median(Rr - dat*Kmul); %Kadd = median(Rr - dat*Kmul);
printf("coefficients: Kadd = %s, Kmul = %g\n", num2str(Kadd), Kmul); printf("coefficients:\n\tKadd = %s\n\tKmul = %s\n\tKmul2 = %s\n", num2str(Kadd), ...
newR = D(:,[11:18]) .* Kmul + Kadd; num2str(Kmul), num2str(Kmul2));
printf("stat:\n\t<Kmul> = %g, sigma = %g\n\t<Kmul2> = %g, sigma = %g\n", ...
median(Kmul), std(Kmul), median(Kmul2), std(Kmul2));
dd = D(:,[11:18]);
newR = dd.^2 .* Kmul2 + dd .* Kmul + Kadd;
plot(Time, newR); plot(Time, newR);
addlabels(Time, newR, T, Rr); addlabels(Time, newR, T, Rr);
Tit = sprintf("External 24-bit ADC, corrected"); Tit = sprintf("External 24-bit ADC, corrected");

View File

@ -0,0 +1,57 @@
function [Time T Tfxd] = get_T(filename, filter_treshold)
% convert ADU into T in Kelvins
% filename - name of file with temperature data
% filter_treshold - treshold level
D = dlmread(filename);
if(isempty(D)) return; endif;
Time = (D(:,1)*2^24+D(:,2))/1000;
% measured coefficients
Kadd = [35.628 34.595 35.088 34.754 33.936 33.604 33.966 34.816];
Kmul = [0.00014524 0.00014577 0.0001462 0.00014628 0.00014577 0.00014545 0.00014558 0.00014523];
Kmul2 = [3.6789e-11 3.688e-11 3.6878e-11 3.6894e-11 3.6923e-11 3.6929e-11 3.6914e-11 3.6841e-11];
Readed = D(:,[11:18]);
nstr = [size(Readed, 1) 1];
Kadd = repmat(Kadd, nstr);
Kmul = repmat(Kmul, nstr);
Kmul2 = repmat(Kmul2, nstr);
R = Readed.^2 .* Kmul2 + Readed .* Kmul + Kadd;
T = H705(R);
% filtering
if(nargin == 2)
for i = 1:2
DT = diff(T);
[r c] = ind2sub(size(DT), find(DT < -filter_treshold));
T(r+1, :) = [];
R(r+1, :) = [];
Time(r+1, :) = [];
endfor
endif
plot(Time, R);
Tit = sprintf("Resistance, \\Omega");
xlabel("Time, s"); ylabel("R, \\Omega"); title(Tit);
print -dpng -color resistance.png;
close
plot(Time, T);
Tit = sprintf("Temperature, ^\\circ{}C");
xlabel("Time, s"); ylabel("T, ^\\circ{}C"); title(Tit);
print -dpng -color temperatures.png;
close
% calculate difference between thermometers
Tavr = mean(T, 2);
Tadd = mean(T - repmat(Tavr, [1 8]));
Tfxd = T - repmat(Tadd,[size(T,1) 1]);
plot(Time, Tfxd);
Tit = sprintf("Temperature fixed to average value, ^\\circ{}C");
xlabel("Time, s"); ylabel("T, ^\\circ{}C"); title(Tit);
print -dpng -color temperatures_fixed.png;
close
printf("differences:\n"); printf("%g\n", -Tadd);
endfunction

View File

@ -0,0 +1,72 @@
4030000 179
4110000 178.5
4120000 178
4190000 205
4230000 204.5
4250000 204
4310000 223
4340000 222.5
4400000 222
4460000 261
4500000 260.5
4530000 260
4590000 297
4620000 296.75
4690000 296.5
4750000 384
4780000 383.5
4820000 383
4970000 432
5010000 431.5
5040000 431
5110000 494
5140000 493.5
5170000 493
5260000 538
5310000 537.75
5350000 537.5
5450000 581
5480000 580.25
5560000 580.5
5610000 627
5650000 626.5
5680000 626
5850000 683
5880000 682.25
5910000 681.5
6000000 707
6030000 706.5
6070000 706
6130000 758
6160000 757.5
6200000 757
6290000 850
6330000 849
6360000 848
6440000 892
6490000 891.5
6540000 891
6600000 944
6650000 943.5
6740000 943
6790000 1001
6840000 1000.5
6880000 1000
6940000 1057
7010000 1056.5
7040000 1056
7100000 1082
7140000 1081.75
7180000 1081.5
7300000 1105
7330000 1104.5
7370000 1104
7420000 1147
7460000 1146.5
7510000 1146
7580000 1211
7620000 1210.5
7660000 1210
7710000 1246
7750000 1245
7790000 1244

Binary file not shown.