Skip to content

Commit

Permalink
merging dev version to avoid conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
edyoshikun committed Jul 28, 2023
1 parent f7d36fb commit 948a3f6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 61 deletions.
8 changes: 4 additions & 4 deletions basler/src/USB_THREAD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ void* USB_THREAD(void* data)
thd_data->incoming->flags |= USB_HERE;
flg.unlock();

if (thd_data->incoming->flags & START_COUNT && thd_data->incoming->flags & NEW_CNT) {
//if (thd_data->incoming->flags & START_COUNT && thd_data->incoming->flags & NEW_CNT) {
//printf("flags: %u\n", incoming.flags);
printf("fps: %u\n", thd_data->incoming->fps);
//printf("fps: %u\n", thd_data->incoming->fps);
//printf("USB.incoming.flags %u after\n", thd_data->incoming->flags);
//printf("time_waiting: %u\n", incoming.time_waiting);
printf("counter: %zu, period: %lu\n", thd_data->incoming->count, thd_data->incoming->time_waiting);
}
//printf("counter: %zu, period: %lu\n", thd_data->incoming->count, thd_data->incoming->time_waiting);
//}
//printf("success: bulk read %d bytes\n", ret);
//printf("flags: %u\n", incoming.flags);
//printf("fps: %u\n", incoming.fps);
Expand Down
90 changes: 44 additions & 46 deletions basler/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
aab: 10.02.21 removed buffer prefill in buffer swap
ehm: 04.11.22 removed unecessary parts of code
ehm: 08.20.22 merged timelapse functionality from dev
*/

Expand Down Expand Up @@ -97,8 +98,8 @@ uint32_t vert = vert_max;
uint32_t horz_off_set = 0;
uint32_t vert_off_set = 0;
uint32_t bitDepth = 8;

float fps = 5; /* Change Me after updating Napari */
/* Change Me after updating Napari */
float fps = 5;
//uint32_t fps = 65;
uint32_t z_frames = 100;
double gain = 0;
Expand All @@ -114,6 +115,7 @@ void SetPixelFormat_unofficial(INodeMap& nodemap, String_t format);


//Directory name images to be saved.
// TODO:Should probably be set from pycro or micro manager.
string strDirectryName = "D:\\Ant1 Test";//\\binaries";
// From Basler Fast Write Example Not currently used;
string strMetaFileName = "Meta.txt";
Expand All @@ -123,6 +125,17 @@ string raw_dir = "D:\\Ant1 Test";// \\Tiff";
string proj_sub_dir;


// From Basler Sample Code for fast binary writes;
void saveBuffer(const char* FileName, CGrabResultPtr ptrGrabResult)
{
ofstream fs(FileName, std::ifstream::binary);
const uint8_t* pImageBuffer = (uint8_t*)ptrGrabResult->GetBuffer();
fs.write((char*)pImageBuffer, ptrGrabResult->GetPayloadSize());
//How big it be?
//printf("PayloadSize: %ld\n", (long)ptrGrabResult->GetPayloadSize());
fs.close();
}

/********************** LIGHTNING FAST VCR REPAIR **************************************************
* This Buffer to disk method uses the Windows SDK File Handle methods
* to store data very rapidly to our NVME Raid array the larger the file
Expand Down Expand Up @@ -207,19 +220,26 @@ void saveBigBuffer(const char* FileName, uint8_t* buffer/*, uint8_t cam_count*/,
}


/* This little function is for the convert Binary to .raw .tif phase post acquisition.*/
/* This little function is for the convert Binary to tif phase*/
void readFile(const char* fileName, uint64_t* outNumberofBytes, uint8_t* chunk)
{
ifstream fs(fileName, std::ifstream::binary);
fs.seekg(0, fs.end);
long long int size = fs.tellg();
fs.seekg(0, fs.beg);

//fs.read((char*)chunk, size);
//char* bufferTemp = new char[size];
// allocate memory for file content
/*if (fs)
std::cout << "all characters read successfully.";
else
std::cout << "error: only " << fs.gcount() << " could be read" << std::endl;
std::cout << "size: " << size << std::endl;*/
//buffer->push_back(bufferTemp);
//returning the file size, needed for converting the buffer into an Pylon image into a bitmap
*outNumberofBytes = size;
fs.close();


HANDLE hFile = INVALID_HANDLE_VALUE;
LPOFSTRUCT lpReOpenBuff;

Expand Down Expand Up @@ -274,7 +294,6 @@ void readFile(const char* fileName, uint64_t* outNumberofBytes, uint8_t* chunk)
// asynchronous writes.
printf("Error: dwBytesWritten != dwBytesToWrite\n");
}
// Nothing to see here
bytes_read += dwBytesRead;
std::cout << "^";
if (size - bytes_read < dwBytesToRead) {
Expand Down Expand Up @@ -307,21 +326,6 @@ void mkdirTree(string sub, string dir) {
mkdirTree(sub.substr(i + 1), dir);
}


/* Not Currently in use From Basler binary write sample code*/
//void Save_Metadata(list<string>& strList, string strMetaFilename)
//{
// ofstream fs(strMetaFilename);
// for (auto it = strList.begin();it != strList.end(); it++)
// {
// string s = *it;
// fs.write(s.c_str(), s.length());
// fs.write("\n", 1);
// }
// fs.close();
//}


/*Interesting I think the normal Sleep function is allows context switching and "sleeps threads the same"*/
void sleep(int sec) {
for (int i = sec; i > 0; --i) {
Expand Down Expand Up @@ -510,9 +514,8 @@ int main(int argc, char* argv[])
incoming.exp = exposure;
incoming.bpp = bitDepth;
incoming.capTime = seconds;

incoming.lapse_min = lapse_minutes; /* Add after we update Napari */
incoming.lapse_count = lapse_count; /* Add after we update Napari */
incoming.lapse_min = lapse_minutes;
incoming.lapse_count = lapse_count;
usb_incoming.flags = incoming.flags = 0;

server_thread_data.incoming_data = &incoming;
Expand All @@ -530,6 +533,8 @@ int main(int argc, char* argv[])
usb_thread_data.crit = &crit;
usb_thread_data.usb_srv_mtx = &crit3;

printf("Size of TCP_IP_Data: %d\n", sizeof(TCP_IP_DAT));

// Start the USB and Server Threads
std::thread SRVR_THD_OBJ(SERVER_THREAD, (void*)&server_thread_data);
std::thread USB_THD_OBJ(USB_THREAD, (void*)&usb_thread_data);
Expand Down Expand Up @@ -628,9 +633,8 @@ int main(int argc, char* argv[])
z_frames = incoming.z_frames;

/* Time Lapse Values */
/* Add after updating Napari */
//lapse_minutes = incoming.lapse_min;
//lapse_count = incoming.lapse_count;
lapse_minutes = incoming.lapse_min;
lapse_count = incoming.lapse_count;

//std::cout << "gain: " << gain << " incoming.gain: " << incoming.gain << std::endl;
raw_dir = incoming.path;
Expand Down Expand Up @@ -686,15 +690,14 @@ int main(int argc, char* argv[])
//outgoing.flags &= ~LIVE_RUNNING;
signal_live.notify_one();
}
/* Add Me sometime For big fun */
//else if (incoming.flags & LAPSE_CAPTURE && ~(outgoing.flags & (CAPTURING | CONVERTING | LIVE_RUNNING)) && outgoing.flags & CAMERAS_ACQUIRED) {
// incoming.flags &= ~LAPSE_CAPTURE;
// //usb_outgoing.flags |= LAPSE_CAPTURE;
// outgoing.flags |= CAPTURING;
// prot.unlock();
// lapse_capture(&serials, &camera_names, &camera_zNums, cam_dat, &total_cams, &image_size);
// outgoing.flags &= ~CAPTURING;
//}
else if (incoming.flags & LAPSE_CAPTURE && ~(outgoing.flags & (CAPTURING | CONVERTING | LIVE_RUNNING)) && outgoing.flags & CAMERAS_ACQUIRED) {
incoming.flags &= ~LAPSE_CAPTURE;
//usb_outgoing.flags |= LAPSE_CAPTURE;
outgoing.flags |= CAPTURING;
prot.unlock();
lapse_capture(&serials, &camera_names, &camera_zNums, cam_dat, &total_cams, &image_size);
outgoing.flags &= ~CAPTURING;
}
else if (incoming.flags & EXIT_THREAD) {
usb_outgoing.flags |= EXIT_THREAD;
prot.unlock();
Expand All @@ -710,10 +713,6 @@ int main(int argc, char* argv[])

}





// usb_thread_data.incoming->flags |= EXIT_THREAD;
USB_THD_OBJ.join();
SRVR_THD_OBJ.join();
Expand All @@ -730,7 +729,6 @@ int main(int argc, char* argv[])
//cout << "Size writen: " << sizeof(frame_buffer) * c_countOfImagesToGrab << endl;
//cout << "Throughput: " << sizeof(frame_buffer) * c_countOfImagesToGrab / (elapsed * 1e-6) << endl;


//while (1);
// after grabbing has been done, write the meta file in same directory
//Save_Metadata(Metasdata, strDirectryName + strMetaFileName);
Expand Down Expand Up @@ -924,7 +922,7 @@ void start_capture(std::vector<std::string>* serials, std::vector<std::string>*
myfile << "Bit Depth: " << (int)bitDepth << std::endl;
myfile << "Gain (dB): " << (float)gain << std::endl;
/* After Napari */
//myfile << "Frames Per Second: " << (float)fps << std::endl;
myfile << "Frames Per Second: " << (float)fps << std::endl;
myfile << "Frames Per Second: " << (int)fps << std::endl;
myfile << "Exposure time(us): " << (int)exposure << std::endl;

Expand Down Expand Up @@ -1384,7 +1382,7 @@ void start_capture(std::vector<std::string>* serials, std::vector<std::string>*



std::cout << std::endl << "Finished Converting to tif" << std::endl;
std::cout << std::endl << "Finished splitting into raw files" << std::endl;
if (!(outgoing.flags & Z_STACK_RUNNING)) {
uint32_t max_dropped = 0;
// Checking For Longer than acceptable Frame Times
Expand Down Expand Up @@ -1948,7 +1946,7 @@ void lapse_capture(std::vector<std::string>* serials, std::vector<std::string>*



std::cout << std::endl << "Finished Converting to raw" << std::endl;
std::cout << std::endl << "Finished seperating images to raw" << std::endl;

/*if (!(outgoing.flags & Z_STACK_RUNNING)) {
uint32_t max_dropped = 0;
Expand Down Expand Up @@ -2135,7 +2133,6 @@ void live_capture(std::vector<std::string>* serials, std::vector<std::string>* c

CGrabResultPtr ptrGrabResult;
INodeMap& nodemap = cam->camPtr->GetNodeMap();

//Find if all the cameras are ready
std::mutex sleeper;
std::unique_lock<std::mutex> sleepDiddy(sleeper);
Expand Down Expand Up @@ -2174,7 +2171,8 @@ void live_capture(std::vector<std::string>* serials, std::vector<std::string>* c
//std::cout << "thd: " << (int)cam->number << " joining" << std::endl;
};

std::cout << "Building Threads: " << std::endl;

std::cout << "Building Live Threads: " << std::endl;
std::vector<std::thread> threads;
for (int i = 0; i < *total_cams; i++) {
// To place Cameras in memory array in Z depth order (1 to 25) - 1
Expand Down
19 changes: 8 additions & 11 deletions basler/src/project_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ typedef struct cam_event {
#define MAX_CAMS (25u)
//#define EXIT_USB 0x8000 Big Yikes

/* These Serials only apply to our batch of basler cameras. */
// Camera Serials
#define CAM_1 23206716
#define CAM_2 23206693
Expand Down Expand Up @@ -159,15 +160,8 @@ typedef struct cam_event {

/* To Be Added After Napari Is Updated */

//typedef struct usb_data {
// float fps;
// uint32_t flags;
// uint32_t time_waiting; // Currently Time between not ready and ready
// uint64_t count;
//};

typedef struct usb_data {
uint16_t fps;
float fps;
uint32_t flags;
uint32_t time_waiting; // Currently Time between not ready and ready
uint64_t count;
Expand All @@ -177,17 +171,20 @@ typedef struct usb_data {
typedef struct TCP_IP_DAT {
uint32_t horz;
uint32_t vert;
uint32_t fps;
float fps;
uint32_t exp;
uint32_t bpp;
uint32_t z_frames;
uint32_t capTime;
char path[255];
char proName[255];
float lapse_min;
uint32_t lapse_count;
char path[256];
char proName[256];
uint32_t flags;
double gain;
};


typedef struct USB_THD_DATA {
// Do I need this?
usb_data* incoming;
Expand Down

0 comments on commit 948a3f6

Please sign in to comment.