1

I have tried to implement convolution decoding using Viterbi algorithm in unetstack. However, there are some issues that I am facing.

  1. The data is not getting sent to node 2. (arr - line 43 of MulAgent.groovy )
  2. In some cases getting an error-

    groovy.lang.MissingMethodException:No signature of method:Script2.send() is applicable for argument types:(java.lang.Integer, java.lang.Integer)
    values: [2,1010]
    //where 2, 1010 are the input values that we are giving

mul-sim.groovy(first file that opens and asks for input of data)

import org.arl.fjage.Message
import org.arl.unet.*
import org.arl.mac.*
import org.arl.unet.phy.*

import org.arl.fjage.RealTimePlatform

println'''

OUTPUT TABLE
+----+----------+----------+
|    |    0     |    1     |
+----+----------+----------+
| a  | 00(a)    |  11(b)   |  
+----+----------+----------+
| b  | 10(c)    |  01(d)   |  
+----+----------+----------+
| c  | 11(a)    |  00(b)   |  
+----+----------+----------+
| d  | 01(c)    |  10(d)   |  
+----+----------+----------+ '''         
println '''
2-node network to perform sender - receiver operation
-----------------------------------------
Node 1 will send an encoded value to node 2

The agent MulAgent present at node 2, will decode the received data and send the value to node 1  checking

You can interact with node 1 in the console shell. For example, try:

    send <to-address> , <  data>

For example:

    send 2, 1011

When you are done, exit the shell by pressing ^D or entering:

    shutdown
    '''
    platform = RealTimePlatform
    // run simulation forever
    simulate {
         node '1', address: 1, remote: 1101, location: [0, 0, 0], shell: true,  stack: { container ->
       container.shell.addInitrc "${script.parent}/fshrc.groovy"
    }
    node '2', address: 2, remote: 1102, location: [1.km, 0, 0], shell:5102, stack: { container ->
    container.add 'mul', new MulAgent()
    }
    }

MulAgent.groovy( Agent file 

//Agent for the program that contains the decoding code import org.arl.fjage.Message import org.arl.unet.* import org.arl.mac.*

class MulAgent extends UnetAgent {

final static int PROTOCOL = Protocol.DATA int received_data int new_data def arr = new int[4][2] def temp = new int[2] def code=new int[4][2] int i int k int j = 0 int error_bit; int column_error = 0 int row_error = 0 int m = 4 int n = 4 int count

void startup() { def phy = agentForService Services.PHYSICAL subscribe topic(phy) }

void processMessage(Message msg) { if (msg instanceof DatagramNtf && msg.protocol == PROTOCOL) { for(i=0;i<2;i++) { temp[i] = msg.data[i] println "Recieved data printing in Agent is ${temp[i]}" }
for(i=0;i<2;i++) arr[j][i] = temp[i]; println "Array in Agent is ${arr}}" println "Recieved data printing in Agent is ${temp}"

  println "Recieved total data printing in Agent is ${temp}"
   send new DatagramReq(recipient: msg.sender,to: msg.from, protocol: Protocol.MAC, data: arr[j])
   j++

// start /*******************************************************************/ /* / / convolution decoding using viterbi / / ------------------------------------------ / / Step 1: take input as the encoded dataword / / Step 2: Sub module to calculate hamming distance /
/
Step 2: code for decoding using viterbi algorithm */
/*******************************************************************/ code=arr; int state[]=[0,,0,0,0,0,0,0] //state int mem[]=[0,0,0,0,0,0,0,0,0,0] //memory int path=0; //path matrix //int data[]=[1,1,0,1] int n,l; for (int j=0;j<4;j++) { for(int i=8;i>=0;i--) { mem[i+i]=mem[i]; //shifting by one bit } for (int i=0;i<8;i++) { state[i]=mem[i]; } //disp(mem); state[i]=0; //introduce 0 mem[i]=0; // to calculate the hamming distance int out1=((mem[1]^mem[2]^mem[4]^mem[5]^mem[6]^mem[7]^mem[8])^ ((mem[1]^mem[2]^mem[3]^mem[5]^mem[6]^mem[7]^mem[8])); //disp(out1); //output with 0 state[i]=1; //introduce 1 mem[i]=1; int out2=((mem[1]^mem[2]^mem[4]^mem[5]^mem[6]^mem[7]^mem[8])^ ((mem[1]^mem[2]^mem[3]^mem[5]^mem[6]^mem[7]^mem[8]));

int l=(code[j][0]^out1)+(code[j][1]^out)); //hamming distance with out1 int m=(code[j][0]^out2)+(code[j][1]^out2)); //hamming distance with out2

if(l<m)  {   //consider with minimum hamming distance
   path=path+l;
    state[1]=0;
    mem[1]=0;
    data[j]=0;}
else
 {   path=path+m;
    data[j]=1;
 }




if(l<m)    
  { path=path+l;
    decode[k]=0;}
else if(l>m)
 {   path=path+m;
     decode[k]=1;
 }

println"path value =$path" int code=data; }

def codew=new int[4][2] codew=code;//detecting 0 bit error int correct=0; int detect=0; int n; for(i=0;i<2;i++) if(codew[i][j]) codew[i][j]=0;

for(int i=0;i<4;i++)

    if(path!=0) //one error detected
     { if(y==codew) //corrected
      { correct=correct+1;
            detect=detect+1;
         }
        }      
    if(path!=0) //detected
      {  if(y!=codew) //not corrected
          {  detect=detect+1;
          }
        }
   n++;
    if(codew[i][j])
        codew[i][j]=0;
    else
        codew[i][j]=1;

} if(detect==0) println"detection completed" println"$code" else if(detect!=0) println"detection completed" println"$code"

}
}

fshrc.groovy (the received word is encoded and sent for decoding)

import org.arl.unet.* import org.arl.unet.phy.* import org.arl.unet.* import org.arl.unet.phy.* import org.arl.unet.mac.* //import org.arl.unet.nodeinfo.NodeInfo //import org.arl.unet.PDU import org.arl.fjage.* //import static org.arl.unet.Services.* //import static org.arl.unet.phy.Physical.*

subcribe phy

send = { addr, value -> println "sending $value to node $addr" def y= new int[4]; def a=new int[4]; a=[1, 1, 1, 1] y=[0, 0, 0, 0] int i=3 println "$value" int x=value;

while(x!=0) { y[i]=x%10; println "$y" x=x/10; i--; } def code=new int[4][2];

/*code word encoded using generator functions g1=1101 g2=1110 */

for(i=0;i<4;i++) {
int bit = y[3-i]; a[3-i] = bit;
code[i][0] = a[0]^a[1]^a[3]; code[i][1] = a[0]^a[1]^a[2]; }

println"The 4 bit encoded codeword:"

//The code word is printed

println"$code"

//println "sending ${value[0]} to node $addr "

phy << new DatagramReq(to: addr, protocol: Protocol.DATA, data: code[0])
def txNtf1= receive(TxFrameNtf, 1000)
def rxNtf1 = receive({ it instanceof RxFrameNtf && it.from == addr}, 5000)
  if (txNtf1 && rxNtf1 && rxNtf1.from == addr)
    println "Data Received at ${rxNtf.to} from ${rxNtf.from} is: ${rxNtf.data}" 

//println "sending ${value[1]} to node $addr " phy << new DatagramReq(to: addr, protocol: Protocol.DATA, data: code[1]) def txNtf2 = receive(TxFrameNtf, 1000) def rxNtf2 = receive({ it instanceof RxFrameNtf && it.from == addr}, 5000) if (txNtf2 && rxNtf2 && rxNtf2.from == addr) println "Data Received at ${rxNtf2.to} from ${rxNtf2.from} is: ${rxNtf2.data}"

// println "sending ${value[2]} to node $addr " phy << new DatagramReq(to: addr, protocol: Protocol.DATA, data: code[2]) def txNtf3 = receive(TxFrameNtf, 1000) def rxNtf3 = receive({ it instanceof RxFrameNtf && it.from == addr}, 5000) if (txNtf3 && rxNtf3 && rxNtf3.from == addr) println "Data Received at ${rxNtf3.to} from ${rxNtf3.from} is: ${rxNtf3.data}"

//println "sending ${value[3]} to node $addr " phy << new DatagramReq(to: addr, protocol: Protocol.DATA, data: code[3]) def txNtf4 = receive(TxFrameNtf, 1000) def rxNtf4 = receive({ it instanceof RxFrameNtf && it.from == addr}, 5000) if (txNtf4 && rxNtf4 && rxNtf4.from == addr) println "Data Received at ${rxNtf4.to} from ${rxNtf4.from} is: ${rxNtf4.data}"

}


marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
abha
  • 11
  • 1
  • I don't quite understand what you're trying to achieve with the code. For example, you have an example: `send 2, 1011`, but I can't see how this is implemented, or even what it is expected to do. The `send` shell command sends a message object, and doesn't take the arguments you have in the example. Also, you seem to be mixing your number system. It sounds like you want binary 1011, but the number 1011 is interpreted as a normal decimal number in Groovy/Java. – Mandar Chitre Apr 13 '19 at 07:13

0 Answers0