-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patcher generating patchlist working. Needs update to get params from…
… arduino
- Loading branch information
1 parent
726d822
commit 1367510
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env python | ||
#coding: utf-8 | ||
|
||
# | ||
# Code to create patchlist for the pizzanetmap :) | ||
# | ||
|
||
import pnmp | ||
import urllib2 | ||
import string | ||
import re | ||
|
||
|
||
URL = "http://www.komsys.org/pizza-netmap/src/pizza-netmap2/nms-simulator/switchlist.txt" | ||
COM_PORT = '/dev/tty.usbmodemfd121' | ||
|
||
statusmap = [ re.split("\s", string.rstrip(u)) for u in urllib2.urlopen(URL).readlines() ] | ||
|
||
arduino = pnmp.api(COM_PORT) | ||
|
||
|
||
def color(i): | ||
try: | ||
return ["light orange", "orange", "green", "light blue", "blue", "light green", "light brown", "brown"][i] | ||
except: | ||
print "ERROR color" | ||
|
||
|
||
|
||
|
||
|
||
num_ports = 4 | ||
num_cores = 2 | ||
|
||
distros_in_core = [2,3] | ||
|
||
|
||
def patchPins(lvl, c,d,p,n): | ||
res="" | ||
pin=1 | ||
while pin <= 8: | ||
if (n >= len(statusmap)): | ||
return n,res | ||
res += "%s%s %u.%u.%u.%u (%s)\n" % ("\t"*lvl, statusmap[n-1][0], c,d,p,pin, color(pin-1)) | ||
pin += 1 | ||
n += 1 | ||
return n, res | ||
|
||
|
||
def patchPorts(lvl, c,d,p,n): | ||
res="" | ||
res2 = "" | ||
for p in range(1, num_ports+1): | ||
res += "\n%s#Port %u\n" % ("\t"*lvl, p) | ||
n, res2 = patchPins(lvl+1, c,d,p,n) | ||
res += res2 | ||
return n, res | ||
|
||
def patchDistros(lvl, c,d,p,n): | ||
res="" | ||
res2 = "" | ||
for d in range(1, distros_in_core[c-1]+1): | ||
res += "\n%s#Distro %u\n" % ("\t"*lvl, d) | ||
n,res2 = patchPorts(lvl+1,c,d,p,n) | ||
res += res2 | ||
return n, res | ||
|
||
|
||
|
||
def patchCores(lvl=0,c=1,d=1,p=1,n=1 ): | ||
res="" | ||
res2="" | ||
|
||
n=1 | ||
c=1 | ||
d=1 | ||
p=1 | ||
res += """ | ||
#Patchlist.txt | ||
#sysname core.distro.port.pin | ||
""" | ||
for c in range(1, num_cores+1): | ||
d=1 | ||
res += "\n%s#Core %u\n" % ("\t"*lvl, c) | ||
n, res2 = patchDistros(lvl+1, c,d,p,n) | ||
res += res2 | ||
return res | ||
|
||
print ( patchCores()) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,3 +155,6 @@ def getNodeCount(self, line=-1): | |
|
||
def clean_the_mess_up_after_you(self): | ||
self.arduino.close() | ||
|
||
|
||
|
Binary file not shown.