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 Center および File ExchangeWSNs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by