Permalink
Browse files

Fixed a operator precedence bug in reading bits from serial

  • Loading branch information...
1 parent d7d2530 commit bc4fbdbd90d1e870681d0e4ffcc44e26f3f1d512 @technocake technocake committed Mar 26, 2013
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#CONFIG
-COM_PORT = '/dev/tty.usbmodemfa131'
+COM_PORT = '/dev/tty.usbmodemfd121'
URL = "File:///Users/technocake/code/pizza-netmap2/nms-simulator/switchlist.txt"
POLL_INTERVAL = 5 #Seconds between update
View
Binary file not shown.
@@ -34,7 +34,7 @@ def list_com_ports():
if __name__ == '__main__':
print ("Init")
- #print ( list_com_ports())
+ print ( list_com_ports())
api = pnmp.api(COM_PORT)
View
Binary file not shown.
@@ -234,7 +234,7 @@ void loop(){
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);
+ registers[rb++] = ((bits & (0x01 << i )) != 0);
else if (c < number_of_cores)
{
c++;
@@ -0,0 +1,2 @@
+build:
+ gcc -std=c99 bitmanip.c -o bitmanip
View
Binary file not shown.
@@ -0,0 +1,66 @@
+#include "stdio.h"
+#include "stdlib.h"
+#include "stdbool.h"
+#define number_of_cores 2
+
+
+/*
+ * Struct to keep track on how many distro switches,
+ * and pins are connected to each core switch.
+ */
+
+typedef struct
+{
+ int n_distros;
+ int n_pins;
+ bool active;
+} _core;
+
+ _core * core_stat;
+
+
+
+int main(int argc, char const *argv[])
+{
+
+ core_stat = (_core *) malloc(number_of_cores * sizeof(_core));
+ if (core_stat != NULL) {
+ core_stat[0].n_distros = 4;
+ core_stat[0].n_pins = 32;
+ core_stat[0].active = 1;
+ core_stat[1].n_distros = 4;
+ core_stat[1].n_pins = 32;
+ core_stat[1].active = 1;
+ }
+
+ int c = 0;
+ int rb = 0;
+
+ bool registers[9] = {true, false,true,true,true,true,true,true,true};
+ bool val;
+
+ int bits = 0x92;
+
+
+ for (int i = 0; i < 7; ++i)
+ {
+ if ( rb < core_stat[c].n_pins ) {// Filling up one core at a time.
+ val = ((bits & (0x01 << i )) != 0);
+ registers[rb++] = val;
+ if (val)
+ printf("1" );
+ else
+ printf("0");
+ }
+ else if (c < number_of_cores)
+ {
+ c++;
+ rb = 0;
+
+
+ }
+
+ }
+ return 0;
+}
+

0 comments on commit bc4fbdb

Please sign in to comment.