|
From: Shubham J. <shu...@da...> - 2013-10-08 07:32:16
|
Respected David Kopf sir,
It is something else. Java is unable to initialise the shared variable. It always sets it to 0.
Also, the iteration is outputting this 0(before loop), 1, 1, 2, 3, 4, ... in case of a single node in simulation.
If I use two nodes and increment at both, I get 0(before loop),1,0(before loop),1,1,2,3,4...
There is a one second timer in the loop.
Thanking you,
Yours sincerely,
Shubham Jain
----- Original Message -----
From: "Shubham Jain" <shu...@da...>
To: "David Kopf" <da...@em...>
Cc: "Contiki developer mailing list" <con...@li...>
Sent: Tuesday, October 8, 2013 12:05:24 PM
Subject: Re: [Contiki-developers] Sharing some variables among motes in cooja
Respected David Kopf sir,
I am still facing a small problem. The shared variable gets initialised again after one iteration.
The iteration consists of
mysharedvar++;
followed by debugs for printing (difference is also coming between PRINTF() and COOJA_DEBUG_PRINTF() in printing the initial value which comes 0 at one node even if I initialised it to 1 in java)
I have initialised in java and not in micro.
Even if I use only one node the variable gets initialised two times. I even tried
if(mysharedvar == 1) {
mysharedvar++;
mysharedvar--;
}
in the loop, but still after one iteration, it got re-initialised.
The loop is just a while(1). After two iterations, it works without any problem.
I have done this:
public synchronized void notifyWriteAfter(int dstAddress, int data, Memory.AccessMode mode) {
try {
MspMote.mySharedJavaVar = myMemory.getByteValueOf("mysharedvar");
System.out.println("mySharedJavaVar is"+MspMote.mySharedJavaVar);
} catch (EmulationException e) {
String trace = e.getMessage() + "\n\n" + getStackTrace();
throw (ContikiError)
new ContikiError(trace).initCause(e);
}
}
public synchronized void notifyReadBefore(int addr, Memory.AccessMode mode, Memory.AccessType type) {
try{
myMemory.setByteValueOf("mysharedvar",MspMote.mySharedJavaVar);//update the mote memory with the java global
System.out.println("mySharedJavaVar is"+MspMote.mySharedJavaVar);
} catch (EmulationException e) {
String trace = e.getMessage() + "\n\n" + getStackTrace();
throw (ContikiError)
new ContikiError(trace).initCause(e);
}
}
Kindly, help.
Thanking you,
Yours sincerely,
Shubham Jain
----- Original Message -----
From: "Shubham Jain" <shu...@da...>
To: "David Kopf" <da...@em...>
Cc: "Contiki developer mailing list" <con...@li...>
Sent: Monday, October 7, 2013 9:02:26 PM
Subject: Re: [Contiki-developers] Sharing some variables among motes in cooja
Respected David Kopf sir,
Problem was that I had not implemented notifyReadBefore(). Now it is working. Thanks a lot!
Yours sincerely,
Shubham Jain
----- Original Message -----
From: Shubham Jain <shu...@da...>
To: David Kopf <da...@em...>
Cc: Contiki developer mailing list <con...@li...>
Sent: Mon, 07 Oct 2013 19:19:46 +0530 (IST)
Subject: Re: [Contiki-developers] Sharing some variables among motes in cooja
Respected David Kopf sir,
addWatchPoint() gets called with the right addresses.
I declared mySharedJavaVar as public static. Still the variable is getting incremented independently in the two motes.
I made notifyWriteAfter as synchronized.
Each node's node id is also different for different nodes?
Does notifyObservers() do anything?
Thanking you,
Yours sincerely,
Shubham Jain
----- Original Message -----
From: David Kopf <da...@em...>
To: Shubham Jain <shu...@da...>
Cc: Contiki developer mailing list <con...@li...>
Sent: Mon, 07 Oct 2013 17:49:12 +0530 (IST)
Subject: Re: [Contiki-developers] Sharing some variables among motes in cooja
Is your watchpoint routine getting called with the correct value? Each node
will have a different instance so the mysharedvar memory address can be
different, but mySharedJavaVar has to be common among all instances. Perhaps
you are not creating that as a global java variable.
-----Original Message-----
From: Shubham Jain
Sent: Monday, October 07, 2013 5:23 AM
To: David Kopf
Cc: Contiki developer mailing list
Subject: Re: [Contiki-developers] Sharing some variables among motes in
cooja
Respected David Kopf sir,
I am now incrementing (mysharedvar) and printing in a while loop. Still I do
not get the same variable at both nodes although speed has increased :-).
Address in contiki-sky.map and varAddr are same. As I have two types of
motes udp-sender and udp-sink, two addresses get allocated to mysharedvar,
but I need sharing only at sink(s) so I use it but not able to still share
the variable among sinks also.
addMemoryMonitor was not compiling, so I have done the following similar to
node_id which is in interfaces/MspMoteID.java:
/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java
...
import se.sics.mspsim.core.Memory;
import se.sics.mspsim.core.Memory.AccessMode;
import se.sics.mspsim.core.MemoryMonitor;
public abstract class MspMote extends AbstractEmulatedMote implements Mote,
WatchpointMote {
...
private MemoryMonitor memM = null;
private byte mySharedJavaVar;// = 2;
...
private void addMonitor(String variable, GenericNode node,
MemoryMonitor monitor) {
int address = myMemory.getVariableAddress(variable);
node.getCPU().addWatchPoint(address, monitor);
}
/**
* Prepares CPU, memory and ELF module.
*
* @param fileELF ELF file
* @param cpu MSP430 cpu
* @throws IOException Preparing mote failed
*/
protected void prepareMote(File fileELF, GenericNode node) throws
IOException {
...
heapStartAddress = map.heapStartAddress;
if (memM == null) {
memM = new MemoryMonitor.Adapter() {
@Override
public void notifyWriteAfter(int dstAddress, int
data, Memory.AccessMode mode) {
try {
mySharedJavaVar = myMemory.getByteValueOf("mysharedvar");//Shubham
myMemory.setByteValueOf("mysharedvar",mySharedJavaVar);//update the mote
memory with the java global
} catch (EmulationException e) {
String trace = e.getMessage() + "\n\n" + getStackTrace();
throw (ContikiError)
new ContikiError(trace).initCause(e);
}
}
};
addMonitor("mysharedvar",node,memM);
}
myCpu.reset();
}
Thanking you,
Yours sincerely,
Shubham Jain
----- Original Message -----
From: David Kopf <da...@em...>
To: Shubham Jain <shu...@da...>
Cc: Contiki developer mailing list
<con...@li...>
Sent: Sun, 06 Oct 2013 22:24:07 +0530 (IST)
Subject: Re: [Contiki-developers] Sharing some variables among motes in
cooja
Well that should work, adding some prints to mspMoteMemory.java should show
what is going wrong. Compare the varAddr below with the address of your
global on the mote.
public byte getByteValueOf(String varName) throws UnknownVariableException {
MapEntry entry = getMapEntry(varName);
int varAddr = entry.getAddress();
byte[] varData = getMemorySegment(varAddr, 1);
return varData[0];
}
public void setByteValueOf(String varName, byte newVal) throws
UnknownVariableException {
MapEntry entry = getMapEntry(varName);
int varAddr = entry.getAddress();
byte[] varData = new byte[1];
varData[0] = newVal;
setMemorySegment(varAddr, varData);
}
I am not very familiar with the msp simulator would guess you
addMemoryMonitor during mote initialization, then then your notifyReadBefore
and notifyWriteAfter routines will get called when the variable is accessed.
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
MemoryCPUMonitor t = new MemoryCPUMonitor(mm, address, size);
cpuMonitorArray.add(t);
for (int a = address; a < address+size; a++) {
cpu.addWatchPoint(a, t);
}
return true;
}
-----Original Message-----
From: Shubham Jain
Sent: Sunday, October 06, 2013 11:24 AM
To: David Kopf
Cc: Contiki developer mailing list
Subject: Re: [Contiki-developers] Sharing some variables among motes in
cooja
Respected David Kopf sir,
I used byte in java and uint8_t in micro. I used ByteValue methods with the
right string (I had noticed it).
Still it remains 0. I did not increment as that would not make any
difference, I had initialised it to 2 in java.
Could you please elaborate on this: Fastest would be to have the simulator
give your custom routine a call only
when the RAM address is accessed (this is needed for example for
memory-mapped io registers)
|