diff --git a/app/src/processing/app/preproc/PdePreprocessor.java b/app/src/processing/app/preproc/PdePreprocessor.java index a30f36c52..10e4b3dd5 100644 --- a/app/src/processing/app/preproc/PdePreprocessor.java +++ b/app/src/processing/app/preproc/PdePreprocessor.java @@ -257,9 +257,23 @@ public class PdePreprocessor { // pre-processor directive p += "|" + "(^\\s*#.*?$)"; + StringBuilder sb = new StringBuilder(in); Pattern pattern = Pattern.compile(p, Pattern.MULTILINE | Pattern.DOTALL); - Matcher matcher = pattern.matcher(in); - return matcher.replaceAll(" "); + Matcher matcher = pattern.matcher(sb); + while (matcher.find()) { + String replacement = composeReplacementString(new StringBuilder(sb.subSequence(matcher.start(), matcher.end()))); + sb.replace(matcher.start(), matcher.end(), replacement); + } + return sb.toString(); + } + + private String composeReplacementString(StringBuilder sb) { + for (int i = 0; i < sb.length(); i++) { + if (sb.charAt(i) != '\n') { + sb.setCharAt(i, ' '); + } + } + return sb.toString(); } /** @@ -388,7 +402,10 @@ public class PdePreprocessor { } else { // continue blanking this area - p[index++] = ' '; + if (p[index] != '\n') { + p[index] = ' '; + } + index++; } } if (!endOfRainbow) { diff --git a/app/test/processing/app/preproc/Baladuino.nocomments.ino b/app/test/processing/app/preproc/Baladuino.nocomments.ino new file mode 100644 index 000000000..81324031c --- /dev/null +++ b/app/test/processing/app/preproc/Baladuino.nocomments.ino @@ -0,0 +1,304 @@ + + + + + + + + + + + + +#define ENABLE_TOOLS +#define ENABLE_SPP +#define ENABLE_PS3 +#define ENABLE_WII +#define ENABLE_XBOX +#define ENABLE_ADK + +#include "Balanduino.h" +#include +#include + +#ifdef ENABLE_ADK +#include +#endif + + + +#include + +#ifdef ENABLE_XBOX +#include +#endif +#ifdef ENABLE_SPP +#include +#endif +#ifdef ENABLE_PS3 +#include +#endif +#ifdef ENABLE_WII +#include +#endif + + +Kalman kalman; + +#if defined(ENABLE_SPP) || defined(ENABLE_PS3) || defined(ENABLE_WII) || defined(ENABLE_XBOX) || defined(ENABLE_ADK) +#define ENABLE_USB +USB Usb; +#endif + +#ifdef ENABLE_ADK + +ADK adk(&Usb, "TKJ Electronics", + "Balanduino", + "Android App for Balanduino", + "0.5.0", + "https://play.google.com/store/apps/details?id=com.tkjelectronics.balanduino", + "1234"); +#endif + +#ifdef ENABLE_XBOX +XBOXRECV Xbox(&Usb); +#endif + +#if defined(ENABLE_SPP) || defined(ENABLE_PS3) || defined(ENABLE_WII) +USBHub Hub(&Usb); +BTD Btd(&Usb); +#endif + +#ifdef ENABLE_SPP +SPP SerialBT(&Btd, "Balanduino", "0000"); +#endif + +#ifdef ENABLE_PS3 +PS3BT PS3(&Btd); +#endif + +#ifdef ENABLE_WII +WII Wii(&Btd); + + + + +#endif + +void setup() { + + Serial.begin(115200); + + + if (!checkInitializationFlags()) + readEEPROMValues(); + + + pinMode(leftEncoder1, INPUT); + pinMode(leftEncoder2, INPUT); + pinMode(rightEncoder1, INPUT); + pinMode(rightEncoder2, INPUT); + attachInterrupt(0, leftEncoder, CHANGE); + attachInterrupt(1, rightEncoder, CHANGE); + + + pinMode(leftEnable, OUTPUT); + pinMode(rightEnable, OUTPUT); + digitalWrite(leftEnable, HIGH); + digitalWrite(rightEnable, HIGH); + + + sbi(pwmPortDirection, leftPWM); + sbi(leftPortDirection, leftA); + sbi(leftPortDirection, leftB); + sbi(pwmPortDirection, rightPWM); + sbi(rightPortDirection, rightA); + sbi(rightPortDirection, rightB); + + + + TCCR1B = _BV(WGM13) | _BV(CS10); + ICR1 = PWMVALUE; + + + + + TCCR1A = _BV(COM1A1) | _BV(COM1B1); + setPWM(leftPWM, 0); + setPWM(rightPWM, 0); + + + pinMode(buzzer, OUTPUT); + +#ifdef ENABLE_USB + if (Usb.Init() == -1) { + Serial.print(F("OSC did not start")); + digitalWrite(buzzer, HIGH); + while (1); + } +#endif + + + +#ifdef ENABLE_PS3 + PS3.attachOnInit(onInit); +#endif +#ifdef ENABLE_WII + Wii.attachOnInit(onInit); +#endif +#ifdef ENABLE_XBOX + Xbox.attachOnInit(onInit); +#endif + + + Wire.begin(); + + while (i2cRead(0x75, i2cBuffer, 1)); + if (i2cBuffer[0] != 0x68) { + Serial.print(F("Error reading sensor")); + digitalWrite(buzzer, HIGH); + while (1); + } + + i2cBuffer[0] = 19; + i2cBuffer[1] = 0x00; + i2cBuffer[2] = 0x00; + i2cBuffer[3] = 0x00; + while (i2cWrite(0x19, i2cBuffer, 4, false)); + while (i2cWrite(0x6B, 0x09, true)); + + delay(100); + + + while (i2cRead(0x3D, i2cBuffer, 4)); + accY = ((i2cBuffer[0] << 8) | i2cBuffer[1]); + accZ = ((i2cBuffer[2] << 8) | i2cBuffer[3]); + + + accAngle = (atan2((double)accY - cfg.accYzero, (double)accZ - cfg.accZzero) + PI) * RAD_TO_DEG; + + kalman.setAngle(accAngle); + pitch = accAngle; + gyroAngle = accAngle; + + + calibrateGyro(); + + pinMode(LED_BUILTIN, OUTPUT); + + + digitalWrite(buzzer, HIGH); + delay(100); + digitalWrite(buzzer, LOW); + + + kalmanTimer = micros(); + pidTimer = kalmanTimer; + encoderTimer = kalmanTimer; + imuTimer = millis(); + reportTimer = imuTimer; + ledTimer = imuTimer; + blinkTimer = imuTimer; +} + +void loop() { +#ifdef ENABLE_WII + if (Wii.wiimoteConnected) + Usb.Task(); +#endif + + + while (i2cRead(0x3D, i2cBuffer, 8)); + accY = ((i2cBuffer[0] << 8) | i2cBuffer[1]); + accZ = ((i2cBuffer[2] << 8) | i2cBuffer[3]); + gyroX = ((i2cBuffer[6] << 8) | i2cBuffer[7]); + + + + accAngle = (atan2((double)accY - cfg.accYzero, (double)accZ - cfg.accZzero) + PI) * RAD_TO_DEG; + + uint32_t timer = micros(); + + if ((accAngle < 90 && pitch > 270) || (accAngle > 270 && pitch < 90)) { + kalman.setAngle(accAngle); + pitch = accAngle; + gyroAngle = accAngle; + } else { + gyroRate = ((double)gyroX - gyroXzero) / 131.0; + double dt = (double)(timer - kalmanTimer) / 1000000.0; + gyroAngle += gyroRate * dt; + if (gyroAngle < 0 || gyroAngle > 360) + gyroAngle = pitch; + pitch = kalman.getAngle(accAngle, gyroRate, dt); + } + kalmanTimer = timer; + + +#ifdef ENABLE_WII + if (Wii.wiimoteConnected) + Usb.Task(); +#endif + + + timer = micros(); + + + if ((layingDown && (pitch < cfg.targetAngle - 10 || pitch > cfg.targetAngle + 10)) || (!layingDown && (pitch < cfg.targetAngle - 45 || pitch > cfg.targetAngle + 45))) { + layingDown = true; + stopAndReset(); + } else { + layingDown = false; + updatePID(cfg.targetAngle, targetOffset, turningOffset, (double)(timer - pidTimer) / 1000000.0); + } + pidTimer = timer; + + + timer = micros(); + if (timer - encoderTimer >= 100000) { + encoderTimer = timer; + int32_t wheelPosition = getWheelsPosition(); + wheelVelocity = wheelPosition - lastWheelPosition; + lastWheelPosition = wheelPosition; + + if (abs(wheelVelocity) <= 40 && !stopped) { + targetPosition = wheelPosition; + stopped = true; + } + + batteryCounter++; + if (batteryCounter > 10) { + batteryCounter = 0; + batteryVoltage = (double)analogRead(VBAT) / 63.050847458; + if (batteryVoltage < 10.2 && batteryVoltage > 5) + digitalWrite(buzzer, HIGH); + else + digitalWrite(buzzer, LOW); + } + } + + +#ifdef ENABLE_USB + readUsb(); +#endif +#ifdef ENABLE_TOOLS + checkSerialData(); +#endif +#if defined(ENABLE_TOOLS) || defined(ENABLE_SPP) + printValues(); +#endif + +#if defined(ENABLE_SPP) || defined(ENABLE_PS3) || defined(ENABLE_WII) + if (Btd.isReady()) { + timer = millis(); + if ((Btd.watingForConnection && timer - blinkTimer > 1000) || (!Btd.watingForConnection && timer - blinkTimer > 100)) { + blinkTimer = timer; + ledState = !ledState; + digitalWrite(LED_BUILTIN, ledState); + } + } else if (ledState) { + ledState = !ledState; + digitalWrite(LED_BUILTIN, ledState); + } +#endif +} + diff --git a/app/test/processing/app/preproc/Baladuino.stripped.ino b/app/test/processing/app/preproc/Baladuino.stripped.ino index e02cd39c8..168eedd37 100644 --- a/app/test/processing/app/preproc/Baladuino.stripped.ino +++ b/app/test/processing/app/preproc/Baladuino.stripped.ino @@ -1,80 +1,99 @@ - + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - + + + - -Kalman kalman; - - -USB Usb; - - - -ADK adk(&Usb, , - , - , - , - , - ); - - -XBOXRECV Xbox(&Usb); - - -USBHub Hub(&Usb); -BTD Btd(&Usb); - - -SPP SerialBT(&Btd, , ); - - -PS3BT PS3(&Btd); - - -WII Wii(&Btd); - - - - - + + + + + + + + + + + + + + + + + + + + + + +Kalman kalman; + + + +USB Usb; + + + + +ADK adk(&Usb, , + , + , + , + , + ); + + + +XBOXRECV Xbox(&Usb); + + + +USBHub Hub(&Usb); +BTD Btd(&Usb); + + + +SPP SerialBT(&Btd, , ); + + + +PS3BT PS3(&Btd); + + + +WII Wii(&Btd); + + + + + void setup() { - + Serial.begin(115200); - + if (!checkInitializationFlags()) - readEEPROMValues(); + readEEPROMValues(); - + pinMode(leftEncoder1, INPUT); pinMode(leftEncoder2, INPUT); pinMode(rightEncoder1, INPUT); @@ -82,13 +101,13 @@ void setup() { attachInterrupt(0, leftEncoder, CHANGE); attachInterrupt(1, rightEncoder, CHANGE); - + pinMode(leftEnable, OUTPUT); pinMode(rightEnable, OUTPUT); digitalWrite(leftEnable, HIGH); digitalWrite(rightEnable, HIGH); - + sbi(pwmPortDirection, leftPWM); sbi(leftPortDirection, leftA); sbi(leftPortDirection, leftB); @@ -96,82 +115,83 @@ void setup() { sbi(rightPortDirection, rightA); sbi(rightPortDirection, rightB); - - - TCCR1B = _BV(WGM13) | _BV(CS10); - ICR1 = PWMVALUE; + + + TCCR1B = _BV(WGM13) | _BV(CS10); + ICR1 = PWMVALUE; - - - + + + TCCR1A = _BV(COM1A1) | _BV(COM1B1); - setPWM(leftPWM, 0); + setPWM(leftPWM, 0); setPWM(rightPWM, 0); - + pinMode(buzzer, OUTPUT); - - if (Usb.Init() == -1) { - Serial.print(F( )); + + + if (Usb.Init() == -1) { + Serial.print(F( )); digitalWrite(buzzer, HIGH); - while (1); + while (1); } - + - - - + + + PS3.attachOnInit(onInit); - - + + Wii.attachOnInit(onInit); - - + + Xbox.attachOnInit(onInit); - + - + Wire.begin(); while (i2cRead(0x75, i2cBuffer, 1)); - if (i2cBuffer[0] != 0x68) { - Serial.print(F( )); + if (i2cBuffer[0] != 0x68) { + Serial.print(F( )); digitalWrite(buzzer, HIGH); - while (1); + while (1); } - i2cBuffer[0] = 19; - i2cBuffer[1] = 0x00; - i2cBuffer[2] = 0x00; - i2cBuffer[3] = 0x00; - while (i2cWrite(0x19, i2cBuffer, 4, false)); - while (i2cWrite(0x6B, 0x09, true)); + i2cBuffer[0] = 19; + i2cBuffer[1] = 0x00; + i2cBuffer[2] = 0x00; + i2cBuffer[3] = 0x00; + while (i2cWrite(0x19, i2cBuffer, 4, false)); + while (i2cWrite(0x6B, 0x09, true)); - delay(100); + delay(100); - + while (i2cRead(0x3D, i2cBuffer, 4)); accY = ((i2cBuffer[0] << 8) | i2cBuffer[1]); accZ = ((i2cBuffer[2] << 8) | i2cBuffer[3]); - - + + accAngle = (atan2((double)accY - cfg.accYzero, (double)accZ - cfg.accZzero) + PI) * RAD_TO_DEG; - kalman.setAngle(accAngle); + kalman.setAngle(accAngle); pitch = accAngle; gyroAngle = accAngle; - + calibrateGyro(); - pinMode(LED_BUILTIN, OUTPUT); + pinMode(LED_BUILTIN, OUTPUT); - + digitalWrite(buzzer, HIGH); delay(100); digitalWrite(buzzer, LOW); - + kalmanTimer = micros(); pidTimer = kalmanTimer; encoderTimer = kalmanTimer; @@ -182,100 +202,102 @@ void setup() { } void loop() { - - if (Wii.wiimoteConnected) + + if (Wii.wiimoteConnected) Usb.Task(); - + - + while (i2cRead(0x3D, i2cBuffer, 8)); accY = ((i2cBuffer[0] << 8) | i2cBuffer[1]); accZ = ((i2cBuffer[2] << 8) | i2cBuffer[3]); gyroX = ((i2cBuffer[6] << 8) | i2cBuffer[7]); - - + + accAngle = (atan2((double)accY - cfg.accYzero, (double)accZ - cfg.accZzero) + PI) * RAD_TO_DEG; uint32_t timer = micros(); - + if ((accAngle < 90 && pitch > 270) || (accAngle > 270 && pitch < 90)) { kalman.setAngle(accAngle); pitch = accAngle; gyroAngle = accAngle; } else { - gyroRate = ((double)gyroX - gyroXzero) / 131.0; + gyroRate = ((double)gyroX - gyroXzero) / 131.0; double dt = (double)(timer - kalmanTimer) / 1000000.0; - gyroAngle += gyroRate * dt; + gyroAngle += gyroRate * dt; if (gyroAngle < 0 || gyroAngle > 360) - gyroAngle = pitch; - pitch = kalman.getAngle(accAngle, gyroRate, dt); + gyroAngle = pitch; + pitch = kalman.getAngle(accAngle, gyroRate, dt); } kalmanTimer = timer; - - - if (Wii.wiimoteConnected) - Usb.Task(); - + - + + if (Wii.wiimoteConnected) + Usb.Task(); + + + timer = micros(); - - + + if ((layingDown && (pitch < cfg.targetAngle - 10 || pitch > cfg.targetAngle + 10)) || (!layingDown && (pitch < cfg.targetAngle - 45 || pitch > cfg.targetAngle + 45))) { - layingDown = true; + layingDown = true; stopAndReset(); } else { - layingDown = false; + layingDown = false; updatePID(cfg.targetAngle, targetOffset, turningOffset, (double)(timer - pidTimer) / 1000000.0); } pidTimer = timer; - + timer = micros(); - if (timer - encoderTimer >= 100000) { + if (timer - encoderTimer >= 100000) { encoderTimer = timer; int32_t wheelPosition = getWheelsPosition(); wheelVelocity = wheelPosition - lastWheelPosition; lastWheelPosition = wheelPosition; - - if (abs(wheelVelocity) <= 40 && !stopped) { + + if (abs(wheelVelocity) <= 40 && !stopped) { targetPosition = wheelPosition; stopped = true; } batteryCounter++; - if (batteryCounter > 10) { + if (batteryCounter > 10) { batteryCounter = 0; - batteryVoltage = (double)analogRead(VBAT) / 63.050847458; - if (batteryVoltage < 10.2 && batteryVoltage > 5) + batteryVoltage = (double)analogRead(VBAT) / 63.050847458; + if (batteryVoltage < 10.2 && batteryVoltage > 5) digitalWrite(buzzer, HIGH); else digitalWrite(buzzer, LOW); } } - - + + readUsb(); - - + + checkSerialData(); - - + + printValues(); - - + + + if (Btd.isReady()) { timer = millis(); if ((Btd.watingForConnection && timer - blinkTimer > 1000) || (!Btd.watingForConnection && timer - blinkTimer > 100)) { blinkTimer = timer; ledState = !ledState; - digitalWrite(LED_BUILTIN, ledState); + digitalWrite(LED_BUILTIN, ledState); } - } else if (ledState) { + } else if (ledState) { ledState = !ledState; - digitalWrite(LED_BUILTIN, ledState); + digitalWrite(LED_BUILTIN, ledState); } - + } diff --git a/app/test/processing/app/preproc/CharWithEscapedDoubleQuote.nocomments.ino b/app/test/processing/app/preproc/CharWithEscapedDoubleQuote.nocomments.ino new file mode 100644 index 000000000..0b2af8b5f --- /dev/null +++ b/app/test/processing/app/preproc/CharWithEscapedDoubleQuote.nocomments.ino @@ -0,0 +1,339 @@ +#include +#include + + +#define DS3231_I2C_ADDRESS 104 +#define DS3231_TIME_CAL_ADDR 0 +#define DS3231_ALARM1_ADDR 7 +#define DS3231_ALARM2_ADDR 11 +#define DS3231_CONTROL_ADDR 14 +#define DS3231_STATUS_ADDR 15 + +#define DS3231_TEMPERATURE_ADDR 17 + + +SoftwareSerial GPRS( 7, 8 ); +byte buffer[ 64 ]; +int count = 0, e = 0, count2 = 0, t = 0, q; +char temp, lastCaller[13] = "blank"; +boolean callIncoming = false, done; + + +byte time[ 7 ]; +byte time_A1[ 5 ]; +byte time_A2[ 4 ]; +byte received[1]; +float temperature; + + +char telescopeNames[6][4]; + + + + + + + + + +void setPowerStateTo( int newState ) +{ + if( newState != 1 && newState != 0 ) { + Serial.print( "Error: Invalid powerstate. Current powerstate = " ); + Serial.print( getPowerState() ); + Serial.print( "\n" ); + } + else { + if( newState == getPowerState() ) { + Serial.print( "Powerstate = " ); + Serial.print( newState ); + Serial.print( " remains unchanged.\n" ); + } + else { + powerUpOrDown(); + Serial.print( "Powerstate changed from " ); + Serial.print( 1 - newState ); + Serial.print( " to " ); + Serial.print( newState ); + Serial.print( "\n" ); + } + } + delay( 5000 ); +} + +int getPowerState() +{ + int ret; + if ( digitalRead(18) == 0 && digitalRead(19) == 0 ) + ret = 1; + else + ret = 0; + + return ret; +} + +void powerUpOrDown() +{ + pinMode( 9, OUTPUT ); + digitalWrite( 9, LOW ); + delay( 1000 ); + digitalWrite( 9, HIGH ); + delay( 2000 ); + digitalWrite( 9, LOW ); + delay( 3000 ); +} + + + + + +void clearBufferArray() +{ + for( int i = 0; i < count; i++ ) + buffer[ i ] = NULL; +} + +void makeMissedCall( char num[] ) +{ + int i; + char in[ 18 ] = "ATD"; + for( i = 3; i <= 14; i++ ) + in[ i ] = num[ i - 3] ; + in[ 15 ] = ';'; + in[ 16 ] = '\r'; + in[ 17 ] = '\0'; + GPRS.write( in ); + delay( 10000 ); + GPRS.write( "ATH\r\0" ); + delay( 1000 ); +} + +void sendTextMessage( char number[], char messg[] ) +{ + char temp[ 27 ] = "AT + CMGS = \""; + for( q = 0; q < 12; q++ ) + temp[ q + 13 ] = number[ q ]; + temp[ 25 ] = '\"'; + temp[ 26 ] = '\0'; + + GPRS.println( "AT+CMGF=1\r" ); + delay( 1000 ); + GPRS.println( temp ); + delay( 1000 ); + GPRS.println( messg ); + delay( 1000 ); + GPRS.println( (char) 26 ); + delay( 1000 ); +} + +void analise(byte incoming[], int length) +{ + e = 0; + done = false; + while( e < length && !done){ + temp = char( incoming[e] ); + switch( temp ){ + case 'R': + { + if( length > e + 3 && !callIncoming ) { + if(char( incoming[e + 1] ) == 'I' + && char( incoming[e + 2] ) == 'N' + && char( incoming[e + 3] ) == 'G'){ + GPRS.write("AT+CLCC\r"); + delay(500); + GPRS.write("ATH\r"); + callIncoming = true; + done = true; + } + } + } + break; + case '+': + { + if(char( buffer[ e + 1]) == '2' && length > e + 11 && callIncoming){ + for(t = 0; t < 12; t++) + lastCaller[t] = char( buffer[ e + t ]); + lastCaller[12] = '\0'; + callIncoming = false; + done = true; + } + } + break; + case 'l': + Serial.println(lastCaller); + break; + } + e++; + } +} + + + + + + + + + + +byte decToBcd( byte b ) +{ + return ( b / 10 << 4 ) + b % 10; +} + +boolean getBit( byte addr, int pos ) +{ + byte temp = getByte( addr ); + return boolean( (temp >> pos) & B00000001 ); +} + +void setBit( byte addr, int pos, boolean newBit ) +{ + boolean oldBit = getBit( addr, pos ); + byte temp = received[ 0 ]; + if ( oldBit != newBit ) + { + if( newBit ) + temp += (B00000001 << pos); + else + temp -= (B00000001 << pos); + } + setByte( addr, temp ); +} + +byte getByte( byte addr ) +{ + byte temp; + if( getBytes( addr, 1) ) + temp = received[ 0 ]; + else temp = -1; + return temp; +} + +boolean getBytes( byte addr, int amount ) +{ + boolean wireWorked = false; + Wire.beginTransmission( DS3231_I2C_ADDRESS ); + Wire.write( addr ); + Wire.endTransmission(); + Wire.requestFrom( DS3231_I2C_ADDRESS, amount ); + if( Wire.available() ){ + received[amount]; + for( int i = 0; i < amount; i++){ + received[ i ] = Wire.read(); + } + wireWorked = true; + } + return wireWorked; +} + +void setByte( byte addr, byte newByte ) +{ + setBytes( addr, &newByte, 1); +} + +void setBytes( byte addr, byte newBytes[], int amount ) +{ + Wire.beginTransmission( DS3231_I2C_ADDRESS ); + Wire.write( addr ); + for( int i = 0; i < amount; i++ ) + Wire.write( newBytes[ i ] ); + Wire.endTransmission(); +} + +void getTime() +{ + if( getBytes( DS3231_TIME_CAL_ADDR, 7) ) + { + for(int i = 0; i < 7; i++) + time[ i ] = received[ i ]; + + time[ 0 ] = ( ( time[ 0 ] & B01110000 ) >> 4 ) * 10 + ( time[ 0 ] & B00001111 ); + time[ 1 ] = ( ( time[ 1 ] & B01110000 ) >> 4 ) * 10 + ( time[ 1 ] & B00001111 ); + time[ 2 ] = ( ( time[ 2 ] & B00110000 ) >> 4 ) * 10 + ( time[ 2 ] & B00001111 ); + time[ 4 ] = ( ( time[ 4 ] & B00110000 ) >> 4 ) * 10 + ( time[ 4 ] & B00001111 ); + time[ 5 ] = ( ( time[ 5 ] & B00010000 ) >> 4 ) * 10 + ( time[ 5 ] & B00001111 ); + time[ 6 ] = ( ( time[ 6 ] & B11110000 ) >> 4 ) * 10 + ( time[ 6 ] & B00001111 ); + } +} + +void setTime( byte newTime[ 7 ] ) +{ + for(int i = 0; i < 7; i++) + newTime[i] = decToBcd(newTime[i]); + setBytes( DS3231_TIME_CAL_ADDR, newTime, 7 ); +} + +void getRTCTemperature() +{ + + if( getBytes( DS3231_TEMPERATURE_ADDR, 2 ) ) + { + temperature = ( received[ 0 ] & B01111111 ); + temperature += ( ( received[ 1 ] >> 6 ) * 0.25 ); + } +} + +void gprsListen() +{ + if( GPRS.available() ) { + while( GPRS.available() ) { + buffer[ count++ ] = GPRS.read(); + if ( count == 64 ) + break; + } + Serial.write( buffer, count ); + analise( buffer, count ); + clearBufferArray(); + count = 0; + } + if (Serial.available()) + GPRS.write(Serial.read()); +} + +void printTime() +{ + getTime(); + Serial.print( int( time[ 3 ] ) ); + Serial.print( ' ' ); + Serial.print( int( time[ 2 ] ) ); + Serial.print( ':' ); + Serial.print( int( time[ 1 ] ) ); + Serial.print( ':' ); + Serial.print( int( time[ 0 ] ) ); + Serial.print( ' ' ); + Serial.print( int( time[ 4 ] ) ); + Serial.print( '/' ); + Serial.print( int( time[ 5 ] ) ); + Serial.print( "/20" ); + Serial.print( int( time[ 6 ] ) ); + Serial.println(); +} + + + + + +void setup() +{ + + GPRS.begin( 9600 ); + delay(1000); + setPowerStateTo(1); + delay(1000); + + + Wire.begin(); + delay(1000); + + Serial.begin(9600); + delay(1000); + +} + +void loop() +{ + gprsListen(); + getTime(); +} + diff --git a/app/test/processing/app/preproc/CharWithEscapedDoubleQuote.stripped.ino b/app/test/processing/app/preproc/CharWithEscapedDoubleQuote.stripped.ino index 0de0f0db2..1579c0907 100644 --- a/app/test/processing/app/preproc/CharWithEscapedDoubleQuote.stripped.ino +++ b/app/test/processing/app/preproc/CharWithEscapedDoubleQuote.stripped.ino @@ -1,68 +1,70 @@ - - + + - - - - - - - - - + + + + + + + + + - -SoftwareSerial GPRS( 7, 8 ); -byte buffer[ 64 ]; + +SoftwareSerial GPRS( 7, 8 ); +byte buffer[ 64 ]; int count = 0, e = 0, count2 = 0, t = 0, q; -char temp, lastCaller[13] = ; +char temp, lastCaller[13] = ; boolean callIncoming = false, done; - -byte time[ 7 ]; -byte time_A1[ 5 ]; -byte time_A2[ 4 ]; -byte received[1]; -float temperature; + +byte time[ 7 ]; +byte time_A1[ 5 ]; +byte time_A2[ 4 ]; +byte received[1]; +float temperature; - + char telescopeNames[6][4]; - + + + - - - + + + void setPowerStateTo( int newState ) { - if( newState != 1 && newState != 0 ) { - Serial.print( ); + if( newState != 1 && newState != 0 ) { + Serial.print( ); Serial.print( getPowerState() ); - Serial.print( ); + Serial.print( ); } else { - if( newState == getPowerState() ) { - Serial.print( ); + if( newState == getPowerState() ) { + Serial.print( ); Serial.print( newState ); - Serial.print( ); + Serial.print( ); } else { - powerUpOrDown(); - Serial.print( ); + powerUpOrDown(); + Serial.print( ); Serial.print( 1 - newState ); - Serial.print( ); + Serial.print( ); Serial.print( newState ); - Serial.print( ); + Serial.print( ); } } - delay( 5000 ); + delay( 5000 ); } -int getPowerState() +int getPowerState() { int ret; - if ( digitalRead(18) == 0 && digitalRead(19) == 0 ) + if ( digitalRead(18) == 0 && digitalRead(19) == 0 ) ret = 1; else ret = 0; @@ -70,7 +72,7 @@ int getPowerState() return ret; } -void powerUpOrDown() +void powerUpOrDown() { pinMode( 9, OUTPUT ); digitalWrite( 9, LOW ); @@ -81,11 +83,11 @@ void powerUpOrDown() delay( 3000 ); } - - - + + + -void clearBufferArray() +void clearBufferArray() { for( int i = 0; i < count; i++ ) buffer[ i ] = NULL; @@ -94,227 +96,233 @@ void clearBufferArray() void makeMissedCall( char num[] ) { int i; - char in[ 18 ] = ; - for( i = 3; i <= 14; i++ ) + char in[ 18 ] = ; + for( i = 3; i <= 14; i++ ) in[ i ] = num[ i - 3] ; - in[ 15 ] = ; + in[ 15 ] = ; in[ 16 ] = '\r'; in[ 17 ] = '\0'; - GPRS.write( in ); - delay( 10000 ); - GPRS.write( ); + GPRS.write( in ); + delay( 10000 ); + GPRS.write( ); delay( 1000 ); } void sendTextMessage( char number[], char messg[] ) { - char temp[ 27 ] = ; - for( q = 0; q < 12; q++ ) + char temp[ 27 ] = ; + for( q = 0; q < 12; q++ ) temp[ q + 13 ] = number[ q ]; - temp[ 25 ] = ; + temp[ 25 ] = ; temp[ 26 ] = '\0'; - GPRS.println( ); + GPRS.println( ); delay( 1000 ); - GPRS.println( temp ); + GPRS.println( temp ); delay( 1000 ); - GPRS.println( messg ); + GPRS.println( messg ); delay( 1000 ); - GPRS.println( (char) 26 ); + GPRS.println( (char) 26 ); delay( 1000 ); } -void analise(byte incoming[], int length) +void analise(byte incoming[], int length) { - e = 0; - done = false; - while( e < length && !done){ - temp = char( incoming[e] ); - switch( temp ){ - case : + e = 0; + done = false; + while( e < length && !done){ + temp = char( incoming[e] ); + switch( temp ){ + case : { - if( length > e + 3 && !callIncoming ) { - if(char( incoming[e + 1] ) == - && char( incoming[e + 2] ) == - && char( incoming[e + 3] ) == ){ - GPRS.write( ); - delay(500); - GPRS.write( ); - callIncoming = true; - done = true; + if( length > e + 3 && !callIncoming ) { + if(char( incoming[e + 1] ) == + && char( incoming[e + 2] ) == + && char( incoming[e + 3] ) == ){ + GPRS.write( ); + delay(500); + GPRS.write( ); + callIncoming = true; + done = true; } } } break; - case : + case : { - if(char( buffer[ e + 1]) == && length > e + 11 && callIncoming){ - for(t = 0; t < 12; t++) - lastCaller[t] = char( buffer[ e + t ]); + if(char( buffer[ e + 1]) == && length > e + 11 && callIncoming){ + for(t = 0; t < 12; t++) + lastCaller[t] = char( buffer[ e + t ]); lastCaller[12] = '\0'; - callIncoming = false; - done = true; + callIncoming = false; + done = true; } } break; - case : - Serial.println(lastCaller); + case : + Serial.println(lastCaller); break; } - e++; + e++; } } - + + + - + + + -byte decToBcd( byte b ) +byte decToBcd( byte b ) { return ( b / 10 << 4 ) + b % 10; } -boolean getBit( byte addr, int pos ) +boolean getBit( byte addr, int pos ) { byte temp = getByte( addr ); return boolean( (temp >> pos) & B00000001 ); } -void setBit( byte addr, int pos, boolean newBit ) +void setBit( byte addr, int pos, boolean newBit ) { - boolean oldBit = getBit( addr, pos ); - byte temp = received[ 0 ]; - if ( oldBit != newBit ) + boolean oldBit = getBit( addr, pos ); + byte temp = received[ 0 ]; + if ( oldBit != newBit ) { - if( newBit ) - temp += (B00000001 << pos); + if( newBit ) + temp += (B00000001 << pos); else - temp -= (B00000001 << pos); + temp -= (B00000001 << pos); } - setByte( addr, temp ); + setByte( addr, temp ); } -byte getByte( byte addr ) +byte getByte( byte addr ) { byte temp; - if( getBytes( addr, 1) ) - temp = received[ 0 ]; - else temp = -1; + if( getBytes( addr, 1) ) + temp = received[ 0 ]; + else temp = -1; return temp; } -boolean getBytes( byte addr, int amount ) -{ +boolean getBytes( byte addr, int amount ) +{ boolean wireWorked = false; - Wire.beginTransmission( DS3231_I2C_ADDRESS ); - Wire.write( addr ); - Wire.endTransmission(); - Wire.requestFrom( DS3231_I2C_ADDRESS, amount ); + Wire.beginTransmission( DS3231_I2C_ADDRESS ); + Wire.write( addr ); + Wire.endTransmission(); + Wire.requestFrom( DS3231_I2C_ADDRESS, amount ); if( Wire.available() ){ - received[amount]; + received[amount]; for( int i = 0; i < amount; i++){ - received[ i ] = Wire.read(); + received[ i ] = Wire.read(); } - wireWorked = true; + wireWorked = true; } return wireWorked; } -void setByte( byte addr, byte newByte ) +void setByte( byte addr, byte newByte ) { - setBytes( addr, &newByte, 1); + setBytes( addr, &newByte, 1); } -void setBytes( byte addr, byte newBytes[], int amount ) +void setBytes( byte addr, byte newBytes[], int amount ) { - Wire.beginTransmission( DS3231_I2C_ADDRESS ); - Wire.write( addr ); + Wire.beginTransmission( DS3231_I2C_ADDRESS ); + Wire.write( addr ); for( int i = 0; i < amount; i++ ) - Wire.write( newBytes[ i ] ); - Wire.endTransmission(); + Wire.write( newBytes[ i ] ); + Wire.endTransmission(); } -void getTime() +void getTime() { - if( getBytes( DS3231_TIME_CAL_ADDR, 7) ) + if( getBytes( DS3231_TIME_CAL_ADDR, 7) ) { - for(int i = 0; i < 7; i++) + for(int i = 0; i < 7; i++) time[ i ] = received[ i ]; - - time[ 0 ] = ( ( time[ 0 ] & B01110000 ) >> 4 ) * 10 + ( time[ 0 ] & B00001111 ); - time[ 1 ] = ( ( time[ 1 ] & B01110000 ) >> 4 ) * 10 + ( time[ 1 ] & B00001111 ); - time[ 2 ] = ( ( time[ 2 ] & B00110000 ) >> 4 ) * 10 + ( time[ 2 ] & B00001111 ); - time[ 4 ] = ( ( time[ 4 ] & B00110000 ) >> 4 ) * 10 + ( time[ 4 ] & B00001111 ); - time[ 5 ] = ( ( time[ 5 ] & B00010000 ) >> 4 ) * 10 + ( time[ 5 ] & B00001111 ); - time[ 6 ] = ( ( time[ 6 ] & B11110000 ) >> 4 ) * 10 + ( time[ 6 ] & B00001111 ); + + time[ 0 ] = ( ( time[ 0 ] & B01110000 ) >> 4 ) * 10 + ( time[ 0 ] & B00001111 ); + time[ 1 ] = ( ( time[ 1 ] & B01110000 ) >> 4 ) * 10 + ( time[ 1 ] & B00001111 ); + time[ 2 ] = ( ( time[ 2 ] & B00110000 ) >> 4 ) * 10 + ( time[ 2 ] & B00001111 ); + time[ 4 ] = ( ( time[ 4 ] & B00110000 ) >> 4 ) * 10 + ( time[ 4 ] & B00001111 ); + time[ 5 ] = ( ( time[ 5 ] & B00010000 ) >> 4 ) * 10 + ( time[ 5 ] & B00001111 ); + time[ 6 ] = ( ( time[ 6 ] & B11110000 ) >> 4 ) * 10 + ( time[ 6 ] & B00001111 ); } } -void setTime( byte newTime[ 7 ] ) +void setTime( byte newTime[ 7 ] ) { for(int i = 0; i < 7; i++) - newTime[i] = decToBcd(newTime[i]); - setBytes( DS3231_TIME_CAL_ADDR, newTime, 7 ); + newTime[i] = decToBcd(newTime[i]); + setBytes( DS3231_TIME_CAL_ADDR, newTime, 7 ); } -void getRTCTemperature() +void getRTCTemperature() { - - if( getBytes( DS3231_TEMPERATURE_ADDR, 2 ) ) + + if( getBytes( DS3231_TEMPERATURE_ADDR, 2 ) ) { - temperature = ( received[ 0 ] & B01111111 ); - temperature += ( ( received[ 1 ] >> 6 ) * 0.25 ); + temperature = ( received[ 0 ] & B01111111 ); + temperature += ( ( received[ 1 ] >> 6 ) * 0.25 ); } } void gprsListen() { - if( GPRS.available() ) { - while( GPRS.available() ) { - buffer[ count++ ] = GPRS.read(); - if ( count == 64 ) + if( GPRS.available() ) { + while( GPRS.available() ) { + buffer[ count++ ] = GPRS.read(); + if ( count == 64 ) break; } - Serial.write( buffer, count ); + Serial.write( buffer, count ); analise( buffer, count ); - clearBufferArray(); - count = 0; + clearBufferArray(); + count = 0; } - if (Serial.available()) - GPRS.write(Serial.read()); + if (Serial.available()) + GPRS.write(Serial.read()); } -void printTime() +void printTime() { getTime(); - Serial.print( int( time[ 3 ] ) ); - Serial.print( ); - Serial.print( int( time[ 2 ] ) ); - Serial.print( ); - Serial.print( int( time[ 1 ] ) ); - Serial.print( ); - Serial.print( int( time[ 0 ] ) ); - Serial.print( ); - Serial.print( int( time[ 4 ] ) ); - Serial.print( ); - Serial.print( int( time[ 5 ] ) ); - Serial.print( ); - Serial.print( int( time[ 6 ] ) ); + Serial.print( int( time[ 3 ] ) ); + Serial.print( ); + Serial.print( int( time[ 2 ] ) ); + Serial.print( ); + Serial.print( int( time[ 1 ] ) ); + Serial.print( ); + Serial.print( int( time[ 0 ] ) ); + Serial.print( ); + Serial.print( int( time[ 4 ] ) ); + Serial.print( ); + Serial.print( int( time[ 5 ] ) ); + Serial.print( ); + Serial.print( int( time[ 6 ] ) ); Serial.println(); } - + + + void setup() { - + GPRS.begin( 9600 ); delay(1000); setPowerStateTo(1); delay(1000); - + Wire.begin(); delay(1000); @@ -325,6 +333,6 @@ void setup() void loop() { - gprsListen(); - getTime(); + gprsListen(); + getTime(); } diff --git a/app/test/processing/app/preproc/IncludeBetweenMultilineComment.nocomments.ino b/app/test/processing/app/preproc/IncludeBetweenMultilineComment.nocomments.ino new file mode 100644 index 000000000..9981e5806 --- /dev/null +++ b/app/test/processing/app/preproc/IncludeBetweenMultilineComment.nocomments.ino @@ -0,0 +1,16 @@ +#include + + + +CapacitiveSensorDue cs_13_8 = CapacitiveSensorDue(13,8); +void setup() +{ + Serial.begin(9600); +} +void loop() +{ + long total1 = cs_13_8.read(30); + Serial.println(total1); + delay(100); +} + diff --git a/app/test/processing/app/preproc/IncludeBetweenMultilineComment.stripped.ino b/app/test/processing/app/preproc/IncludeBetweenMultilineComment.stripped.ino index 3aece7c1f..aeb99c235 100644 --- a/app/test/processing/app/preproc/IncludeBetweenMultilineComment.stripped.ino +++ b/app/test/processing/app/preproc/IncludeBetweenMultilineComment.stripped.ino @@ -1,5 +1,7 @@ - - + + + + CapacitiveSensorDue cs_13_8 = CapacitiveSensorDue(13,8); void setup() { diff --git a/app/test/processing/app/preproc/LineContinuations.nocomments.ino b/app/test/processing/app/preproc/LineContinuations.nocomments.ino new file mode 100644 index 000000000..1f220926a --- /dev/null +++ b/app/test/processing/app/preproc/LineContinuations.nocomments.ino @@ -0,0 +1,35 @@ +const char *foo = "\ +hello \ +world\n"; + + + +void setup() +{ +} + +void loop() +{ +} + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/test/processing/app/preproc/LineContinuations.stripped.ino b/app/test/processing/app/preproc/LineContinuations.stripped.ino index ffe2ea529..622928751 100644 --- a/app/test/processing/app/preproc/LineContinuations.stripped.ino +++ b/app/test/processing/app/preproc/LineContinuations.stripped.ino @@ -1,6 +1,8 @@ -const char *foo = ; +const char *foo = + + ; - + void setup() { @@ -9,4 +11,24 @@ void setup() void loop() { } - + + + + + + + + + + + + + + + + + + + + + diff --git a/app/test/processing/app/preproc/PdePreprocessorTest.java b/app/test/processing/app/preproc/PdePreprocessorTest.java index ba938a420..2b9960777 100644 --- a/app/test/processing/app/preproc/PdePreprocessorTest.java +++ b/app/test/processing/app/preproc/PdePreprocessorTest.java @@ -14,12 +14,18 @@ public class PdePreprocessorTest { String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("RemoteCallLogger_v1e0.ino").getFile())); PdePreprocessor pdePreprocessor = new PdePreprocessor(); - String actualOutput = pdePreprocessor.strip(s); - String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("RemoteCallLogger_v1e0.stripped.ino").getFile())); + String stippedOutput = pdePreprocessor.strip(s); + String expectedStrippedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("RemoteCallLogger_v1e0.stripped.ino").getFile())); - assertEquals(expectedOutput, actualOutput); + assertEquals(expectedStrippedOutput, stippedOutput); pdePreprocessor.writePrefix(s); + + String actualCodeWithoutComments = pdePreprocessor.program; + String expectedCodeWithoutComments = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("RemoteCallLogger_v1e0.nocomments.ino").getFile())); + + assertEquals(expectedCodeWithoutComments, actualCodeWithoutComments); + assertEquals(2, pdePreprocessor.getExtraImports().size()); assertEquals("SoftwareSerial.h", pdePreprocessor.getExtraImports().get(0)); assertEquals("Wire.h", pdePreprocessor.getExtraImports().get(1)); @@ -30,12 +36,18 @@ public class PdePreprocessorTest { String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("IncludeBetweenMultilineComment.ino").getFile())); PdePreprocessor pdePreprocessor = new PdePreprocessor(); - String actualOutput = pdePreprocessor.strip(s); - String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("IncludeBetweenMultilineComment.stripped.ino").getFile())); + String stippedOutput = pdePreprocessor.strip(s); + String expectedStrippedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("IncludeBetweenMultilineComment.stripped.ino").getFile())); - assertEquals(expectedOutput, actualOutput); + assertEquals(expectedStrippedOutput, stippedOutput); pdePreprocessor.writePrefix(s); + + String actualCodeWithoutComments = pdePreprocessor.program; + String expectedCodeWithoutComments = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("IncludeBetweenMultilineComment.nocomments.ino").getFile())); + + assertEquals(expectedCodeWithoutComments, actualCodeWithoutComments); + assertEquals(1, pdePreprocessor.getExtraImports().size()); assertEquals("CapacitiveSensorDue.h", pdePreprocessor.getExtraImports().get(0)); } @@ -45,12 +57,18 @@ public class PdePreprocessorTest { String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("Baladuino.ino").getFile())); PdePreprocessor pdePreprocessor = new PdePreprocessor(); - String actualOutput = pdePreprocessor.strip(s); - String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("Baladuino.stripped.ino").getFile())); + String stippedOutput = pdePreprocessor.strip(s); + String expectedStrippedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("Baladuino.stripped.ino").getFile())); - assertEquals(expectedOutput, actualOutput); + assertEquals(expectedStrippedOutput, stippedOutput); pdePreprocessor.writePrefix(s); + + String actualCodeWithoutComments = pdePreprocessor.program; + String expectedCodeWithoutComments = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("Baladuino.nocomments.ino").getFile())); + + assertEquals(expectedCodeWithoutComments, actualCodeWithoutComments); + assertEquals(9, pdePreprocessor.getExtraImports().size()); assertEquals("Balanduino.h", pdePreprocessor.getExtraImports().get(0)); assertEquals("Wire.h", pdePreprocessor.getExtraImports().get(1)); @@ -68,12 +86,18 @@ public class PdePreprocessorTest { String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("StringWithCcomment.ino").getFile())); PdePreprocessor pdePreprocessor = new PdePreprocessor(); - String actualOutput = pdePreprocessor.strip(s); - String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("StringWithCcomment.stripped.ino").getFile())); + String stippedOutput = pdePreprocessor.strip(s); + String expectedStrippedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("StringWithCcomment.stripped.ino").getFile())); - assertEquals(expectedOutput, actualOutput); + assertEquals(expectedStrippedOutput, stippedOutput); pdePreprocessor.writePrefix(s); + + String actualCodeWithoutComments = pdePreprocessor.program; + String expectedCodeWithoutComments = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("StringWithCcomment.nocomments.ino").getFile())); + + assertEquals(expectedCodeWithoutComments, actualCodeWithoutComments); + assertEquals(0, pdePreprocessor.getExtraImports().size()); } @@ -82,12 +106,18 @@ public class PdePreprocessorTest { String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("CharWithEscapedDoubleQuote.ino").getFile())); PdePreprocessor pdePreprocessor = new PdePreprocessor(); - String actualOutput = pdePreprocessor.strip(s); - String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("CharWithEscapedDoubleQuote.stripped.ino").getFile())); + String stippedOutput = pdePreprocessor.strip(s); + String expectedStrippedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("CharWithEscapedDoubleQuote.stripped.ino").getFile())); - assertEquals(expectedOutput, actualOutput); + assertEquals(expectedStrippedOutput, stippedOutput); pdePreprocessor.writePrefix(s); + + String actualCodeWithoutComments = pdePreprocessor.program; + String expectedCodeWithoutComments = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("CharWithEscapedDoubleQuote.nocomments.ino").getFile())); + + assertEquals(expectedCodeWithoutComments, actualCodeWithoutComments); + assertEquals(2, pdePreprocessor.getExtraImports().size()); assertEquals("SoftwareSerial.h", pdePreprocessor.getExtraImports().get(0)); assertEquals("Wire.h", pdePreprocessor.getExtraImports().get(1)); @@ -98,12 +128,18 @@ public class PdePreprocessorTest { String s = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("LineContinuations.ino").getFile())); PdePreprocessor pdePreprocessor = new PdePreprocessor(); - String actualOutput = pdePreprocessor.strip(s); - String expectedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("LineContinuations.stripped.ino").getFile())); + String stippedOutput = pdePreprocessor.strip(s); + String expectedStrippedOutput = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("LineContinuations.stripped.ino").getFile())); - assertEquals(expectedOutput, actualOutput); + assertEquals(expectedStrippedOutput, stippedOutput); pdePreprocessor.writePrefix(s); + + String actualCodeWithoutComments = pdePreprocessor.program; + String expectedCodeWithoutComments = FileUtils.readFileToString(new File(PdePreprocessorTest.class.getResource("LineContinuations.nocomments.ino").getFile())); + + assertEquals(expectedCodeWithoutComments, actualCodeWithoutComments); + assertEquals(0, pdePreprocessor.getExtraImports().size()); } diff --git a/app/test/processing/app/preproc/RemoteCallLogger_v1e0.nocomments.ino b/app/test/processing/app/preproc/RemoteCallLogger_v1e0.nocomments.ino new file mode 100644 index 000000000..bbf15560e --- /dev/null +++ b/app/test/processing/app/preproc/RemoteCallLogger_v1e0.nocomments.ino @@ -0,0 +1,344 @@ + +#include +#include + + +#define DS3231_I2C_ADDRESS 104 +#define DS3231_TIME_CAL_ADDR 0 +#define DS3231_ALARM1_ADDR 7 +#define DS3231_ALARM2_ADDR 11 +#define DS3231_CONTROL_ADDR 14 +#define DS3231_STATUS_ADDR 15 + +#define DS3231_TEMPERATURE_ADDR 17 + + +SoftwareSerial GPRS( 7, 8 ); +byte buffer[ 64 ]; +int count = 0, e = 0, count2 = 0, t = 0, q; +char temp, lastCaller[13] = "blank"; +boolean callIncoming = false, done; + + +byte time[ 7 ]; +byte time_A1[ 5 ]; +byte time_A2[ 4 ]; +byte received[1]; +float temperature; + + +char telescopeNames[6][4]; + + + + + + + + + +void setPowerStateTo( int newState ) +{ + if( newState != 1 && newState != 0 ) { + Serial.print( "Error: Invalid powerstate. Current powerstate = " ); + Serial.print( getPowerState() ); + Serial.print( "\n" ); + } + else { + if( newState == getPowerState() ) { + Serial.print( "Powerstate = " ); + Serial.print( newState ); + Serial.print( " remains unchanged.\n" ); + } + else { + powerUpOrDown(); + Serial.print( "Powerstate changed from " ); + Serial.print( 1 - newState ); + Serial.print( " to " ); + Serial.print( newState ); + Serial.print( "\n" ); + } + } + delay( 5000 ); +} + +int getPowerState() +{ + int ret; + if ( digitalRead(18) == 0 && digitalRead(19) == 0 ) + ret = 1; + else + ret = 0; + + return ret; +} + +void powerUpOrDown() +{ + pinMode( 9, OUTPUT ); + digitalWrite( 9, LOW ); + delay( 1000 ); + digitalWrite( 9, HIGH ); + delay( 2000 ); + digitalWrite( 9, LOW ); + delay( 3000 ); +} + + + + + +void clearBufferArray() +{ + for( int i = 0; i < count; i++ ) + buffer[ i ] = NULL; +} + +void makeMissedCall( char num[] ) +{ + int i; + char in[ 18 ] = "ATD"; + for( i = 3; i <= 14; i++ ) + in[ i ] = num[ i - 3] ; + in[ 15 ] = ';'; + in[ 16 ] = '\r'; + in[ 17 ] = '\0'; + GPRS.write( in ); + delay( 10000 ); + GPRS.write( "ATH\r\0" ); + delay( 1000 ); +} + +void sendTextMessage( char number[], char messg[] ) +{ + char temp[ 27 ] = "AT + CMGS = \""; + for( q = 0; q < 12; q++ ) + temp[ q + 13 ] = number[ q ]; + temp[ 25 ] = '\"'; + temp[ 26 ] = '\0'; + + GPRS.println( "AT+CMGF=1\r" ); + delay( 1000 ); + GPRS.println( temp ); + delay( 1000 ); + GPRS.println( messg ); + delay( 1000 ); + GPRS.println( (char) 26 ); + delay( 1000 ); +} + +void analise(byte incoming[], int length) +{ + e = 0; + done = false; + while( e < length && !done){ + temp = char( incoming[e] ); + switch( temp ){ + case 'R': + { + if( length > e + 3 && !callIncoming ) { + if(char( incoming[e + 1] ) == 'I' + && char( incoming[e + 2] ) == 'N' + && char( incoming[e + 3] ) == 'G'){ + GPRS.write("AT+CLCC\r"); + delay(500); + GPRS.write("ATH\r"); + callIncoming = true; + done = true; + } + } + } + break; + case '+': + { + if(char( buffer[ e + 1]) == '2' && length > e + 11 && callIncoming){ + for(t = 0; t < 12; t++) + lastCaller[t] = char( buffer[ e + t ]); + lastCaller[12] = '\0'; + callIncoming = false; + done = true; + } + } + break; + case 'l': + Serial.println(lastCaller); + break; + } + e++; + } +} + + + + + + + + + + +byte decToBcd( byte b ) +{ + return ( b / 10 << 4 ) + b % 10; +} + +boolean getBit( byte addr, int pos ) +{ + byte temp = getByte( addr ); + return boolean( (temp >> pos) & B00000001 ); +} + +void setBit( byte addr, int pos, boolean newBit ) +{ + boolean oldBit = getBit( addr, pos ); + byte temp = received[ 0 ]; + if ( oldBit != newBit ) + { + if( newBit ) + temp += (B00000001 << pos); + else + temp -= (B00000001 << pos); + } + setByte( addr, temp ); +} + +byte getByte( byte addr ) +{ + byte temp; + if( getBytes( addr, 1) ) + temp = received[ 0 ]; + else temp = -1; + return temp; +} + +boolean getBytes( byte addr, int amount ) +{ + boolean wireWorked = false; + Wire.beginTransmission( DS3231_I2C_ADDRESS ); + Wire.write( addr ); + Wire.endTransmission(); + Wire.requestFrom( DS3231_I2C_ADDRESS, amount ); + if( Wire.available() ){ + received[amount]; + for( int i = 0; i < amount; i++){ + received[ i ] = Wire.read(); + } + wireWorked = true; + } + return wireWorked; +} + +void setByte( byte addr, byte newByte ) +{ + setBytes( addr, &newByte, 1); +} + +void setBytes( byte addr, byte newBytes[], int amount ) +{ + Wire.beginTransmission( DS3231_I2C_ADDRESS ); + Wire.write( addr ); + for( int i = 0; i < amount; i++ ) + Wire.write( newBytes[ i ] ); + Wire.endTransmission(); +} + +void getTime() +{ + if( getBytes( DS3231_TIME_CAL_ADDR, 7) ) + { + for(int i = 0; i < 7; i++) + time[ i ] = received[ i ]; + + time[ 0 ] = ( ( time[ 0 ] & B01110000 ) >> 4 ) * 10 + ( time[ 0 ] & B00001111 ); + time[ 1 ] = ( ( time[ 1 ] & B01110000 ) >> 4 ) * 10 + ( time[ 1 ] & B00001111 ); + time[ 2 ] = ( ( time[ 2 ] & B00110000 ) >> 4 ) * 10 + ( time[ 2 ] & B00001111 ); + time[ 4 ] = ( ( time[ 4 ] & B00110000 ) >> 4 ) * 10 + ( time[ 4 ] & B00001111 ); + time[ 5 ] = ( ( time[ 5 ] & B00010000 ) >> 4 ) * 10 + ( time[ 5 ] & B00001111 ); + time[ 6 ] = ( ( time[ 6 ] & B11110000 ) >> 4 ) * 10 + ( time[ 6 ] & B00001111 ); + } +} + +void setTime( byte newTime[ 7 ] ) +{ + for(int i = 0; i < 7; i++) + newTime[i] = decToBcd(newTime[i]); + setBytes( DS3231_TIME_CAL_ADDR, newTime, 7 ); +} + +void getRTCTemperature() +{ + + if( getBytes( DS3231_TEMPERATURE_ADDR, 2 ) ) + { + temperature = ( received[ 0 ] & B01111111 ); + temperature += ( ( received[ 1 ] >> 6 ) * 0.25 ); + } +} + +void gprsListen() +{ + if( GPRS.available() ) { + while( GPRS.available() ) { + buffer[ count++ ] = GPRS.read(); + if ( count == 64 ) + break; + } + Serial.write( buffer, count ); + analise( buffer, count ); + clearBufferArray(); + count = 0; + } + if (Serial.available()) + GPRS.write(Serial.read()); +} + +void printTime() +{ + getTime(); + Serial.print( int( time[ 3 ] ) ); + Serial.print( ' ' ); + Serial.print( int( time[ 2 ] ) ); + Serial.print( ':' ); + Serial.print( int( time[ 1 ] ) ); + Serial.print( ':' ); + Serial.print( int( time[ 0 ] ) ); + Serial.print( ' ' ); + Serial.print( int( time[ 4 ] ) ); + Serial.print( '/' ); + Serial.print( int( time[ 5 ] ) ); + Serial.print( "/20" ); + Serial.print( int( time[ 6 ] ) ); + Serial.println(); +} + + + + + +void setup() +{ + + GPRS.begin( 9600 ); + delay(1000); + setPowerStateTo(1); + delay(1000); + + + Wire.begin(); + delay(1000); + + Serial.begin(9600); + delay(1000); + +} + +void loop() +{ + gprsListen(); + getTime(); +} + + + + + diff --git a/app/test/processing/app/preproc/RemoteCallLogger_v1e0.stripped.ino b/app/test/processing/app/preproc/RemoteCallLogger_v1e0.stripped.ino index 706544402..75b4393ff 100644 --- a/app/test/processing/app/preproc/RemoteCallLogger_v1e0.stripped.ino +++ b/app/test/processing/app/preproc/RemoteCallLogger_v1e0.stripped.ino @@ -1,68 +1,71 @@ - - - - - - - - - - - + + - -SoftwareSerial GPRS( 7, 8 ); -byte buffer[ 64 ]; + + + + + + + + + + + +SoftwareSerial GPRS( 7, 8 ); +byte buffer[ 64 ]; int count = 0, e = 0, count2 = 0, t = 0, q; -char temp, lastCaller[13] = ; +char temp, lastCaller[13] = ; boolean callIncoming = false, done; - -byte time[ 7 ]; -byte time_A1[ 5 ]; -byte time_A2[ 4 ]; -byte received[1]; -float temperature; + +byte time[ 7 ]; +byte time_A1[ 5 ]; +byte time_A2[ 4 ]; +byte received[1]; +float temperature; - + char telescopeNames[6][4]; - + + + - - - + + + void setPowerStateTo( int newState ) { - if( newState != 1 && newState != 0 ) { - Serial.print( ); + if( newState != 1 && newState != 0 ) { + Serial.print( ); Serial.print( getPowerState() ); - Serial.print( ); + Serial.print( ); } else { - if( newState == getPowerState() ) { - Serial.print( ); + if( newState == getPowerState() ) { + Serial.print( ); Serial.print( newState ); - Serial.print( ); + Serial.print( ); } else { - powerUpOrDown(); - Serial.print( ); + powerUpOrDown(); + Serial.print( ); Serial.print( 1 - newState ); - Serial.print( ); + Serial.print( ); Serial.print( newState ); - Serial.print( ); + Serial.print( ); } } - delay( 5000 ); + delay( 5000 ); } -int getPowerState() +int getPowerState() { int ret; - if ( digitalRead(18) == 0 && digitalRead(19) == 0 ) + if ( digitalRead(18) == 0 && digitalRead(19) == 0 ) ret = 1; else ret = 0; @@ -70,7 +73,7 @@ int getPowerState() return ret; } -void powerUpOrDown() +void powerUpOrDown() { pinMode( 9, OUTPUT ); digitalWrite( 9, LOW ); @@ -81,11 +84,11 @@ void powerUpOrDown() delay( 3000 ); } - - - + + + -void clearBufferArray() +void clearBufferArray() { for( int i = 0; i < count; i++ ) buffer[ i ] = NULL; @@ -94,227 +97,233 @@ void clearBufferArray() void makeMissedCall( char num[] ) { int i; - char in[ 18 ] = ; - for( i = 3; i <= 14; i++ ) + char in[ 18 ] = ; + for( i = 3; i <= 14; i++ ) in[ i ] = num[ i - 3] ; - in[ 15 ] = ; + in[ 15 ] = ; in[ 16 ] = '\r'; in[ 17 ] = '\0'; - GPRS.write( in ); - delay( 10000 ); - GPRS.write( ); + GPRS.write( in ); + delay( 10000 ); + GPRS.write( ); delay( 1000 ); } void sendTextMessage( char number[], char messg[] ) { - char temp[ 27 ] = ; - for( q = 0; q < 12; q++ ) + char temp[ 27 ] = ; + for( q = 0; q < 12; q++ ) temp[ q + 13 ] = number[ q ]; - temp[ 25 ] = ; + temp[ 25 ] = ; temp[ 26 ] = '\0'; - GPRS.println( ); + GPRS.println( ); delay( 1000 ); - GPRS.println( temp ); + GPRS.println( temp ); delay( 1000 ); - GPRS.println( messg ); + GPRS.println( messg ); delay( 1000 ); - GPRS.println( (char) 26 ); + GPRS.println( (char) 26 ); delay( 1000 ); } -void analise(byte incoming[], int length) +void analise(byte incoming[], int length) { - e = 0; - done = false; - while( e < length && !done){ - temp = char( incoming[e] ); - switch( temp ){ - case : + e = 0; + done = false; + while( e < length && !done){ + temp = char( incoming[e] ); + switch( temp ){ + case : { - if( length > e + 3 && !callIncoming ) { - if(char( incoming[e + 1] ) == - && char( incoming[e + 2] ) == - && char( incoming[e + 3] ) == ){ - GPRS.write( ); - delay(500); - GPRS.write( ); - callIncoming = true; - done = true; + if( length > e + 3 && !callIncoming ) { + if(char( incoming[e + 1] ) == + && char( incoming[e + 2] ) == + && char( incoming[e + 3] ) == ){ + GPRS.write( ); + delay(500); + GPRS.write( ); + callIncoming = true; + done = true; } } } break; - case : + case : { - if(char( buffer[ e + 1]) == && length > e + 11 && callIncoming){ - for(t = 0; t < 12; t++) - lastCaller[t] = char( buffer[ e + t ]); + if(char( buffer[ e + 1]) == && length > e + 11 && callIncoming){ + for(t = 0; t < 12; t++) + lastCaller[t] = char( buffer[ e + t ]); lastCaller[12] = '\0'; - callIncoming = false; - done = true; + callIncoming = false; + done = true; } } break; - case : - Serial.println(lastCaller); + case : + Serial.println(lastCaller); break; } - e++; + e++; } } - + + + - + + + -byte decToBcd( byte b ) +byte decToBcd( byte b ) { return ( b / 10 << 4 ) + b % 10; } -boolean getBit( byte addr, int pos ) +boolean getBit( byte addr, int pos ) { byte temp = getByte( addr ); return boolean( (temp >> pos) & B00000001 ); } -void setBit( byte addr, int pos, boolean newBit ) +void setBit( byte addr, int pos, boolean newBit ) { - boolean oldBit = getBit( addr, pos ); - byte temp = received[ 0 ]; - if ( oldBit != newBit ) + boolean oldBit = getBit( addr, pos ); + byte temp = received[ 0 ]; + if ( oldBit != newBit ) { - if( newBit ) - temp += (B00000001 << pos); + if( newBit ) + temp += (B00000001 << pos); else - temp -= (B00000001 << pos); + temp -= (B00000001 << pos); } - setByte( addr, temp ); + setByte( addr, temp ); } -byte getByte( byte addr ) +byte getByte( byte addr ) { byte temp; - if( getBytes( addr, 1) ) - temp = received[ 0 ]; - else temp = -1; + if( getBytes( addr, 1) ) + temp = received[ 0 ]; + else temp = -1; return temp; } -boolean getBytes( byte addr, int amount ) -{ +boolean getBytes( byte addr, int amount ) +{ boolean wireWorked = false; - Wire.beginTransmission( DS3231_I2C_ADDRESS ); - Wire.write( addr ); - Wire.endTransmission(); - Wire.requestFrom( DS3231_I2C_ADDRESS, amount ); + Wire.beginTransmission( DS3231_I2C_ADDRESS ); + Wire.write( addr ); + Wire.endTransmission(); + Wire.requestFrom( DS3231_I2C_ADDRESS, amount ); if( Wire.available() ){ - received[amount]; + received[amount]; for( int i = 0; i < amount; i++){ - received[ i ] = Wire.read(); + received[ i ] = Wire.read(); } - wireWorked = true; + wireWorked = true; } return wireWorked; } -void setByte( byte addr, byte newByte ) +void setByte( byte addr, byte newByte ) { - setBytes( addr, &newByte, 1); + setBytes( addr, &newByte, 1); } -void setBytes( byte addr, byte newBytes[], int amount ) +void setBytes( byte addr, byte newBytes[], int amount ) { - Wire.beginTransmission( DS3231_I2C_ADDRESS ); - Wire.write( addr ); + Wire.beginTransmission( DS3231_I2C_ADDRESS ); + Wire.write( addr ); for( int i = 0; i < amount; i++ ) - Wire.write( newBytes[ i ] ); - Wire.endTransmission(); + Wire.write( newBytes[ i ] ); + Wire.endTransmission(); } -void getTime() +void getTime() { - if( getBytes( DS3231_TIME_CAL_ADDR, 7) ) + if( getBytes( DS3231_TIME_CAL_ADDR, 7) ) { - for(int i = 0; i < 7; i++) + for(int i = 0; i < 7; i++) time[ i ] = received[ i ]; - - time[ 0 ] = ( ( time[ 0 ] & B01110000 ) >> 4 ) * 10 + ( time[ 0 ] & B00001111 ); - time[ 1 ] = ( ( time[ 1 ] & B01110000 ) >> 4 ) * 10 + ( time[ 1 ] & B00001111 ); - time[ 2 ] = ( ( time[ 2 ] & B00110000 ) >> 4 ) * 10 + ( time[ 2 ] & B00001111 ); - time[ 4 ] = ( ( time[ 4 ] & B00110000 ) >> 4 ) * 10 + ( time[ 4 ] & B00001111 ); - time[ 5 ] = ( ( time[ 5 ] & B00010000 ) >> 4 ) * 10 + ( time[ 5 ] & B00001111 ); - time[ 6 ] = ( ( time[ 6 ] & B11110000 ) >> 4 ) * 10 + ( time[ 6 ] & B00001111 ); + + time[ 0 ] = ( ( time[ 0 ] & B01110000 ) >> 4 ) * 10 + ( time[ 0 ] & B00001111 ); + time[ 1 ] = ( ( time[ 1 ] & B01110000 ) >> 4 ) * 10 + ( time[ 1 ] & B00001111 ); + time[ 2 ] = ( ( time[ 2 ] & B00110000 ) >> 4 ) * 10 + ( time[ 2 ] & B00001111 ); + time[ 4 ] = ( ( time[ 4 ] & B00110000 ) >> 4 ) * 10 + ( time[ 4 ] & B00001111 ); + time[ 5 ] = ( ( time[ 5 ] & B00010000 ) >> 4 ) * 10 + ( time[ 5 ] & B00001111 ); + time[ 6 ] = ( ( time[ 6 ] & B11110000 ) >> 4 ) * 10 + ( time[ 6 ] & B00001111 ); } } -void setTime( byte newTime[ 7 ] ) +void setTime( byte newTime[ 7 ] ) { for(int i = 0; i < 7; i++) - newTime[i] = decToBcd(newTime[i]); - setBytes( DS3231_TIME_CAL_ADDR, newTime, 7 ); + newTime[i] = decToBcd(newTime[i]); + setBytes( DS3231_TIME_CAL_ADDR, newTime, 7 ); } -void getRTCTemperature() +void getRTCTemperature() { - - if( getBytes( DS3231_TEMPERATURE_ADDR, 2 ) ) + + if( getBytes( DS3231_TEMPERATURE_ADDR, 2 ) ) { - temperature = ( received[ 0 ] & B01111111 ); - temperature += ( ( received[ 1 ] >> 6 ) * 0.25 ); + temperature = ( received[ 0 ] & B01111111 ); + temperature += ( ( received[ 1 ] >> 6 ) * 0.25 ); } } void gprsListen() { - if( GPRS.available() ) { - while( GPRS.available() ) { - buffer[ count++ ] = GPRS.read(); - if ( count == 64 ) + if( GPRS.available() ) { + while( GPRS.available() ) { + buffer[ count++ ] = GPRS.read(); + if ( count == 64 ) break; } - Serial.write( buffer, count ); + Serial.write( buffer, count ); analise( buffer, count ); - clearBufferArray(); - count = 0; + clearBufferArray(); + count = 0; } - if (Serial.available()) - GPRS.write(Serial.read()); + if (Serial.available()) + GPRS.write(Serial.read()); } -void printTime() +void printTime() { getTime(); - Serial.print( int( time[ 3 ] ) ); - Serial.print( ); - Serial.print( int( time[ 2 ] ) ); - Serial.print( ); - Serial.print( int( time[ 1 ] ) ); - Serial.print( ); - Serial.print( int( time[ 0 ] ) ); - Serial.print( ); - Serial.print( int( time[ 4 ] ) ); - Serial.print( ); - Serial.print( int( time[ 5 ] ) ); - Serial.print( ); - Serial.print( int( time[ 6 ] ) ); + Serial.print( int( time[ 3 ] ) ); + Serial.print( ); + Serial.print( int( time[ 2 ] ) ); + Serial.print( ); + Serial.print( int( time[ 1 ] ) ); + Serial.print( ); + Serial.print( int( time[ 0 ] ) ); + Serial.print( ); + Serial.print( int( time[ 4 ] ) ); + Serial.print( ); + Serial.print( int( time[ 5 ] ) ); + Serial.print( ); + Serial.print( int( time[ 6 ] ) ); Serial.println(); } - + + + void setup() { - + GPRS.begin( 9600 ); delay(1000); setPowerStateTo(1); delay(1000); - + Wire.begin(); delay(1000); @@ -325,8 +334,8 @@ void setup() void loop() { - gprsListen(); - getTime(); + gprsListen(); + getTime(); } diff --git a/app/test/processing/app/preproc/StringWithCcomment.nocomments.ino b/app/test/processing/app/preproc/StringWithCcomment.nocomments.ino new file mode 100644 index 000000000..9655c4ad4 --- /dev/null +++ b/app/test/processing/app/preproc/StringWithCcomment.nocomments.ino @@ -0,0 +1,14 @@ +void setup() { + + + + Serial.println("Accept: */*"); + Serial.println("Accept: \" */*"); + Serial.println("Accept: \\"); // */*"); +} + +void loop() { + + +} + diff --git a/app/test/processing/app/preproc/StringWithCcomment.stripped.ino b/app/test/processing/app/preproc/StringWithCcomment.stripped.ino index 60c701cdf..e5fe15583 100644 --- a/app/test/processing/app/preproc/StringWithCcomment.stripped.ino +++ b/app/test/processing/app/preproc/StringWithCcomment.stripped.ino @@ -1,13 +1,13 @@ void setup() { - - - - Serial.println( ); - Serial.println( ); - Serial.println( ); + + + + Serial.println( ); + Serial.println( ); + Serial.println( ); } void loop() { - + }