Skip to content

Commit

Permalink
Support inputting template file: node test.js -t template.txt -f test…
Browse files Browse the repository at this point in the history
….jpg
  • Loading branch information
yushulx committed Oct 17, 2019
1 parent 3c45c2b commit 6de40b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/command-line/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ if (args.includes('-f')) {
if (args.includes('-t')) {
let tIndex = args.indexOf('-t');
if (args[tIndex + 1]) {
template = fs.readFileSync(args[tIndex + 1])
templatefile = fs.readFileSync(args[tIndex + 1])
dbr.setParameters(templatefile);
}
else {
console.log('Please add a template file.');
Expand Down
8 changes: 3 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
var license = '';
var license = 'LICENSE-KEY';

if (process.platform === 'win32') {
console.log('Windows');
license = 't0068NQAAACqUjZa21C+W7fRdPkf2FRFRr+QpfVC2tDsl/8t25TzYCNxl5s0OkuwFgEMGNfN95Z0HYQ55ROi1px9JqVAP7/c=';
}
else if(process.platform === 'linux') {
console.log('Linux');
license = 't0068NQAAAIY/7KegDlZn7YiPdAj0cbA11n2CwuCEWnk2KYla55ozdfmoasjRIpHhl0EUZmko/zxfxFLH3FpLw694uihoCVM=';
}
else if(process.platform === 'darwin') {
console.log('macOS');
license = 't0068NQAAAIY/7KegDlZn7YiPdAj0cbA11n2CwuCEWnk2KYla55ozdfmoasjRIpHhl0EUZmko/zxfxFLH3FpLw694uihoCVM=';
}
else {
console.log('Unknown Operating System');
Expand Down Expand Up @@ -38,5 +35,6 @@ module.exports = {
decodeYUYVAsync: dbr.decodeYUYVAsync,
formats: formats,
initLicense: dbr.initLicense,
barcodeTypes: barcodeTypes
barcodeTypes: barcodeTypes,
setParameters: dbr.setParameters
};
24 changes: 24 additions & 0 deletions src/dbr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using namespace v8;

#define DBR_NO_MEMORY 0
#define DBR_SUCCESS 1
#define DEFAULT_MEMORY_SIZE 4096

// barcode reader handler
void* hBarcode = NULL;
Expand Down Expand Up @@ -389,6 +390,28 @@ void DecodeBase64Async(const FunctionCallbackInfo<Value>& args) {
uv_queue_work(uv_default_loop(), &worker->request, (uv_work_cb)DetectionWorking, (uv_after_work_cb)DetectionDone);
}

/*
* setParameters(json)
*/
void SetParameters(const FunctionCallbackInfo<Value>& args) {
if (!createDBR()) {return;}

Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);

// Get arguments
String::Utf8Value params(args[0]->ToString()); // json string
char *json = *params;

// Update template setting
char errorMessage[DEFAULT_MEMORY_SIZE];
int ret = DBR_InitRuntimeSettingsWithString(hBarcode, json, CM_OVERWRITE, errorMessage, 256);
if (ret)
{
printf("Returned value: %d, error message: %s\n", ret, errorMessage);
}
}

void Init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "create", Create);
NODE_SET_METHOD(exports, "destroy", Destroy);
Expand All @@ -397,6 +420,7 @@ void Init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "initLicense", InitLicense);
NODE_SET_METHOD(exports, "decodeFileAsync", DecodeFileAsync);
NODE_SET_METHOD(exports, "decodeBase64Async", DecodeBase64Async);
NODE_SET_METHOD(exports, "setParameters", SetParameters);
}

NODE_MODULE(dbr, Init)

0 comments on commit 6de40b3

Please sign in to comment.