wireless sensor network code error

조회 수: 1 (최근 30일)
Samah EL QASSAH
Samah EL QASSAH 2016년 6월 21일
댓글: Walter Roberson 2016년 6월 22일
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:
%
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 6월 21일
This appears to refer to the third-party package TrueTime
Samah EL QASSAH
Samah EL QASSAH 2016년 6월 22일
Yes, it's true.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
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.

추가 답변 (1개)

Samah EL QASSAH
Samah EL QASSAH 2016년 6월 22일
Thank you, I understand the problem.
This is my node on Simulink
Can you help me more? I have read about "mxCreateDoubleScalar" but I didn't understand what I have to do.
  댓글 수: 1
Walter Roberson
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 WSNs에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by