Skip to content

Commit

Permalink
Merge branch 'main' into CR-Config-API
Browse files Browse the repository at this point in the history
  • Loading branch information
cristian-recoseanu committed Oct 23, 2023
2 parents 4610bcc + f308805 commit 7476048
Show file tree
Hide file tree
Showing 9 changed files with 663 additions and 168 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ These are the configuration keys which can be specified in the configuration fil
* [AMWA IS-12 NMOS Control Protocol](https://specs.amwa.tv/is-12)
* [MS-05-01 NMOS Control Architecture](https://specs.amwa.tv/ms-05-01)
* [MS-05-02 NMOS Control Framework](https://specs.amwa.tv/ms-05-02)
* [MS-05-03 NMOS Control Block Specifications](https://specs.amwa.tv/ms-05-03)
* [BCP-002-02 NMOS Asset Distinguishing Information](https://specs.amwa.tv/bcp-002-02)

<!-- INTRO-END -->
175 changes: 156 additions & 19 deletions code/src/NCModel/Blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class NcBlock extends NcObject
}
}

return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'OID could not be found');
return new CommandResponseError(handle, NcMethodStatus.BadOid, 'OID could not be found');
}

//'1m2'
Expand All @@ -92,17 +92,135 @@ export class NcBlock extends NcObject
}
}

return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'OID could not be found');
return new CommandResponseError(handle, NcMethodStatus.BadOid, 'OID could not be found');
}

public override InvokeMethod(oid: number, methodId: NcElementId, args: { [key: string]: any; } | null, handle: number): CommandResponseNoValue
{
if(oid == this.oid)
{
let key: string = `${methodId.level}m${methodId.index}`;

switch(key)
{
case '1m3': //GetSequenceItem
{
if(args != null &&
'id' in args &&
'index' in args)
{
let propertyId = args['id'] as NcElementId;
let index = args['index'] as number;

if(propertyId)
{
if(index >= 0)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
switch(propertyKey)
{
case '2p2':
{
let itemValue = this.members[index];
if(itemValue)
return new CommandResponseWithValue(handle, NcMethodStatus.OK, itemValue);
else
return new CommandResponseError(handle, NcMethodStatus.IndexOutOfBounds, 'Index could not be found');
}
default:
return new CommandResponseError(handle, NcMethodStatus.PropertyNotImplemented, 'Property could not be found');
}
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid index argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '1m4': //SetSequenceItem
{
if(args != null &&
'id' in args &&
'index' in args &&
'value' in args)
{
let propertyId = args['id'] as NcElementId;
if(propertyId)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
return new CommandResponseError(handle, NcMethodStatus.Readonly, `Property ${propertyKey} is readonly`);
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '1m5': //AddSequenceItem
{
if(args != null &&
'id' in args &&
'value' in args)
{
let propertyId = args['id'] as NcElementId;
if(propertyId)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
return new CommandResponseError(handle, NcMethodStatus.Readonly, `Property ${propertyKey} is readonly`);
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '1m6': //RemoveSequenceItem
{
if(args != null &&
'id' in args &&
'index' in args)
{
let propertyId = args['id'] as NcElementId;
if(propertyId)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
return new CommandResponseError(handle, NcMethodStatus.Readonly, `Property ${propertyKey} is readonly`);
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '1m7': //GetSequenceLength
{
if(args != null &&
'id' in args)
{
let propertyId = args['id'] as NcElementId;
if(propertyId)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
switch(propertyKey)
{
case '2p2':
{
let length = this.members.length;

return new CommandResponseWithValue(handle, NcMethodStatus.OK, length);
}
default:
return new CommandResponseError(handle, NcMethodStatus.PropertyNotImplemented, 'Property could not be found');
}
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '2m1':
{
if(args != null)
Expand Down Expand Up @@ -164,18 +282,18 @@ export class NcBlock extends NcObject
{
if(args != null)
{
if('id' in args)
if('classId' in args)
{
if('includeDerived' in args)
{
let id = args['id'] as number[];
let classId = args['classId'] as number[];
let includeDerived = args['includeDerived'] as boolean;
let recurse = args['recurse'] as boolean;

if(recurse)
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.GenerateMemberDescriptorsByClassId(id, includeDerived, true));
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.GenerateMemberDescriptorsByClassId(classId, includeDerived, true));
else
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.GenerateMemberDescriptorsByClassId(id, includeDerived, false));
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.GenerateMemberDescriptorsByClassId(classId, includeDerived, false));
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'No includeDerived argument provided');
Expand Down Expand Up @@ -204,7 +322,7 @@ export class NcBlock extends NcObject
}
}

return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'OID could not be found');
return new CommandResponseError(handle, NcMethodStatus.BadOid, 'OID could not be found');
}

public override GenerateMemberDescriptor() : NcBlockMemberDescriptor
Expand Down Expand Up @@ -249,8 +367,8 @@ export class NcBlock extends NcObject
let currentClassDescriptor = new NcClassDescriptor(`${NcBlock.name} class descriptor`,
NcBlock.staticClassID, NcBlock.name, null,
[
new NcPropertyDescriptor(new NcElementId(2, 1), "enabled", "NcBoolean", true, true, false, false, null, "TRUE if block is functional"),
new NcPropertyDescriptor(new NcElementId(2, 2), "members", "NcBlockMemberDescriptor", true, true, false, true, null, "Descriptors of this block's members"),
new NcPropertyDescriptor(new NcElementId(2, 1), "enabled", "NcBoolean", true, false, false, null, "TRUE if block is functional"),
new NcPropertyDescriptor(new NcElementId(2, 2), "members", "NcBlockMemberDescriptor", true, false, true, null, "Descriptors of this block's members"),
],
[
new NcMethodDescriptor(new NcElementId(2, 1), "GetMemberDescriptors", "NcMethodResultBlockMemberDescriptors",
Expand All @@ -265,7 +383,7 @@ export class NcBlock extends NcObject
new NcParameterDescriptor("recurse", "NcBoolean", false, false, null, "TRUE to search nested blocks")
], "Finds members with given role name or fragment"),
new NcMethodDescriptor(new NcElementId(2, 4), "FindMembersByClassId", "NcMethodResultBlockMemberDescriptors", [
new NcParameterDescriptor("id", "NcClassId", false, false, null, "Class id to search for"),
new NcParameterDescriptor("classId", "NcClassId", false, false, null, "Class id to search for"),
new NcParameterDescriptor("includeDerived", "NcBoolean", false, false, null, "If TRUE it will also include derived class descriptors"),
new NcParameterDescriptor("recurse", "NcBoolean", false, false, null, "TRUE to search nested blocks")
], "Finds members with given class id")
Expand Down Expand Up @@ -537,8 +655,27 @@ export class RootBlock extends NcBlock
case MessageType.Command:
{
let msgCommand = JSON.parse(msg) as ProtocolCommand;
socket.send(this.ProcessCommand(msgCommand, socket).ToJson());
isMessageValid = true;

let invalidCommands = msgCommand.commands.filter(x => isNaN(+x.handle));
if(invalidCommands.length > 0)
{
isMessageValid = false;
errorMessage = `One of the commands has an invalid handle`;
}
else
{
let invalidCommands = msgCommand.commands.filter(x => x.handle <= 0 || x.handle > 65535);
if(invalidCommands.length > 0)
{
isMessageValid = false;
errorMessage = `One of the commands has an invalid handle`;
}
else
{
socket.send(this.ProcessCommand(msgCommand, socket).ToJson());
isMessageValid = true;
}
}
}
break;
default:
Expand Down Expand Up @@ -592,11 +729,11 @@ export class RootBlock extends NcBlock
if(member)
return member.Get(commandMsg.oid, propertyId, commandMsg.handle);
else
return new CommandResponseError(commandMsg.handle, NcMethodStatus.InvalidRequest, "OID could not be found");
return new CommandResponseError(commandMsg.handle, NcMethodStatus.BadOid, "OID could not be found");
}
}
else
return new CommandResponseError(commandMsg.handle, NcMethodStatus.InvalidRequest, "OID could not be found");
return new CommandResponseError(commandMsg.handle, NcMethodStatus.BadOid, "OID could not be found");
}
else if (this.IsGenericSetter(commandMsg.methodId))
{
Expand All @@ -613,11 +750,11 @@ export class RootBlock extends NcBlock
if(member)
return member.Set(commandMsg.oid, propertyId, propertyValue, commandMsg.handle);
else
return new CommandResponseError(commandMsg.handle, NcMethodStatus.InvalidRequest, "OID could not be found");
return new CommandResponseError(commandMsg.handle, NcMethodStatus.BadOid, "OID could not be found");
}
}
else
return new CommandResponseError(commandMsg.handle, NcMethodStatus.InvalidRequest, "OID could not be found");
return new CommandResponseError(commandMsg.handle, NcMethodStatus.BadOid, "OID could not be found");
}
else
{
Expand All @@ -629,11 +766,11 @@ export class RootBlock extends NcBlock
if(member)
return member.InvokeMethod(commandMsg.oid, commandMsg.methodId, commandMsg.arguments, commandMsg.handle);
else
return new CommandResponseError(commandMsg.handle, NcMethodStatus.InvalidRequest, "OID could not be found");
return new CommandResponseError(commandMsg.handle, NcMethodStatus.BadOid, "OID could not be found");
}
}

return new CommandResponseError(commandMsg.handle, NcMethodStatus.InvalidRequest, "OID could not be found");
return new CommandResponseError(commandMsg.handle, NcMethodStatus.BadOid, "OID could not be found");
}

public IsGenericGetter(propertyId: NcElementId) : boolean
Expand Down
Loading

0 comments on commit 7476048

Please sign in to comment.