Commit 2f6ec193 authored by Andrey Filippov's avatar Andrey Filippov

debugging with new drivers

parent 90486df4
...@@ -55,6 +55,9 @@ ...@@ -55,6 +55,9 @@
#define TRAILER_SIZE 0x02 #define TRAILER_SIZE 0x02
/** @brief The length of MakerNote buffer in @e long */ /** @brief The length of MakerNote buffer in @e long */
#define MAKERNOTE_LEN 16 #define MAKERNOTE_LEN 16
#ifndef GLOBALPARS_SNGL // until kernel recompiled, will go to c313a.h
#define GLOBALPARS_SNGL(x) (globalPars[(x)-FRAMEPAR_GLOBALS]) ///< should work in drivers and applications, First 32 parameter values are not erased with initGlobalPars
#endif
/** /**
* @struct file_set * @struct file_set
...@@ -89,6 +92,8 @@ struct file_set { ...@@ -89,6 +92,8 @@ struct file_set {
int exif_dev_fd; int exif_dev_fd;
const char *exifmeta_dev_name; const char *exifmeta_dev_name;
int exifmeta_dev_fd; int exifmeta_dev_fd;
const char *framepars_dev_name;
int framepars_dev_fd;
}; };
static struct file_set files[SENSOR_PORTS]; static struct file_set files[SENSOR_PORTS];
...@@ -122,10 +127,24 @@ const char *jhead_fnames[] = { ...@@ -122,10 +127,24 @@ const char *jhead_fnames[] = {
}; };
#endif #endif
static const char *exif_dev_names[SENSOR_PORTS] = { DEV393_PATH(DEV393_EXIF0), DEV393_PATH(DEV393_EXIF1), static const char *exif_dev_names[SENSOR_PORTS] = {
DEV393_PATH(DEV393_EXIF2), DEV393_PATH(DEV393_EXIF3)}; DEV393_PATH(DEV393_EXIF0),
static const char *exifmeta_dev_names[SENSOR_PORTS] = { DEV393_PATH(DEV393_EXIF_META0), DEV393_PATH(DEV393_EXIF_META1), DEV393_PATH(DEV393_EXIF1),
DEV393_PATH(DEV393_EXIF_META2), DEV393_PATH(DEV393_EXIF_META3)}; DEV393_PATH(DEV393_EXIF2),
DEV393_PATH(DEV393_EXIF3)};
static const char *exifmeta_dev_names[SENSOR_PORTS] = {
DEV393_PATH(DEV393_EXIF_META0),
DEV393_PATH(DEV393_EXIF_META1),
DEV393_PATH(DEV393_EXIF_META2),
DEV393_PATH(DEV393_EXIF_META3)};
static const char *framepars_dev_names[SENSOR_PORTS] = {
DEV393_PATH(DEV393_FRAMEPARS0),
DEV393_PATH(DEV393_FRAMEPARS1),
DEV393_PATH(DEV393_FRAMEPARS2),
DEV393_PATH(DEV393_FRAMEPARS3)};
const char app_args[] = "Usage:\n%s -p <port_number_1> [<port_number_2> <port_number_3> <port_number_4>]\n" \ const char app_args[] = "Usage:\n%s -p <port_number_1> [<port_number_2> <port_number_3> <port_number_4>]\n" \
"Start image server, bind it to ports <port_number_1> <port_number_2> <port_number_3> <port_number_4>\n" \ "Start image server, bind it to ports <port_number_1> <port_number_2> <port_number_3> <port_number_4>\n" \
...@@ -172,8 +191,10 @@ int framePointersXML(struct file_set *fset); ...@@ -172,8 +191,10 @@ int framePointersXML(struct file_set *fset);
int metaXML(struct file_set *fset, int mode); // mode: 0 - new (send headers), 1 - continue, 2 - finish int metaXML(struct file_set *fset, int mode); // mode: 0 - new (send headers), 1 - continue, 2 - finish
int printExifXML(int exif_page, struct file_set *fset); int printExifXML(int exif_page, struct file_set *fset);
int out1x1gif(void); int out1x1gif(void);
void waitFrameSync(); void waitFrameSync(struct file_set *fset);
unsigned long getCurrentFrameNumber();
unsigned long getCurrentFrameNumberSensor ( struct file_set *fset);
unsigned long getCurrentFrameNumberCompressor( struct file_set *fset);
/** @brief Read no more then 255 bytes from file */ /** @brief Read no more then 255 bytes from file */
#define saferead255(f, d, l) read(f, d, ((l) < 256) ? (l) : 255) #define saferead255(f, d, l) read(f, d, ((l) < 256) ? (l) : 255)
...@@ -199,6 +220,7 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -199,6 +220,7 @@ int printExifXML(int exif_page, struct file_set *fset)
printf("<error>\"Opening %s\"</error>\n", DEV393_PATH(DEV393_EXIF_METADIR)); printf("<error>\"Opening %s\"</error>\n", DEV393_PATH(DEV393_EXIF_METADIR));
return -2; // Error opening Exif directory return -2; // Error opening Exif directory
} }
for (indx = 0; indx < ExifKmlNumber; indx++) exif_dir[indx].ltag = 0; for (indx = 0; indx < ExifKmlNumber; indx++) exif_dir[indx].ltag = 0;
while (read(fd_exifdir, &dir_table_entry, sizeof(dir_table_entry)) > 0) { while (read(fd_exifdir, &dir_table_entry, sizeof(dir_table_entry)) > 0) {
switch (dir_table_entry.ltag) { switch (dir_table_entry.ltag) {
...@@ -233,6 +255,7 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -233,6 +255,7 @@ int printExifXML(int exif_page, struct file_set *fset)
} }
} }
close(fd_exifdir); close(fd_exifdir);
// fprintf(stderr, "%s:%d:%s: Starting - 2\n", __FILE__, __LINE__, __FUNCTION__);
// Create XML files itself // Create XML files itself
long rational3[6]; long rational3[6];
...@@ -243,81 +266,85 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -243,81 +266,85 @@ int printExifXML(int exif_page, struct file_set *fset)
double seconds = 0.0; double seconds = 0.0;
double longitude = 0.0, latitude = 0.0, altitude = 0.0, heading = 0.0, roll = 0.0, pitch = 0.0, exposure = 0.0; double longitude = 0.0, latitude = 0.0, altitude = 0.0, heading = 0.0, roll = 0.0, pitch = 0.0, exposure = 0.0;
val[255] = '\0'; val[255] = '\0';
int fd_exif = open(fset->exif_dev_name, O_RDONLY); // int fd_exif = open(fset->exif_dev_name, O_RDONLY);
if (fd_exif < 0) { if (fset->exif_dev_fd <0)
fset->exif_dev_fd = open(fset->exif_dev_name, O_RDONLY);
if (fset->exif_dev_fd < 0) {
printf("<error>\"Opening %s\"</error>\n", fset->exif_dev_name); printf("<error>\"Opening %s\"</error>\n", fset->exif_dev_name);
return -3; return -3;
} }
fset->exif_dev_fd = fd_exif; // fset->exif_dev_fd = fd_exif;
exif_page_start = lseek(fd_exif, exif_page, SEEK_END); // select specified Exif page exif_page_start = lseek(fset->exif_dev_fd, exif_page, SEEK_END); // select specified Exif page
if (exif_page_start < 0) { if (exif_page_start < 0) {
printf("<error>\"Exif page (%d) is out of range\"</error>\n", exif_page); printf("<error>\"Exif page (%d) is out of range\"</error>\n", exif_page);
close(fd_exif); fprintf(stderr, "%s:%d:%s: Exif page (%d) is out of range\n", __FILE__, __LINE__, __FUNCTION__, exif_page);
close(fset->exif_dev_fd);
fset->exif_dev_fd = -1;
return -1; // Error opening Exif return -1; // Error opening Exif
} }
// Image Description // Image Description
if (exif_dir[Exif_Image_ImageDescription_Index].ltag == Exif_Image_ImageDescription) { // Exif_Image_ImageDescription is present in template if (exif_dir[Exif_Image_ImageDescription_Index].ltag == Exif_Image_ImageDescription) { // Exif_Image_ImageDescription is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_Image_ImageDescription_Index].dst, exif_page_start + exif_dir[Exif_Image_ImageDescription_Index].dst,
SEEK_SET); SEEK_SET);
saferead255(fd_exif, val, exif_dir[Exif_Image_ImageDescription_Index].len); saferead255(fset->exif_dev_fd, val, exif_dir[Exif_Image_ImageDescription_Index].len);
printf("<ImageDescription>\"%s\"</ImageDescription>\n", val); printf("<ImageDescription>\"%s\"</ImageDescription>\n", val);
} }
// Exif_Image_ImageNumber_Index 0x13 // Exif_Image_ImageNumber_Index 0x13
if (exif_dir[Exif_Image_ImageNumber_Index].ltag == Exif_Image_ImageNumber) { // Exif_Image_ImageNumber_Index is present in template if (exif_dir[Exif_Image_ImageNumber_Index].ltag == Exif_Image_ImageNumber) { // Exif_Image_ImageNumber_Index is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_Image_ImageNumber_Index].dst, exif_page_start + exif_dir[Exif_Image_ImageNumber_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, rational3, 4); read(fset->exif_dev_fd, rational3, 4);
sprintf(val, "%ld", (long)__cpu_to_be32( rational3[0])); sprintf(val, "%ld", (long)__cpu_to_be32( rational3[0]));
printf("<ImageNumber>\"%s\"</ImageNumber>\n", val); printf("<ImageNumber>\"%s\"</ImageNumber>\n", val);
} }
// Exif_Image_Orientation_Index 0x14 // Exif_Image_Orientation_Index 0x14
if (exif_dir[Exif_Image_Orientation_Index].ltag == Exif_Image_Orientation) { // Exif_Image_Orientation_Index is present in template if (exif_dir[Exif_Image_Orientation_Index].ltag == Exif_Image_Orientation) { // Exif_Image_Orientation_Index is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_Image_Orientation_Index].dst, exif_page_start + exif_dir[Exif_Image_Orientation_Index].dst,
SEEK_SET); SEEK_SET);
rational3[0] = 0; rational3[0] = 0;
read(fd_exif, rational3, 2); read(fset->exif_dev_fd, rational3, 2);
sprintf(val, "%ld", (long)( rational3[0] >> 8)); sprintf(val, "%ld", (long)( rational3[0] >> 8));
printf("<Orientation>\"%s\"</Orientation>\n", val); printf("<Orientation>\"%s\"</Orientation>\n", val);
} }
// Exif_Image_PageNumber // Exif_Image_PageNumber
if (exif_dir[Exif_Image_PageNumber_Index].ltag == Exif_Image_PageNumber) { // Exif_Image_Orientation_Index is present in template if (exif_dir[Exif_Image_PageNumber_Index].ltag == Exif_Image_PageNumber) { // Exif_Image_Orientation_Index is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_Image_PageNumber_Index].dst, exif_page_start + exif_dir[Exif_Image_PageNumber_Index].dst,
SEEK_SET); SEEK_SET);
rational3[0] = 0; rational3[0] = 0;
read(fd_exif, rational3, 2); read(fset->exif_dev_fd, rational3, 2);
sprintf(val, "%u", __cpu_to_be16(rational3[0])); sprintf(val, "%u", __cpu_to_be16(rational3[0]));
printf("<SensorNumber>\"%s\"</SensorNumber>\n", val); printf("<SensorNumber>\"%s\"</SensorNumber>\n", val);
} }
// DateTimeOriginal (with subseconds) // DateTimeOriginal (with subseconds)
if (exif_dir[Exif_Photo_DateTimeOriginal_Index].ltag == Exif_Photo_DateTimeOriginal) { if (exif_dir[Exif_Photo_DateTimeOriginal_Index].ltag == Exif_Photo_DateTimeOriginal) {
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_Photo_DateTimeOriginal_Index].dst, exif_page_start + exif_dir[Exif_Photo_DateTimeOriginal_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, val, 19); read(fset->exif_dev_fd, val, 19);
val[19] = '\0'; val[19] = '\0';
if (exif_dir[Exif_Photo_SubSecTimeOriginal_Index].ltag == Exif_Photo_SubSecTimeOriginal) { if (exif_dir[Exif_Photo_SubSecTimeOriginal_Index].ltag == Exif_Photo_SubSecTimeOriginal) {
val[19] = '.'; val[19] = '.';
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_Photo_SubSecTimeOriginal_Index].dst, exif_page_start + exif_dir[Exif_Photo_SubSecTimeOriginal_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, &val[20], 7); read(fset->exif_dev_fd, &val[20], 7);
val[27] = '\0'; val[27] = '\0';
} }
printf("<DateTimeOriginal>\"%s\"</DateTimeOriginal>\n", val); printf("<DateTimeOriginal>\"%s\"</DateTimeOriginal>\n", val);
} }
// Exif_Photo_ExposureTime // Exif_Photo_ExposureTime
if (exif_dir[Exif_Photo_ExposureTime_Index].ltag == Exif_Photo_ExposureTime) { // Exif_Photo_ExposureTime is present in template if (exif_dir[Exif_Photo_ExposureTime_Index].ltag == Exif_Photo_ExposureTime) { // Exif_Photo_ExposureTime is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_Photo_ExposureTime_Index].dst, exif_page_start + exif_dir[Exif_Photo_ExposureTime_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, rational3, 8); read(fset->exif_dev_fd, rational3, 8);
exposure = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]); exposure = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]);
sprintf(val, "%f", exposure); sprintf(val, "%f", exposure);
printf("<ExposureTime>\"%s\"</ExposureTime>\n", val); printf("<ExposureTime>\"%s\"</ExposureTime>\n", val);
...@@ -325,10 +352,10 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -325,10 +352,10 @@ int printExifXML(int exif_page, struct file_set *fset)
// Exif_Photo_MakerNote // Exif_Photo_MakerNote
if (exif_dir[Exif_Photo_MakerNote_Index].ltag == Exif_Photo_MakerNote) { // Exif_Photo_MakerNote is present in template if (exif_dir[Exif_Photo_MakerNote_Index].ltag == Exif_Photo_MakerNote) { // Exif_Photo_MakerNote is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_Photo_MakerNote_Index].dst, exif_page_start + exif_dir[Exif_Photo_MakerNote_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, makerNote, 64); read(fset->exif_dev_fd, makerNote, 64);
sprintf(val, sprintf(val,
"0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx", "0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx",
(long)__cpu_to_be32(makerNote[0]), (long)__cpu_to_be32(makerNote[0]),
...@@ -352,26 +379,26 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -352,26 +379,26 @@ int printExifXML(int exif_page, struct file_set *fset)
// GPS measure mode // GPS measure mode
if (exif_dir[Exif_GPSInfo_GPSMeasureMode_Index].ltag == Exif_GPSInfo_GPSMeasureMode) { if (exif_dir[Exif_GPSInfo_GPSMeasureMode_Index].ltag == Exif_GPSInfo_GPSMeasureMode) {
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_GPSMeasureMode_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_GPSMeasureMode_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, val, 1); read(fset->exif_dev_fd, val, 1);
val[1] = '\0'; val[1] = '\0';
printf("<GPSMeasureMode>\"%s\"</GPSMeasureMode>\n", val); printf("<GPSMeasureMode>\"%s\"</GPSMeasureMode>\n", val);
} }
// GPS date/time // GPS date/time
if (exif_dir[Exif_GPSInfo_GPSDateStamp_Index].ltag == Exif_GPSInfo_GPSDateStamp) { if (exif_dir[Exif_GPSInfo_GPSDateStamp_Index].ltag == Exif_GPSInfo_GPSDateStamp) {
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_GPSDateStamp_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_GPSDateStamp_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, val, 10); read(fset->exif_dev_fd, val, 10);
val[10] = '\0'; val[10] = '\0';
if (exif_dir[Exif_GPSInfo_GPSTimeStamp_Index].ltag == Exif_GPSInfo_GPSTimeStamp) { if (exif_dir[Exif_GPSInfo_GPSTimeStamp_Index].ltag == Exif_GPSInfo_GPSTimeStamp) {
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_GPSTimeStamp_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_GPSTimeStamp_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, rational3, 24); read(fset->exif_dev_fd, rational3, 24);
hours = __cpu_to_be32( rational3[0]); hours = __cpu_to_be32( rational3[0]);
minutes = __cpu_to_be32( rational3[2]); minutes = __cpu_to_be32( rational3[2]);
seconds = (1.0 * (__cpu_to_be32( rational3[4]) + 1)) / __cpu_to_be32( rational3[5]); // GPS likes ".999", let's inc by one - anyway will round that out seconds = (1.0 * (__cpu_to_be32( rational3[4]) + 1)) / __cpu_to_be32( rational3[5]); // GPS likes ".999", let's inc by one - anyway will round that out
...@@ -383,16 +410,16 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -383,16 +410,16 @@ int printExifXML(int exif_page, struct file_set *fset)
// knowing format provided from GPS - degrees and minutes only, no seconds: // knowing format provided from GPS - degrees and minutes only, no seconds:
// GPS Longitude // GPS Longitude
if (exif_dir[Exif_GPSInfo_GPSLongitude_Index].ltag == Exif_GPSInfo_GPSLongitude) { // Exif_GPSInfo_GPSLongitude is present in template if (exif_dir[Exif_GPSInfo_GPSLongitude_Index].ltag == Exif_GPSInfo_GPSLongitude) { // Exif_GPSInfo_GPSLongitude is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_GPSLongitude_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_GPSLongitude_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, rational3, 24); read(fset->exif_dev_fd, rational3, 24);
longitude = __cpu_to_be32( rational3[0]) / (1.0 * __cpu_to_be32( rational3[1])) + __cpu_to_be32( rational3[2]) / (60.0 * __cpu_to_be32( rational3[3])); longitude = __cpu_to_be32( rational3[0]) / (1.0 * __cpu_to_be32( rational3[1])) + __cpu_to_be32( rational3[2]) / (60.0 * __cpu_to_be32( rational3[3]));
if (exif_dir[Exif_GPSInfo_GPSLongitudeRef_Index].ltag == Exif_GPSInfo_GPSLongitudeRef) { if (exif_dir[Exif_GPSInfo_GPSLongitudeRef_Index].ltag == Exif_GPSInfo_GPSLongitudeRef) {
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_GPSLongitudeRef_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_GPSLongitudeRef_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, val, 1); read(fset->exif_dev_fd, val, 1);
if (val[0] != 'E') longitude = -longitude; if (val[0] != 'E') longitude = -longitude;
} }
sprintf(val, "%f", longitude); sprintf(val, "%f", longitude);
...@@ -400,16 +427,16 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -400,16 +427,16 @@ int printExifXML(int exif_page, struct file_set *fset)
} }
// GPS Latitude // GPS Latitude
if (exif_dir[Exif_GPSInfo_GPSLatitude_Index].ltag == Exif_GPSInfo_GPSLatitude) { // Exif_GPSInfo_GPSLatitude is present in template if (exif_dir[Exif_GPSInfo_GPSLatitude_Index].ltag == Exif_GPSInfo_GPSLatitude) { // Exif_GPSInfo_GPSLatitude is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_GPSLatitude_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_GPSLatitude_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, rational3, 24); read(fset->exif_dev_fd, rational3, 24);
latitude = __cpu_to_be32( rational3[0]) / (1.0 * __cpu_to_be32( rational3[1])) + __cpu_to_be32( rational3[2]) / (60.0 * __cpu_to_be32( rational3[3])); latitude = __cpu_to_be32( rational3[0]) / (1.0 * __cpu_to_be32( rational3[1])) + __cpu_to_be32( rational3[2]) / (60.0 * __cpu_to_be32( rational3[3]));
if (exif_dir[Exif_GPSInfo_GPSLatitudeRef_Index].ltag == Exif_GPSInfo_GPSLatitudeRef) { if (exif_dir[Exif_GPSInfo_GPSLatitudeRef_Index].ltag == Exif_GPSInfo_GPSLatitudeRef) {
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_GPSLatitudeRef_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_GPSLatitudeRef_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, val, 1); read(fset->exif_dev_fd, val, 1);
if (val[0] != 'N') latitude = -latitude; if (val[0] != 'N') latitude = -latitude;
} }
sprintf(val, "%f", latitude); sprintf(val, "%f", latitude);
...@@ -417,17 +444,17 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -417,17 +444,17 @@ int printExifXML(int exif_page, struct file_set *fset)
} }
// GPS Altitude // GPS Altitude
if (exif_dir[Exif_GPSInfo_GPSAltitude_Index].ltag == Exif_GPSInfo_GPSAltitude) { // Exif_GPSInfo_GPSAltitude is present in template if (exif_dir[Exif_GPSInfo_GPSAltitude_Index].ltag == Exif_GPSInfo_GPSAltitude) { // Exif_GPSInfo_GPSAltitude is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_GPSAltitude_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_GPSAltitude_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, rational3, 8); read(fset->exif_dev_fd, rational3, 8);
altitude = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]); altitude = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]);
if (exif_dir[Exif_GPSInfo_GPSAltitudeRef_Index].ltag == Exif_GPSInfo_GPSAltitudeRef) { if (exif_dir[Exif_GPSInfo_GPSAltitudeRef_Index].ltag == Exif_GPSInfo_GPSAltitudeRef) {
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_GPSAltitudeRef_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_GPSAltitudeRef_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, val, 1); read(fset->exif_dev_fd, val, 1);
if (val[0] != '\0') altitude = -altitude; if (val[0] != '\0') altitude = -altitude;
} }
sprintf(val, "%f", altitude); sprintf(val, "%f", altitude);
...@@ -435,10 +462,10 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -435,10 +462,10 @@ int printExifXML(int exif_page, struct file_set *fset)
} }
// Compass Direction (magnetic) // Compass Direction (magnetic)
if (exif_dir[Exif_GPSInfo_CompassDirection_Index].ltag == Exif_GPSInfo_CompassDirection) { // Exif_GPSInfo_CompassDirection is present in template if (exif_dir[Exif_GPSInfo_CompassDirection_Index].ltag == Exif_GPSInfo_CompassDirection) { // Exif_GPSInfo_CompassDirection is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_CompassDirection_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_CompassDirection_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, rational3, 8); read(fset->exif_dev_fd, rational3, 8);
heading = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]); heading = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]);
sprintf(val, "%f", heading); sprintf(val, "%f", heading);
printf("<CompassDirection>\"%s\"</CompassDirection>\n", val); printf("<CompassDirection>\"%s\"</CompassDirection>\n", val);
...@@ -446,17 +473,17 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -446,17 +473,17 @@ int printExifXML(int exif_page, struct file_set *fset)
// Processing 'hacked' pitch and roll (made of Exif destination latitude/longitude) // Processing 'hacked' pitch and roll (made of Exif destination latitude/longitude)
// Compass Roll // Compass Roll
if (exif_dir[Exif_GPSInfo_CompassRoll_Index].ltag == Exif_GPSInfo_CompassRoll) { // Exif_GPSInfo_CompassRoll is present in template if (exif_dir[Exif_GPSInfo_CompassRoll_Index].ltag == Exif_GPSInfo_CompassRoll) { // Exif_GPSInfo_CompassRoll is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_CompassRoll_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_CompassRoll_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, rational3, 8); read(fset->exif_dev_fd, rational3, 8);
roll = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]); roll = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]);
if (exif_dir[Exif_GPSInfo_CompassRollRef_Index].ltag == Exif_GPSInfo_CompassRollRef) { if (exif_dir[Exif_GPSInfo_CompassRollRef_Index].ltag == Exif_GPSInfo_CompassRollRef) {
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_CompassRollRef_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_CompassRollRef_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, val, 1); read(fset->exif_dev_fd, val, 1);
if (val[0] != EXIF_COMPASS_ROLL_ASCII[0]) roll = -roll; if (val[0] != EXIF_COMPASS_ROLL_ASCII[0]) roll = -roll;
} }
sprintf(val, "%f", roll); sprintf(val, "%f", roll);
...@@ -465,23 +492,25 @@ int printExifXML(int exif_page, struct file_set *fset) ...@@ -465,23 +492,25 @@ int printExifXML(int exif_page, struct file_set *fset)
// Compass Pitch // Compass Pitch
if (exif_dir[Exif_GPSInfo_CompassPitch_Index].ltag == Exif_GPSInfo_CompassPitch) { // Exif_GPSInfo_CompassPitch is present in template if (exif_dir[Exif_GPSInfo_CompassPitch_Index].ltag == Exif_GPSInfo_CompassPitch) { // Exif_GPSInfo_CompassPitch is present in template
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_CompassPitch_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_CompassPitch_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, rational3, 8); read(fset->exif_dev_fd, rational3, 8);
pitch = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]); pitch = (1.0 * __cpu_to_be32( rational3[0])) / __cpu_to_be32( rational3[1]);
if (exif_dir[Exif_GPSInfo_CompassPitchRef_Index].ltag == Exif_GPSInfo_CompassPitchRef) { if (exif_dir[Exif_GPSInfo_CompassPitchRef_Index].ltag == Exif_GPSInfo_CompassPitchRef) {
lseek(fd_exif, lseek(fset->exif_dev_fd,
exif_page_start + exif_dir[Exif_GPSInfo_CompassPitchRef_Index].dst, exif_page_start + exif_dir[Exif_GPSInfo_CompassPitchRef_Index].dst,
SEEK_SET); SEEK_SET);
read(fd_exif, val, 1); read(fset->exif_dev_fd, val, 1);
if (val[0] != EXIF_COMPASS_PITCH_ASCII[0]) pitch = -pitch; if (val[0] != EXIF_COMPASS_PITCH_ASCII[0]) pitch = -pitch;
} }
sprintf(val, "%f", pitch); sprintf(val, "%f", pitch);
printf("<CompassPitch>\"%s\"</CompassPitch>\n", val); printf("<CompassPitch>\"%s\"</CompassPitch>\n", val);
} }
close(fd_exif); // fprintf(stderr, "%s:%d:%s: Exif done\n", __FILE__, __LINE__, __FUNCTION__);
close(fset->exif_dev_fd);
fset->exif_dev_fd = -1;
return 0; return 0;
} }
...@@ -502,7 +531,13 @@ int metaXML(struct file_set *fset, int mode) ...@@ -502,7 +531,13 @@ int metaXML(struct file_set *fset, int mode)
int frameParamPointer = 0; int frameParamPointer = 0;
struct interframe_params_t frame_params; struct interframe_params_t frame_params;
int jpeg_len, jpeg_start, buff_size, timestamp_start; int jpeg_len, jpeg_start, buff_size, timestamp_start;
int fd_circ = fset->circbuf_fd; if (fset->circbuf_fd <0) {
fset->circbuf_fd = open(fset->cirbuf_fn, O_RDWR);
}
if (fset->circbuf_fd <0) {
printf("Error opening %s\n", fset->cirbuf_fn);
fprintf(stderr, "%s:%d:%s: Error opening %s\n", __FILE__, __LINE__, __FUNCTION__, fset->cirbuf_fn);
}
if (mode == 2) { // just close the xml file if (mode == 2) { // just close the xml file
printf("</meta>\n"); printf("</meta>\n");
...@@ -517,15 +552,16 @@ int metaXML(struct file_set *fset, int mode) ...@@ -517,15 +552,16 @@ int metaXML(struct file_set *fset, int mode)
"<meta>\n"); "<meta>\n");
} }
jpeg_start = lseek(fd_circ, 0, SEEK_CUR); //get the current read pointer jpeg_start = lseek(fset->circbuf_fd, 0, SEEK_CUR); //get the current read pointer
// jpeg_start = lseek(fset->circbuf_fd, 1, SEEK_CUR)-1; //get the current read pointer
D(fprintf(stderr, "jpeg_start= (long)=0x%x\n", jpeg_start >> 2)); D(fprintf(stderr, "jpeg_start= (long)=0x%x\n", jpeg_start >> 2));
if (jpeg_start < 0 ) { if (jpeg_start < 0 ) {
printf("<error>\"No frame at the current pointer\"</error>\n"); printf("<error>\"No frame at the current pointer\"</error>\n");
return -1; return -1;
} }
buff_size = lseek(fd_circ, 0, SEEK_END); buff_size = lseek(fset->circbuf_fd, 0, SEEK_END);
// restore file pointer after lseek-ing the end // restore file pointer after lseek-ing the end
lseek(fd_circ, jpeg_start, SEEK_SET); lseek(fset->circbuf_fd, jpeg_start, SEEK_SET);
frameParamPointer = jpeg_start - 32; frameParamPointer = jpeg_start - 32;
if (frameParamPointer < 0) frameParamPointer += buff_size; if (frameParamPointer < 0) frameParamPointer += buff_size;
...@@ -585,29 +621,59 @@ int metaXML(struct file_set *fset, int mode) ...@@ -585,29 +621,59 @@ int metaXML(struct file_set *fset, int mode)
* @brief Read current frame number from frame parameters buffer * @brief Read current frame number from frame parameters buffer
* @return frame number * @return frame number
*/ */
unsigned long getCurrentFrameNumber() // TODO NC393 - now 2 types of current frame - one being acquired from sensor and the one already compressed
// First one comes from framepars, second - from circbuf (that is more interesting for the imgsrv)
unsigned long getCurrentFrameNumberSensor(struct file_set *fset)
{ {
const char ctlFileName[] = "/dev/frameparsall"; unsigned long frame_number;
int fd_fparmsall = open(ctlFileName, O_RDWR); if (fset->framepars_dev_fd <0)
unsigned long frame_number = lseek(fd_fparmsall, 0, SEEK_CUR ); fset->framepars_dev_fd = open(fset->framepars_dev_name, O_RDWR);
if (fset->framepars_dev_fd <0) {
close(fd_fparmsall); printf("Error opening %s\n", fset->framepars_dev_name);
fprintf(stderr, "%s:%d:%s: Error opening %s\n", __FILE__, __LINE__, __FUNCTION__, fset->framepars_dev_name);
return 0;
}
frame_number = lseek(fset->framepars_dev_fd, 0, SEEK_CUR );
fprintf(stderr, "%s:%d:%s: frame_number= %d\n", __FILE__, __LINE__, __FUNCTION__, frame_number);
return frame_number; return frame_number;
} }
unsigned long getCurrentFrameNumberCompressor(struct file_set *fset)
{
unsigned long frame_number;
if (fset->circbuf_fd <0) {
fset->circbuf_fd = open(fset->cirbuf_fn, O_RDWR);
}
if (fset->circbuf_fd <0) {
printf("Error opening %s\n", fset->cirbuf_fn);
fprintf(stderr, "%s:%d:%s: Error opening %s\n", __FILE__, __LINE__, __FUNCTION__, fset->cirbuf_fn);
return 0;
}
frame_number = lseek(fset->circbuf_fd, LSEEK_CIRC_GETFRAME, SEEK_END );
fprintf(stderr, "%s:%d:%s: frame_number= %d\n", __FILE__, __LINE__, __FUNCTION__, frame_number);
return frame_number;
}
/** /**
* @brief Wait for the next frame to be captured * @brief Wait for the next frame sync (frame captured is handled differently - through wait command)
* @return None * @return None
*/ */
void waitFrameSync()
{
const char ctlFileName[] = "/dev/frameparsall";
int fd_fparmsall = open(ctlFileName, O_RDWR);
lseek(fd_fparmsall, LSEEK_FRAME_WAIT_REL + 1, SEEK_END); // skip 1 frame before returning void waitFrameSync(struct file_set *fset)
close(fd_fparmsall); {
if (fset->framepars_dev_fd <0)
fset->framepars_dev_fd = open(fset->framepars_dev_name, O_RDWR);
if (fset->framepars_dev_fd <0) {
printf("Error opening %s\n", fset->framepars_dev_name);
fprintf(stderr, "%s:%d:%s: Error opening %s\n", __FILE__, __LINE__, __FUNCTION__, fset->framepars_dev_name);
return;
}
lseek(fset->framepars_dev_fd, LSEEK_FRAME_WAIT_REL + 1, SEEK_END); // skip 1 frame before returning
fprintf(stderr, "%s:%d:%s: \n", __FILE__, __LINE__, __FUNCTION__);
} }
/** /**
* @brief Read circular buffer pointers and write them to @e stdout in XML format * @brief Read circular buffer pointers and write them to @e stdout in XML format
* @param[in] fset file set for which the data should be printed * @param[in] fset file set for which the data should be printed
...@@ -615,49 +681,70 @@ void waitFrameSync() ...@@ -615,49 +681,70 @@ void waitFrameSync()
*/ */
int framePointersXML(struct file_set *fset) int framePointersXML(struct file_set *fset)
{ {
const char ctlFileName[] = "/dev/frameparsall"; // const char ctlFileName[] = "/dev/frameparsall";
int fd_fparmsall; // int fd_fparmsall;
char s[512]; // 341; char s[512]; // 341;
int p, wp, rp; int p, wp, rp;
int nf = 0; int nf = 0;
int nfl = 0; int nfl = 0;
int buf_free, buf_used, frame_size; int buf_free, buf_used, frame_size;
int save_p; // save current file pointer, then restore it before return int save_p; // save current file pointer, then restore it before return
int frame8, frame_number, sensor_state, compressor_state; int frame16, frame_number, compressed_frame_number, sensor_state, compressor_state;
char *cp_sensor_state, *cp_compressor_state; char *cp_sensor_state, *cp_compressor_state;
#if 0
struct framepars_all_t **frameParsAll; struct framepars_all_t **frameParsAll;
struct framepars_t *aframePars[SENSOR_PORTS]; struct framepars_t *aframePars[SENSOR_PORTS];
unsigned long *aglobalPars[SENSOR_PORTS]; unsigned long *aglobalPars[SENSOR_PORTS];
int fd_circ = fset->circbuf_fd; #else
//Need to mmap just one port
struct framepars_all_t *frameParsAll;
struct framepars_t *framePars;
unsigned long *globalPars;
fd_fparmsall = open(ctlFileName, O_RDWR); #endif
if (fd_fparmsall < 0) { // check control OK // int fd_circ = fset->circbuf_fd;
printf("Error opening %s\n", ctlFileName); // fprintf(stderr, "%s:%d:%s: Starting\n", __FILE__, __LINE__, __FUNCTION__);
fprintf(stderr, "%s:%d:%s: Error opening %s\n", __FILE__, __LINE__, __FUNCTION__, ctlFileName); if (fset->framepars_dev_fd <0)
fset->framepars_dev_fd = open(fset->framepars_dev_name, O_RDWR);
if (fset->framepars_dev_fd < 0) { // check control OK
printf("Error opening %s\n", fset->framepars_dev_name);
fprintf(stderr, "%s:%d:%s: Error opening %s\n", __FILE__, __LINE__, __FUNCTION__, fset->framepars_dev_name);
fset->framepars_dev_fd = -1;
return -1; return -1;
} }
if (fset->circbuf_fd <0) {
fset->circbuf_fd = open(fset->cirbuf_fn, O_RDWR);
}
if (fset->circbuf_fd <0) {
printf("Error opening %s\n", fset->cirbuf_fn);
fprintf(stderr, "%s:%d:%s: Error opening %s\n", __FILE__, __LINE__, __FUNCTION__, fset->cirbuf_fn);
}
// now try to mmap // now try to mmap
frameParsAll = (struct framepars_all_t**)mmap(0, sizeof(struct framepars_all_t), PROT_READ, MAP_SHARED, fd_fparmsall, 0); frameParsAll = (struct framepars_all_t*) mmap(0, sizeof(struct framepars_all_t), PROT_READ, MAP_SHARED, fset->framepars_dev_fd, 0);
if ((int)frameParsAll == -1) { if ((int)frameParsAll == -1) {
frameParsAll = NULL; frameParsAll = NULL;
printf("Error in mmap /dev/frameparsall"); printf("Error in mmap /dev/frameparsall");
fprintf(stderr, "%s:%d:%s: Error in mmap in %s\n", __FILE__, __LINE__, __FUNCTION__, ctlFileName); fprintf(stderr, "%s:%d:%s: Error in mmap in %s\n", __FILE__, __LINE__, __FUNCTION__, fset->framepars_dev_name);
close(fd_fparmsall); close(fset->framepars_dev_fd);
fd_fparmsall = -1; fset->framepars_dev_fd = -1;
return -1; return -1;
} }
for (int j = 0; j < SENSOR_PORTS; j++) { framePars=frameParsAll->framePars;
aframePars[j] = frameParsAll[j]->framePars; globalPars=frameParsAll->globalPars;
aglobalPars[j] = frameParsAll[j]->globalPars;
} // for (int j = 0; j < SENSOR_PORTS; j++) {
// aframePars[j] = frameParsAll[j]->framePars;
// aglobalPars[j] = frameParsAll[j]->globalPars;
// }
//->port_num
// Read current sensor state - defined in c313a.h // Read current sensor state - defined in c313a.h
frame_number = lseek(fd_fparmsall, 0, SEEK_CUR ); frame_number = lseek(fset->framepars_dev_fd, 0, SEEK_CUR );
frame8 = frame_number & PARS_FRAMES_MASK; compressed_frame_number = lseek(fset->circbuf_fd, LSEEK_CIRC_GETFRAME, SEEK_END );
sensor_state = aframePars[fset->port_num][frame8].pars[P_SENSOR_RUN]; frame16 = frame_number & PARS_FRAMES_MASK;
compressor_state = aframePars[fset->port_num][frame8].pars[P_COMPRESSOR_RUN]; sensor_state = framePars[frame16].pars[P_SENSOR_RUN];
compressor_state = framePars[frame16].pars[P_COMPRESSOR_RUN];
cp_sensor_state = (sensor_state == 0) ? cp_sensor_state = (sensor_state == 0) ?
"SENSOR_RUN_STOP" : "SENSOR_RUN_STOP" :
((sensor_state == 1) ? ((sensor_state == 1) ?
...@@ -669,23 +756,23 @@ int framePointersXML(struct file_set *fset) ...@@ -669,23 +756,23 @@ int framePointersXML(struct file_set *fset)
"COMPRESSOR_RUN_SINGLE" : "COMPRESSOR_RUN_SINGLE" :
((compressor_state == 2) ? "COMPRESSOR_RUN_CONT" : "UNKNOWN")); ((compressor_state == 2) ? "COMPRESSOR_RUN_CONT" : "UNKNOWN"));
save_p = lseek(fd_circ, 0, SEEK_CUR); // save current file pointer before temporarily moving it save_p = lseek(fset->circbuf_fd, 0, SEEK_CUR); // save current file pointer before temporarily moving it
rp = lseek(fd_circ, LSEEK_CIRC_TORP, SEEK_END); // set current rp global rp (may be invalid <0) rp = lseek(fset->circbuf_fd, LSEEK_CIRC_TORP, SEEK_END); // set current rp global rp (may be invalid <0)
wp = lseek(fd_circ, LSEEK_CIRC_TOWP, SEEK_END); // set current rp pointer to FPGA write pointer wp = lseek(fset->circbuf_fd, LSEEK_CIRC_TOWP, SEEK_END); // set current rp pointer to FPGA write pointer
p = wp; p = wp;
while ((p >= 0) & (nf < 500)) { while ((p >= 0) & (nf < 500)) {
if (p == rp) nfl = nf; if (p == rp) nfl = nf;
p = lseek(fd_circ, LSEEK_CIRC_PREV, SEEK_END); p = lseek(fset->circbuf_fd, LSEEK_CIRC_PREV, SEEK_END);
nf++; nf++;
} }
buf_free = GLOBALPARS(fset->port_num, G_FREECIRCBUF); buf_free = GLOBALPARS_SNGL(G_FREECIRCBUF);
frame_size = GLOBALPARS(fset->port_num, G_FRAME_SIZE); frame_size = GLOBALPARS_SNGL(G_FRAME_SIZE);
lseek(fd_circ, save_p, SEEK_SET); // restore file pointer after temporarily moving it lseek(fset->circbuf_fd, save_p, SEEK_SET); // restore file pointer after temporarily moving it
buf_free = lseek(fd_circ, LSEEK_CIRC_FREE, SEEK_END); // will change file pointer buf_free = lseek(fset->circbuf_fd, LSEEK_CIRC_FREE, SEEK_END); // will change file pointer
lseek(fd_circ, save_p, SEEK_SET); // restore file pointer after temporarily moving it lseek(fset->circbuf_fd, save_p, SEEK_SET); // restore file pointer after temporarily moving it
buf_used = lseek(fd_circ, LSEEK_CIRC_USED, SEEK_END); // will change file pointer buf_used = lseek(fset->circbuf_fd, LSEEK_CIRC_USED, SEEK_END); // will change file pointer
lseek(fd_circ, save_p, SEEK_SET); // restore file pointer after temporarily moving it lseek(fset->circbuf_fd, save_p, SEEK_SET); // restore file pointer after temporarily moving it
sprintf(s, "<?xml version=\"1.0\"?>\n" \ sprintf(s, "<?xml version=\"1.0\"?>\n" \
"<frame_pointers>\n" \ "<frame_pointers>\n" \
...@@ -697,6 +784,7 @@ int framePointersXML(struct file_set *fset) ...@@ -697,6 +784,7 @@ int framePointersXML(struct file_set *fset)
" <free>%d</free>\n" \ " <free>%d</free>\n" \
" <used>%d</used>\n" \ " <used>%d</used>\n" \
" <frame>%d</frame>\n" \ " <frame>%d</frame>\n" \
" <compressedFrame>%d</compressedFrame>\n" \
" <frame_size>%d</frame_size>\n" \ " <frame_size>%d</frame_size>\n" \
" <sensor_state>\"%s\"</sensor_state>\n" \ " <sensor_state>\"%s\"</sensor_state>\n" \
" <compressor_state>\"%s\"</compressor_state>\n" \ " <compressor_state>\"%s\"</compressor_state>\n" \
...@@ -709,6 +797,7 @@ int framePointersXML(struct file_set *fset) ...@@ -709,6 +797,7 @@ int framePointersXML(struct file_set *fset)
buf_free, buf_free,
buf_used, buf_used,
frame_number, frame_number,
compressed_frame_number,
frame_size, frame_size,
cp_sensor_state, cp_sensor_state,
cp_compressor_state); cp_compressor_state);
...@@ -721,7 +810,8 @@ int framePointersXML(struct file_set *fset) ...@@ -721,7 +810,8 @@ int framePointersXML(struct file_set *fset)
printf(s); printf(s);
munmap(frameParsAll, sizeof(struct framepars_all_t)); munmap(frameParsAll, sizeof(struct framepars_all_t));
close(fd_fparmsall); close(fset->framepars_dev_fd);
fset->framepars_dev_fd = -1;
D(fprintf(stderr, ">%s< [%d bytes]\n", s, strlen(s))); D(fprintf(stderr, ">%s< [%d bytes]\n", s, strlen(s)));
return 0; return 0;
} }
...@@ -788,8 +878,8 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -788,8 +878,8 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
int buff_size; int buff_size;
int jpeg_len; // bytes int jpeg_len; // bytes
int jpeg_start; // bytes int jpeg_start; // bytes
int fd_head; // int fd_head;
int fd_exif; // int fd_exif;
int head_size; int head_size;
int jpeg_full_size, jpeg_this_size; int jpeg_full_size, jpeg_this_size;
char * jpeg_copy; char * jpeg_copy;
...@@ -799,22 +889,27 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -799,22 +889,27 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
char * extension; char * extension;
jpeg_start = lseek(fset->circbuf_fd, 0, SEEK_CUR); //get the current read pointer jpeg_start = lseek(fset->circbuf_fd, 0, SEEK_CUR); //get the current read pointer
// jpeg_start = lseek(fset->circbuf_fd, 1, SEEK_CUR)-1; //just for testing, until rebuilt/rebooted kernel
D(fprintf(stderr, "jpeg_start (long) = 0x%x\n", jpeg_start)); D(fprintf(stderr, "jpeg_start (long) = 0x%x\n", jpeg_start));
fd_head = open(fset->jphead_fn, O_RDWR); if (fset->jphead_fd<0)
if (fd_head < 0) { // check control OK fset->jphead_fd = open(fset->jphead_fn, O_RDWR);
if (fset->jphead_fd < 0) { // check control OK
fprintf(stderr, "Error opening %s\n", fset->jphead_fn); fprintf(stderr, "Error opening %s\n", fset->jphead_fn);
return -1; return -1;
} }
fset->jphead_fd = fd_head; // fset->jphead_fd = fd_head;
lseek(fd_head, jpeg_start + 1, SEEK_END); // create JPEG header, find out it's size lseek(fset->jphead_fd, jpeg_start + 1, SEEK_END); // create JPEG header, find out it's size
head_size = lseek(fd_head, 0, SEEK_END); head_size = lseek(fset->jphead_fd, 0, SEEK_END);
if (head_size > JPEG_HEADER_MAXSIZE) { if (head_size > JPEG_HEADER_MAXSIZE) {
fprintf(stderr, "%s:%d: Too big JPEG header (%d > %d)", __FILE__, __LINE__, head_size, JPEG_HEADER_MAXSIZE ); fprintf(stderr, "%s:%d: Too big JPEG header (%d > %d)", __FILE__, __LINE__, head_size, JPEG_HEADER_MAXSIZE );
close(fd_head); close(fset->jphead_fd);
fset->jphead_fd = -1;
return -2; return -2;
} }
/* find total buffer length (it is in defines, actually in c313a.h */ /* find total buffer length (it is in defines, actually in c313a.h */
buff_size = lseek(fset->circbuf_fd, 0, SEEK_END); buff_size = lseek(fset->circbuf_fd, 0, SEEK_END); // it is supposed to be open?
/* restore file poinetr after lseek-ing the end */ /* restore file poinetr after lseek-ing the end */
lseek(fset->circbuf_fd, jpeg_start, SEEK_SET); lseek(fset->circbuf_fd, jpeg_start, SEEK_SET);
D(fprintf(stderr, "position (longs) = 0x%x\n", (int)lseek(fset->circbuf_fd, 0, SEEK_CUR))); D(fprintf(stderr, "position (longs) = 0x%x\n", (int)lseek(fset->circbuf_fd, 0, SEEK_CUR)));
...@@ -823,35 +918,48 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -823,35 +918,48 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
frameParamPointer = jpeg_start - sizeof(struct interframe_params_t) + 4; frameParamPointer = jpeg_start - sizeof(struct interframe_params_t) + 4;
if (frameParamPointer < 0) if (frameParamPointer < 0)
frameParamPointer += buff_size; frameParamPointer += buff_size;
fprintf(stderr, "frameParamPointer = 0x%x, jpeg_start = 0x%x, buff_size = 0x%x\n", // fprintf(stderr, "frameParamPointer = 0x%x, jpeg_start = 0x%x, buff_size = 0x%x\n",frameParamPointer, jpeg_start, buff_size);
frameParamPointer, jpeg_start, buff_size);
memcpy(&frame_params, (unsigned long*)&ccam_dma_buf[frameParamPointer >> 2], sizeof(struct interframe_params_t) - 4); memcpy(&frame_params, (unsigned long*)&ccam_dma_buf[frameParamPointer >> 2], sizeof(struct interframe_params_t) - 4);
jpeg_len = frame_params.frame_length; jpeg_len = frame_params.frame_length;
color_mode = frame_params.color; color_mode = frame_params.color;
if (frame_params.signffff != 0xffff) { if (frame_params.signffff != 0xffff) {
fprintf(stderr, "wrong signature signff = 0x%x \n", (int)frame_params.signffff); fprintf(stderr, "wrong signature signff = 0x%x \n", (int)frame_params.signffff);
#ifdef ELPHEL_DEBUG_THIS for (i=0; i< sizeof(struct interframe_params_t)/4;i++){
fprintf(stderr, "%08lx ",ccam_dma_buf[(frameParamPointer >> 2) + i]);
if (!((i+1) & 0x7)){
fprintf(stderr, "\n ");
}
}
#if ELPHEL_DEBUG_THIS
lseek(fset->circbuf_fd, LSEEK_CIRC_STOP_COMPRESSOR, SEEK_END); lseek(fset->circbuf_fd, LSEEK_CIRC_STOP_COMPRESSOR, SEEK_END);
#endif #endif
close(fd_head); close(fset->jphead_fd);
fset->jphead_fd = -1;
return -4; return -4;
} }
if (use_Exif) { if (use_Exif) {
D(fprintf(stderr,"frame_params.meta_index=0x%x\n",(int) frame_params.meta_index)); D(fprintf(stderr,"frame_params.meta_index=0x%x\n",(int) frame_params.meta_index));
// read Exif to buffer: // read Exif to buffer:
fd_exif = open(fset->exif_dev_name, O_RDONLY); if (fset->exif_dev_fd <0)
if (fd_exif < 0) { // check control OK fset->exif_dev_fd = open(fset->exif_dev_name, O_RDONLY);
if (fset->exif_dev_fd < 0) { // check control OK
fprintf(stderr, "Error opening %s\n", fset->exif_dev_name); fprintf(stderr, "Error opening %s\n", fset->exif_dev_name);
close(fd_head); close(fset->jphead_fd);
fset->jphead_fd = -1;
return -5; return -5;
} }
exifDataSize = lseek(fd_exif, 1, SEEK_END); // at the beginning of page 1 - position == page length exifDataSize = lseek(fset->exif_dev_fd, 1, SEEK_END); // at the beginning of page 1 - position == page length
if (exifDataSize < 0) exifDataSize = 0; // error from lseek; if (exifDataSize < 0) exifDataSize = 0; // error from lseek;
if (!exifDataSize) close(fd_exif); if (!exifDataSize){
close(fset->exif_dev_fd);
fset->exif_dev_fd = -1;
}
} else { } else {
frame_params.meta_index=0; frame_params.meta_index=0;
fd_exif = -1; fset->exif_dev_fd = -1;
} }
// Maybe make buffer that will fit both Exif and JPEG? // Maybe make buffer that will fit both Exif and JPEG?
// Get metadata, update Exif and JFIF headers if ep and ed pointers are non-zero (NULL will generate files with JFIF-only headers) // Get metadata, update Exif and JFIF headers if ep and ed pointers are non-zero (NULL will generate files with JFIF-only headers)
...@@ -859,8 +967,8 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -859,8 +967,8 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
jpeg_full_size = jpeg_len + head_size + 2 + exifDataSize; jpeg_full_size = jpeg_len + head_size + 2 + exifDataSize;
fprintf(stderr, "jpeg_len = 0x%x, head_size = 0x%x, exifDataSize = 0x%x, jpeg_full_size = 0x%x\n", // fprintf(stderr, "jpeg_len = 0x%x, head_size = 0x%x, exifDataSize = 0x%x, jpeg_full_size = 0x%x\n",
jpeg_len, head_size, exifDataSize, jpeg_full_size); // jpeg_len, head_size, exifDataSize, jpeg_full_size);
if (bufferImageData) jpeg_this_size = jpeg_full_size; // header+frame if (bufferImageData) jpeg_this_size = jpeg_full_size; // header+frame
else jpeg_this_size = head_size + exifDataSize; // only header else jpeg_this_size = head_size + exifDataSize; // only header
...@@ -880,14 +988,16 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -880,14 +988,16 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
} }
} }
lseek(fd_head, 0, 0); lseek(fset->jphead_fd, 0, 0);
read(fd_head, &jpeg_copy[exifDataSize], head_size); read(fset->jphead_fd, &jpeg_copy[exifDataSize], head_size);
close(fd_head); close(fset->jphead_fd);
fset->jphead_fd = -1;
if (exifDataSize > 0) { // insert Exif if (exifDataSize > 0) { // insert Exif
memcpy(jpeg_copy, &jpeg_copy[exifDataSize], 2); // copy first 2 bytes of the JFIF header before Exif memcpy(jpeg_copy, &jpeg_copy[exifDataSize], 2); // copy first 2 bytes of the JFIF header before Exif
lseek(fd_exif,frame_params.meta_index,SEEK_END); // select meta page to use (matching frame) lseek(fset->exif_dev_fd,frame_params.meta_index,SEEK_END); // select meta page to use (matching frame)
read(fd_exif, &jpeg_copy[2], exifDataSize); // Insert Exif itself read(fset->exif_dev_fd, &jpeg_copy[2], exifDataSize); // Insert Exif itself
close(fd_exif); close(fset->exif_dev_fd);
fset->exif_dev_fd = -1;
} }
switch (color_mode) { switch (color_mode) {
// case COLORMODE_MONO6: //! monochrome, (4:2:0), // case COLORMODE_MONO6: //! monochrome, (4:2:0),
...@@ -934,7 +1044,7 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -934,7 +1044,7 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
else printf("Content-Disposition: inline; filename=\"elphelimg_%ld.%s\"\r\n", frame_params.timestamp_sec, extension); // opens in browser, asks to save on right-click else printf("Content-Disposition: inline; filename=\"elphelimg_%ld.%s\"\r\n", frame_params.timestamp_sec, extension); // opens in browser, asks to save on right-click
if (bufferImageData) { /* Buffer the whole file before sending over the network to make sure it will not be corrupted if the circular buffer will be overrun) */ if (bufferImageData) { /* Buffer the whole file before sending over the network to make sure it will not be corrupted if the circular buffer will be overrun) */
#ifdef ELPHEL_DEBUG_THIS #if ELPHEL_DEBUG_THIS
unsigned long start_time, end_time; unsigned long start_time, end_time;
start_time = lseek(fset->circbuf_fd, LSEEK_CIRC_UTIME, SEEK_END); start_time = lseek(fset->circbuf_fd, LSEEK_CIRC_UTIME, SEEK_END);
#endif #endif
...@@ -947,7 +1057,7 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav ...@@ -947,7 +1057,7 @@ int sendImage(struct file_set *fset, int bufferImageData, int use_Exif, int sav
} else { /* single segment */ } else { /* single segment */
memcpy(&jpeg_copy[l], (unsigned long* )&ccam_dma_buf[jpeg_start >> 2], jpeg_len); memcpy(&jpeg_copy[l], (unsigned long* )&ccam_dma_buf[jpeg_start >> 2], jpeg_len);
} }
#ifdef ELPHEL_DEBUG_THIS #if ELPHEL_DEBUG_THIS
end_time = lseek(fset->circbuf_fd, LSEEK_CIRC_UTIME, SEEK_END); end_time = lseek(fset->circbuf_fd, LSEEK_CIRC_UTIME, SEEK_END);
D(fprintf(stderr, "memcpy time = %lu\n", end_time - start_time)); D(fprintf(stderr, "memcpy time = %lu\n", end_time - start_time));
#endif #endif
...@@ -1008,7 +1118,7 @@ void sendBuffer(void * buffer, int len) ...@@ -1008,7 +1118,7 @@ void sendBuffer(void * buffer, int len)
void listener_loop(struct file_set *fset) void listener_loop(struct file_set *fset)
{ {
char errormsg[1024]; char errormsg[1024];
int fd_circ; // int fd_circ;
int this_p; // current frame pointer (bytes) int this_p; // current frame pointer (bytes)
int rslt; int rslt;
int buf_images = 0; int buf_images = 0;
...@@ -1066,50 +1176,55 @@ void listener_loop(struct file_set *fset) ...@@ -1066,50 +1176,55 @@ void listener_loop(struct file_set *fset)
fflush(stdout); fflush(stdout);
_exit(0); _exit(0);
} }
// Process 'frame' and 'wframe' commands - theys do not need circbuf // Process 'frame' and 'wframe' commands - they do not need circbuf (now they do!)
if ((strncmp(cp, "frame", 5) == 0) || (strncmp(cp, "wframe", 6) == 0)) { if ((strncmp(cp, "frame", 5) == 0) || (strncmp(cp, "wframe", 6) == 0) || (strncmp(cp, "sframe", 6) == 0)) {
if (strncmp(cp, "wframe", 6) == 0) waitFrameSync(); if (strncmp(cp, "wframe", 6) == 0) waitFrameSync(fset);
printf("HTTP/1.0 200 OK\r\n"); printf("HTTP/1.0 200 OK\r\n");
printf("Server: Elphel Imgsrv\r\n"); printf("Server: Elphel Imgsrv\r\n");
printf("Content-Length: 11\r\n"); printf("Content-Length: 11\r\n");
printf("Content-Type: text/plain\r\n"); printf("Content-Type: text/plain\r\n");
printf("\r\n"); printf("\r\n");
printf("%010ld\r\n", getCurrentFrameNumber()); if (strncmp(cp, "frame", 5) == 0)
printf("%010ld\r\n", getCurrentFrameNumberCompressor(fset));
else //sframe
printf("%010ld\r\n", getCurrentFrameNumberSensor(fset));
fflush(stdout); fflush(stdout);
_exit(0); _exit(0);
} }
// now process the commands one at a time, but first - open the circbuf file and setup the pointer // now process the commands one at a time, but first - open the circbuf file and setup the pointer
fd_circ = open(fset->cirbuf_fn, O_RDWR); if (fset->circbuf_fd<0)
if (fd_circ < 0) { // check control OK fset->circbuf_fd = open(fset->cirbuf_fn, O_RDWR);
if (fset->circbuf_fd < 0) { // check control OK
fprintf(stderr, "Error opening %s\n", fset->cirbuf_fn); fprintf(stderr, "Error opening %s\n", fset->cirbuf_fn);
out1x1gif(); out1x1gif();
fflush(stdout); fflush(stdout);
_exit(0); _exit(0);
} }
fset->circbuf_fd = fd_circ; // fset->circbuf_fd = fd_circ;
/* find total buffer length (it is in defines, actually in c313a.h */ /* find total buffer length (it is in defines, actually in c313a.h */
buff_size = lseek(fd_circ, 0, SEEK_END); buff_size = lseek(fset->circbuf_fd, 0, SEEK_END);
fprintf(stderr, "%s: read circbuf size: %d\n", __func__, buff_size); // fprintf(stderr, "%s: read circbuf size: %d\n", __func__, buff_size);
/* now let's try mmap itself */ /* now let's try mmap itself */
ccam_dma_buf = (unsigned long*)mmap(0, buff_size, PROT_READ, MAP_SHARED, fd_circ, 0); ccam_dma_buf = (unsigned long*)mmap(0, buff_size, PROT_READ, MAP_SHARED, fset->circbuf_fd, 0);
if ((int)ccam_dma_buf == -1) { if ((int)ccam_dma_buf == -1) {
fprintf(stderr, "Error in mmap\n"); fprintf(stderr, "Error in mmap\n");
close(fd_circ); // - caller opened, caller - to close close(fset->circbuf_fd); // - caller opened, caller - to close
fset->circbuf_fd = -1;
out1x1gif(); out1x1gif();
fflush(stdout); fflush(stdout);
_exit(0); _exit(0);
} }
this_p = lseek(fd_circ, LSEEK_CIRC_LAST, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_LAST, SEEK_END);
D(fprintf(stderr, "%s: current frame pointer this_p (in bytes): 0x%x\n", __func__, this_p)); D(fprintf(stderr, "%s: current frame pointer this_p (in bytes): 0x%x\n", __func__, this_p));
// continue with iterating through the commands // continue with iterating through the commands
while ((cp1 = strsep(&cp, "/?&"))) { while ((cp1 = strsep(&cp, "/?&"))) {
// if the first character is a digit, it is a file pointer // if the first character is a digit, it is a file pointer
if (strchr("0123456789", cp1[0])) { if (strchr("0123456789", cp1[0])) {
this_p = lseek(fd_circ, strtol(cp1, NULL, 10), SEEK_SET); this_p = lseek(fset->circbuf_fd, strtol(cp1, NULL, 10), SEEK_SET);
} else if ((strcmp(cp1, "img") == 0) || (strcmp(cp1, "bimg") == 0) || (strcmp(cp1, "simg") == 0) || (strcmp(cp1, "sbimg") == 0)) { } else if ((strcmp(cp1, "img") == 0) || (strcmp(cp1, "bimg") == 0) || (strcmp(cp1, "simg") == 0) || (strcmp(cp1, "sbimg") == 0)) {
fprintf(stderr, "%s: processing img command\n", __func__); fprintf(stderr, "%s: processing img command\n", __func__);
if (sent2socket > 0) break; // image/xmldata was already sent to socket, ignore if (sent2socket > 0) break; // image/xmldata was already sent to socket, ignore
if (lseek(fd_circ, LSEEK_CIRC_READY, SEEK_END) < 0) { // here passes OK, some not ready error is later, in sendimage (make it return different numbers) if (lseek(fset->circbuf_fd, LSEEK_CIRC_READY, SEEK_END) < 0) { // here passes OK, some not ready error is later, in sendimage (make it return different numbers)
rslt = out1x1gif(); rslt = out1x1gif();
fprintf(stderr, "%s: no frame is available\n", __func__); fprintf(stderr, "%s: no frame is available\n", __func__);
} else { } else {
...@@ -1135,7 +1250,7 @@ void listener_loop(struct file_set *fset) ...@@ -1135,7 +1250,7 @@ void listener_loop(struct file_set *fset)
// multipart - always last // multipart - always last
} else if ((strncmp(cp1, "mimg", 4) == 0) || (strncmp(cp1, "bmimg", 5) == 0) || (strncmp(cp1, "mbimg", 5) == 0)) { } else if ((strncmp(cp1, "mimg", 4) == 0) || (strncmp(cp1, "bmimg", 5) == 0) || (strncmp(cp1, "mbimg", 5) == 0)) {
if (sent2socket > 0) break; // image/xmldata was already sent to socket, ignore if (sent2socket > 0) break; // image/xmldata was already sent to socket, ignore
if (lseek(fd_circ, LSEEK_CIRC_READY, SEEK_END) < 0) // here passes OK, some not ready error is later, in sendimage (make it return different numbers) if (lseek(fset->circbuf_fd, LSEEK_CIRC_READY, SEEK_END) < 0) // here passes OK, some not ready error is later, in sendimage (make it return different numbers)
rslt = out1x1gif(); rslt = out1x1gif();
else { else {
buf_images = (strncmp(cp1, "mimg", 4) == 0) ? 0 : 1; buf_images = (strncmp(cp1, "mimg", 4) == 0) ? 0 : 1;
...@@ -1154,13 +1269,13 @@ void listener_loop(struct file_set *fset) ...@@ -1154,13 +1269,13 @@ void listener_loop(struct file_set *fset)
rslt = sendImage(fset, buf_images, exif_enable, 0); // verify driver that file pointer did not move rslt = sendImage(fset, buf_images, exif_enable, 0); // verify driver that file pointer did not move
fflush(stdout); fflush(stdout);
if (rslt >= 0) for (skip = 0; skip < slow; skip++) { if (rslt >= 0) for (skip = 0; skip < slow; skip++) {
this_p = lseek(fd_circ, LSEEK_CIRC_NEXT, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_NEXT, SEEK_END);
// If these "next" is not ready yet - wait, else - use latest image // If these "next" is not ready yet - wait, else - use latest image
if ((lseek(fd_circ, LSEEK_CIRC_VALID, SEEK_END) >= 0) && // no sense to wait if the pointer is invalid if ((lseek(fset->circbuf_fd, LSEEK_CIRC_VALID, SEEK_END) >= 0) && // no sense to wait if the pointer is invalid
(lseek(fd_circ, LSEEK_CIRC_READY, SEEK_END) < 0) && // or the frame is already ready (lseek(fset->circbuf_fd, LSEEK_CIRC_READY, SEEK_END) < 0) && // or the frame is already ready
(lseek(fd_circ, LSEEK_CIRC_VALID, SEEK_END) >= 0)) // test valid once again, after not ready - it might change (lseek(fset->circbuf_fd, LSEEK_CIRC_VALID, SEEK_END) >= 0)) // test valid once again, after not ready - it might change
this_p = lseek(fd_circ, LSEEK_CIRC_WAIT, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_WAIT, SEEK_END);
else this_p = lseek(fd_circ, LSEEK_CIRC_LAST, SEEK_END); else this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_LAST, SEEK_END);
} }
} }
_exit(0); _exit(0);
...@@ -1180,26 +1295,26 @@ void listener_loop(struct file_set *fset) ...@@ -1180,26 +1295,26 @@ void listener_loop(struct file_set *fset)
} else if (strcmp(cp1, "exif") == 0) { } else if (strcmp(cp1, "exif") == 0) {
exif_enable = 1; exif_enable = 1;
} else if (strcmp(cp1, "torp") == 0) { } else if (strcmp(cp1, "torp") == 0) {
this_p = lseek(fd_circ, LSEEK_CIRC_TORP, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_TORP, SEEK_END);
} else if (strcmp(cp1, "towp") == 0) { } else if (strcmp(cp1, "towp") == 0) {
this_p = lseek(fd_circ, LSEEK_CIRC_TOWP, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_TOWP, SEEK_END);
} else if (strcmp(cp1, "prev") == 0) { } else if (strcmp(cp1, "prev") == 0) {
this_p = lseek(fd_circ, LSEEK_CIRC_PREV, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_PREV, SEEK_END);
} else if (strcmp(cp1, "next") == 0) { } else if (strcmp(cp1, "next") == 0) {
this_p = lseek(fd_circ, LSEEK_CIRC_NEXT, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_NEXT, SEEK_END);
} else if (strcmp(cp1, "last") == 0) { } else if (strcmp(cp1, "last") == 0) {
this_p = lseek(fd_circ, LSEEK_CIRC_LAST, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_LAST, SEEK_END);
} else if (strcmp(cp1, "first") == 0) { } else if (strcmp(cp1, "first") == 0) {
this_p = lseek(fd_circ, LSEEK_CIRC_FIRST, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_FIRST, SEEK_END);
} else if (strcmp(cp1, "second") == 0) { } else if (strcmp(cp1, "second") == 0) {
this_p = lseek(fd_circ, LSEEK_CIRC_SCND, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_SCND, SEEK_END);
} else if (strcmp(cp1, "save") == 0) { } else if (strcmp(cp1, "save") == 0) {
this_p = lseek(fd_circ, LSEEK_CIRC_SETP, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_SETP, SEEK_END);
} else if (strcmp(cp1, "wait") == 0) { } else if (strcmp(cp1, "wait") == 0) {
if ((lseek(fd_circ, LSEEK_CIRC_VALID, SEEK_END) >= 0) && // no sense to wait if the pointer is invalid if ((lseek(fset->circbuf_fd, LSEEK_CIRC_VALID, SEEK_END) >= 0) && // no sense to wait if the pointer is invalid
(lseek(fd_circ, LSEEK_CIRC_READY, SEEK_END) < 0) && // or the frame is already ready (lseek(fset->circbuf_fd, LSEEK_CIRC_READY, SEEK_END) < 0) && // or the frame is already ready
(lseek(fd_circ, LSEEK_CIRC_VALID, SEEK_END) >= 0)) // test valid once again, after not ready - it might change (lseek(fset->circbuf_fd, LSEEK_CIRC_VALID, SEEK_END) >= 0)) // test valid once again, after not ready - it might change
this_p = lseek(fd_circ, LSEEK_CIRC_WAIT, SEEK_END); this_p = lseek(fset->circbuf_fd, LSEEK_CIRC_WAIT, SEEK_END);
} else if (strcmp(cp1, "trig") == 0) { } else if (strcmp(cp1, "trig") == 0) {
int fd_fpga = open("/dev/fpgaio", O_RDWR); int fd_fpga = open("/dev/fpgaio", O_RDWR);
if (fd_fpga >= 0) { if (fd_fpga >= 0) {
...@@ -1296,6 +1411,8 @@ void init_file_set(struct file_set *fset, int fset_sz) ...@@ -1296,6 +1411,8 @@ void init_file_set(struct file_set *fset, int fset_sz)
fset[i].exif_dev_fd = -1; fset[i].exif_dev_fd = -1;
fset[i].exifmeta_dev_name = exifmeta_dev_names[i]; fset[i].exifmeta_dev_name = exifmeta_dev_names[i];
fset[i].exifmeta_dev_fd = -1; fset[i].exifmeta_dev_fd = -1;
fset[i].framepars_dev_name = framepars_dev_names[i];
fset[i].framepars_dev_fd = -1;
fset[i].port_num = 0; fset[i].port_num = 0;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment