File: Data.java

package info (click to toggle)
tinyos 2.1.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 47,476 kB
  • ctags: 36,607
  • sloc: ansic: 63,646; cpp: 14,974; java: 10,358; python: 5,215; makefile: 1,724; sh: 902; asm: 597; xml: 392; perl: 74; awk: 46
file content (74 lines) | stat: -rw-r--r-- 2,184 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Copyright (c) 2006 Intel Corporation
 * All rights reserved.
 *
 * This file is distributed under the terms in the attached INTEL-LICENSE     
 * file. If you do not find these files, copies can be found by writing to
 * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
 * 94704.  Attention:  Intel License Inquiry.
 */

import java.util.*;

/* Hold all data received from motes */
class Data {
    /* The mote data is stored in a flat array indexed by a mote's identifier.
       A null value indicates no mote with that identifier. */
    private Node[] nodes = new Node[256];
    private Oscilloscope parent;

    Data(Oscilloscope parent) {
    this.parent = parent;
    }

    /* Data received from mote nodeId containing NREADINGS samples from
       messageId * NREADINGS onwards. Tell parent if this is a new node. */
    void update(int nodeId, int messageId, int readings[]) {
    if (nodeId >= nodes.length) {
        int newLength = nodes.length * 2;
        if (nodeId >= newLength)
        newLength = nodeId + 1;

        Node newNodes[] = new Node[newLength];
        System.arraycopy(nodes, 0, newNodes, 0, nodes.length);
        nodes = newNodes;
    }
    Node node = nodes[nodeId];
    if (node == null) {
        nodes[nodeId] = node = new Node(nodeId);
        parent.newNode(nodeId);
    }
    node.update(messageId, readings);
    }

    /* Return value of sample x for mote nodeId, or -1 for missing data */
    int getData(int nodeId, int x) {
    if (nodeId >= nodes.length || nodes[nodeId] == null)
        return -1;
    return nodes[nodeId].getData(x);
    }

    /* Return number of last known sample on mote nodeId. Returns 0 for
       unknown motes. */
    int maxX(int nodeId) {
    if (nodeId >= nodes.length || nodes[nodeId] == null)
        return 0;
    return nodes[nodeId].maxX();
    }

    /* Return number of largest known sample on all motes (0 if there are no
       motes) */
    int maxX() {
    int max = 0;

    for (int i = 0; i < nodes.length; i++)
        if (nodes[i] != null) {
        int nmax = nodes[i].maxX();

        if (nmax > max)
            max = nmax;
        }

    return max;
    }
}