From 522c47fbbb9d2d3d39e9a8a76fa59a45630b3e4e Mon Sep 17 00:00:00 2001 From: Donald Delmar Davis Date: Fri, 24 May 2013 19:26:25 -0700 Subject: Its alive. There are some minor issues. --- RetoolingForOpenSprints/NewClock/NewClock.ino | 88 ++++++++ .../NewClock/NewClock/NewClock.ino | 85 -------- .../RaceInABox2/RaceInABox2.ino | 61 ++++++ .../RaceInABox2/RaceInABox2/RaceInABox2.ino | 61 ------ RetoolingForOpenSprints/basic_msg/basic_msg.ino | 229 +++++++++++++++++++++ .../basic_msg/basic_msg/basic_msg.ino | 229 --------------------- RetoolingForOpenSprints/raceinabox/bikewedge.py | 97 +++++++++ RetoolingForOpenSprints/raceinabox/netsuck.py | 77 ------- 8 files changed, 475 insertions(+), 452 deletions(-) create mode 100644 RetoolingForOpenSprints/NewClock/NewClock.ino delete mode 100644 RetoolingForOpenSprints/NewClock/NewClock/NewClock.ino create mode 100644 RetoolingForOpenSprints/RaceInABox2/RaceInABox2.ino delete mode 100644 RetoolingForOpenSprints/RaceInABox2/RaceInABox2/RaceInABox2.ino create mode 100644 RetoolingForOpenSprints/basic_msg/basic_msg.ino delete mode 100644 RetoolingForOpenSprints/basic_msg/basic_msg/basic_msg.ino create mode 100644 RetoolingForOpenSprints/raceinabox/bikewedge.py delete mode 100644 RetoolingForOpenSprints/raceinabox/netsuck.py (limited to 'RetoolingForOpenSprints') diff --git a/RetoolingForOpenSprints/NewClock/NewClock.ino b/RetoolingForOpenSprints/NewClock/NewClock.ino new file mode 100644 index 0000000..22194c3 --- /dev/null +++ b/RetoolingForOpenSprints/NewClock/NewClock.ino @@ -0,0 +1,88 @@ +/*------------------------------------------------------------------------------------ + * rough in of new clock. + * bikewedge proxy provides the number of steps wanted from goldsprints data. + * this should do some pid ling around so that it will be less jerkey. + * requires the modified stepper motors to do half stepping. + * + * (c) 2013 Donald Delmar Davis, Suspect Devices + * + */ + +#include +#define MIN_MILLIS_PER_STEP 8 +#define STEPPER_STEPS 200 +#define STEPS_PER_REVOLUTION 2132 +#define INBUFFERLENGTH 100 +char inbuffer[INBUFFERLENGTH]; +int bufferIndex; +int yellowGoal=0; +int blueGoal=0; +int yellowPosition=0; +int bluePosition=0; +int stepCount = 0; +long int lastStepMillis; + +Stepper blue(STEPPER_STEPS, 8,9,10,11,1); +Stepper yellow(STEPPER_STEPS, 2,3,4,5,1); + +void setup() { + // initialize the serial port: + Serial.begin(115200); +} + +void loop() { + int target; + while (Serial.available()) { + // get the new byte: + char inChar = (char)Serial.read(); + // add it to the inputString: + if (bufferIndex3) { + target=atoi(inbuffer+3); + if (target>STEPS_PER_REVOLUTION) target=STEPS_PER_REVOLUTION; + if (inbuffer[1]=='1') { + blueGoal=target; + Serial.println(inbuffer+3); + } else { + yellowGoal=target; + } + } else if (inbuffer[0]=='v') { + Serial.println("RaceClock 0.1"); + Serial.flush(); + } else if (inbuffer[0]=='s') { + if (blueGoal||yellowGoal) { + blueGoal=yellowGoal=STEPS_PER_REVOLUTION; + } + } + + bufferIndex=0; //reset input + + } + } + if ((millis()-lastStepMillis)>MIN_MILLIS_PER_STEP){ + if ((blueGoal==STEPS_PER_REVOLUTION)&&((bluePosition==0)||(blueGoal==bluePosition))){ + blueGoal=bluePosition=0; + } + if ((yellowGoal==STEPS_PER_REVOLUTION)&&((yellowPosition==0)||(yellowGoal==yellowPosition))){ + yellowGoal=yellowPosition=0; + } + + if ((blueGoal>bluePosition) && (bluePositionyellowPosition) && (yellowPosition -#define MIN_MILLIS_PER_STEP 3 -#define STEPPER_STEPS 200 -#define STEPS_PER_REVOLUTION 2132 // for your motor -#define INBUFFERLENGTH 100 -char inbuffer[INBUFFERLENGTH]; -int bufferIndex; -int yellowGoal=0; -int blueGoal=0; -int yellowPosition=0; -int bluePosition=0; -int stepCount = 0; // number of steps the motor has taken -long int lastStepMillis; - -Stepper blue(STEPPER_STEPS, 8,9,10,11,1); -Stepper yellow(STEPPER_STEPS, 2,3,4,5,1); - -void setup() { - // initialize the serial port: - Serial.begin(115200); -} - -void loop() { - int target; - while (Serial.available()) { - // get the new byte: - char inChar = (char)Serial.read(); - // add it to the inputString: - if (bufferIndex3) { - target=atoi(inbuffer+3); - if (target>STEPS_PER_REVOLUTION)target=STEPS_PER_REVOLUTION; - if (inbuffer[1]=='1') { - blueGoal=target;//analogWrite(MOTOR1PWM,bike1speed); - Serial.println(inbuffer+3); - Serial.print("blueGoal="); Serial.println(blueGoal); - Serial.print("bluePosition="); Serial.println(bluePosition); - } else { - yellowGoal=target;//analogWrite(MOTOR2PWM,bike1speed); - } - } else if (inbuffer[0]=='v') { - Serial.println("RaceClock 0.1"); - Serial.flush(); - } else if (inbuffer[0]=='s') { - blueGoal=yellowGoal=STEPS_PER_REVOLUTION; - } - - bufferIndex=0; //reset input - - } - } - if ((millis()-lastStepMillis)>MIN_MILLIS_PER_STEP){ - if ((blueGoal>bluePosition) && (bluePosition<=STEPS_PER_REVOLUTION)){ - blue.step(-1); - bluePosition++; - } - - if ((yellowGoal>yellowPosition) && (yellowPosition<=STEPS_PER_REVOLUTION)) { - yellow.step(-1); - yellowPosition++; - } - lastStepMillis=millis(); - } - if ((bluePosition==STEPS_PER_REVOLUTION)&&(blueGoal==bluePosition)){ - blueGoal=bluePosition=0; - } - if ((yellowPosition==STEPS_PER_REVOLUTION)&&(yellowGoal==yellowPosition)){ - yellowGoal=yellowPosition=0; - } - -} - - diff --git a/RetoolingForOpenSprints/RaceInABox2/RaceInABox2.ino b/RetoolingForOpenSprints/RaceInABox2/RaceInABox2.ino new file mode 100644 index 0000000..06a3251 --- /dev/null +++ b/RetoolingForOpenSprints/RaceInABox2/RaceInABox2.ino @@ -0,0 +1,61 @@ +/* + RaceInABox + + */ +#define MOTOR1DIR 2 +#define MOTOR2DIR 4 +#define MOTOR1PWM 3 +#define MOTOR2PWM 5 +#define MOTOR1CLOCKWISE digitalWrite(MOTOR1DIR, HIGH); +#define MOTOR1COUNTERCLOCKWISE digitalWrite(MOTOR1DIR, LOW); +#define MOTOR2CLOCKWISE digitalWrite(MOTOR2DIR, HIGH); +#define MOTOR2COUNTERCLOCKWISE digitalWrite(MOTOR2DIR, LOW); +#define INBUFFERLENGTH 32 +char inbuffer[INBUFFERLENGTH]; + +void setup() { + Serial.begin(115200); + pinMode(MOTOR1DIR, OUTPUT); + pinMode(MOTOR2DIR, OUTPUT); + pinMode(MOTOR1PWM, OUTPUT); + pinMode(MOTOR2PWM, OUTPUT); + analogWrite(MOTOR1PWM, 0); + analogWrite(MOTOR2PWM, 0); + + MOTOR1CLOCKWISE; + MOTOR2CLOCKWISE; +} +bool isClockwise = true; +uint8_t bufferIndex=0; +uint8_t bike1speed; + +void loop() { + while (Serial.available()) { + // get the new byte: + char inChar = (char)Serial.read(); + // add it to the inputString: + if (bufferIndex3) { + bike1speed=(uint8_t) atoi(inbuffer+3); + if (inbuffer[1]=='1') { + analogWrite(MOTOR1PWM,bike1speed); + } else { + analogWrite(MOTOR2PWM,bike1speed); + } + } else if (inbuffer[0]=='v') { + Serial.println("RaceInABox 0.1"); + Serial.flush(); + } + + bufferIndex=0; //reset input + + } +} +} + + diff --git a/RetoolingForOpenSprints/RaceInABox2/RaceInABox2/RaceInABox2.ino b/RetoolingForOpenSprints/RaceInABox2/RaceInABox2/RaceInABox2.ino deleted file mode 100644 index 06a3251..0000000 --- a/RetoolingForOpenSprints/RaceInABox2/RaceInABox2/RaceInABox2.ino +++ /dev/null @@ -1,61 +0,0 @@ -/* - RaceInABox - - */ -#define MOTOR1DIR 2 -#define MOTOR2DIR 4 -#define MOTOR1PWM 3 -#define MOTOR2PWM 5 -#define MOTOR1CLOCKWISE digitalWrite(MOTOR1DIR, HIGH); -#define MOTOR1COUNTERCLOCKWISE digitalWrite(MOTOR1DIR, LOW); -#define MOTOR2CLOCKWISE digitalWrite(MOTOR2DIR, HIGH); -#define MOTOR2COUNTERCLOCKWISE digitalWrite(MOTOR2DIR, LOW); -#define INBUFFERLENGTH 32 -char inbuffer[INBUFFERLENGTH]; - -void setup() { - Serial.begin(115200); - pinMode(MOTOR1DIR, OUTPUT); - pinMode(MOTOR2DIR, OUTPUT); - pinMode(MOTOR1PWM, OUTPUT); - pinMode(MOTOR2PWM, OUTPUT); - analogWrite(MOTOR1PWM, 0); - analogWrite(MOTOR2PWM, 0); - - MOTOR1CLOCKWISE; - MOTOR2CLOCKWISE; -} -bool isClockwise = true; -uint8_t bufferIndex=0; -uint8_t bike1speed; - -void loop() { - while (Serial.available()) { - // get the new byte: - char inChar = (char)Serial.read(); - // add it to the inputString: - if (bufferIndex3) { - bike1speed=(uint8_t) atoi(inbuffer+3); - if (inbuffer[1]=='1') { - analogWrite(MOTOR1PWM,bike1speed); - } else { - analogWrite(MOTOR2PWM,bike1speed); - } - } else if (inbuffer[0]=='v') { - Serial.println("RaceInABox 0.1"); - Serial.flush(); - } - - bufferIndex=0; //reset input - - } -} -} - - diff --git a/RetoolingForOpenSprints/basic_msg/basic_msg.ino b/RetoolingForOpenSprints/basic_msg/basic_msg.ino new file mode 100644 index 0000000..21a94c7 --- /dev/null +++ b/RetoolingForOpenSprints/basic_msg/basic_msg.ino @@ -0,0 +1,229 @@ +/* + * Arduino wiring: + * + * Digital pin Connected to + * ----------- ------------ + * 2 Sensor 0 + * 3 Sensor 1 + * 4 Sensor 2 + * 5 Sensor 3 + * + * 9 Racer0 Start LED anode, Stop LED cathode + * 10 Racer1 Start LED anode, Stop LED cathode + * 11 Racer2 Start LED anode, Stop LED cathode + * 12 Racer3 Start LED anode, Stop LED cathode + * + */ + +int statusLEDPin = 13; +long statusBlinkInterval = 250; +int lastStatusLEDValue = LOW; +long previousStatusBlinkMillis = 0; + +boolean raceStarted = false; +boolean raceStarting = false; +boolean mockMode = false; +unsigned long raceStartMillis; +unsigned long currentTimeMillis; + +int val = 0; + +int racer0GoLedPin = 9; +int racer1GoLedPin = 10; +int racer2GoLedPin = 11; +int racer3GoLedPin = 12; + +int sensorPins[4] = {2,3,4,5}; +int previoussensorValues[4] = {HIGH,HIGH,HIGH,HIGH}; +int values[4] = {0,0,0,0}; +unsigned long racerTicks[4] = {0,0,0,0}; +unsigned long racerFinishTimeMillis[4]; + +unsigned long lastCountDownMillis; +int lastCountDown; + +unsigned int charBuff[8]; +unsigned int charBuffLen = 0; +boolean isReceivingRaceLength = false; + +int raceLengthTicks = 20; +int previousFakeTickMillis = 0; + +int updateInterval = 50; +unsigned long lastUpdateMillis = 0; + +void setup() { + Serial.begin(115200); + pinMode(statusLEDPin, OUTPUT); + pinMode(racer0GoLedPin, OUTPUT); + pinMode(racer1GoLedPin, OUTPUT); + pinMode(racer2GoLedPin, OUTPUT); + pinMode(racer3GoLedPin, OUTPUT); + digitalWrite(racer0GoLedPin, LOW); + digitalWrite(racer1GoLedPin, LOW); + digitalWrite(racer2GoLedPin, LOW); + digitalWrite(racer3GoLedPin, LOW); + for(int i=0; i<=3; i++) + { + pinMode(sensorPins[i], INPUT); + digitalWrite(sensorPins[i], HIGH); + } + +} + +void blinkLED() { + if (millis() - previousStatusBlinkMillis > statusBlinkInterval) { + previousStatusBlinkMillis = millis(); + + lastStatusLEDValue = !lastStatusLEDValue; + + digitalWrite(statusLEDPin, lastStatusLEDValue); + } + +} + +void raceStart() { + raceStartMillis = millis(); +} + + +void checkSerial(){ + if(Serial.available()) { + val = Serial.read(); + if(isReceivingRaceLength) { + if(val != '\r') { + charBuff[charBuffLen] = val; + charBuffLen++; + } + else if(charBuffLen==2) { + // received all the parts of the distance. time to process the value we received. + // The maximum for 2 chars would be 65 535 ticks. + // For a 0.25m circumference roller, that would be 16384 meters = 10.1805456 miles. + raceLengthTicks = charBuff[1] * 256 + charBuff[0]; + isReceivingRaceLength = false; + Serial.print("OK "); + Serial.println(raceLengthTicks,DEC); + } + else { + Serial.println("ERROR receiving tick lengths"); + } + } + else { + if(val == 'l') { + charBuffLen = 0; + isReceivingRaceLength = true; + } + if(val == 'v') { + Serial.print("basic-1"); + } + if(val == 'g') { + for(int i=0; i<=3; i++) + { + racerTicks[i] = 0; + racerFinishTimeMillis[i] = 256*0; + } + + raceStarting = true; + raceStarted = false; + lastCountDown = 4; + lastCountDownMillis = millis(); + } + + else if(val == 'm') { + // toggle mock mode + mockMode = !mockMode; + } + + if(val == 's') { + raceStarted = false; + + digitalWrite(racer0GoLedPin,LOW); + digitalWrite(racer1GoLedPin,LOW); + digitalWrite(racer2GoLedPin,LOW); + digitalWrite(racer3GoLedPin,LOW); + } + } + } +} + +void printStatusUpdate() { + if(currentTimeMillis - lastUpdateMillis > updateInterval) { + lastUpdateMillis = currentTimeMillis; + for(int i=0; i<=3; i++) + { + Serial.print(i); + Serial.print(": "); + Serial.println(racerTicks[i], DEC); + } + Serial.print("t: "); + Serial.println(currentTimeMillis, DEC); + } +} + +void loop() { + blinkLED(); + + checkSerial(); + + + if (raceStarting) { + if((millis() - lastCountDownMillis) > 1000){ + lastCountDown -= 1; + lastCountDownMillis = millis(); + } + if(lastCountDown == 0) { + raceStart(); + raceStarting = false; + raceStarted = true; + + digitalWrite(racer0GoLedPin,HIGH); + digitalWrite(racer1GoLedPin,HIGH); + digitalWrite(racer2GoLedPin,HIGH); + digitalWrite(racer3GoLedPin,HIGH); + } + } + if (raceStarted) { + currentTimeMillis = millis() - raceStartMillis; + + for(int i=0; i<=3; i++) + { + if(!mockMode) { + values[i] = digitalRead(sensorPins[i]); + if(values[i] == HIGH && previoussensorValues[i] == LOW){ + racerTicks[i]++; + if(racerFinishTimeMillis[i] == 0 && racerTicks[i] >= raceLengthTicks) { + racerFinishTimeMillis[i] = currentTimeMillis; + Serial.print(i); + Serial.print("f: "); + Serial.println(racerFinishTimeMillis[i], DEC); + digitalWrite(racer0GoLedPin+i,LOW); + } + } + previoussensorValues[i] = values[i]; + } + else { + if(currentTimeMillis - lastUpdateMillis > updateInterval) { + racerTicks[i]+=(i+1); + if(racerFinishTimeMillis[i] == 0 && racerTicks[i] >= raceLengthTicks) { + racerFinishTimeMillis[i] = currentTimeMillis; + Serial.print(i); + Serial.print("f: "); + Serial.println(racerFinishTimeMillis[i], DEC); + digitalWrite(racer0GoLedPin+i,LOW); + } + } + } + } + } + + + if(racerFinishTimeMillis[0] != 0 && racerFinishTimeMillis[1] != 0 && racerFinishTimeMillis[2] != 0 && racerFinishTimeMillis[3] != 0){ + if(raceStarted) { + raceStarted = false; + printStatusUpdate(); + } + } else { + printStatusUpdate(); + } +} + diff --git a/RetoolingForOpenSprints/basic_msg/basic_msg/basic_msg.ino b/RetoolingForOpenSprints/basic_msg/basic_msg/basic_msg.ino deleted file mode 100644 index 55d52c3..0000000 --- a/RetoolingForOpenSprints/basic_msg/basic_msg/basic_msg.ino +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Arduino wiring: - * - * Digital pin Connected to - * ----------- ------------ - * 2 Sensor 0 - * 3 Sensor 1 - * 4 Sensor 2 - * 5 Sensor 3 - * - * 9 Racer0 Start LED anode, Stop LED cathode - * 10 Racer1 Start LED anode, Stop LED cathode - * 11 Racer2 Start LED anode, Stop LED cathode - * 12 Racer3 Start LED anode, Stop LED cathode - * - */ - -int statusLEDPin = 13; -long statusBlinkInterval = 250; -int lastStatusLEDValue = LOW; -long previousStatusBlinkMillis = 0; - -boolean raceStarted = false; -boolean raceStarting = false; -boolean mockMode = false; -unsigned long raceStartMillis; -unsigned long currentTimeMillis; - -int val = 0; - -int racer0GoLedPin = 9; -int racer1GoLedPin = 10; -int racer2GoLedPin = 11; -int racer3GoLedPin = 12; - -int sensorPins[4] = {2,3,4,5}; -int previoussensorValues[4] = {HIGH,HIGH,HIGH,HIGH}; -int values[4] = {0,0,0,0}; -unsigned long racerTicks[4] = {0,0,0,0}; -unsigned long racerFinishTimeMillis[4]; - -unsigned long lastCountDownMillis; -int lastCountDown; - -unsigned int charBuff[8]; -unsigned int charBuffLen = 0; -boolean isReceivingRaceLength = false; - -int raceLengthTicks = 20; -int previousFakeTickMillis = 0; - -int updateInterval = 250; -unsigned long lastUpdateMillis = 0; - -void setup() { - Serial.begin(115200); - pinMode(statusLEDPin, OUTPUT); - pinMode(racer0GoLedPin, OUTPUT); - pinMode(racer1GoLedPin, OUTPUT); - pinMode(racer2GoLedPin, OUTPUT); - pinMode(racer3GoLedPin, OUTPUT); - digitalWrite(racer0GoLedPin, LOW); - digitalWrite(racer1GoLedPin, LOW); - digitalWrite(racer2GoLedPin, LOW); - digitalWrite(racer3GoLedPin, LOW); - for(int i=0; i<=3; i++) - { - pinMode(sensorPins[i], INPUT); - digitalWrite(sensorPins[i], HIGH); - } - -} - -void blinkLED() { - if (millis() - previousStatusBlinkMillis > statusBlinkInterval) { - previousStatusBlinkMillis = millis(); - - lastStatusLEDValue = !lastStatusLEDValue; - - digitalWrite(statusLEDPin, lastStatusLEDValue); - } - -} - -void raceStart() { - raceStartMillis = millis(); -} - - -void checkSerial(){ - if(Serial.available()) { - val = Serial.read(); - if(isReceivingRaceLength) { - if(val != '\r') { - charBuff[charBuffLen] = val; - charBuffLen++; - } - else if(charBuffLen==2) { - // received all the parts of the distance. time to process the value we received. - // The maximum for 2 chars would be 65 535 ticks. - // For a 0.25m circumference roller, that would be 16384 meters = 10.1805456 miles. - raceLengthTicks = charBuff[1] * 256 + charBuff[0]; - isReceivingRaceLength = false; - Serial.print("OK "); - Serial.println(raceLengthTicks,DEC); - } - else { - Serial.println("ERROR receiving tick lengths"); - } - } - else { - if(val == 'l') { - charBuffLen = 0; - isReceivingRaceLength = true; - } - if(val == 'v') { - Serial.print("basic-1"); - } - if(val == 'g') { - for(int i=0; i<=3; i++) - { - racerTicks[i] = 0; - racerFinishTimeMillis[i] = 256*0; - } - - raceStarting = true; - raceStarted = false; - lastCountDown = 4; - lastCountDownMillis = millis(); - } - - else if(val == 'm') { - // toggle mock mode - mockMode = !mockMode; - } - - if(val == 's') { - raceStarted = false; - - digitalWrite(racer0GoLedPin,LOW); - digitalWrite(racer1GoLedPin,LOW); - digitalWrite(racer2GoLedPin,LOW); - digitalWrite(racer3GoLedPin,LOW); - } - } - } -} - -void printStatusUpdate() { - if(currentTimeMillis - lastUpdateMillis > updateInterval) { - lastUpdateMillis = currentTimeMillis; - for(int i=0; i<=3; i++) - { - Serial.print(i); - Serial.print(": "); - Serial.println(racerTicks[i], DEC); - } - Serial.print("t: "); - Serial.println(currentTimeMillis, DEC); - } -} - -void loop() { - blinkLED(); - - checkSerial(); - - - if (raceStarting) { - if((millis() - lastCountDownMillis) > 1000){ - lastCountDown -= 1; - lastCountDownMillis = millis(); - } - if(lastCountDown == 0) { - raceStart(); - raceStarting = false; - raceStarted = true; - - digitalWrite(racer0GoLedPin,HIGH); - digitalWrite(racer1GoLedPin,HIGH); - digitalWrite(racer2GoLedPin,HIGH); - digitalWrite(racer3GoLedPin,HIGH); - } - } - if (raceStarted) { - currentTimeMillis = millis() - raceStartMillis; - - for(int i=0; i<=3; i++) - { - if(!mockMode) { - values[i] = digitalRead(sensorPins[i]); - if(values[i] == HIGH && previoussensorValues[i] == LOW){ - racerTicks[i]++; - if(racerFinishTimeMillis[i] == 0 && racerTicks[i] >= raceLengthTicks) { - racerFinishTimeMillis[i] = currentTimeMillis; - Serial.print(i); - Serial.print("f: "); - Serial.println(racerFinishTimeMillis[i], DEC); - digitalWrite(racer0GoLedPin+i,LOW); - } - } - previoussensorValues[i] = values[i]; - } - else { - if(currentTimeMillis - lastUpdateMillis > updateInterval) { - racerTicks[i]+=(i+1); - if(racerFinishTimeMillis[i] == 0 && racerTicks[i] >= raceLengthTicks) { - racerFinishTimeMillis[i] = currentTimeMillis; - Serial.print(i); - Serial.print("f: "); - Serial.println(racerFinishTimeMillis[i], DEC); - digitalWrite(racer0GoLedPin+i,LOW); - } - } - } - } - } - - - if(racerFinishTimeMillis[0] != 0 && racerFinishTimeMillis[1] != 0 && racerFinishTimeMillis[2] != 0 && racerFinishTimeMillis[3] != 0){ - if(raceStarted) { - raceStarted = false; - printStatusUpdate(); - } - } else { - printStatusUpdate(); - } -} - diff --git a/RetoolingForOpenSprints/raceinabox/bikewedge.py b/RetoolingForOpenSprints/raceinabox/bikewedge.py new file mode 100644 index 0000000..f47a854 --- /dev/null +++ b/RetoolingForOpenSprints/raceinabox/bikewedge.py @@ -0,0 +1,97 @@ +"""------------------------------------------------------------------------bikewedge.py + + DESCRIPTION: This code intercepts both sides of opensprints/goldsprintsfx + "conversation" to control a visual indication of progress using something + like a phsical clock or a race tree. + This makes it possible to not have a projector that costs more than your rollers. + It also makes it possible to do outdoor or mobile events. + + COPYRIGHT: (c) 2013 Donald Delmar Davis, Suspect Devices, All Rights Reserved. + This is free software released under modified BSD (details included in source). + + TECHNICAL: This is a basic combination of the client and server software from the + python in a nutshell book. It makes a lot of assumtions and should do a better + job of recovering when the pile of flash or the serial proxy crashes (which + happens). + It creates a server on 5331 (the only port gold sprints checks) and expects + to listen to serproxy on 5330 it talks to the clock on 5332 + it should eventually check and start serproxy and the goldsprints programs. + it should also do a better job of recovering from issues created by externals. + + It has a lot of number foo (hard coding) in it that should be cleaned up + +""" +import socket +import re +isocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) +osocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) +csocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) +isocket.connect(('localhost',5330)) +#isocket.setblocking(0) +isocket.settimeout(0.2) +print "Connected to serproxy" +csocket.connect(('localhost',5332)) +csocket.settimeout(0.2) +print "Connected to clock" +osocket.bind(('',5331)) +osocket.listen(1) + +try: + while True: + connection,address=osocket.accept() + if not connection: break + print "Connected From", address + #connection.setblocking(0) + connection.settimeout(0.2) + while True: + try: + receivedData = connection.recv(8192) + except socket.error: + receivedData=None + if receivedData is not None: + #print ">"+re.escape(str(receivedData))+">"+str(len(receivedData)) + isocket.sendall(receivedData) + for chunk in receivedData.split('\x00'): + if len(chunk)>0 and chunk[0] == 's': + print "(RE)SET RACE !!!" + csocket.sendall("s\n"); + if len(receivedData)==0: + print "ISSUE WITH CLIENT" + + try: + sentData = isocket.recv(8192) + except socket.error: + sentData=None + if sentData is not None: + #print "<"+re.escape(str(sentData))+"<"+str(len(sentData)) + connection.sendall(sentData) + for chunk in sentData.split('\x00'): + #if len(chunk.rstrip('\r')): + # print "<",re.escape(chunk),len(chunk) + if len(chunk) > 4 and chunk[0]=='0' : + done1=(float(chunk[3:])/1566.0) * 100.00 + if done1>100.00 : + done1=100.00 + print "Bike # 1 is ", str(int(done1)), "percent done" + csocket.sendall("d1:"+str(int(21.32*(done1)))+"\n") + if len(chunk) > 4 and chunk[0]=='1' : + done2=(float(chunk[3:])/1566.0) * 100.00 + if done2>100.00 : + done2=100.00 + print "Bike # 2 is ", str(int(done2)), "percent done" + csocket.sendall("d2:"+str(int(21.32*(done2)))+"\n") + + if len(sentData)==0: + print "ISSUE WITH SERPROXY" + try: + isocket.sendall("\rv\r\x00") + except socket.error: + isocket.close() + isocket.connect(('localhost',5330)) + break +finally: + #need to see if connections is defined.... + connection.close() + csocket.close() + osocket.close() + isocket.close() diff --git a/RetoolingForOpenSprints/raceinabox/netsuck.py b/RetoolingForOpenSprints/raceinabox/netsuck.py deleted file mode 100644 index 98af13b..0000000 --- a/RetoolingForOpenSprints/raceinabox/netsuck.py +++ /dev/null @@ -1,77 +0,0 @@ -"""-------------------------------------------------------------------------netsuck.py - DESCRIPTION: This code intercepts both sides of opensprints/goldsprintsfx - "conversation" to control a visual indication of progress using something - like a phsical clock or a race tree. - This makes it possible to not have a projector that costs more than your rollers. - It also makes it possible to do outdoor or mobile events. - - COPYRIGHT: (c) 2013 Donald Delmar Davis, Suspect Devices, All Rights Reserved. - This is free software released under modified BSD (details included in source). - - TECHNICAL: This is a basic combination of the client and server software from the - python in a nutshell book. It makes a lot of assumtions and should do a better - job of recovering when the pile of flash or the serial proxy crashes (which - happens). - It creates a server on 5331 (the only port gold sprints checks) and expects - to listen to serproxy on 5330 -""" -import socket -import re -isocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) -osocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) -isocket.connect(('localhost',5330)) -#isocket.setblocking(0) -isocket.settimeout(0.2) -print "Connected to serproxy" -osocket.bind(('',5331)) -osocket.listen(1) - -try: - while True: - connection,address=osocket.accept() - if not connection: break - print "Connected From", address - #connection.setblocking(0) - connection.settimeout(0.2) - while True: - try: - receivedData = connection.recv(8192) - except socket.error: - receivedData=None - if receivedData is not None: - #print ">"+re.escape(str(receivedData))+">"+str(len(receivedData)) - isocket.sendall(receivedData) - for chunk in receivedData.split('\x00'): - if len(chunk)>0 and chunk[0] == 's': - print "(RE)SET RACE !!!" - if len(receivedData)==0: - print "ISSUE WITH CLIENT" - - try: - sentData = isocket.recv(8192) - except socket.error: - sentData=None - if sentData is not None: - #print "<"+re.escape(str(sentData))+"<"+str(len(sentData)) - connection.sendall(sentData) - for chunk in sentData.split('\x00'): - #if len(chunk.rstrip('\r')): - # print "<",re.escape(chunk),len(chunk) - if len(chunk) > 4 and chunk[0]=='0' : - done1=int((float(chunk[3:])/1566.0) * 100.00) - print "Bike # 1 is ", str(done1), "percent done" - if len(chunk) > 4 and chunk[0]=='1' : - done1=int((float(chunk[3:])/1566.0) * 100.00) - print "Bike # 2 is ", str(done1), "percent done" - if len(sentData)==0: - print "ISSUE WITH SERPROXY" - try: - isocket.sendall("\rv\r\x00") - except socket.error: - isocket.close() - isocket.connect(('localhost',5330)) - break -finally: - connection.close() - osocket.close() - isocket.close() -- cgit v1.2.3