Skip to content

Commit

Permalink
feat: support multiple printers
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandur authored and kalinkrustev committed Jul 26, 2017
1 parent 5032bcb commit cbd1a98
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions ndc.js
Expand Up @@ -4,6 +4,7 @@ var defaultFormat = require('./ndc.messages');

function NDC(config, validator, logger) {
this.fieldSeparator = config.fieldSeparator || '\u001c';
this.groupSeparator = config.groupSeparator || '\u001d';
this.val = validator || null;
this.log = logger || {};
this.codes = {};
Expand Down Expand Up @@ -528,10 +529,18 @@ NDC.prototype.encode = function(message, $meta, context) {
// bufferString += command.messageClass;
command.fieldsSplit.forEach((field) => {
if (field.length) {
if (field === 'FS') {
bufferString += this.fieldSeparator;
} else {
bufferString += message[field] || '';
switch (field) {
case 'FS':
bufferString += this.fieldSeparator;
break;
case 'GS':
bufferString += this.groupSeparator;
break;
case 'printers':
bufferString += (message[field] || []).map(printer => printer.printer + printer.printerData).join(this.groupSeparator);
break;
default:
bufferString += message[field] || '';
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion ndc.messages.json
Expand Up @@ -340,7 +340,7 @@
"messageClass": "4",
"messageSubclass": ""
},
"fields": "messageClass,responseFlag,FS,luno,FS,timeVariantNumber,FS,nextState,FS,type1Notes,type2Notes,type3Notes,type4Notes,FS,sernum,function,screen,screenUpdate,screenMessage,FS,coordination,cardReturn,printer,printerData"
"fields": "messageClass,responseFlag,FS,luno,FS,timeVariantNumber,FS,nextState,FS,type1Notes,type2Notes,type3Notes,type4Notes,FS,sernum,function,screen,screenUpdate,screenMessage,FS,coordination,cardReturn,printers"
},
"tmAlert2": {
"mtid": "request",
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ut-codec",
"version": "5.10.1",
"version": "5.10.2-printer.1",
"main": "./index.js",
"dependencies": {
"iconv-lite": "0.4.15",
Expand Down

0 comments on commit cbd1a98

Please sign in to comment.