{"version":3,"file":"SetPortEnable.mjs","names":[],"sources":["../../generated/api/SetPortEnable.ts"],"sourcesContent":["import { encodeUIntLE, ErrorType, Request, Session } from '@novastar/codec';\nimport AddressMapping from '../AddressMapping';\n\ndeclare module '@novastar/codec' {\n  interface API {\n    SetPortEnable(\n      addr: number,\n      bBroadcast: boolean,\n      portEnable: number,\n      index: number\n    ): Promise<void>;\n    trySetPortEnable(addr: number, portEnable: number, index: number): Promise<ErrorType | null>;\n  }\n}\nexport default function createSetPortEnable<Broadcast extends boolean>(\n  addr: number,\n  bBroadcast: Broadcast,\n  portEnable: number,\n  index: number\n): Request<Broadcast> {\n  const $data = encodeUIntLE(portEnable, AddressMapping.PortEnableOccupancy);\n  const req = new Request($data, bBroadcast, 'SetPortEnable');\n  req.destination = addr;\n  req.address = 0;\n  if (index >= AddressMapping.New32PortOccupancy) {\n    req.address =\n      AddressMapping.PortEnableNext32Addr +\n      AddressMapping.PortOccupancy * (index - AddressMapping.New32PortOccupancy);\n  } else if (index >= AddressMapping.New16PortOccupancy) {\n    req.address =\n      AddressMapping.PortEnableNext16Addr +\n      AddressMapping.PortOccupancy * (index - AddressMapping.New16PortOccupancy);\n  } else if (index >= AddressMapping.NewPortOccupancy) {\n    req.address =\n      AddressMapping.PortEnableNextAddr +\n      AddressMapping.PortOccupancy * (index - AddressMapping.NewPortOccupancy);\n  } else {\n    req.address = AddressMapping.PortEnableAddr + AddressMapping.PortOccupancy * index;\n  }\n  return req;\n}\nSession.prototype.SetPortEnable = async function SetPortEnable(\n  this: Session,\n  addr: number,\n  bBroadcast: boolean,\n  portEnable: number,\n  index: number\n): Promise<void> {\n  const req = createSetPortEnable(addr, bBroadcast, portEnable, index);\n  await this.connection.send(req);\n};\nSession.prototype.trySetPortEnable = async function trySetPortEnable(\n  this: Session,\n  addr: number,\n  portEnable: number,\n  index: number\n): Promise<ErrorType | null> {\n  const req = createSetPortEnable(addr, false, portEnable, index);\n  return (await this.connection.trySend(req))?.ack ?? null;\n};\n"],"mappings":";;;;AAcA,SAAwB,oBACtB,MACA,YACA,YACA,OACoB;CAEpB,MAAM,MAAM,IAAI,QADF,aAAa,aACC,GAAG,YAAY,eAAe;CAC1D,IAAI,cAAc;CAClB,IAAI,UAAU;CACd,IAAI,aACF,IAAI,0BAE8B;MAC7B,IAAI,YACT,IAAI,0BAE8B;MAC7B,IAAI,YACT,IAAI,0BAE8B;MAElC,IAAI,yBAAyE;CAE/E,OAAO;AACT;AACA,QAAQ,UAAU,gBAAgB,eAAe,cAE/C,MACA,YACA,YACA,OACe;CACf,MAAM,MAAM,oBAAoB,MAAM,YAAY,YAAY,KAAK;CACnE,MAAM,KAAK,WAAW,KAAK,GAAG;AAChC;AACA,QAAQ,UAAU,mBAAmB,eAAe,iBAElD,MACA,YACA,OAC2B;CAC3B,MAAM,MAAM,oBAAoB,MAAM,OAAO,YAAY,KAAK;CAC9D,QAAQ,MAAM,KAAK,WAAW,QAAQ,GAAG,IAAI,OAAO;AACtD"}