int main(void){ //Local variables for xbee char transmitString[8]; uint8_t errorTimer = 20; //Locals for ADXL int16_t z = 0; int16_t z_low = 0; int16_t z_high = 0; int16_t x = 0; int16_t x_low = 0; int16_t x_high = 0; char messurementString[6]; //variable for iterations int i; //variables for gps char* ptr; char* tmpPtr; char ts[11] = " "; char lat[11] = " "; char latd[2]= " "; char lon[11]= " "; char lond[2]= " "; char fix[2]= "0"; char sats[3]= " "; char velocity[6] = " "; char *ptrToNMEA[] = {ts, lat, latd, lon, lond, fix, sats}; uint8_t messageIterator; //variables for sd card //initialize sdcard (it uses the same SPI as Xbee) uint8_t sdBuffer[512]; uint16_t sdBufferCurrentSymbol = 0; uint8_t sector = 0; uint32_t mstrDir = 0; uint32_t cluster = 0; uint32_t filesize = 0; uint16_t fatSect, fsInfoSector; //Periph variable uint16_t ADC_value; //Timer string char timerString[8]; //Leds and buttons, gpio's initializeUserButton(); initializeEveryGreenLed(); initializeEveryRedLed(); setupGpsGpio(); //SPI attention pin for incoming data alert initializeXbeeATTnPin(); //Usart1 for debugging and serial communication Usart1_Init(9600); //System clock for delays initialiseSysTick(); //SPI1 for xbee InitialiseSPI1_GPIO(); InitialiseSPI1(); //Timer for counter (1s) Initialize_timer(); Timer_interrupt_enable(); //ADC for voltage control adcPinConfig(); adcConfig(); //Xbee initialization (check if there arent unread data) //... transmitter shouldn't have any received messages from others XBEE_CS_LOW(); while(errorTimer--){ SPI1_TransRecieve(0x00); } XBEE_CS_HIGH(); //Dewi Module wont start until the button is pressed while(moduleStatus == MODULE_NOT_RUNNING){ ADC_value = (ADC_GetConversionValue(ADC1)); ADC_value = (ADC_value * 330) / 128; batteryIndicationStartup(ADC_value); blinkGreenLeds(7); } //12 seconds to choose the modules to use //One redStartup take about 500ms, so let it spin for twenty times //Default state is 1 (only acc is on) turnOnGreenLeds(state); for(errorTimer = 0 ; errorTimer < 6 ; errorTimer++){ redStartup(REAL_REAL_SLOW_DELAY); } //Setup state is cleared moduleStatus = MODULE_APPLYING_PARAMS; //ADXL362Z if(state&0x01){ //SPI2 for ADXL InitialiseSPI2_GPIO(); InitialiseSPI2(); initializeADXL362(); blinkRedLed3(); while(!return_ADXL_ready()){ //wait time for caps to discharge delayMs(2000); initializeADXL362(); delayMs(1000); blinkRedLed3(); } } //GPS if((state&0x02) >> 1){ //Usart 2 for gps communication Usart2_Init(BAUD_4800); ConfigureUsart2Interrupt(); errorTimer = 40; turnGpsOn(); while(!GPIO_ReadInputDataBit(GPS_PORTC,WAKEUP_PIN)){ blinkRedLed2(); delayMs(1000); } delayMs(400); gps_dissableMessage($GPGSA); delayMs(400); gps_dissableMessage($GPGSV); delayMs(400); gps_dissableMessage($GPRMC); delayMs(400); gps_dissableMessage($GPVTG); delayMs(400); gps_setRate($GPGGA, 1); //Wait for enough satellites while(fix[0] == '0' && errorTimer > 0 ){ if(gpsDataUpdated){ errorTimer--; gpsDataUpdated = false; messageIterator = 0; // Make sure that you are comparing GPGGA message // $PSRF and $GPVTG messages are possable at the startup if(strncmp(gpsReceiveString,"$GPGGA", 6) == 0){ ptr = &gpsReceiveString[7]; //This value could change whether the $ is used or not for(; messageIterator < 7; messageIterator ++){ tmpPtr = ptrToNMEA[messageIterator]; while(*ptr++ != ','){ *ptrToNMEA[messageIterator]++ = *(ptr-1); } ptrToNMEA[messageIterator] = tmpPtr; } } SEND_SERIAL_MSG("Waiting for sats...\r\n"); blinkRedLed4(); } } //if not enough satellites are found, turn off gps if(!errorTimer){ SEND_SERIAL_MSG("GPS timeout...\r\n"); hibernateGps(); state &= 0xFD; } else{ //if satellites found -> turn on $GPVTG to monitor velocity /* delayMs(400); gps_setRate($GPVTG,1); delayMs(400); blinkRedLed4(); gps_dissableMessage($GPGGA);*/ SEND_SERIAL_MSG("SATs found...\r\n"); } } //SD if((state&0x04) >> 2){ errorTimer = 10; while(!initializeSD() && errorTimer-- > 1){ delayMs(300); blinkRedLed5(); } if(!errorTimer){ //If sd card doesnt turn on, dont log anything to it state &= 0xFB; } else{ findDetailsOfFAT(sdBuffer,&fatSect,&mstrDir, &fsInfoSector); findDetailsOfFile("LOGFILE",sdBuffer,mstrDir,&filesize,&cluster,§or); SEND_SERIAL_BYTE(errorTimer+ASCII_DIGIT_OFFSET); SEND_SERIAL_MSG(":ERROR_TIMER\r\n"); SEND_SERIAL_BYTE(filesize+ASCII_DIGIT_OFFSET); SEND_SERIAL_MSG(":FILESIZE\r\n"); SEND_SERIAL_BYTE(sector+ASCII_DIGIT_OFFSET); SEND_SERIAL_MSG(":SECTOR\r\n"); SEND_SERIAL_BYTE(cluster+ASCII_DIGIT_OFFSET); SEND_SERIAL_MSG(":CLUSTER\r\n"); SEND_SERIAL_BYTE((fatSect%10000)/1000+ASCII_DIGIT_OFFSET); SEND_SERIAL_BYTE((fatSect%1000)/100+ASCII_DIGIT_OFFSET); SEND_SERIAL_BYTE((fatSect%100)/10+ASCII_DIGIT_OFFSET); SEND_SERIAL_BYTE((fatSect%10)+ASCII_DIGIT_OFFSET); SEND_SERIAL_MSG(":FAT_SECT\r\n"); SEND_SERIAL_BYTE((mstrDir%100000)/10000+ASCII_DIGIT_OFFSET); SEND_SERIAL_BYTE((mstrDir%10000)/1000+ASCII_DIGIT_OFFSET); SEND_SERIAL_BYTE((mstrDir%1000)/100+ASCII_DIGIT_OFFSET); SEND_SERIAL_BYTE((mstrDir%100)/10+ASCII_DIGIT_OFFSET); SEND_SERIAL_BYTE((mstrDir%10)+ASCII_DIGIT_OFFSET); SEND_SERIAL_MSG(":MSTR_DIR\r\n"); SEND_SERIAL_BYTE(fsInfoSector+ASCII_DIGIT_OFFSET); SEND_SERIAL_MSG(":FS_INFO_SECT\r\n"); /* * Program halts during this function */ findLastClusterOfFile("LOGFILE",sdBuffer, &cluster,fatSect,mstrDir); if(filesize < 512) filesize = 512; appendTextToTheSD("\nNEW LOG", '\n', &sdBufferCurrentSymbol, sdBuffer, "LOGFILE", &filesize, mstrDir, fatSect, &cluster, §or); } } moduleStatus = MODULE_IDLE_READY; turnOnGreenLeds(state); SEND_SERIAL_MSG("NODE READY!!!\r\n"); while(moduleStatus == MODULE_IDLE_READY){ blinkGreenLeds(state); redStartup(DELAY); } while(1){ switch(moduleStatus){ case MODULE_RUNNING: delayMs(600); //Transmit acc data if(state&0x01){ getX(&x,&x_low,&x_high); itoa(x, messurementString); transmitString[0] = '0'; transmitString[1] = ' '; strcpy(&transmitString[2],&messurementString[0]); transmitRequest(0x0013A200, 0x40E3E13C, TRANSOPT_DISACK, transmitString); //if sd card is active, log data to it if((state&0x04) >> 2){ itoa(globalCounter,timerString); appendTextToTheSD(timerString, '\t', &sdBufferCurrentSymbol, sdBuffer, "LOGFILE", &filesize, mstrDir, fatSect, &cluster, §or); appendTextToTheSD(transmitString, '\t', &sdBufferCurrentSymbol, sdBuffer, "LOGFILE", &filesize, mstrDir, fatSect, &cluster, §or); xorGreenLed(2); } xorGreenLed(0); } delayMs(600); //Transmit gps data if((state&0x02) >> 1){ if(strncmp(gpsReceiveString,"$GPVTG" , 6) == 0){ gps_parseGPVTG(gpsReceiveString,velocity); } else{ strcpy(velocity,"999.9"); } SEND_SERIAL_MSG(gpsReceiveString); SEND_SERIAL_MSG(":GPS\r\n"); transmitString[0] = '1'; transmitString[1] = ' '; strcpy(&transmitString[2],velocity); transmitRequest(0x0013A200, 0x40E3E13C, TRANSOPT_DISACK, transmitString); if((state&0x04) >> 2){ appendTextToTheSD(transmitString, '\n', &sdBufferCurrentSymbol, sdBuffer, "LOGFILE", &filesize, mstrDir, fatSect, &cluster, §or); xorGreenLed(2); } SEND_SERIAL_MSG(transmitString); SEND_SERIAL_MSG(" MESSAGE_SENT\r\n"); xorGreenLed(1); } break; case MODULE_IDLE_READY: if(turnOffTimer > 0){ turnOffTimer--; blinkGreenLeds(state); redStartup(DELAY); } else{ blinkGreenLeds(state); ADC_value = (ADC_GetConversionValue(ADC1)); ADC_value = (ADC_value * 330) / 128; batteryIndicationStartup(ADC_value); } break; case MODULE_TURNING_OFF: if((state&0x04) >> 2){ goToIdleState(); } if((state&0x02) >> 1){ hibernateGps(); } state = 0; turnOffTimer = 0; moduleStatus = MODULE_IDLE_READY; break; } }
int main(void){ /* * Local variables for XBEE */ char xbeeTransmitString[32]; /* * Local variables for Accelerometer */ int16_t z = 0; int16_t z_low = 0; int16_t z_high = 0; int16_t x = 0; int16_t x_low = 0; int16_t x_high = 0; char messurementString[6]; /* * Local variables for GPS */ char* ptr; char* tmpPtr; char ts[11] = " "; char lat[11] = " "; char latd[2]= " "; char lon[11]= " "; char lond[2]= " "; char fix[2]= "0"; char sats[3]= " "; char velocity[6] = " "; char *ptrToNMEA[] = {ts, lat, latd, lon, lond, fix, sats}; uint8_t messageIterator; /* * Local variables for SD card */ uint8_t sdBuffer[512]; uint16_t sdBufferCurrentSymbol = 0; uint8_t sector = 0; uint32_t mstrDir = 0; uint32_t cluster = 0; uint32_t filesize = 0; uint16_t fatSect, fsInfoSector; /* * ADC, Timer and other loco's */ uint16_t ADC_value; uint8_t errorTimer = 20; char timerString[16] = " "; /* * Initializing gpio's */ initializeUserButton(); initializeEveryRedLed(); initializeEveryGreenLed(); setupGpsGpio(); adcPinConfig(); initializeXbeeATTnPin(); /* * Initializing peripherals */ Usart2_Init(BAUD_4800); Usart1_Init(BAUD_9600); ConfigureUsart2Interrupt(); //used for delayMs() //not meant for using in interrupt routines initialiseSysTick(); //SPI1 for XBEE and SD card InitialiseSPI1_GPIO(); InitialiseSPI1(); //SPI2 used for accelerometer InitialiseSPI2_GPIO(); InitialiseSPI2(); //ADC is used for battery monitoring adcConfig(); //Timer counter with i=100ms Initialize_timer(); Timer_interrupt_enable(); /* * Initializing XBEE */ XBEE_CS_LOW(); while(errorTimer--){ SPI1_TransRecieve(0x00); } XBEE_CS_HIGH(); delayMs(1000); errorTimer = 20; XBEE_CS_LOW(); while(errorTimer--){ SPI1_TransRecieve(0x00); } XBEE_CS_HIGH(); /* * Start module only when button is pressed * Meanwhile, check the battery voltage */ while(moduleStatus == MODULE_NOT_RUNNING){ ADC_value = (ADC_GetConversionValue(ADC1)); ADC_value = (ADC_value * 330) / 128; batteryIndicationStartup(ADC_value); blinkGreenLeds(7); //if node is initialized through another XBEE if(xbeeDataUpdated){ if(xbeeReceiveBuffer[XBEE_DATA_MODE_OFFSET] == 'C'){ if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'G'){ state = 0x07; delayMs(100); strcpy(&xbeeTransmitString[0],"C O#"); xbeeTransmitString[4] = state + ASCII_DIGIT_OFFSET; xbeeTransmitString[5] = '\0'; transmitRequest(SERIAL_ADDR_HIGH,SERIAL_ADDR_LOW,TRANSOPT_DISACK, 0x00,xbeeTransmitString); xbeeDataUpdated = false; break; } else if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'H'){ //Accelerometer state |=0x01; delayMs(100); strcpy(&xbeeTransmitString[0],"C O#"); xbeeTransmitString[4] = state + ASCII_DIGIT_OFFSET; xbeeTransmitString[5] = '\0'; transmitRequest(SERIAL_ADDR_HIGH,SERIAL_ADDR_LOW,TRANSOPT_DISACK, 0x00,xbeeTransmitString); xbeeDataUpdated = false; break; } else if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'I'){ //GPS state |=0x02; delayMs(100); strcpy(&xbeeTransmitString[0],"C O#"); xbeeTransmitString[4] = state + ASCII_DIGIT_OFFSET; xbeeTransmitString[5] = '\0'; transmitRequest(SERIAL_ADDR_HIGH,SERIAL_ADDR_LOW,TRANSOPT_DISACK, 0x00,xbeeTransmitString); xbeeDataUpdated = false; break; } else if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'J'){ //SD state &=0x04; delayMs(100); strcpy(&xbeeTransmitString[0],"C O#"); xbeeTransmitString[4] = state + ASCII_DIGIT_OFFSET; xbeeTransmitString[5] = '\0'; transmitRequest(SERIAL_ADDR_HIGH,SERIAL_ADDR_LOW,TRANSOPT_DISACK, 0x00,xbeeTransmitString); xbeeDataUpdated = false; break; } } } } /* * LED blinking that indicates need to... * choose the method for integrity detection */ turnOnGreenLeds(state); for(errorTimer = 0 ; errorTimer < 8 ; errorTimer++){ redStartup(REAL_REAL_SLOW_DELAY); turnOnGreenLeds(state); if(xbeeDataUpdated){ if(xbeeReceiveBuffer[XBEE_DATA_MODE_OFFSET] == 'C'){ if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'G'){ state = 0x07; } else if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'H'){ //Accelerometer state |=0x01; } else if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'I'){ //GPS state |=0x02; } else if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'J'){ //SD state |=0x04; } } xbeeDataUpdated = false; delayMs(100); strcpy(&xbeeTransmitString[0],"C O#"); xbeeTransmitString[4] = state + ASCII_DIGIT_OFFSET; xbeeTransmitString[5] = '\0'; transmitRequest(SERIAL_ADDR_HIGH,SERIAL_ADDR_LOW,TRANSOPT_DISACK, 0x00,xbeeTransmitString); } } moduleStatus = MODULE_APPLYING_PARAMS; /* * Initialize Accelerometer if chosen */ if(state&0x01){ //SPI2 for ADXL initializeADXL362(); blinkRedLed1(); while(!return_ADXL_ready()){ //wait time for caps to discharge delayMs(2000); initializeADXL362(); delayMs(1000); blinkRedLed1(); } } /* * Initialize GPS if chosen */ //GPS module has 40 seconds to find enough satellites errorTimer = 50; if((state&0x02) >> 1){ turnGpsOn(); while(!GPIO_ReadInputDataBit(GPS_PORTC,WAKEUP_PIN) && errorTimer > 0){ turnGpsOn(); delayMs(1000); blinkRedLed2(); errorTimer--; SEND_SERIAL_MSG("Pulling GPS pin...\r\n"); } delayMs(GPS_MSG_INIT_DELAY); gps_dissableMessage($GPGSA); delayMs(GPS_MSG_INIT_DELAY); gps_dissableMessage($GPGSV); delayMs(GPS_MSG_INIT_DELAY); gps_dissableMessage($GPRMC); delayMs(GPS_MSG_INIT_DELAY); gps_dissableMessage($GPVTG); delayMs(GPS_MSG_INIT_DELAY); gps_setRate($GPGGA, 1); while(fix[0] == '0' && errorTimer > 0 ){ if(gpsDataUpdated){ errorTimer--; gpsDataUpdated = false; messageIterator = 0; // Make sure that you are comparing GPGGA message // $PSRF and $GPVTG messages are possable at the startup if(strncmp(gpsReceiveString,"$GPGGA", 6) == 0){ ptr = &gpsReceiveString[7]; //This value could change whether the $ is used or not for(; messageIterator < 7; messageIterator ++){ tmpPtr = ptrToNMEA[messageIterator]; while(*ptr++ != ','){ *ptrToNMEA[messageIterator]++ = *(ptr-1); } ptrToNMEA[messageIterator] = tmpPtr; } } SEND_SERIAL_MSG("Waiting for sats...\r\n"); blinkRedLed2(); } } //if not enough satellites are found, turn off gps if(!errorTimer){ SEND_SERIAL_MSG("GPS timeout...\r\n"); hibernateGps(); state &= 0xFD; } else{ //if satellites found -> turn on $GPVTG to monitor velocity delayMs(400); gps_setRate($GPVTG,1); delayMs(400); blinkRedLed2(); gps_dissableMessage($GPGGA); SEND_SERIAL_MSG("SATs found...\r\n"); } } /* * Initialize SD if chosen */ if((state&0x04) >> 2){ errorTimer = 10; while(!initializeSD() && errorTimer-- > 1){ delayMs(300); blinkRedLed3(); } if(!errorTimer){ //If sd card doesnt turn on, dont log anything to it state &= 0xFB; } else{ findDetailsOfFAT(sdBuffer,&fatSect,&mstrDir, &fsInfoSector); findDetailsOfFile("LOGFILE",sdBuffer,mstrDir,&filesize,&cluster,§or); /* * Program halts during this function */ findLastClusterOfFile("LOGFILE",sdBuffer, &cluster,fatSect,mstrDir); if(filesize < 512) filesize = 512; appendTextToTheSD("\nNEW LOG", '\n', &sdBufferCurrentSymbol, sdBuffer, "LOGFILE", &filesize, mstrDir, fatSect, &cluster, §or); } } /* * Send request to coordinator for time synchronization */ transmitRequest(COORDINATOR_ADDR_HIGH,COORDINATOR_ADDR_LOW,TRANSOPT_DISACK, 0x00,"C 0"); /* * Send response to serial node about readiness */ delayMs(100); strcpy(&xbeeTransmitString[0],"C N#"); xbeeTransmitString[4] = state + ASCII_DIGIT_OFFSET; xbeeTransmitString[5] = '\0'; transmitRequest(SERIAL_ADDR_HIGH,SERIAL_ADDR_LOW,TRANSOPT_DISACK, 0x00,xbeeTransmitString); /* * Wait for input to start communication */ moduleStatus = MODULE_IDLE_READY; turnOnGreenLeds(state); while(moduleStatus == MODULE_IDLE_READY){ /* * While indicating need for input * Check if coordinator has sent ACK message */ if(xbeeDataUpdated){ if(xbeeReceiveBuffer[XBEE_DATA_MODE_OFFSET] == 'C'){ if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == '1'){ globalCounter = atoi(&xbeeReceiveBuffer[16]) + TIMER_SYNC_DELAY; } else if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'K'){ moduleStatus = MODULE_RUNNING; } } xbeeDataUpdated = false; } blinkGreenLeds(state); redStartup(DELAY); } while(1){ /* * Check in what state module is running */ switch(moduleStatus){ case MODULE_RUNNING: delayMs(800); /* * Send Accelerometer data if chosen */ if(state&0x01){ getZ(&z,&z_low,&z_high); itoa(z, messurementString); xbeeTransmitString[0] = 'M'; xbeeTransmitString[1] = ' '; xbeeTransmitString[2] = '0'; xbeeTransmitString[3] = ' '; strcpy(&xbeeTransmitString[4],&messurementString[0]); transmitRequest(0x0013A200, 0x40E3E13C, TRANSOPT_DISACK, 0x00, xbeeTransmitString); /* * Log data to SD card if chosen */ if((state&0x04) >> 2){ itoa(globalCounter,timerString); appendTextToTheSD(timerString, '\t', &sdBufferCurrentSymbol, sdBuffer, "LOGFILE", &filesize, mstrDir, fatSect, &cluster, §or); appendTextToTheSD(xbeeTransmitString, '\t', &sdBufferCurrentSymbol, sdBuffer, "LOGFILE", &filesize, mstrDir, fatSect, &cluster, §or); xorGreenLed(2); } xorGreenLed(0); } delayMs(800); /* * Send GPS data if chosen */ if((state&0x02) >> 1){ if(strncmp(gpsReceiveString,"$GPVTG" , 6) == 0){ gps_parseGPVTG(gpsReceiveString,velocity); } else{ strcpy(velocity,"999.9"); } xbeeTransmitString[0] = 'M'; xbeeTransmitString[1] = ' '; xbeeTransmitString[2] = '1'; xbeeTransmitString[3] = ' '; strcpy(&xbeeTransmitString[4],velocity); transmitRequest(0x0013A200, 0x40E3E13C, TRANSOPT_DISACK, 0x00, xbeeTransmitString); /* * Log data to SD card if chosen */ if((state&0x04) >> 2){ appendTextToTheSD(xbeeTransmitString, '\n', &sdBufferCurrentSymbol, sdBuffer, "LOGFILE", &filesize, mstrDir, fatSect, &cluster, §or); xorGreenLed(2); } xorGreenLed(1); } break; case MODULE_IDLE_READY: if(turnOffTimer > 0){ turnOffTimer--; blinkGreenLeds(state); redStartup(DELAY); } else{ blinkGreenLeds(state); ADC_value = (ADC_GetConversionValue(ADC1)); ADC_value = (ADC_value * 330) / 128; batteryIndicationStartup(ADC_value); } break; case MODULE_TURNING_OFF: if((state&0x04) >> 2){ goToIdleState(); } if((state&0x02) >> 1){ hibernateGps(); } state = 0; turnOffTimer = 0; moduleStatus = MODULE_IDLE_READY; break; } if(xbeeDataUpdated){ if(xbeeReceiveBuffer[XBEE_DATA_MODE_OFFSET] == 'C'){ if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'K'){ moduleStatus = MODULE_RUNNING; } else if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'L'){ moduleStatus = MODULE_IDLE_READY; } else if(xbeeReceiveBuffer[XBEE_DATA_TYPE_OFFSET] == 'M'){ moduleStatus = MODULE_TURNING_OFF; } } xbeeDataUpdated = false; delayMs(100); strcpy(&xbeeTransmitString[0],"C O#"); xbeeTransmitString[4] = state + ASCII_DIGIT_OFFSET; xbeeTransmitString[5] = '\0'; transmitRequest(SERIAL_ADDR_HIGH,SERIAL_ADDR_LOW,TRANSOPT_DISACK, 0x00,xbeeTransmitString); } }
int main(void){ int c; int b; int counterNewPassword = 0; int counterInputPassword = 0; int counterOldPassword = 0; initPins(); initCounterValues(); initTimers(); initSerial(); while (1) { c = getchar(); if (isdigit(c)) { previousChar = c; if (c == '6') { if (strcmp(password, inputPassword) == 0) { allowEntry(); } else { prohibitEntry(); } delayMS(counterDelay); disableLedsAndRelay(); memset(inputPassword, 0, 9); memset(oldPassword, 0, 9); previousChar = '~'; counterInputPassword = 0; counterOldPassword = 0; } else if (c == '7') { if (strlen(newPassword) > 0 & strcmp(oldPassword, password) == 0) { memset(password, 0, 9); strcpy(password, newPassword); memset(newPassword, 0, 9); previousChar = '~'; counterNewPassword = 0; blinkGreenLeds(); } else { blinkRedLeds(); } memset(oldPassword, 0, 9); counterOldPassword = 0; } else { memset(inputPassword, 0, 9); memset(newPassword, 0, 9); counterNewPassword = 0; counterInputPassword = 0; } } else if (c >= 'A' & c <= '|') { switch (previousChar) { case '1': if (c >= 'A' & c <= 'J' & counterInputPassword < 8) { //unosimo password u string inputPassword inputPassword[counterInputPassword] = c; counterInputPassword++; } if (c >= 'a' & c <= 'j' & counterInputPassword < 8) { newPassword[counterNewPassword] = c - 32; counterNewPassword++; } break; case '2': if (islower(c)) { if (c <= 'm') { //dozvoli paljenje ledica ledStatus = 1; } else { //blokiraj paljene ledica ledStatus = 0; } } else { if (c <= 'M') { //dozvoli koristenje senzora sensorStatus = 1; blinkGreenLeds(); } else { //blokiraj koristenje senzora sensorStatus = 0; blinkGreenLeds(); } } break; case '3': if (islower(c)) { if (c <= 'x') { //radno vrijeme u satima, npr. 1,2,3... workingHours = c - 'a'; } } else { if (c <= 'X') { //sati koji ovise o trenutnoj vrijednosti brojaca; droid aplikacija ih racuna te salje ovdje currentCounterHours = c - 'A'; } } break; case '4': //trenutne minute counterMinutes = c - 'A'; break; case '5': if (islower(c)) { if (c <= 'm') { for (b = 0; b < 3; b++) { blinkGreenLeds(); } } else { for (b = 0; b < 3; b++) { blinkRedLeds(); } } } else { if (c >= 'D' & c <= 'K') { //kasnjenje ulaza u milisekundama, npr.1000,2000....10000 counterDelay = 1000 * (c - 'A'); } } break; case '8': if (c >= 'A' & c <= 'J' & counterOldPassword < 8) { //unosimo password u string oldPassword oldPassword[counterOldPassword] = c; counterOldPassword++; } break; ; default: disableLedsAndRelay(); break; } } if (sensorStatus) { if (IO0PIN & (1 << sensorPin)) { if (currentCounterHours < workingHours) { allowEntry(); } else { prohibitEntry(); } } else { disableLedsAndRelay(); } } else { disableLedsAndRelay(); } } }