Last active
August 29, 2015 14:04
-
-
Save wiless/8bd189af0e05933018b0 to your computer and use it in GitHub Desktop.
Sample code for executing link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/binary" | |
"flag" | |
"fmt" | |
"math/rand" | |
"net" | |
"strconv" | |
"time" | |
// "wiless/gocmm" | |
// "reflect" | |
"wiless/gocomm" | |
// "wiless/gocomm/cdma" | |
"wiless/gocomm/channel" | |
"wiless/gocomm/chipset" | |
"wiless/gocomm/modem" | |
"wiless/gocomm/sink" | |
"wiless/gocomm/sources" | |
) | |
var N int | |
var USERS int | |
func init() { | |
N = 20 | |
USERS = 1 | |
rand.Seed(time.Now().UTC().UnixNano()) | |
flag.Parse() | |
fmt.Printf("\n No of Args %d ", flag.NArg()) | |
if flag.NArg() == 0 { | |
fmt.Printf("\n Defaults : Using a frame of %d bits with %d users \n", N, USERS) | |
} else { | |
N, _ = strconv.Atoi(flag.Args()[0]) | |
USERS, _ = strconv.Atoi(flag.Args()[1]) | |
fmt.Printf("\n Using a frame of %d bits with %d users \n", N, USERS) | |
} | |
} | |
func main() { | |
t := time.Now() | |
bsrc := new(sources.BitSource) | |
bsrc.SetSize(N) | |
bsrc.InitializeChip() | |
// testmodem1 := sources.BitSource | |
testmodem2 := modem.NewModem(2) | |
demodem := modem.NewModem(2) | |
var chem channel.ChannelEmulator | |
chem.InitializeChip() | |
chem.SetNoise(0, 2) | |
// var newwire chipset.Wire | |
var wire1, wire2, wire3 chipset.Wire | |
var chip1, chip2, chip3 chipset.Chip | |
var chip4 chipset.Chip | |
bitch := (bsrc.PinByName("bitOut").Channel.(gocomm.BitChannel)) | |
// var bitch gocomm.BitChannel | |
// fmt.Printf("\n TYPE OF CHannel is %v", reflect.TypeOf(bitch)) | |
chip1 = bsrc | |
chip2 = testmodem2 | |
chip3 = demodem | |
chip4 = chem | |
wire1.Join(chip1, chip2) | |
wire2.Join(chip2, chip4) | |
wire3.Join(chip4, chip3) | |
go bsrc.GenBit(bitch) | |
var success bool | |
var outpin string | |
outpin = chip1.PinByID(chip1.ModuleByName("GenBit").OutPins[0]).Name | |
success, outpin = wire1.ConnectPins(outpin, "modulate") | |
success, outpin = wire2.ConnectPins(outpin, "awgn") | |
success, outpin = wire3.ConnectPins(outpin, "demodulate") | |
if success { | |
pin := wire3.DestinationChip.PinByName(outpin) | |
Sink(pin) | |
} | |
return | |
//< This waits till done is returned from all the USER's channel from the SinkData | |
// for i := 0; i < USERS; i++ { | |
// <-done[i] | |
// } | |
fmt.Println("\n", time.Now()) | |
fmt.Printf("\nTime Elaspsed %v \n", time.Since(t)) | |
} | |
func Sink(pin chipset.PinInfo) { | |
fmt.Printf("\n=======================\n Will Sink DataOut from Pin %v", pin) | |
count := 1 | |
switch pin.DataType.Name() { | |
case "BitChannel": | |
for i := 0; i < count; i++ { | |
// fmt.Printf("\n Status of Channel %d = %#v ", i, pin.Channel) | |
ddata := <-pin.Channel.(gocomm.BitChannel) | |
// fmt.Printf(" SPECIAL MESSAGE %s", ddata.Message) | |
if ddata.Message == "" { | |
fmt.Printf("\nPin : %s - Read Bit %d = %v ", pin.Name, i, ddata.Ch) | |
} else { | |
fmt.Printf("\nPin : %s - Read Bit %d = %v : %s", pin.Name, i, ddata.Ch, ddata.Message) | |
} | |
count = ddata.MaxExpected | |
// ddata := choutData.Ch | |
// max = choutData.MaxExpected | |
// fmt.Printf(" %d %d", uint8(real(ddata)), uint8(imag(ddata))) | |
// fmt.Printf("\n %d @ max Symbols limit = %d %s ", i, max, choutData.Message) | |
} | |
case "Complex128Channel": | |
for i := 0; i < count; i++ { | |
ddata := <-pin.Channel.(gocomm.Complex128Channel) | |
// fmt.Printf(" SPECIAL MESSAGE %s", ddata.Message) | |
if ddata.Message == "" { | |
fmt.Printf("\nPin : %s - Read Complex %d = %v ", pin.Name, i, ddata.Ch) | |
} else { | |
fmt.Printf("\nPin : %s - Read Complex %d = %v : %s", pin.Name, i, ddata.Ch, ddata.Message) | |
} | |
count = ddata.MaxExpected | |
// ddata := choutData.Ch | |
// max = choutData.MaxExpected | |
// fmt.Printf(" %d %d", uint8(real(ddata)), uint8(imag(ddata))) | |
// fmt.Printf("\n %d @ max Symbols limit = %d %s ", i, max, choutData.Message) | |
} | |
default: | |
fmt.Printf("\n Unknown Data type") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment