source: ResearchApps/PHY/WARPLAB/WARPLab_v6p2/M_Code_Reference/warplab_networkCheck.m

Last change on this file was 1814, checked in by chunter, 12 years ago

more organizing

File size: 5.0 KB
Line 
1function [status, results] = warplab_networkCheck(numNodes) 
2warplab_defines;
3status = 0;
4
5TIMEOUT = 3;
6
7%%%% results is a cell array of two elements
8%%%%    {1} a struct containing system-level diagnoses
9%%%%    {2} an array of structs containing node-level diagnoses
10%%%% Note: cell {2} is only populated if system-level checks pass
11
12results{1} = struct('nicSetup',[],'pnet',[]);
13%%%% Check that a WARP subnet exists
14fprintf('checking set up of computer network interfaces...\n')
15if(ispc)
16   [status, temp] = system('ipconfig /all');
17   temp = strfind(temp,strcat(WARP_subnet,ComputerAddr));
18   if(isempty(temp))
19       myMsg = sprintf('no interface found for IP %s',strcat(WARP_subnet,ComputerAddr));
20       fprintf('----Error! %s\n',myMsg)
21       status = -1;
22       results{1}.nicSetup = -1;
23       return;
24   else
25       results{1}.nicSetup = 0;
26       fprintf('\b ok\n');
27   end
28elseif(ismac||isunix)
29   [status, temp] = system('ifconfig -a');
30   temp = strfind(temp,strcat(WARP_subnet,ComputerAddr));
31   if(isempty(temp))
32       myMsg = sprintf('no interface found for IP %s',strcat(WARP_subnet,ComputerAddr));
33       fprintf('----Error! %s\n',myMsg)
34       status = -1;
35       results{1}.nicSetup = -1;
36       return;
37   else
38       results{1}.nicSetup = 0;
39       fprintf('\b ok\n');
40   end
41end 
42%%%%
43
44%%%% Checking Status of pnet Installation
45fprintf('checking installation of pnet...\n')
46temp = which('pnet');
47if(isempty(temp))
48    myMsg = 'pnet not found in path';
49    fprintf('----Error! %s\n',myMsg)
50    status = -1;
51    results{1}.pnet = -1;
52    return;
53elseif(strcmp(temp((end-length(mexext)+1):end),mexext)==0)
54    myMsg = 'pnet found, but it is not a compiled mex file';
55    fprintf('----Error! %s\n',myMsg)
56    status = -1;
57    results{1}.pnet = -1;
58    return;
59else
60    results{1}.pnet = 0;
61    fprintf('\b ok\n');
62end
63%%%%
64
65pnet('closeall');
66
67%[socketHandles, packetNum] = warplab_initialize(numNodes);
68
69nodes = 1:numNodes;
70IPAddrs = warplab_IP2int(strcat(WARP_subnet,'.0')) + nodes;
71UDP_Ports = NodeStartingPort + nodes-1;
72packetNum = 1;
73
74syncSock = pnet('udpsocket', SyncPort);
75pnet(syncSock, 'setreadtimeout', 1);
76pnet(syncSock, 'udpconnect', strcat(WARP_subnet,SyncAddr), SyncPort);
77packetNum = 1;
78
79for currNode = 1:numNodes
80    nodeStruct(currNode) = struct('serialNumber',[],'fpgaDNA',[],'numRadios',[],'hwGeneration',[],'warplabVersion',[],'respondsToCommands',[],'receivesSync',[]);
81   
82    %UDP Connections to individual nodes
83    thisSock = pnet('udpsocket', UDP_Ports(currNode));
84    pnet(thisSock, 'udpconnect', warplab_int2IP(IPAddrs(currNode)), UDP_Ports(currNode));
85    pnet(thisSock, 'setreadtimeout', 1);
86
87    disp(sprintf('checking configuration of Node %d...',currNode))
88   
89%%%% Check to make sure sync packets are being received
90    temp = warplab_sendCmd(thisSock, NETWORKCHECK, packetNum);
91    warplab_sendSync(syncSock);
92   
93    if(length(temp)==1)
94       if(temp==0)
95              myMsg = 'node not responding to commands';
96              fprintf('----Error! %s\n',myMsg)
97              status = -1;
98              nodeStruct(currNode).respondsToCommands = -1;
99              continue;
100       end
101    else
102       nodeStruct(currNode).respondsToCommands = 0;
103    end
104   
105    pause(TIMEOUT)
106    temp = warplab_sendCmd(thisSock, NETWORKCHECK, packetNum);
107    warplab_sendSync(syncSock);
108    pause(TIMEOUT)
109    if(temp(4)~=1)
110        myMsg = 'sync packet not received';
111        fprintf('----Error! %s\n',myMsg)
112        status = -1;
113        nodeStruct(currNode).receivesSync = -1;
114    else
115        fprintf('\b ok\n');
116        nodeStruct(currNode).receivesSync = 0;
117    end
118%%%%
119
120%%%% Read board information and verify that the latest version of WARPLab
121%%%% isbeing used
122    temp = warplab_sendCmd(thisSock, BOARDINFO, packetNum);
123    nodeStruct(currNode).serialNumber = temp(4);
124    nodeStruct(currNode).fpgaDNA = bitshift(temp(5),32)+temp(6);
125    nodeStruct(currNode).hwGeneration = bitand(bitshift(temp(7),-24),255);
126    nodeStruct(currNode).numRadios = bitand(bitshift(temp(7),-16),255);
127    nodeStruct(currNode).warplabVersion = double(bitand(bitshift(temp(7),-8),255))+double(bitand(temp(7),255))/10;
128%%%%
129
130end
131
132results{2} = nodeStruct;
133
134fprintf('\n\nResults Summary:\n');
135    fprintf('Node | S/N |HWGEN|WLVER|RADIO| ACK | SYNC\n');
136for currNode = 1:numNodes
137    fprintf('-----------------------------------------\n');
138   
139    if(nodeStruct(currNode).respondsToCommands==0)
140        ackStat = '   OK';
141    else
142        ackStat = ' FAIL';
143    end
144   
145    if(nodeStruct(currNode).receivesSync==0)
146        syncStat = '   OK';
147    else
148        syncStat = ' FAIL';
149    end
150   
151    if(nodeStruct(currNode).respondsToCommands==0)
152        fprintf('%5d|%5d|%5d|%5.1f|%5d|%s|%s\n',currNode,nodeStruct(currNode).serialNumber,nodeStruct(currNode).hwGeneration,nodeStruct(currNode).warplabVersion,nodeStruct(currNode).numRadios,ackStat,syncStat);
153    else
154        fprintf('%5d|     |     |     |     |%s|%s\n',currNode,ackStat,syncStat);
155    end
156end
157
158
159pnet('closeall');
Note: See TracBrowser for help on using the repository browser.