(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@iotize/tap/service/impl/target'), require('@iotize/common/utility'), require('rxjs'), require('@iotize/ionic'), require('@angular/common')) :
    typeof define === 'function' && define.amd ? define('@iotize/ionic/target/common', ['exports', '@angular/core', '@angular/forms', '@iotize/tap/service/impl/target', '@iotize/common/utility', 'rxjs', '@iotize/ionic', '@angular/common'], factory) :
    (global = global || self, factory((global.iotize = global.iotize || {}, global.iotize.ionic = global.iotize.ionic || {}, global.iotize.ionic.target = global.iotize.ionic.target || {}, global.iotize.ionic.target.common = {}), global.ng.core, global.ng.forms, global.target, global.utility, global.rxjs, global.iotize.ionic, global.ng.common));
}(this, (function (exports, core, forms, target, utility, rxjs, ionic, common) { 'use strict';

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */
    /* global Reflect, Promise */

    var extendStatics = function(d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };

    function __extends(d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }

    var __assign = function() {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };

    function __rest(s, e) {
        var t = {};
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
            t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                    t[p[i]] = s[p[i]];
            }
        return t;
    }

    function __decorate(decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    }

    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); }
    }

    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
    }

    function __awaiter(thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
            function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }

    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f) throw new TypeError("Generator is already executing.");
            while (_) try {
                if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
                if (y = 0, t) op = [op[0] & 2, t.value];
                switch (op[0]) {
                    case 0: case 1: t = op; break;
                    case 4: _.label++; return { value: op[1], done: false };
                    case 5: _.label++; y = op[1]; op = [0]; continue;
                    case 7: op = _.ops.pop(); _.trys.pop(); continue;
                    default:
                        if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                        if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                        if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                        if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                        if (t[2]) _.ops.pop();
                        _.trys.pop(); continue;
                }
                op = body.call(thisArg, _);
            } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
            if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
        }
    }

    function __createBinding(o, m, k, k2) {
        if (k2 === undefined) k2 = k;
        o[k2] = m[k];
    }

    function __exportStar(m, exports) {
        for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) exports[p] = m[p];
    }

    function __values(o) {
        var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
        if (m) return m.call(o);
        if (o && typeof o.length === "number") return {
            next: function () {
                if (o && i >= o.length) o = void 0;
                return { value: o && o[i++], done: !o };
            }
        };
        throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
    }

    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m) return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
        }
        catch (error) { e = { error: error }; }
        finally {
            try {
                if (r && !r.done && (m = i["return"])) m.call(i);
            }
            finally { if (e) throw e.error; }
        }
        return ar;
    }

    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }

    function __spreadArrays() {
        for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
        for (var r = Array(s), k = 0, i = 0; i < il; i++)
            for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
                r[k] = a[j];
        return r;
    };

    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }

    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
    }

    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }

    function __asyncValues(o) {
        if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
    }

    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
        return cooked;
    };

    function __importStar(mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
        result.default = mod;
        return result;
    }

    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }

    function __classPrivateFieldGet(receiver, privateMap) {
        if (!privateMap.has(receiver)) {
            throw new TypeError("attempted to get private field on non-instance");
        }
        return privateMap.get(receiver);
    }

    function __classPrivateFieldSet(receiver, privateMap, value) {
        if (!privateMap.has(receiver)) {
            throw new TypeError("attempted to set private field on non-instance");
        }
        privateMap.set(receiver, value);
        return value;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: lib/definitions.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /** @type {?} */
    var SERIAL_SETTINGS_FIELDS = [
        'baudRate',
        'dataBits',
        'bitParity',
        'stopBits',
        'hardwareFlowControl',
        'handshakeDelimiter',
        'timeout'
    ];
    /** @type {?} */
    var MODBUS_SETTINGS_FIELDS = __spread(SERIAL_SETTINGS_FIELDS, [
        'offsetFirstRegister',
        'slave'
    ]);
    /** @type {?} */
    var TAPNPASS_SETTINGS_FIELDS = [
        'physicalPort'
    ];
    /** @type {?} */
    var ALL_SETTINGS_FIELDS = __spread(SERIAL_SETTINGS_FIELDS, MODBUS_SETTINGS_FIELDS);
    var ProtocolConfigurationError = /** @class */ (function (_super) {
        __extends(ProtocolConfigurationError, _super);
        function ProtocolConfigurationError(msg, cause) {
            var _this = _super.call(this, msg) || this;
            _this.cause = cause;
            _this.code = 'ProtocolConfigurationError';
            return _this;
        }
        /**
         * @param {?} err
         * @param {?} msg
         * @return {?}
         */
        ProtocolConfigurationError.tapResponseError = /**
         * @param {?} err
         * @param {?} msg
         * @return {?}
         */
        function (err, msg) {
            /** @type {?} */
            var fullMsg = msg + " - " + err.message;
            return new ProtocolConfigurationError(fullMsg, err);
        };
        return ProtocolConfigurationError;
    }(Error));
    if (false) {
        /** @type {?} */
        ProtocolConfigurationError.prototype.code;
        /** @type {?} */
        ProtocolConfigurationError.prototype.cause;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: lib/protocol-configuration.service.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /** @type {?} */
    var TAG = 'SerialSettings';
    var ProtocolConfigurationService = /** @class */ (function () {
        function ProtocolConfigurationService(tapService) {
            this.tapService = tapService;
            this._s3pProtocolConfiguration = {
                mode: target.TargetS3PProtocolConfiguration.Mode.INDEXED,
                delay: 1
            };
            this._defaultSettings = {
                serial: {
                    physicalPort: target.SerialSettings.PhysicalPort.AUTO,
                    stopBits: target.SerialSettings.StopBits.ONE,
                    bitParity: target.SerialSettings.BitParity.NONE,
                    dataBits: target.SerialSettings.DataBits._8,
                    hardwareFlowControl: target.SerialSettings.HardwareFlowControl.NONE,
                    handshakeDelimiter: target.SerialSettings.HandshakeDelimiter.NONE,
                    timeout: 50,
                    baudRate: 187500,
                },
                modbus: {
                    offsetFirstRegister: false,
                    slave: 0
                }
            };
            this.pendingSettings$ = new rxjs.BehaviorSubject(this._defaultSettings); // displayed settings
            // displayed settings
            this.loading = new rxjs.BehaviorSubject(false);
            // real settings
            this.errors = new rxjs.Subject();
            this._tapSettings = undefined;
        }
        Object.defineProperty(ProtocolConfigurationService.prototype, "pendingSettings", {
            get: /**
             * @return {?}
             */
            function () {
                return this.pendingSettings$.value;
            },
            set: /**
             * @param {?} settings
             * @return {?}
             */
            function (settings) {
                this.pendingSettings$.next(settings);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ProtocolConfigurationService.prototype, "tap", {
            get: /**
             * @return {?}
             */
            function () {
                return this.tapService.tap;
            },
            enumerable: true,
            configurable: true
        });
        /**
         * @return {?}
         */
        ProtocolConfigurationService.prototype.refresh = /**
         * @return {?}
         */
        function () {
            return __awaiter(this, void 0, void 0, function () {
                var tapSettings, err_1, error;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            this.loading.next(true);
                            _a.label = 1;
                        case 1:
                            _a.trys.push([1, 3, , 4]);
                            return [4 /*yield*/, this.tap.service.target.getSerialModbusConfiguration()];
                        case 2:
                            tapSettings = (_a.sent()).body();
                            this._tapSettings = tapSettings;
                            this.pendingSettings$.next(tapSettings);
                            // debug(TAG, 'Refreshed settings: ', this.pendingSettings);
                            this.loading.next(false);
                            return [3 /*break*/, 4];
                        case 3:
                            err_1 = _a.sent();
                            error = ProtocolConfigurationError.tapResponseError(err_1, 'Failed reading serial settings from Tap');
                            this.loading.next(false);
                            this.onError(error);
                            throw error;
                        case 4: return [2 /*return*/];
                    }
                });
            });
        };
        /**
         * @param {?=} temporary
         * @param {?=} reconnectTarget
         * @return {?}
         */
        ProtocolConfigurationService.prototype.applyChanges = /**
         * @param {?=} temporary
         * @param {?=} reconnectTarget
         * @return {?}
         */
        function (temporary, reconnectTarget) {
            if (temporary === void 0) { temporary = true; }
            if (reconnectTarget === void 0) { reconnectTarget = true; }
            return __awaiter(this, void 0, void 0, function () {
                var error_1;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            this.loading.next(true);
                            _a.label = 1;
                        case 1:
                            _a.trys.push([1, 5, , 6]);
                            return [4 /*yield*/, this.setSerialModbusConfiguration(temporary)];
                        case 2:
                            _a.sent();
                            if (!reconnectTarget) return [3 /*break*/, 4];
                            return [4 /*yield*/, this.reconnectTarget()];
                        case 3:
                            _a.sent();
                            _a.label = 4;
                        case 4:
                            this._tapSettings = __assign({}, this.pendingSettings);
                            this.loading.next(false);
                            return [3 /*break*/, 6];
                        case 5:
                            error_1 = _a.sent();
                            this.loading.next(false);
                            this.onError(error_1);
                            throw error_1;
                        case 6: return [2 /*return*/];
                    }
                });
            });
        };
        /**
         * @return {?}
         */
        ProtocolConfigurationService.prototype.discardChanges = /**
         * @return {?}
         */
        function () {
            /** @type {?} */
            var prevSettings = (this._tapSettings ? this._tapSettings : this._defaultSettings);
            this.pendingSettings$.next(prevSettings);
        };
        /**
         * @return {?}
         */
        ProtocolConfigurationService.prototype.hasChanges = /**
         * @return {?}
         */
        function () {
            if (!this._tapSettings) {
                return true;
            }
            return !utility.deepEqual(this.pendingSettings, this._tapSettings);
        };
        /**
         * @private
         * @param {?=} temporary
         * @return {?}
         */
        ProtocolConfigurationService.prototype.setSerialModbusConfiguration = /**
         * @private
         * @param {?=} temporary
         * @return {?}
         */
        function (temporary) {
            if (temporary === void 0) { temporary = true; }
            return __awaiter(this, void 0, void 0, function () {
                var err_2;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            _a.trys.push([0, 5, , 6]);
                            if (!temporary) return [3 /*break*/, 2];
                            return [4 /*yield*/, this.tap.service.target.setSerialModbusConfiguration(this.pendingSettings)];
                        case 1:
                            (_a.sent()).successful();
                            return [3 /*break*/, 4];
                        case 2: return [4 /*yield*/, this.tap.service.target.putSerialModbusConfiguration(this.pendingSettings)];
                        case 3:
                            (_a.sent()).successful();
                            _a.label = 4;
                        case 4: return [3 /*break*/, 6];
                        case 5:
                            err_2 = _a.sent();
                            throw ProtocolConfigurationError.tapResponseError(err_2, "Failed writing serial settings to Tap");
                        case 6: return [2 /*return*/];
                    }
                });
            });
        };
        /**
         * @return {?}
         */
        ProtocolConfigurationService.prototype.reconnectTarget = /**
         * @return {?}
         */
        function () {
            return __awaiter(this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, this.tap.service.target.disconnect()];
                        case 1:
                            _a.sent();
                            return [4 /*yield*/, this.tap.service.target.connect()];
                        case 2:
                            _a.sent();
                            return [2 /*return*/];
                    }
                });
            });
        };
        /**
         * @param {?} error
         * @return {?}
         */
        ProtocolConfigurationService.prototype.onError = /**
         * @param {?} error
         * @return {?}
         */
        function (error) {
            this.errors.next(error);
        };
        ProtocolConfigurationService.decorators = [
            { type: core.Injectable, args: [{
                        providedIn: 'root'
                    },] }
        ];
        /** @nocollapse */
        ProtocolConfigurationService.ctorParameters = function () { return [
            { type: ionic.CurrentDeviceService }
        ]; };
        /** @nocollapse */ ProtocolConfigurationService.ɵprov = core.ɵɵdefineInjectable({ factory: function ProtocolConfigurationService_Factory() { return new ProtocolConfigurationService(core.ɵɵinject(ionic.CurrentDeviceService)); }, token: ProtocolConfigurationService, providedIn: "root" });
        return ProtocolConfigurationService;
    }());
    if (false) {
        /**
         * @type {?}
         * @protected
         */
        ProtocolConfigurationService.prototype._s3pProtocolConfiguration;
        /**
         * @type {?}
         * @protected
         */
        ProtocolConfigurationService.prototype._defaultSettings;
        /** @type {?} */
        ProtocolConfigurationService.prototype.pendingSettings$;
        /** @type {?} */
        ProtocolConfigurationService.prototype.loading;
        /**
         * @type {?}
         * @private
         */
        ProtocolConfigurationService.prototype._tapSettings;
        /** @type {?} */
        ProtocolConfigurationService.prototype.errors;
        /** @type {?} */
        ProtocolConfigurationService.prototype.tapService;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: lib/tap-protocol-configuration-form/tap-protocol-configuration-form.component.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    /** @type {?} */
    var TAG$1 = 'TapProtocolConfiguration';
    var TapProtocolConfigurationFormComponent = /** @class */ (function () {
        function TapProtocolConfigurationFormComponent(formBuilder, protocolConfigurationService) {
            this.protocolConfigurationService = protocolConfigurationService;
            this.customBaudRate = false;
            this.baudRates = [
                300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200,
                187500, 230400, 460800, 921600
            ];
            this.fields = ALL_SETTINGS_FIELDS;
            this.valueChanges = new core.EventEmitter();
            // TODO add validators
            /** @type {?} */
            var formConfig = {
                baudRate: ['', [forms.Validators.required]],
                bitParity: [''],
                dataBits: [''],
                hardwareFlowControl: [''],
                handshakeDelimiter: [
                    target.SerialSettings.HandshakeDelimiter.NONE
                ],
                physicalPort: [''],
                stopBits: [''],
                offsetFirstRegister: [''],
                // identification: [''],
                // ledStatus: [''],
                slave: [''],
                timeout: [''],
            };
            this.form = formBuilder.group(formConfig);
        }
        Object.defineProperty(TapProtocolConfigurationFormComponent.prototype, "values", {
            set: /**
             * @param {?} v
             * @return {?}
             */
            function (v) {
                if (v) {
                    this.updateFormValue(v);
                }
            },
            enumerable: true,
            configurable: true
        });
        /**
         * @param {?} field
         * @return {?}
         */
        TapProtocolConfigurationFormComponent.prototype.hasField = /**
         * @param {?} field
         * @return {?}
         */
        function (field) {
            return this.fields.indexOf(field) >= 0;
        };
        Object.defineProperty(TapProtocolConfigurationFormComponent.prototype, "SerialSettings", {
            get: /**
             * @return {?}
             */
            function () {
                return target.SerialSettings;
            },
            enumerable: true,
            configurable: true
        });
        /**
         * @param {?} settings
         * @return {?}
         */
        TapProtocolConfigurationFormComponent.prototype.updateFormValue = /**
         * @param {?} settings
         * @return {?}
         */
        function (settings) {
            /** @type {?} */
            var newValues = __assign(__assign({}, settings.modbus), settings.serial);
            for (var key in newValues) {
                /** @type {?} */
                var field = this.form.get(key);
                if (field) {
                    field.setValue(newValues[key], {
                        emitEvent: false
                    });
                }
            }
        };
        /**
         * @return {?}
         */
        TapProtocolConfigurationFormComponent.prototype.ngOnInit = /**
         * @return {?}
         */
        function () {
            var _this = this;
            // debug(TAG, 'ngOnInit');
            /** @type {?} */
            var settings = this.protocolConfigurationService.pendingSettings;
            this.updateFormValue(settings);
            this.form.valueChanges
                .subscribe((/**
             * @param {?} newValue
             * @return {?}
             */
            function (newValue) {
                // debug(TAG, 'Protocol configuration changed:', newValue);
                /** @type {?} */
                var netProtocolConfig = {
                    modbus: {
                        offsetFirstRegister: newValue.offsetFirstRegister,
                        slave: newValue.slave
                    },
                    serial: {
                        baudRate: newValue.baudRate,
                        bitParity: newValue.bitParity,
                        dataBits: newValue.dataBits,
                        handshakeDelimiter: newValue.handshakeDelimiter,
                        hardwareFlowControl: newValue.hardwareFlowControl,
                        physicalPort: newValue.physicalPort,
                        stopBits: newValue.stopBits,
                        timeout: newValue.timeout
                    }
                };
                _this.valueChanges.emit(netProtocolConfig);
                _this.protocolConfigurationService.pendingSettings = netProtocolConfig;
            }));
            this.protocolConfigurationService
                .pendingSettings$
                .subscribe((/**
             * @param {?} newSettings
             * @return {?}
             */
            function (newSettings) {
                // debug(TAG, 'Refreshing form value', newSettings);
                if (_this.baudRates.indexOf(newSettings.serial.baudRate) === -1) {
                    _this.customBaudRate = true;
                }
                _this.form.setValue(newSettings, {
                    emitEvent: false
                });
            }));
        };
        TapProtocolConfigurationFormComponent.decorators = [
            { type: core.Component, args: [{
                        selector: 'tap-protocol-configuration-form',
                        template: "<form [formGroup]=\"form\">\r\n    <ion-item *ngIf=\"hasField('baudRate')\">\r\n        <ion-label>\r\n            Baud rate\r\n        </ion-label>\r\n        <!-- <ion-button fill=\"clear\" slot=\"end\" (click)=\"customBaudRate = !customBaudRate\">\r\n                    <ion-icon name=\"swap\"></ion-icon>\r\n                </ion-button> -->\r\n        <ion-input slot=\"end\" *ngIf=\"customBaudRate\" type=\"number\" [formControlName]=\"'baudRate'\"></ion-input>\r\n        <ion-select slot=\"end\" *ngIf=\"!customBaudRate\" [formControlName]=\"'baudRate'\">\r\n            <ion-select-option *ngFor=\"let baud of baudRates\" [value]=\"baud\">\r\n                {{baud}}\r\n                bauds\r\n            </ion-select-option>\r\n        </ion-select>\r\n    </ion-item>\r\n    <ion-item *ngIf=\"hasField('dataBits')\">\r\n        <ion-label>Data bits</ion-label>\r\n        <ion-select [formControlName]=\"'dataBits'\">\r\n            <ion-select-option *ngFor=\"let option of SerialSettings.DataBits | enum\" [value]=\"option.key\">\r\n                {{option.value | trim:'_'}}\r\n            </ion-select-option>\r\n        </ion-select>\r\n    </ion-item>\r\n    <ion-item *ngIf=\"hasField('stopBits')\">\r\n        <ion-label>Stop bit</ion-label>\r\n        <ion-select [formControlName]=\"'stopBits'\">\r\n            <ion-select-option *ngFor=\"let option of SerialSettings.StopBits | enum\" [value]=\"option.key\">{{option.value}}\r\n            </ion-select-option>\r\n        </ion-select>\r\n    </ion-item>\r\n    <ion-item *ngIf=\"hasField('bitParity')\">\r\n        <ion-label>Parity</ion-label>\r\n        <ion-select [formControlName]=\"'bitParity'\">\r\n            <ion-select-option *ngFor=\"let option of SerialSettings.BitParity | enum\" [value]=\"option.key\">\r\n                {{option.value}}\r\n            </ion-select-option>\r\n        </ion-select>\r\n    </ion-item>\r\n\r\n    <ion-item *ngIf=\"hasField('hardwareFlowControl')\">\r\n        <ion-label>Hardware flow control</ion-label>\r\n        <ion-select [formControlName]=\"'hardwareFlowControl'\">\r\n            <ion-select-option *ngFor=\"let option of SerialSettings.HardwareFlowControl | enum\" [value]=\"option.key\">\r\n                {{option.value}}\r\n            </ion-select-option>\r\n        </ion-select>\r\n    </ion-item>\r\n<!-- \r\n    <ion-item *ngIf=\"hasField('handshakeDelimiter')\">\r\n        <ion-label>Handshake delimiter</ion-label>\r\n        <ion-select [formControlName]=\"'handshakeDelimiter'\">\r\n            <ion-select-option *ngFor=\"let option of SerialSettings.HandshakeDelimiter | enum\" [value]=\"option.key\">\r\n                {{option.value}}</ion-select-option>\r\n        </ion-select>\r\n    </ion-item> -->\r\n\r\n    <!-- TAPNPASS -->\r\n    <ion-item *ngIf=\"hasField('slave')\">\r\n        <ion-label>Slave number</ion-label>\r\n        <ion-input slot=\"end\" type=\"number\" [formControlName]=\"'slave'\" ></ion-input>\r\n    </ion-item>\r\n\r\n    <ion-item *ngIf=\"hasField('physicalPort')\">\r\n        <ion-label>Physical port</ion-label>\r\n        <ion-select [formControlName]=\"'physicalPort'\">\r\n            <ion-select-option *ngFor=\"let option of SerialSettings.PhysicalPort | enum\" [value]=\"option.key\">\r\n                {{option.value}}</ion-select-option>\r\n        </ion-select>\r\n    </ion-item>\r\n\r\n    <ion-item *ngIf=\"hasField('timeout')\">\r\n        <ion-label>Timeout</ion-label>\r\n        <ion-input slot=\"end\" type=\"number\" [formControlName]=\"'timeout'\"></ion-input>\r\n    </ion-item>\r\n\r\n    <ion-item *ngIf=\"hasField('offsetFirstRegister')\">\r\n        <ion-label>Offset first register</ion-label>\r\n        <ion-select [formControlName]=\"'offsetFirstRegister'\">\r\n            <ion-select-option [value]=\"false\">No</ion-select-option>\r\n            <ion-select-option [value]=\"true\">Yes</ion-select-option>\r\n        </ion-select>\r\n    </ion-item>\r\n</form>\r\n",
                        styles: ["ion-input{text-align:right}"]
                    }] }
        ];
        /** @nocollapse */
        TapProtocolConfigurationFormComponent.ctorParameters = function () { return [
            { type: forms.FormBuilder },
            { type: ProtocolConfigurationService }
        ]; };
        TapProtocolConfigurationFormComponent.propDecorators = {
            customBaudRate: [{ type: core.Input }],
            baudRates: [{ type: core.Input }],
            fields: [{ type: core.Input }],
            values: [{ type: core.Input }],
            valueChanges: [{ type: core.Output }]
        };
        return TapProtocolConfigurationFormComponent;
    }());
    if (false) {
        /** @type {?} */
        TapProtocolConfigurationFormComponent.prototype.customBaudRate;
        /** @type {?} */
        TapProtocolConfigurationFormComponent.prototype.baudRates;
        /** @type {?} */
        TapProtocolConfigurationFormComponent.prototype.fields;
        /** @type {?} */
        TapProtocolConfigurationFormComponent.prototype.valueChanges;
        /** @type {?} */
        TapProtocolConfigurationFormComponent.prototype.form;
        /** @type {?} */
        TapProtocolConfigurationFormComponent.prototype.protocolConfigurationService;
    }

    /**
     * @fileoverview added by tsickle
     * Generated from: lib/tap-protocol-configuration.module.ts
     * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
     */
    var TapProtocolConfigurationModule = /** @class */ (function () {
        function TapProtocolConfigurationModule() {
        }
        TapProtocolConfigurationModule.decorators = [
            { type: core.NgModule, args: [{
                        declarations: [
                            TapProtocolConfigurationFormComponent
                        ],
                        exports: [
                            TapProtocolConfigurationFormComponent
                        ],
                        imports: [
                            common.CommonModule,
                            ionic.LibCommonModule,
                            forms.FormsModule,
                            forms.ReactiveFormsModule
                        ],
                        providers: [
                            ProtocolConfigurationService
                        ]
                    },] }
        ];
        return TapProtocolConfigurationModule;
    }());

    exports.ALL_SETTINGS_FIELDS = ALL_SETTINGS_FIELDS;
    exports.MODBUS_SETTINGS_FIELDS = MODBUS_SETTINGS_FIELDS;
    exports.ProtocolConfigurationError = ProtocolConfigurationError;
    exports.ProtocolConfigurationService = ProtocolConfigurationService;
    exports.SERIAL_SETTINGS_FIELDS = SERIAL_SETTINGS_FIELDS;
    exports.TAPNPASS_SETTINGS_FIELDS = TAPNPASS_SETTINGS_FIELDS;
    exports.TapProtocolConfigurationFormComponent = TapProtocolConfigurationFormComponent;
    exports.TapProtocolConfigurationModule = TapProtocolConfigurationModule;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=iotize-ionic-target-common.umd.js.map
