00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <time.h>
00031 #include <ctype.h>
00032 #include <math.h>
00033 #include <errno.h>
00034 #include <unistd.h>
00035 #include <string.h>
00036 #include <sys/types.h>
00037 #include <sys/stat.h>
00038 #include <fcntl.h>
00039 #include <dirent.h>
00040 #include <signal.h>
00041 #include <unistd.h>
00042 #include <sys/time.h>
00043 #include <sys/resource.h>
00044
00045 #include "common.h"
00046
00047
00048 struct IndexType {
00049 struct Titan2TimeType t;
00050 int type;
00051 int channel;
00052 int toDisk;
00053 int32_t flashCycleBegin;
00054 int32_t beginAddress;
00055 int32_t flashCycleEnd;
00056 int32_t endAddress;
00057 int32_t duration;
00058 int32_t max0;
00059 int32_t max1;
00060 int32_t max2;
00061 };
00062
00063 int32_t lastDataOffset=-1;
00064 int32_t lastIndexOffset=1<<31;
00065
00068 void ReadSize(char *fsize)
00069 {
00070 FILE *f;
00071 char od[512];
00072 int i;
00073
00074 f=fopen(fsize,"rb");
00075 lastDataOffset=0;
00076 lastIndexOffset=0;
00077 if (f!=NULL)
00078 {
00079
00080 if (fread(od, 512, 1, f)==1)
00081 {
00082 for (i=0; i<4; i++)
00083 {
00084 lastDataOffset+=((od[i]&0xff)<<(8*i));
00085 lastIndexOffset+=((od[4+i]&0xff)<<(8*i));
00086 }
00087 PrintLog("End of data at offset %d\n",lastDataOffset);
00088 PrintLog("End of index at offset %d\n",lastIndexOffset);
00089 }
00090 else
00091 {
00092 PrintError("could not read %s: %m\n",fsize);
00093 exit(0);
00094 }
00095 fclose(f);
00096 }
00097 else
00098 {
00099 PrintError("could not open %s: %m\n",fsize);
00100 exit(0);
00101 }
00102 }
00103
00106 void CutDataFile(char *fdata)
00107 {
00108 FILE *f;
00109 char buffer[4096];
00110 int done;
00111 done=0;
00112
00113 PrintLog("Extracting %dMb\n",lastDataOffset/1024/1024);
00114 f=fopen(fdata,"rb");
00115 if (f!=NULL)
00116 {
00117
00118 while ((done<lastDataOffset)&&(fread(buffer,4096,1,f)==1))
00119 {
00120 fwrite(buffer,4096,1,stdout);
00121 done+=4096;
00122 if ((done%10485760)==0)
00123 {
00124 PrintLog("%4dMb done...\n",done/1024/1024);
00125 }
00126 }
00127 fclose(f);
00128 }
00129 else
00130 {
00131 PrintError("could not open %s: %m\n",fdata);
00132 exit(0);
00133 }
00134 }
00135
00136
00141 int UpdateIndex(struct IndexType *ndx, char *index)
00142 {
00143 memset(ndx,0,sizeof(struct IndexType));
00144 ndx->t.usecond=frame2i32_64(index,0)<<32;
00145 if (ndx->t.usecond<=0)
00146 {
00147 return(-1);
00148 }
00149 ndx->type=index[5]&0xff;
00150
00151 switch (ndx->type)
00152 {
00153 case 0:
00154
00155 ndx->channel=index[4]&0x7f;
00156 if (index[4]&0x80)
00157 {
00158 ndx->toDisk=1;
00159 }
00160 if (frame2i32(index,16)==0)
00161 {
00162 ndx->flashCycleBegin=-1;
00163 ndx->endAddress=-1;
00164 ndx->flashCycleEnd=-1;
00165 ndx->beginAddress=frame2i32(index,12);
00166
00167 if (ndx->beginAddress<0)
00168 {
00169 return(-1);
00170 }
00171 PrintLog("%s %2d %10d %s\n",
00172 StrTimeNS(&(ndx->t)),
00173 ndx->channel,
00174 ndx->beginAddress,
00175 ndx->toDisk?"normal":"todisk");
00176
00177 }
00178 else
00179 {
00180 ndx->flashCycleBegin=index[12]&0xff;
00181 ndx->beginAddress=frame2i24(index,13);
00182 ndx->flashCycleEnd=index[8]&0xff;
00183 ndx->endAddress=frame2i24(index,9);
00184
00185 ndx->duration=frame2i24(index,20);
00186 ndx->max0=frame2i24(index,23);
00187 ndx->max1=frame2i24(index,26);
00188 ndx->max2=frame2i24(index,29);
00189
00190 if (ndx->beginAddress<0)
00191 {
00192 return(-1);
00193 }
00194 if (ndx->endAddress<0)
00195 {
00196 return(-1);
00197 }
00198 PrintLog("%s %2d "
00199 " %2d %10d"
00200 " %2d %10d"
00201 " %s "
00202 " %5d"
00203 " %6d %6d %6d\n",
00204 StrTimeNS(&(ndx->t)),
00205 ndx->channel,
00206 ndx->flashCycleBegin,
00207 ndx->beginAddress,
00208 ndx->flashCycleEnd,
00209 ndx->endAddress,
00210 ndx->toDisk?"normal":"todisk",
00211 ndx->duration,
00212 ndx->max0,
00213 ndx->max1,
00214 ndx->max2);
00215 }
00216
00217 break;
00218 case 1:
00219 ndx->beginAddress=frame2i32(index,12);
00220
00221 if (ndx->beginAddress<0)
00222 {
00223 return(-1);
00224 }
00225 PrintLog("%s %10d\n",
00226 StrTimeNS(&(ndx->t)),
00227 ndx->beginAddress);
00228
00229 break;
00230 case 2:
00231 break;
00232 case 3:
00233 break;
00234 default:
00235 return(-1);
00236 }
00237 return(ndx->type);
00238 }
00239
00242 void ReadIndex(char *fndx)
00243 {
00244 FILE *f;
00245 char index[32];
00246
00247 struct IndexType indexInfo;
00248
00249 f=fopen(fndx,"rb");
00250 if (f!=NULL)
00251 {
00252
00253 while ((fread(index,32,1,f)==1)&&(ftell(f)<lastIndexOffset))
00254 {
00255
00256 if (UpdateIndex(&indexInfo,index)==-1)
00257 {
00258 continue;
00259 }
00260
00261
00262
00263
00264
00265 if (ndx2tl)
00266 {
00267 }
00268
00269
00270 if (ndx2cache)
00271 {
00272 }
00273 }
00274 }
00275
00276 else
00277 {
00278 PrintError("could not open %s: %m\n",fndx);
00279 }
00280 }