plugwise.js
function sendCommand(command, mac, params, callback, scope) {

        var commandParts = [];
        // check for callback instead of params
        if (typeof params == 'function') {
            callback = params;
            params = '';
            scope = callback;
        }

        var completeCommand = '';

        completeCommand += command.request;
        commandParts.push(command.request);
        if (mac) {
            commandParts.push(mac);
            completeCommand += mac;
        }

        if (params) {
            commandParts.push(params);
            completeCommand += params;
        }

        var crcChecksum = crc.crc16(completeCommand).toString(16).toUpperCase();

        if (crcChecksum.length < 2) {
            crcChecksum = "000" + crcChecksum;
        }
        else if (crcChecksum.length < 3) {
            crcChecksum = "00" + crcChecksum;
        }
        else if (crcChecksum.length < 4) {
            crcChecksum = "0" + crcChecksum;
        }

        commandParts.push(crcChecksum);
        completeCommand = protocolCommands.frames.start + commandParts.join("") + protocolCommands.frames.end;

        commandStack.push({mac: mac,command: command, ack:'', callback: callback, scope: scope});

        if (options.log > 0) {
            console.log('---');
            console.log(command.color + "SEND " , command.name + ":\t" +  commandParts.join("\t") + colors.reset); 
        }

        sp.write(completeCommand);

        // we use a counter to know how many ack we are up in compared to commands
        ackCounter -= 1;

        return completeCommand;
    }
function sendCommand(command, mac, params, callback, scope) {

        var commandParts = [];
        // check for callback instead of params
        if (typeof params == 'function') {
            callback = params;
            params = '';
            scope = callback;
        }

        var completeCommand = '';

        completeCommand += command.request;
        commandParts.push(command.request);
        if (mac) {
            commandParts.push(mac);
            completeCommand += mac;
        }

        if (params) {
            commandParts.push(params);
            completeCommand += params;
        }

        var crcChecksum = crc.crc16(completeCommand).toString(16).toUpperCase();

        if (crcChecksum.length < 2) {
            crcChecksum = "000" + crcChecksum;
        }
        else if (crcChecksum.length < 3) {
            crcChecksum = "00" + crcChecksum;
        }
        else if (crcChecksum.length < 4) {
            crcChecksum = "0" + crcChecksum;
        }

        commandParts.push(crcChecksum);
        completeCommand = protocolCommands.frames.start + commandParts.join("") + protocolCommands.frames.end;

        commandStack.push({mac: mac,command: command, ack:'', callback: callback, scope: scope});

        if (options.log > 0) {
            console.log('---');
            console.log(command.color + "SEND " , command.name + ":\t" +  commandParts.join("\t") + colors.reset); 
        }

        sp.write(completeCommand);

        // we use a counter to know how many ack we are up in compared to commands
        ackCounter -= 1;

        return completeCommand;
    }
function sendCommand ( command , mac , params , callback , scope ) { var commandParts = [ ] ; // check for callback instead of params if ( typeof params == 'function' ) { callback = params ; params = '' ; scope = callback ; } var completeCommand = '' ; completeCommand += command . request ; commandParts . push ( command . request ) ; if ( mac ) { commandParts . push ( mac ) ; completeCommand += mac ; } if ( params ) { commandParts . push ( params ) ; completeCommand += params ; } var crcChecksum = crc . crc16 ( completeCommand ) . toString ( 16 ) . toUpperCase ( ) ; if ( crcChecksum . length < 2 ) { crcChecksum = "000" + crcChecksum ; } else if ( crcChecksum . length < 3 ) { crcChecksum = "00" + crcChecksum ; } else if ( crcChecksum . length < 4 ) { crcChecksum = "0" + crcChecksum ; } commandParts . push ( crcChecksum ) ; completeCommand = protocolCommands . frames . start + commandParts . join ( "" ) + protocolCommands . frames . end ; commandStack . push ( { mac : mac , command : command , ack : '' , callback : callback , scope : scope } ) ; if ( options . log > 0 ) { console . log ( '---' ) ; console . log ( command . color + "SEND " , command . name + ":\t" + commandParts . join ( "\t" ) + colors . reset ) ; } sp . write ( completeCommand ) ; // we use a counter to know how many ack we are up in compared to commands ackCounter -= 1 ; return completeCommand ; }
builds the command string and sends it
builds the command string and sends it