{"version":3,"file":"SetPortHeight.cjs","names":["Request"],"sources":["../../generated/api/SetPortHeight.ts"],"sourcesContent":["import { encodeUIntLE, ErrorType, Request, Session } from '@novastar/codec';\nimport AddressMapping from '../AddressMapping';\n\ndeclare module '@novastar/codec' {\n  interface API {\n    SetPortHeight(\n      addr: number,\n      bBroadcast: boolean,\n      portHeight: number,\n      index: number\n    ): Promise<void>;\n    trySetPortHeight(addr: number, portHeight: number, index: number): Promise<ErrorType | null>;\n  }\n}\nexport default function createSetPortHeight<Broadcast extends boolean>(\n  addr: number,\n  bBroadcast: Broadcast,\n  portHeight: number,\n  index: number\n): Request<Broadcast> {\n  const $data = encodeUIntLE(portHeight, AddressMapping.PortHeightOccupancy);\n  const req = new Request($data, bBroadcast, 'SetPortHeight');\n  req.destination = addr;\n  req.address = 0;\n  if (index >= AddressMapping.New32PortOccupancy) {\n    req.address =\n      AddressMapping.PortHeightNew32Addr +\n      AddressMapping.PortOccupancy * (index - AddressMapping.New32PortOccupancy);\n  } else if (index >= AddressMapping.New16PortOccupancy) {\n    req.address =\n      AddressMapping.PortHeightNew16Addr +\n      AddressMapping.PortOccupancy * (index - AddressMapping.New16PortOccupancy);\n  } else if (index >= AddressMapping.NewPortOccupancy) {\n    req.address =\n      AddressMapping.PortHeightNewAddr +\n      AddressMapping.PortOccupancy * (index - AddressMapping.NewPortOccupancy);\n  } else {\n    req.address = AddressMapping.PortHeightAddr + AddressMapping.PortOccupancy * index;\n  }\n  return req;\n}\nSession.prototype.SetPortHeight = async function SetPortHeight(\n  this: Session,\n  addr: number,\n  bBroadcast: boolean,\n  portHeight: number,\n  index: number\n): Promise<void> {\n  const req = createSetPortHeight(addr, bBroadcast, portHeight, index);\n  await this.connection.send(req);\n};\nSession.prototype.trySetPortHeight = async function trySetPortHeight(\n  this: Session,\n  addr: number,\n  portHeight: number,\n  index: number\n): Promise<ErrorType | null> {\n  const req = createSetPortHeight(addr, false, portHeight, index);\n  return (await this.connection.trySend(req))?.ack ?? null;\n};\n"],"mappings":";;;;;AAcA,SAAwB,oBACtB,MACA,YACA,YACA,OACoB;CAEpB,MAAM,MAAM,IAAIA,0DADW,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,wBAAQ,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,wBAAQ,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"}