Skip to content

Instantly share code, notes, and snippets.

@daspilker
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daspilker/d55d642a638531ed5f40 to your computer and use it in GitHub Desktop.
Save daspilker/d55d642a638531ed5f40 to your computer and use it in GitHub Desktop.
CoreMedia Release Train Automation
import urllib
import time
import serial
def send(state):
print 'sending %s' % state
serial_port.write(bytearray([len(state)]))
serial_port.write(state)
serial_port = serial.Serial('COM8', 9600, timeout=1)
time.sleep(2)
state = 'NONE'
while True:
data = eval(urllib.urlopen("http://test-ci.coremedia.vm/view/pipeline2/api/python").read())
stages = data['pipelines'][0]['pipelines'][0]['stages']
status1 = stages[0]['tasks'][0]['status']['type']
status2 = stages[1]['tasks'][0]['status']['type']
print "%s - %s" % (status1, status2)
if status1 == 'SUCCESS' and status2 == 'SUCCESS' and not state == 'SUCCESS':
state = 'SUCCESS'
send(state)
elif status1 == 'RUNNING' and status2 == 'IDLE' and not state == 'STEP1':
state = 'STEP1'
send(state)
elif status1 == 'SUCCESS' and status2 == 'QUEUED' and not state == 'STEP1_WAITING':
state = 'STEP1_WAITING'
send(state)
elif status1 == 'SUCCESS' and status2 == 'RUNNING' and not state == 'STEP2':
state = 'STEP2'
send(state)
elif (status1 == 'FAILED' or status2 == 'FAILED') and not state == 'FAILURE':
state = 'FAILURE'
send(state)
time.sleep(2)
#include <Railuino.h>
const word LOCO = ADDR_MFX + 6;
const int SOUND_FUNCTION = 2;
const boolean DEBUG = false;
const int led = 7;
const int led2 = 8;
const word SPEED = 300;
TrackController ctrl(0xdf24, DEBUG);
TrackReporterS88 rprt(1);
void setup() {
Serial.begin(9600);
while (!Serial);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
ctrl.begin();
ctrl.setPower(true);
}
String readString() {
int length = Serial.read();
char serialData[20];
Serial.readBytes(serialData, length);
String s = String(serialData);
return s.substring(0, length);
}
void waitUntil(int contact) {
for(;;) {
rprt.refresh();
if (rprt.getValue(contact)) {
return;
}
delay(50);
}
}
boolean isLocation(int contact) {
rprt.refresh();
return rprt.getValue(contact);
}
int getLocation() {
for (;;) {
rprt.refresh();
for (int i = 1; i <= 16; i++) {
if (rprt.getValue(i)) {
return i;
}
}
}
}
void functions(boolean on) {
ctrl.setLocoFunction(LOCO, 0, on ? 1 : 0);
ctrl.setLocoFunction(LOCO, 1, on ? 1 : 0);
ctrl.setLocoFunction(LOCO, 2, on ? 1 : 0);
}
void horn() {
ctrl.setLocoFunction(LOCO, 3, 1);
delay(1000);
ctrl.setLocoFunction(LOCO, 3, 0);
}
void stop() {
ctrl.setLocoSpeed(LOCO, 0);
delay(5000);
}
void loop() {
if (Serial.available()) {
String command = readString();
if (command == "FAILURE") {
digitalWrite(led, HIGH);
if (!isLocation(1)) {
functions(true);
ctrl.setLocoDirection(LOCO, DIR_REVERSE);
ctrl.setLocoSpeed(LOCO, SPEED);
waitUntil(1);
stop();
functions(false);
horn();
}
} else if (command == "STEP1") {
functions(true);
if (!isLocation(2)) {
if (getLocation() < 2) {
ctrl.setLocoDirection(LOCO, DIR_FORWARD);
} else {
ctrl.setLocoDirection(LOCO, DIR_REVERSE);
}
ctrl.setLocoSpeed(LOCO, SPEED);
waitUntil(2);
stop();
}
} else if (command == "STEP1_WAITING") {
functions(false);
} else if (command == "STEP2") {
functions(true);
if (getLocation() < 3) {
ctrl.setLocoDirection(LOCO, DIR_FORWARD);
} else {
ctrl.setLocoDirection(LOCO, DIR_REVERSE);
}
ctrl.setLocoSpeed(LOCO, SPEED);
digitalWrite(led2, HIGH);
// waitUntil(2);
delay(20000);
stop();
} else if (command == "SUCCESS") {
functions(false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment