Skip to content

Commit

Permalink
patcher generating patchlist working. Needs update to get params from…
Browse files Browse the repository at this point in the history
… arduino
  • Loading branch information
technocake committed Mar 24, 2013
1 parent 726d822 commit 1367510
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
100 changes: 100 additions & 0 deletions pizzadaemon/patcher.py
@@ -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())










3 changes: 3 additions & 0 deletions pizzadaemon/pnmp.py
Expand Up @@ -155,3 +155,6 @@ def getNodeCount(self, line=-1):

def clean_the_mess_up_after_you(self):
self.arduino.close()



Binary file modified pizzadaemon/pnmp.pyc
Binary file not shown.

0 comments on commit 1367510

Please sign in to comment.