Skip to content

Commit

Permalink
Fix/src int act (#52)
Browse files Browse the repository at this point in the history
* fix srcIntAct vs srcExtAct
* update to 1.9.1
* fix testserver
* fix opModeTojson

Signed-off-by: Markus Graube <[email protected]>
  • Loading branch information
markusgraube authored Sep 17, 2019
1 parent 83cc8fc commit 6c76ce7
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@p2olab/polaris-backend",
"version": "1.9.0",
"version": "1.9.1",
"main": "./build/src/index.js",
"types": "./build/src/index.d.ts",
"description": "Server backend for POL recipe execution engine",
Expand Down
11 changes: 6 additions & 5 deletions src/model/core/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,21 @@ export enum OpMode {
srcIntLi = 2048,
srcIntOp = 4096,
srcExtOp = 8192,
srcExtAct = 16384
srcIntAct = 16384
}

export function opModetoJson(opMode: OpMode): OpModeInterface {
const source: 'external' | 'internal' = isExtSource(opMode) ? 'external' : 'internal';
let source: 'external' | 'internal';
let state;
if (isManualState(opMode)) {
state = 'manual';
} else if (isAutomaticState(opMode)) {
state = 'automatic';
source = isExtSource(opMode) ? 'external' : 'internal';
} else if (isOffState(opMode)) {
state = 'off';
}
return {state, source};
return {state: state, source: source};
}

export function isOffState(opMode: OpMode): boolean {
Expand All @@ -129,9 +130,9 @@ export function isManualState(opMode: OpMode): boolean {
}

export function isExtSource(opMode: OpMode): boolean {
return (opMode & OpMode.srcExtAct) === OpMode.srcExtAct;
return (opMode & OpMode.srcIntAct) === 0;
}

export function isIntSource(opMode: OpMode): boolean {
return (opMode & OpMode.srcExtAct) === 0;
return (opMode & OpMode.srcIntAct) === OpMode.srcIntAct;
}
9 changes: 5 additions & 4 deletions src/model/dataAssembly/mixins/OpMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,25 @@ export function OpModeDA<TBase extends Constructor<DataAssembly>>(Base: TBase) {
* Set data assembly to automatic operation mode and source to external source
*/
public async setToAutomaticOperationMode(): Promise<void> {
catDataAssembly.debug(`[${this.name}] Current opMode = ${this.communication.OpMode.value}`);
catDataAssembly.info(`[${this.name}] Current opMode = ${this.communication.OpMode.value}`);
if (isOffState(this.communication.OpMode.value)) {
catDataAssembly.trace('First go to Manual state');
catDataAssembly.trace(`[${this.name}] First go to Manual state`);
this.writeOpMode(OpMode.stateManOp);
await this.waitForOpModeToPassSpecificTest(isManualState);
}

if (isManualState(this.communication.OpMode.value)) {
catDataAssembly.trace('Then to automatic');
catDataAssembly.trace(`[${this.name}] Then to automatic`);
this.writeOpMode(OpMode.stateAutOp);
await this.waitForOpModeToPassSpecificTest(isAutomaticState);
}

if (!isExtSource(this.communication.OpMode.value)) {
catDataAssembly.trace('Finally to Ext');
catDataAssembly.trace(`[${this.name}] Finally to Ext`);
this.writeOpMode(OpMode.srcExtOp);
await this.waitForOpModeToPassSpecificTest(isExtSource);
}
catDataAssembly.info(`[${this.name}] Current opMode = ${this.communication.OpMode.value}`);
}

public async setToManualOperationMode() {
Expand Down
3 changes: 2 additions & 1 deletion src/moduleTestServer/ModuleTestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ export class TestServerService {
} else if (opModeInt === OpMode.stateAutOp) {
this.varOpmode = this.varOpmode & ~OpMode.stateManAct;
this.varOpmode = this.varOpmode | OpMode.stateAutAct;
this.varOpmode = this.varOpmode | OpMode.srcIntAct;
} else if (opModeInt === OpMode.srcExtOp) {
this.varOpmode = this.varOpmode | OpMode.srcExtAct;
this.varOpmode = this.varOpmode & ~OpMode.srcIntAct;
} else {
return StatusCodes.Bad;
}
Expand Down
3 changes: 2 additions & 1 deletion src/moduleTestServer/ModuleTestVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ export abstract class TestServerVariable {
} else if (opModeInt === OpMode.stateAutOp) {
this.opMode = this.opMode & ~OpMode.stateManAct;
this.opMode = this.opMode | OpMode.stateAutAct;
this.opMode = this.opMode | OpMode.srcIntAct;
} else if (opModeInt === OpMode.srcExtOp) {
this.opMode = this.opMode | OpMode.srcExtAct;
this.opMode = this.opMode & ~OpMode.srcIntAct;
} else {
return StatusCodes.Bad;
}
Expand Down
6 changes: 3 additions & 3 deletions test/model/core/Service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ describe('Service', () => {
service.setOperationMode();

await service.waitForOpModeToPassSpecificTest(isAutomaticState);
expect(service.opMode).to.equal(OpMode.stateAutAct);
expect(service.opMode).to.equal(OpMode.stateAutAct + OpMode.srcIntAct);

await service.waitForOpModeToPassSpecificTest(isExtSource);
expect(service.opMode).to.equal(OpMode.stateAutAct + OpMode.srcExtAct);
expect(service.opMode).to.equal(OpMode.stateAutAct);
});

it('full service state cycle', async () => {
Expand All @@ -175,7 +175,7 @@ describe('Service', () => {
expect(result).to.have.property('name', 'Service1');
expect(result).to.have.property('opMode').to.deep.equal({
state: 'off',
source: 'internal'
source: undefined
});

await service.setOperationMode();
Expand Down
6 changes: 3 additions & 3 deletions test/model/dataAssembly/DataAssembly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,17 @@ describe('DataAssembly', () => {

await da.waitForOpModeToPassSpecificTest(isOffState);
let opMode = da.getOpMode();
expect(opModetoJson(opMode)).to.deep.equal({state: 'off', source: 'internal'});
expect(opModetoJson(opMode)).to.deep.equal({state: 'off', source: undefined});

(moduleServer.services[0].parameter[0] as TestServerVariable).opMode = OpMode.stateManAct;
await da.waitForOpModeToPassSpecificTest(isManualState);
opMode = da.getOpMode();
expect(opModetoJson(opMode)).to.deep.equal({state: 'manual', source: 'internal'});
expect(opModetoJson(opMode)).to.deep.equal({state: 'manual', source: undefined});

(moduleServer.services[0].parameter[0] as TestServerVariable).opMode = OpMode.stateAutAct;
await da.waitForOpModeToPassSpecificTest(isAutomaticState);
opMode = da.getOpMode();
expect(opModetoJson(opMode)).to.deep.equal({state: 'automatic', source: 'internal'});
expect(opModetoJson(opMode)).to.deep.equal({state: 'automatic', source: 'external'});

if (da instanceof ExtIntAnaOp) {
expect(da.communication.VOut).to.have.property('nodeId', 'Service1.Parameter1.V');
Expand Down

0 comments on commit 6c76ce7

Please sign in to comment.