constexpr int WDF_BLOCK_HDR_SIZE = 16;
+static UA_StatusCode get_property(Pset &pset, const char* keyname, UA_Variant* valuePtr)
+{
+ UA_StatusCode status = UA_STATUSCODE_BAD;
+ if (pset.exists(keyname))
+ {
+ status = UA_STATUSCODE_GOOD;
+ const auto item = pset.get_item(keyname);
+ switch (item->hdr.type)
+ {
+ case PSET_TYPE_INT:
+ UA_Variant_setScalar(valuePtr, const_cast<int32_t*>(&item->val.lVal), &UA_TYPES[UA_TYPES_INT32]);
+ break;
+ case PSET_TYPE_FLOAT:
+ UA_Variant_setScalar(valuePtr, const_cast<float*>(&item->val.fltVal), &UA_TYPES[UA_TYPES_FLOAT]);
+ break;
+ case PSET_TYPE_DOUBLE:
+ UA_Variant_setScalar(valuePtr, const_cast<double*>(&item->val.dblVal), &UA_TYPES[UA_TYPES_DOUBLE]);
+ break;
+ case PSET_TYPE_STRING:
+ {
+ UA_String str = { 0 };
+ str.length = item->length;
+ str.data = (UA_Byte*)UA_malloc(item->length);
+ memcpy(str.data, item->val.strVal, item->length);
+ UA_Variant_setScalarCopy(valuePtr, &str, &UA_TYPES[UA_TYPES_STRING]);
+ break;
+ }
+ default:
+ status = UA_STATUSCODE_BAD;
+ }
+ }
+ return status;
+}
+
// works for WXDA properties - get by name.
UA_StatusCode wdf_get_property(const char *filename, uint64_t pos, const char *keyname, UA_Variant *valuePtr)
{
{
const auto itemlist = Pset::ParseStream(file, len);
Pset pset(itemlist, nullptr);
- if (pset.exists(keyname))
- {
- status = UA_STATUSCODE_GOOD;
- const auto item = pset.get_item(keyname);
- switch (item->hdr.type)
- {
- case PSET_TYPE_INT:
- UA_Variant_setScalar(valuePtr, const_cast<int32_t*>(&item->val.lVal), &UA_TYPES[UA_TYPES_INT32]);
- break;
- case PSET_TYPE_FLOAT:
- UA_Variant_setScalar(valuePtr, const_cast<float*>(&item->val.fltVal), &UA_TYPES[UA_TYPES_FLOAT]);
- break;
- case PSET_TYPE_DOUBLE:
- UA_Variant_setScalar(valuePtr, const_cast<double*>(&item->val.dblVal), &UA_TYPES[UA_TYPES_DOUBLE]);
- break;
- case PSET_TYPE_STRING:
- {
- UA_String str = { 0 };
- str.length = item->length;
- str.data = (UA_Byte*)UA_malloc(item->length);
- memcpy(str.data, item->val.strVal, item->length);
- UA_Variant_setScalarCopy(valuePtr, &str, &UA_TYPES[UA_TYPES_STRING]);
- break;
- }
- default:
- status = UA_STATUSCODE_BAD;
- }
- }
+ status = get_property(pset, keyname, valuePtr);
}
return status;
}
+uint32_t strntol(const char* str, size_t len, char** end, int base)
+{
+ char buf[24];
+ uint32_t r = 0;
+ const char* beg = str;
+
+ // skip leading spaces
+ for (; beg && len && *beg == ' '; beg++, len--)
+ ;
+
+ if (!len || len >= sizeof(buf)) {
+ if (end)
+ *end = (char*)str;
+ return 0;
+ }
+
+ memcpy(buf, beg, len);
+ buf[len] = '\0';
+ r = strtol(buf, end, base);
+ if (r == LONG_MIN || r == LONG_MAX)
+ return r;
+ if (end)
+ *end = (char*)beg + (*end - buf);
+ return r;
+}
+
uint32_t wdf_get_scan_exposuretime(const char* filename, uint64_t pos)
{
uint32_t value = 0;
const auto& scanitem = nameditems.get_item("Scan");
Pset scan(scanitem->val.childVal, &nameditems);
const auto extime = scan.get_item("Exposure Time");
- value = extime->val.ulVal;
+ switch (extime->hdr.type)
+ {
+ case PSET_TYPE_SHORT:
+ value = static_cast<uint32_t>(extime->val.hVal);
+ break;
+ case PSET_TYPE_INT:
+ value = static_cast<uint32_t>(extime->val.lVal);
+ break;
+ case PSET_TYPE_STRING:
+ value = strntol(extime->val.strVal, extime->length, nullptr, 0);
+ break;
+ }
}
return value;
}