-
Notifications
You must be signed in to change notification settings - Fork 0
Raw retrieval mode #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mikelangmayr
wants to merge
3
commits into
main
Choose a base branch
from
mike/raw-mode-retrieval
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -579,11 +579,17 @@ namespace Camera { | |
| else | ||
| if (std::strncmp(suffix, "HEIGHT", 6)==0) this->frameinfo.bufheight[bufnum] = std::atoi(value_start); | ||
| break; | ||
| case 8: // BUFnCOMPLETE | ||
| case 8: // BUFnCOMPLETE, RAWLINES | ||
| if (std::strncmp(suffix, "COMPLETE", 8)==0) this->frameinfo.bufcomplete[bufnum] = std::atoi(value_start); | ||
| else | ||
| if (std::strncmp(suffix, "RAWLINES", 8)==0) this->frameinfo.bufrawlines[bufnum] = std::atoi(value_start); | ||
| break; | ||
| case 9: // BUFnTIMESTAMP | ||
| case 9: // BUFnTIMESTAMP, RAWOFFSET, RAWBLOCKS | ||
| if (std::strncmp(suffix, "TIMESTAMP", 9)==0) this->frameinfo.buftimestamp[bufnum] = std::strtoull(value_start, nullptr, 16); | ||
| else | ||
| if (std::strncmp(suffix, "RAWOFFSET", 9)==0) this->frameinfo.bufrawoffset[bufnum] = std::strtoul(value_start, nullptr, 10); | ||
| else | ||
| if (std::strncmp(suffix, "RAWBLOCKS", 9)==0) this->frameinfo.bufrawblocks[bufnum] = std::atoi(value_start); | ||
| break; | ||
| case 11: // BUFnRETIMESTAMP, FETIMESTAMP | ||
| if (std::strncmp(suffix, "RETIMESTAMP", 11)==0) this->frameinfo.bufretimestamp[bufnum] = std::strtoull(value_start, nullptr, 16); | ||
|
|
@@ -1608,8 +1614,10 @@ namespace Camera { | |
| this->get_configmap_value("FRAMEMODE", mode->geometry.framemode); | ||
| this->get_configmap_value("RAWENABLE", mode->rawenable); | ||
| this->get_configmap_value("RAWSEL", this->rawinfo.adchan); | ||
| this->get_configmap_value("RAWSAMPLES", this->rawinfo.rawsamples); | ||
| this->get_configmap_value("RAWENDLINE", this->rawinfo.rawlines); | ||
| this->get_configmap_value("RAWSAMPLES", this->rawinfo.samples); | ||
| this->get_configmap_value("RAWSTARTLINE", this->rawinfo.startline); | ||
| this->get_configmap_value("RAWENDLINE", this->rawinfo.endline); | ||
| this->get_configmap_value("RAWSTARTPIXEL", this->rawinfo.startpixel); | ||
|
|
||
| // Read geometry from the mode's configmap (not the global one) since each | ||
| // mode section can override LINECOUNT/PIXELCOUNT | ||
|
|
@@ -1911,11 +1919,10 @@ namespace Camera { | |
| // | ||
| switch (this->frametype) { | ||
| case Camera::ArchonController::FRAME_RAW: | ||
| // Archon buffer base address | ||
| // RAW data lives at bufbase + rawoffset; block count derives from the | ||
| // RAW geometry (RAWSAMPLES x rawlines x 2 bytes), never image_memory | ||
| bufaddr = this->frameinfo.bufbase[index] + this->frameinfo.bufrawoffset[index]; | ||
|
|
||
| // Calculate the number of blocks expected. image_memory is bytes per detector | ||
| bufblocks = (unsigned int) floor( (this->interface->camera_info.image_memory + BLOCK_LEN - 1 ) / BLOCK_LEN ); | ||
| bufblocks = (this->raw_frame_bytes() + BLOCK_LEN - 1) / BLOCK_LEN; | ||
| break; | ||
|
|
||
| case Camera::ArchonController::FRAME_IMAGE: | ||
|
|
@@ -2034,6 +2041,192 @@ namespace Camera { | |
| } | ||
|
|
||
|
|
||
| /***** Camera::ArchonController::is_raw_config_key *************************/ | ||
| /** | ||
| * @brief return true if key is one of the settable RAW config keywords | ||
| */ | ||
| bool ArchonController::is_raw_config_key(const std::string &key) { | ||
| for (const auto* raw_key : {"RAWENABLE", "RAWSEL", "RAWSTARTLINE", | ||
| "RAWENDLINE", "RAWSTARTPIXEL", "RAWSAMPLES"}) { | ||
| if (key == raw_key) return true; | ||
| } | ||
| return false; | ||
| } | ||
| /***** Camera::ArchonController::is_raw_config_key *************************/ | ||
|
|
||
|
|
||
| /***** Camera::ArchonController::raw_geometry ****************************/ | ||
| /** | ||
| * @brief resolve RAW capture geometry for the newest buffer | ||
| * @details Prefers the controller-reported BUFnRAWBLOCKS/BUFnRAWLINES, | ||
| * which already account for the per-line rounding to whole | ||
| * 1024-byte blocks. Falls back to the config keys when the | ||
| * controller has not reported them (e.g. emulator). The line | ||
| * range is inclusive: RAWSTARTLINE=0,RAWENDLINE=1 is two lines. | ||
| */ | ||
| ArchonController::raw_geometry_t ArchonController::raw_geometry() const { | ||
| const auto index = this->frameinfo.index.load(); | ||
| raw_geometry_t geom; | ||
| geom.samples = static_cast<uint32_t>(this->rawinfo.samples); | ||
| geom.blocks_per_line = static_cast<uint32_t>(this->frameinfo.bufrawblocks[index]); | ||
| geom.lines = static_cast<uint32_t>(this->frameinfo.bufrawlines[index]); | ||
|
|
||
| if (geom.blocks_per_line == 0 || geom.lines == 0) { | ||
| geom.blocks_per_line = | ||
| (static_cast<size_t>(geom.samples) * sizeof(uint16_t) + BLOCK_LEN - 1) / BLOCK_LEN; | ||
| const int span = this->rawinfo.endline - this->rawinfo.startline + 1; | ||
| geom.lines = span > 0 ? static_cast<uint32_t>(span) : 0u; | ||
| } | ||
| return geom; | ||
| } | ||
| /***** Camera::ArchonController::raw_geometry ****************************/ | ||
|
|
||
|
|
||
| /***** Camera::ArchonController::raw_frame_bytes **************************/ | ||
| /** | ||
| * @brief padded, size-aware byte count for one RAW fetch | ||
| * @details Each line occupies whole 1024-byte blocks, so the fetch reads | ||
| * blocks_per_line x lines blocks. RAW samples are always 16-bit; | ||
| * RAWSTARTPIXEL only sets where sampling begins in a line and so | ||
| * does not change the count. | ||
| */ | ||
| uint32_t ArchonController::raw_frame_bytes() const { | ||
| const raw_geometry_t geom = this->raw_geometry(); | ||
| return geom.blocks_per_line * geom.lines * BLOCK_LEN; | ||
| } | ||
| /***** Camera::ArchonController::raw_frame_bytes **************************/ | ||
|
|
||
|
|
||
| /***** Camera::ArchonController::get_raw_config **************************/ | ||
| /** | ||
| * @brief report the current RAW configuration keywords | ||
| * @param[out] retstring space-delimited KEY=VALUE pairs | ||
| */ | ||
| long ArchonController::get_raw_config(std::string &retstring) { | ||
| std::ostringstream oss; | ||
| for (const auto* key : {"RAWENABLE", "RAWSEL", "RAWSTARTLINE", | ||
| "RAWENDLINE", "RAWSTARTPIXEL", "RAWSAMPLES"}) { | ||
| auto it = this->configmap.find(key); | ||
| oss << key << "=" << (it != this->configmap.end() ? it->second.value : "?") << " "; | ||
| } | ||
| retstring = oss.str(); | ||
| return NO_ERROR; | ||
| } | ||
| /***** Camera::ArchonController::get_raw_config **************************/ | ||
|
|
||
|
|
||
| /***** Camera::ArchonController::set_raw_config **************************/ | ||
| /** | ||
| * @brief set one or more RAW config keywords then APPLYALL | ||
| * @param[in] args "KEY VALUE [KEY VALUE ...]" | ||
| * @param[out] retstring resulting RAW configuration | ||
| */ | ||
| long ArchonController::set_raw_config(const std::string &args, std::string &retstring) { | ||
| const std::string function("Camera::ArchonController::set_raw_config"); | ||
|
|
||
| std::vector<std::string> tokens; | ||
| Tokenize(args, tokens, " "); | ||
| if (tokens.empty() || tokens.size() % 2 != 0) { | ||
| logwrite(function, "ERROR expected KEY VALUE pairs"); | ||
| retstring = "expected KEY VALUE pairs"; | ||
| return ERROR; | ||
| } | ||
|
|
||
| bool changed = false; | ||
| for (size_t i = 0; i < tokens.size(); i += 2) { | ||
| std::string key = tokens[i]; | ||
| std::transform(key.begin(), key.end(), key.begin(), ::toupper); | ||
| if (!is_raw_config_key(key)) { | ||
| logwrite(function, "ERROR unknown RAW key: "+key); | ||
| retstring = "unknown RAW key: "+key; | ||
| return ERROR; | ||
| } | ||
| if (this->write_config_key(key.c_str(), tokens[i+1].c_str(), changed) != NO_ERROR) { | ||
| retstring = "failed writing "+key; | ||
| return ERROR; | ||
| } | ||
| } | ||
|
|
||
| if (changed && this->send_cmd(APPLYCDS) != NO_ERROR) { | ||
| logwrite(function, "ERROR applying RAW configuration"); | ||
| retstring = "failed to apply"; | ||
| return ERROR; | ||
| } | ||
|
|
||
| // refresh cached geometry from the now-updated configmap | ||
| this->get_configmap_value("RAWSEL", this->rawinfo.adchan); | ||
| this->get_configmap_value("RAWSAMPLES", this->rawinfo.samples); | ||
| this->get_configmap_value("RAWSTARTLINE", this->rawinfo.startline); | ||
| this->get_configmap_value("RAWENDLINE", this->rawinfo.endline); | ||
| this->get_configmap_value("RAWSTARTPIXEL", this->rawinfo.startpixel); | ||
|
|
||
| return this->get_raw_config(retstring); | ||
| } | ||
| /***** Camera::ArchonController::set_raw_config **************************/ | ||
|
|
||
|
|
||
| /***** Camera::ArchonController::read_raw *******************************/ | ||
| /** | ||
| * @brief retrieve RAW (pre-CDS) data from the newest frame buffer | ||
| * @details Reads the size-aware RAW region as 16-bit unsigned samples and | ||
| * dispatches it in-band as a (RAWSAMPLES x rawlines) frame, | ||
| * independent of the post-CDS pixel mode. | ||
| * @param[out] retstring "samples=<w> lines=<h> bytes=<n>" | ||
| */ | ||
| long ArchonController::read_raw(std::string &retstring) { | ||
| const std::string function("Camera::ArchonController::read_raw"); | ||
|
|
||
| this->get_frame_status(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be good to handle the case of |
||
|
|
||
| const raw_geometry_t geom = this->raw_geometry(); | ||
| if (geom.samples == 0 || geom.lines == 0) { | ||
| logwrite(function, "ERROR RAW geometry is empty; check RAW config"); | ||
| retstring = "invalid RAW geometry"; | ||
| return ERROR; | ||
| } | ||
|
|
||
| const size_t fetch_bytes = static_cast<size_t>(geom.blocks_per_line) * geom.lines * BLOCK_LEN; | ||
| std::shared_ptr<char[]> raw_buffer(new char[fetch_bytes]); | ||
| char* bufptr = raw_buffer.get(); | ||
|
|
||
| if (this->read_frame(FRAME_RAW, bufptr) != NO_ERROR) { | ||
| logwrite(function, "ERROR reading RAW frame"); | ||
| retstring = "read failed"; | ||
| return ERROR; | ||
| } | ||
|
|
||
| // The Archon pads each raw line out to whole 1024-byte blocks, so copy only | ||
| // the valid RAWSAMPLES from each line into a contiguous lines x samples array | ||
| const size_t line_stride = static_cast<size_t>(geom.blocks_per_line) * BLOCK_LEN; | ||
| const size_t payload_samples = static_cast<size_t>(geom.lines) * geom.samples; | ||
| std::vector<uint16_t> samples(payload_samples); | ||
| for (uint32_t line = 0; line < geom.lines; ++line) { | ||
| std::memcpy(samples.data() + static_cast<size_t>(line) * geom.samples, | ||
| raw_buffer.get() + line * line_stride, | ||
| static_cast<size_t>(geom.samples) * sizeof(uint16_t)); | ||
| } | ||
|
|
||
| const auto index = this->frameinfo.index.load(); | ||
| const size_t payload_bytes = payload_samples * sizeof(uint16_t); | ||
|
|
||
| Camera::FrameMetadata meta; | ||
| meta.frame_number = this->frameinfo.bufframen[index]; | ||
| meta.timestamp = this->frameinfo.buftimestamp[index]; | ||
| meta.width = geom.samples; | ||
| meta.height = geom.lines; | ||
| meta.bytes_per_pixel = sizeof(uint16_t); | ||
| this->interface->dispatch_frame(reinterpret_cast<const char*>(samples.data()), | ||
| payload_bytes, meta); | ||
|
|
||
| std::ostringstream oss; | ||
| oss << "samples=" << geom.samples << " lines=" << geom.lines << " bytes=" << payload_bytes; | ||
| retstring = oss.str(); | ||
| logwrite(function, retstring); | ||
| return NO_ERROR; | ||
| } | ||
| /***** Camera::ArchonController::read_raw *******************************/ | ||
|
|
||
|
|
||
| /***** Camera::ArchonController::wait_for_readout ***************************/ | ||
| /** | ||
| * @brief creates a wait until the next completed frame buffer is ready | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A question about the use of the
changedbool -So let's say one RAW setting changed, but another one doesn't. Regardless do we apply CDS if one of the RAW values change?
If so would the following case fail: first key RAWSEL
changedwould betrue, then the second key RAWSAMPLESchangedwould befalsesoAPPLYCDSwould be skipped?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
every change of any RAW related keyword or TAPLINE related keyword or CDS related keyword requires an APPLYCDS command before it takes effect. There is no way to know strictly what the current status is of these keywords because one can update the config but not do an APPLYCDS. This is the reason (though it's annoying) why in foxtrot you can't individually set any of those, you have to provide a struct containing all CDS related keywords, so there is never this inconsistency.
Therefore, in my opinion, it's very hard to decide on any situation when you should NOT do APPLYCDS. Because it might be that the values in your config are simply not reflected in the real world anyway, there's no way to tell from just querying the archon.