Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

lol

  • Loading branch information...
commit 54d5c529529b757dbde828fe75c734c2e2a04021 1 parent bc4fbdb
@technocake technocake authored
View
16 doc/patch-cable.txt
@@ -1,9 +1,9 @@
Bit Pin Farge
-A 2 dark orange
-B 1 light orange
-C 6 dark green
-D 3 light green
-E 4 dark blue blå
-F 5 light blue
-G 8 dark brown
-H 7 light brown
+1A 2 dark orange
+2B 1 light orange
+3C 6 dark green
+4D 3 light green
+5E 4 dark blue
+6F 5 light blue
+7G 8 dark brown
+8H 7 light brown
View
3  pizzadaemon/config-example.py
@@ -4,5 +4,6 @@
COM_PORT = '/dev/tty.usbmodemfd121'
URL = "File:///Users/technocake/code/pizza-netmap2/nms-simulator/switchlist.txt"
POLL_INTERVAL = 5 #Seconds between update
-
+COLOR_SUPPORT = False
+SWITCH_DELIM = "\s"
# END CONFIG
View
11 pizzadaemon/config.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+# coding: utf-8
+#CONFIG
+
+COM_PORT = '/dev/tty.usbmodemfd121'
+URL = "File:///Users/technocake/code/pizza-netmap2/nms-simulator/switchlist.txt"
+POLL_INTERVAL = 5 #Seconds between update
+COLOR_SUPPORT = False
+SWITCH_DELIM = "\s"
+
+# END CONFIG
View
BIN  pizzadaemon/config.pyc
Binary file not shown
View
33 pizzadaemon/patcher.py
@@ -10,20 +10,23 @@
import string
import re
-
-URL = "http://www.komsys.org/pizza-netmap/src/pizza-netmap2/nms-simulator/switchlist.txt"
-
-
-statusmap = [ re.split("\s", string.rstrip(u)) for u in urllib2.urlopen(URL).readlines() ]
-
-
-
-
-def color(i):
+from config import *
+#URL = "http://www.komsys.org/pizza-netmap/src/pizza-netmap2/nms-simulator/switchlist.txt"
+
+statusmap = [ re.split(SWITCH_DELIM, string.rstrip(u)) for u in urllib2.urlopen(URL).readlines() ]
+
+BOLD = '\033[1m'
+ENDC = '\033[0m'
+def color(i ,binary=False):
+ if binary and not COLOR_SUPPORT:
+ return ''
+ elif binary:
+ return ['\033[91m' , '\033[93m', '\033[92m', '\033[82m', '\033[94m', '\033[096m', '\033[090m', '\033[097m' ][i]
try:
return ["dark orange", "light orange", "dark green", "light green", "dark blue", "light blue", "dark brown", "light brown"][i]
except:
print "ERROR color"
+ return ''
@@ -41,7 +44,7 @@ def patchPins(lvl, c,d,p,n):
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))
+ res += "%s%s %u.%u.%u.%u (%s%s%s%s)\n" % ("\t"*lvl, statusmap[n-1][0], c,d,p,pin, BOLD, color(pin-1, True), color(pin-1), ENDC)
pin += 1
n += 1
return n, res
@@ -88,13 +91,5 @@ def patchCores(lvl=0,c=1,d=1,p=1,n=1 ):
return res
print ( patchCores())
-
-
-
-
-
-
-
-
View
24 pizzadaemon/pizzadaemon.py
@@ -12,7 +12,7 @@
#
# Config is in config.py. Edit that file.
##
-from config import *
+
# END CONFIG
@@ -25,7 +25,6 @@
def list_com_ports():
from serial.tools import list_ports
-
return "Choose serial device / COM port: \n %s" % '\n'.join(list("\t[%u] : %s" % (i, u[0]) for i,u in enumerate( list_ports.comports() )))
@@ -35,12 +34,31 @@ def list_com_ports():
print ("Init")
print ( list_com_ports())
+
+ from config import *
api = pnmp.api(COM_PORT)
+ #todo, implement..
+ #n_cores, distros_in_cores = api.getNetworkGraph()
+
+ print (
+ """
+ Pizzadaemon
+
+ ________________________________________________
+
+ Cores: %d\t Distros, per core: %s\t
+
+ """ % (2, str([3,2]))
+
+
+
+ )
+
try:
while 1:
- statusmap = [ re.split("\s", string.rstrip(u)) for u in urllib2.urlopen(URL).readlines() ]
+ statusmap = [ re.split(SWITCH_DELIM, string.rstrip(u)) for u in urllib2.urlopen(URL).readlines() ]
print ("Pushing state")
print (statusmap)
api.pushState(statusmap)
View
5 pizzadaemon/pnmp.py
@@ -25,6 +25,8 @@ class api():
PUSHSTATE = [0xF0, 0xF1] #1 bit signaling command and not data (first)
WRITE_LED = [0xF2]
+ GET_NETWORK_GRAPH = [0xF3]
+
def __init__(self, COM_PORT, BAUD_RATE=9600):
@@ -47,9 +49,6 @@ def __init__(self, COM_PORT, BAUD_RATE=9600):
except Exception as e:
print ("error, %s" % e )
self.clean_the_mess_up_after_you() #die
-
-
-
def mapNodes(self, nodemap):
View
BIN  pizzadaemon/pnmp.pyc
Binary file not shown
View
207 pizzanetmap_firmware/pizzanetmap_firmware.ino
@@ -1,36 +1,40 @@
#include "stdlib.h"
-/*
- * Core #1
- *
- */
+/* Core #1 */
+int TX1_Pin = 13; //SER (pin 14 on the 75HC595)
+int RX1_Pin = 12; //last output in a shiftregister chain.
+int CLK1_Pin = 11; //SRCLCK and RCLK
-int TX1_Pin = 13; //SER (pin 14 on the 75HC595)
-int RX1_Pin = 12; //last output in a shiftregister chain.
-int CLK1_Pin = 11; //SRCLCK and RCLK
-
-/*
- * Core #2
- *
- */
-int TX2_Pin = 10; //SER (pin 14 on the 75HC595)
-int RX2_Pin = 9; //last output in a shiftregister chain.
-int CLK2_Pin = 8; //SRCLCK and RCLK
+/* Core #2 */
+int TX2_Pin = 10; //SER (pin 14 on the 75HC595)
+int RX2_Pin = 9; //last output in a shiftregister chain.
+int CLK2_Pin = 8; //SRCLCK and RCLK
-int MR_Pin = 7; // Master Reset
+int MR_Pin = 7; // Master Reset
-#define count_delay 0 // Delay between node count. Visual fx only!
-#define RE_PULSE 8 // Repulse - timeslots between retransmitting pulse.
-#define MAX_NODE_COUNT 512 // if no BKTRK is connected.
-#define number_of_cores 2 // Core switches in use
-#define n_74hc595_per_distro 4 // Shift registers per distro
-#define n_shiftregister_pins 8 // Number of output pins on shiftreg.
+#define count_delay 0 // Delay between node count. Visual fx only!
+#define RE_PULSE 8 // Repulse - timeslots between retransmitting
+# // pulse. @see countNodes
+#define MAX_NODE_COUNT 512 // If no RX is connected, prevents infinity loop,
+# //but also limits supported nodes per core.
+#define number_of_cores 2 // Core switches in use
+#define n_74hc595_per_distro 4 // Shift registers per distro
+#define n_shiftregister_pins 8 // Number of output pins on shiftreg.
/*____________________________________________________________
* END OF CONFIGURATION
*/
+
+/*
+ * BEGIN Protocol
+ */
+#define PUSHSTATE 0xF0 // Start byte for stream of bits
+ // transmission
+#define ENDPUSHSTATE 0xF1 // Stop byte.
+#define WRITE_LED 0xF2 //
+#define GET_NETWORK_GRAPH 0xF3 // Getting stats from this pizzanetmap.
/*
@@ -59,13 +63,18 @@ int active_cores, bits_shifted, tot_nodes, nodes = 0;
char cb; //buffer
+/* functions */
+void writeRegisters();
+void reset(int dt);
+void countNodes (int line, int * nodes);
+
-/*###################################################################################
+/*#############################################################################
*
* SETUP
*
- *##################################################################################*/
+ *###########################################################################*/
void setup(){
//Core #1
@@ -79,31 +88,32 @@ void setup(){
//Reset
pinMode(MR_Pin, OUTPUT);
-
// For the API to work :).
Serial.begin(9600);
+
// Keeping track of core-statistics. i.e numbers.
core_stat = (_core *) malloc(number_of_cores * sizeof(_core));
- if (core_stat == NULL) {
- // No Memory!
- }
+ if (core_stat == NULL) { /* No Memory! */ }
+
//Determine how many nodes connected to each core:
tot_nodes = 0;
active_cores = 0;
- // 1, 2,3,4,5,6,7,8,9,10,11,12
+
+ // 1,2,3,4,5,6,7,8,9,10,11,12
for (int c=0; c < number_of_cores; c++) {
+
nodes=0;
countNodes( c, &nodes);
if (nodes > 0) {
- core_stat[c].n_distros = nodes / (n_shiftregister_pins * n_74hc595_per_distro);
- core_stat[c].n_pins = nodes;
- core_stat[c].active = true;
- tot_nodes += nodes;
- active_cores += 1;
+ core_stat[c].n_distros = nodes / (n_shiftregister_pins * n_74hc595_per_distro);
+ core_stat[c].n_pins = nodes;
+ core_stat[c].active = true;
+ tot_nodes += nodes;
+ active_cores += 1;
}
else { // Error occured
core_stat[c].n_distros = 0;
@@ -112,6 +122,7 @@ void setup(){
}
}
+
// Dynamically allocating the address space of all leds.
registers = (boolean *) malloc( tot_nodes * sizeof(boolean) );
if (registers != NULL) {
@@ -159,97 +170,79 @@ void countNodes (int line, int * nodes) {
void writeRegisters() {
reset(count_delay);
- int c = 0;
-
-
- /* drunken Ninja tricks to get the first active core */
- int i = 0;
- int b = 0;
- int ninja = 0;
-
- for (i = tot_nodes-1; i>=0; i--) {
-
- if ( b > core_stat[c].n_pins ){
- c++;
- b=0;
- }
-
-
-
- delay (count_delay);
- digitalWrite(CLK[c], LOW);
- //Sending pulse in an interval (@see RE_PULSE)
- digitalWrite(TX[c], int(registers[i]));
- digitalWrite(CLK[c], HIGH);
- b++;
-
- }
+ int c = 0; // Core index
+ int i = 0; // bits index on a total basis
+ int b = 0; // bits index on a per core basis
+ for (i = tot_nodes-1; i>=0; i--)
+ {
+ if ( b > core_stat[c].n_pins ){
+ c++;
+ b=0;
+ }
-}
-
-
+ // Shifting one bit: Setting Clk low, write data, Clk High
+ digitalWrite(CLK[c], LOW);
+ delay (count_delay);
+ digitalWrite(TX[c], int(registers[i]));
+ digitalWrite(CLK[c], HIGH);
+ b++;
+ }
+}
-char buffer[50];
-#define PUSHSTATE 0xF0
-#define ENDPUSHSTATE 0xF1
-#define WRITE_LED 0xF2
+/*#############################################################################
+ *
+ * L
+ * O
+ * O
+ * P
+ *###########################################################################*/
-boolean TRANSMIT = false;
-int bits;
-unsigned int rb = 0; // Received bits
+boolean RECV_BITS = false; // RECV_BITS state flag
+unsigned int rb = 0; // Received bits
void loop(){
- int cmd;
- int bytes;
- char led, * ledp;
- int led_int;
- int c;
+ int cmd; // cmd/data) buffer.
+ int bits; // CNAME --> cmd
+ int c; // Core index
if (Serial.available() > 0) {
- cmd = Serial.read();
+ cmd = Serial.read();
- if (!TRANSMIT && cmd == PUSHSTATE)
- {
- TRANSMIT = true;
- rb = 0;
- c=0;
- }
- else if (TRANSMIT && cmd == ENDPUSHSTATE)
- {
- TRANSMIT = false;
- writeRegisters();
-
- }
- else if (TRANSMIT) // Receiving chunk after chunk.
- {
- bits = cmd;
-
- for (int i = 0; i < 7; ++i)
- {
- if ( rb < core_stat[c].n_pins ) // Filling up one core at a time.
- registers[rb++] = ((bits & (0x01 << i )) != 0);
- else if (c < number_of_cores)
- {
- c++;
- rb = 0;
+ if (cmd == PUSHSTATE) {
+ RECV_BITS = true;
+ rb = 0;
+ c = 0;
+ bits_shifted = 0;
+ }else if (cmd == ENDPUSHSTATE) {
+ RECV_BITS = false;
+ writeRegisters();
+ }else if (RECV_BITS) { // Receiving chunk after chunk.
+
+ bits = cmd;
+
+ for (int i = 0; i < 7; ++i) {
+ // Filling up one core at a time, bit for bit.
+ if ( rb < core_stat[c].n_pins ) {
+ registers[rb++] = ((bits & (0x01 << i )) != 0);
+ bits_shifted++;
}
+ else if (c < number_of_cores) {
+ c++;
+ rb = 0;
+ }//end else if
+ }//end for
- }
- }
+ } //end if
+ } // end serial if
+} //end loop
-
- }
-
-
-}
-
Please sign in to comment.
Something went wrong with that request. Please try again.