Exemplo n.º 1
0
func (a *NodeAPI) returnList(count int, nodes []models.Node) (*pb.ListNodeResponse, error) {
	resp := pb.ListNodeResponse{
		TotalCount: int64(count),
	}
	for _, node := range nodes {
		appEUI, err := node.AppEUI.MarshalText()
		if err != nil {
			return nil, err
		}
		devEUI, err := node.DevEUI.MarshalText()
		if err != nil {
			return nil, err
		}
		appKey, err := node.AppKey.MarshalText()
		if err != nil {
			return nil, err
		}

		item := pb.GetNodeResponse{
			DevEUI:      string(devEUI),
			AppEUI:      string(appEUI),
			AppKey:      string(appKey),
			RxDelay:     uint32(node.RXDelay),
			Rx1DROffset: uint32(node.RX1DROffset),
		}

		if node.ChannelListID != nil {
			item.ChannelListID = *node.ChannelListID
		}

		resp.Result = append(resp.Result, &item)
	}
	return &resp, nil
}
Exemplo n.º 2
0
// Get returns the Node for the given DevEUI.
func (a *NodeAPI) Get(ctx context.Context, req *pb.GetNodeRequest) (*pb.GetNodeResponse, error) {
	var eui lorawan.EUI64
	if err := eui.UnmarshalText([]byte(req.DevEUI)); err != nil {
		return nil, err
	}

	node, err := storage.GetNode(a.ctx.DB, eui)
	if err != nil {
		return nil, err
	}

	devEUI, err := node.DevEUI.MarshalText()
	if err != nil {
		return nil, err
	}
	appEUI, err := node.AppEUI.MarshalText()
	if err != nil {
		return nil, err
	}
	appKey, err := node.AppKey.MarshalText()
	if err != nil {
		return nil, err
	}

	resp := pb.GetNodeResponse{
		DevEUI:      string(devEUI),
		AppEUI:      string(appEUI),
		AppKey:      string(appKey),
		RxDelay:     uint32(node.RXDelay),
		Rx1DROffset: uint32(node.RX1DROffset),
	}

	if node.ChannelListID != nil {
		resp.ChannelListID = *node.ChannelListID
	}

	return &resp, nil
}