Permalink
Browse files

latest

  • Loading branch information...
1 parent b1a1a46 commit d8b104f5fca2c5e34bdbefdfaacc56f84489c572 @technocake technocake committed Mar 24, 2013
View
@@ -0,0 +1,10 @@
+# OS generated files #
+######################
+.DS_Store
+.DS_Store?
+._*
+.Spotlight-V100
+.Trashes
+Icon?
+ehthumbs.db
+Thumbs.db
@@ -70,11 +70,23 @@ def weGotMorePizzaAgain(switch):
+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() )))
+
+
if __name__ == '__main__':
print ("Init")
+
+ print ( list_com_ports())
+
+
COM_PORT = '/dev/tty.usbmodemfd121'
+
+
api = pnmp.api(COM_PORT)
print ( api.getNodeCount() )
View
@@ -4,7 +4,8 @@
#
# Python API for the PNMP protocol
#
-import serial
+import serial
+from serial.tools import list_ports
import time
class api():
@@ -31,6 +32,9 @@ def __init__(self, COM_PORT, BAUD_RATE=9600):
self.clean_the_mess_up_after_you() #die
+
+
+
def mapNodes(self, nodemap):
"""
This function is mapping a network node id
View
Binary file not shown.
@@ -0,0 +1,13 @@
+
+A debugging code that will run through a shiftregister, sending a pulse for each 8 bit. Counting the hops.
+
+ Arduino ----> shiftregisterloop
+ ^ |
+ |_________________|
+
+
+
+Pinout:
+
+see the fucking code :).
+
@@ -0,0 +1,130 @@
+
+
+/*
+ * 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
+
+/*
+ * 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
+
+
+#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
+/*____________________________________________________________
+ * END OF CONFIGURATION
+ */
+
+
+/* helper arrays */
+int CLK[number_of_cores] = {CLK1_Pin, CLK2_Pin};
+int RX[number_of_cores] = {RX1_Pin, RX2_Pin};
+int TX[number_of_cores] = {TX1_Pin, TX2_Pin};
+
+uint cores, bits_shifted, tot_nodes = 0;
+int nodes = 0;
+
+
+
+void setup(){
+ //Core #1
+ pinMode(TX1_Pin, OUTPUT);
+ pinMode(CLK1_Pin, OUTPUT);
+ pinMode(RX1_Pin, INPUT);
+ //Core #2
+ pinMode(TX2_Pin, OUTPUT);
+ pinMode(CLK2_Pin, OUTPUT);
+ pinMode(RX2_Pin, INPUT);
+
+ pinMode(MR_Pin, OUTPUT);
+
+
+ Serial.begin(9600);
+
+ //Determine how many nodes connected to each core:
+ tot_nodes = 0;
+ for (uint core = number_of_cores-1; core-- >0;;) {
+ nodes=0;
+ countNodes( core, &nodes);
+
+ if (nodes > 0)
+ tot_nodes += nodes;
+ }
+
+ Serial.print(tot_nodes)
+
+}
+
+
+
+
+void reset(int dt) {
+ digitalWrite(MR_Pin, LOW);
+ delay(dt);
+ digitalWrite(MR_Pin, HIGH);
+}
+
+// Dynamically count the number of nodes on one line.
+
+void countNodes (uint line, int * nodes) {
+ *nodes = 0;
+ int bkval = 0;
+ //reset
+ reset(count_delay);
+
+ do {
+ delay (count_delay);
+ digitalWrite(CLK[line], LOW);
+ //Sending pulse in an interval (@see RE_PULSE)
+ digitalWrite(TX[line], (*nodes)%RE_PULSE == 0);
+ digitalWrite(CLK[line], HIGH);
+ //Counting
+
+ } while ( int(bkval = digitalRead(RX[line])) == 0 && ((*nodes)++) < MAX_NODE_COUNT );
+
+ if (*nodes >= MAX_NODE_COUNT) {
+ *nodes = -1;
+ }
+
+}
+
+
+
+void loop(){
+
+
+ while (1) {
+ if (Serial.available() > 0) {
+
+ }
+ }
+
+
+ //CORE 1
+ countNodes(0, &nodes);
+ if (Serial.available() > 0) {
+
+ Serial.write("Core 1::\t %i nodes counted\n", nodes);
+ }
+
+ delay(1000);
+ // CORE 2
+ countNodes(1, &nodes);
+ if (Serial.available() > 0) {
+
+ printf("Core 2::\t %i nodes counted\n", nodes);
+ }
+}
@@ -43,6 +43,9 @@ static int uart_putchar (char c, FILE *stream)
return 0 ;
}
+
+
+
void setup(){
//Core #1
pinMode(TX1_Pin, OUTPUT);
@@ -64,6 +67,12 @@ void setup(){
// The uart is the standard output device STDOUT.
stdout = &uartout ;
+
+ delay(5);
+
+
+ Serial.print( availableMemory() );
+
}
@@ -101,21 +110,36 @@ void countNodes (int line, int * nodes) {
int nodes = 0;
+// this function will return the number of bytes currently free in RAM
+// written by David A. Mellis
+// based on code by Rob Faludi http://www.faludi.com
+int availableMemory() {
+ int size = 2048; // Use 2048 with ATmega328
+ byte *buf;
+
+ while ((buf = (byte *) malloc(--size)) == NULL)
+ ;
+
+ free(buf);
+
+ return size;
+}
+
void loop(){
//CORE 1
countNodes(0, &nodes);
if (Serial.available() > 0) {
- Serial.flush();
- printf("Core 1::\t %i nodes counted\n", nodes);
+ //Serial.flush();
+ //printf("Core 1::\t %i nodes counted\n", nodes);
}
delay(1000);
// CORE 2
countNodes(1, &nodes);
if (Serial.available() > 0) {
- Serial.flush();
- printf("Core 2::\t %i nodes counted\n", nodes);
+ //Serial.flush();
+ //printf("Core 2::\t %i nodes counted\n", nodes);
}
}

0 comments on commit d8b104f

Please sign in to comment.