wireless sensor network code error
1 次查看(过去 30 天)
显示 更早的评论
I wrote a code to create a WSN with 7 nodes that communicate with each others and where node 7 receive a message from node 1. I have an error that I can't fixed. Help please!
code to initialize node 1:
function node1_init true
ttInitKernel('prioFP');% number of A/D inputs,number of D/A outputs,priority
% init parameters of task
data.a = 0;
data.K = 2;
offset = 0; % time offset is 0
data.exectime = 0.5;
period = 0.0010; % 10 ms, sets period for execution
prio = 1; % basic priority, lower numbers = higher priorities
ttCreatePeriodicTask('sens1_task', offset, period, prio, 'node1code', data);
ttSetPriority(prio, 'sens1_task');
Code node 1:
function [exectime, data] = node1code(seg, data)
switch seg,
case 1,
y = ttAnalogIn(1); % read analog input no 1,
data.a = -data.K * y;
exectime = rand*data.exectime; % we set executing time of read operation
case 2,
ttSendMsg(7, data.a, 80); % send 80 bits to node 3
exectime = 0.5; % we also set delay of this operations
case 3,
exectime = -1; % we are finished, don’t do delay
end
code to nitialize node 7:
function node7_init()
% Init kernel
ttInitKernel('prioFP')
codefcn = 'node7code';
data.u = 0;
prio = 1;
deadline = 10.0;
ttCreateTask('recv_task', deadline, prio, codefcn, data);
ttSetPriority(prio, 'recv_task');
ttAttachNetworkHandler('recv_task')
code node 7:
function [exectime, data] = node7code(seg, data)
switch seg,
case 1,
data.u = ttGetMsg; % read values from node
disp('I got a message');
exectime = 0.0005;
case 2,
ttAnalogOut(1, data.u);
exectime = -1;
end
I get this error:
%
采纳的回答
Walter Roberson
2016-6-21
According to the source code that error is generated when the value to be written is not a scalar double. I suggest you put in some simple code to display the size and class of data.u to see what you are getting instead.
0 个评论
更多回答(1 个)
Samah EL QASSAH
2016-6-22
1 个评论
Walter Roberson
2016-6-22
What you need to do is to add the code
disp(size(data.u))
disp(class(data.u))
before the ttAnalogOut call, and tell us what output was produced.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!