(phy band.Band, b []byte, isUplink bool, cmd *ttnpb.MACCommand)
| 1541 | ) |
| 1542 | |
| 1543 | func (spec MACCommandSpec) append(phy band.Band, b []byte, isUplink bool, cmd *ttnpb.MACCommand) ([]byte, error) { |
| 1544 | desc, ok := spec[cmd.Cid] |
| 1545 | if !ok || desc == nil { |
| 1546 | return nil, errUnknownMACCommand.WithAttributes("cid", fmt.Sprintf("0x%X", int32(cmd.Cid))) |
| 1547 | } |
| 1548 | b = append(b, byte(cmd.Cid)) |
| 1549 | |
| 1550 | var appender func(phy band.Band, b []byte, cmd *ttnpb.MACCommand) ([]byte, error) |
| 1551 | if isUplink { |
| 1552 | appender = desc.AppendUplink |
| 1553 | if appender == nil { |
| 1554 | return nil, errMACCommandUplink.WithAttributes("cid", fmt.Sprintf("0x%X", int32(cmd.Cid))) |
| 1555 | } |
| 1556 | } else { |
| 1557 | appender = desc.AppendDownlink |
| 1558 | if appender == nil { |
| 1559 | return nil, errMACCommandDownlink.WithAttributes("cid", fmt.Sprintf("0x%X", int32(cmd.Cid))) |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | b, err := appender(phy, b, cmd) |
| 1564 | if err != nil { |
| 1565 | return nil, errEncodingMACCommand.WithAttributes("cid", fmt.Sprintf("0x%X", int32(cmd.Cid))).WithCause(err) |
| 1566 | } |
| 1567 | return b, nil |
| 1568 | } |
| 1569 | |
| 1570 | // AppendUplink encodes uplink MAC command cmd, appends it to b and returns any errors encountered. |
| 1571 | func (spec MACCommandSpec) AppendUplink(phy band.Band, b []byte, cmd *ttnpb.MACCommand) ([]byte, error) { |
no test coverage detected