code: func RequestNewChannels(devEUI lorawan.EUI64, maxChannels int, currentChannels, wantedChannels map[int]band.Channel) *storage.MACCommandBlock {
  	var out []lorawan.MACCommand
  
  	// sort by channel index
  	var wantedChannelNumbers []int
  	for i := range wantedChannels {
  		wantedChannelNumbers = append(wantedChannelNumbers, i)
  	}
  	sort.Ints(wantedChannelNumbers)
  
  	for _, i := range wantedChannelNumbers {
  		wanted := wantedChannels[i]
  		current, ok := currentChannels[i]
  		if !ok || current.Frequency != wanted.Frequency || current.MinDR != wanted.MinDR || current.MaxDR != wanted.MaxDR {
  			out = append(out, lorawan.MACCommand{
  				CID: lorawan.NewChannelReq,
  				Payload: &lorawan.NewChannelReqPayload{
  					ChIndex: uint8(i),
  					Freq:    uint32(wanted.Frequency),
  					MinDR:   uint8(wanted.MinDR),
  					MaxDR:   uint8(wanted.MaxDR),
  				},
  			})
  		}
  	}
  
  	if len(out) > maxChannels {
  		out = out[0:maxChannels]
  	}
  
  	if len(out) == 0 {
  		return nil
  	}
  
  	return &storage.MACCommandBlock{
  		CID:         lorawan.NewChannelReq,
  		MACCommands: storage.MACCommands(out),
  	}
  }
docs: // RequestNewChannels creates or modifies the non-common bi-directional
  // channels in case of changes between the current and wanted channels.
  // To avoid generating mac-command blocks which can't be sent, and to
  // modify the channels in multiple batches, the max number of channels to
  // modify must be given. In case of no changes, nil is returned.