Пример #1
0
void readline(char s[],uint8_t m){
  /* Llegeix un numero de caracters m pel port serie
     i els fica en la taula s, en el cas de que es llegeixi
     un caracter no printable deixa de llegir */
  
  uint8_t i=0,a;
  a=serial_get();
  while (m!=i && isgraph(a)){
    s[i] = a;
    i++;
    a=serial_get();
    
  }
  s[i]='\0';
}
Пример #2
0
// Drain data from serial up to and including '\0'
void Comm::serial_drain()
{
    while (true) {
        byte val = serial_get();
        if (val == '\0') {
            break;
        }
    }
}
Пример #3
0
byte Comm::read()
{
    if (m_addr) {               // I'm on I2C
        return wire_get();
    }
    else {                      // I'm on serial
        return serial_get();
    }
}
Пример #4
0
/**@brief Function for the application main entry.
 */
int main(void)
{
  uint32_t err_code;

  load_app();
  gpio_init();
  ble_stack_init();
  device_manager_init();

  juma_init();
  
  // initialize Bluetooth Stack parameters.
  gap_params_init();
  advertising_init();
  services_init();
  dispatch_init();

  flash_init();
  
  if (app) {
			device_current_statue_set(DEVICE_STATUE_APP);
      data_storage_init();
      on_ready();
  } else {
			device_current_statue_set(DEVICE_STATUE_OTA);
      ble_device_set_name("OTA Mode");
      ota_init();
      ble_device_set_advertising_interval(200);
      ble_device_start_advertising();
  }
  
  // Enter main loop.
  for (;;)
  {
      watchDog_sys_SDK_dog1_RR();
    
      if(0 != enter_ota_mode_statue)
      {
        enter_ota_process(NULL);
      }
      else
      {
        dispatch();
      }
      
      serial_get();
      // Switch to a low power state until an event is available for the application
      err_code = sd_app_evt_wait();
      APP_ERROR_CHECK(err_code);
  }
}
Пример #5
0
bool Comm::transmit(byte addr, byte nbytes)
{                               // master
    Wire.beginTransmission(addr);
    // Wire.send(addr);
    // Wire.send(nbytes);
    while (nbytes) {
        --nbytes;
        byte val = serial_get();
        Wire.send(val);
    }
    Wire.send('\0');
    Wire.endTransmission();
    return true;
}
Пример #6
0
void Comm::process_serial()
{
    if (! Serial.available()) {
        return;
    }

    byte addr = serial_get();
    byte pkt = serial_get();
    byte num = serial_get();

    bool okay = false;
    if (!addr) {                // handle by master
        if (m_handler) {
            okay = m_handler(num);
            serial_drain();
        }
        else {
            okay = drain(num);
        }
    }
    else {                      // send to slave
        okay = transmit(addr,num);
        serial_drain();
    }

    if (okay) {
        Serial.print("OK");
    }
    else {
        Serial.print("NO");
    }
    Serial.print(pkt);
    Serial.print(addr);
    Serial.print(num);
    Serial.print('\0');
}
Пример #7
0
int setserial_main(int argc UNUSED_PARAM, char **argv)
{
	int opts;

	opt_complementary = "-1:b-aG:G-ab:a-bG";
	opts = getopt32(argv, "bGavzg");
	argv += optind;

	if (!argv[1]) /* one arg only? */
		opts |= OPT_GET;

	if (!(opts & OPT_GET)) {
		serial_set(argv, opts);
		argv[1] = NULL;
	}

	if (opts & (OPT_VERBOSE | OPT_GET)) {
		do {
			serial_get(*argv++, opts & OPT_MODE_MASK);
		} while (*argv);
	}

	return EXIT_SUCCESS;
}
Пример #8
0
static void
main_thread(void *pdata) {
    QueueSetHandle_t qs;
    QueueSetMemberHandle_t active;

    ASSERT((qs = xQueueCreateSet(SERIAL_RX_SIZE * 3)));
    serial_start(cli_serial, 115200, qs);
    serial_start(&Serial4, 57600, qs);
    serial_start(&Serial5, cfg.gps_baud_rate ? cfg.gps_baud_rate : 57600, qs);
    cli_set_output(cli_serial);
    log_start(cli_serial);
    cl_enabled = 1;

    load_eeprom();
    cfg.flags &= ~FLAG_HOLDOVER_TEST;
    if (cfg.flags & FLAG_GPSEXT) {
        gps_serial = &Serial5;
    } else {
        gps_serial = &Serial4;
    }
    if (!cfg.holdover) {
        cfg.holdover = 60;
    }
    if (!cfg.loopstats_interval) {
        cfg.loopstats_interval = 60;
    }
    ppscapture_start();
    vtimer_start();
    tcpip_start();
    test_reset();
    cli_banner();
    if (!(cfg.flags & FLAG_GPSEXT)) {
        ublox_configure();
        if (HAS_FEATURE(PPSEN) && (cfg.flags & FLAG_PPSEN)) {
            GPIO_OFF(PPSEN);
        }
    }
    cl_enabled = 0;
    while (1) {
        watchdog_main = 5;
        active = xQueueSelectFromSet(qs, pdMS_TO_TICKS(1000));
        if (active == cli_serial->rx_q) {
            int16_t val = serial_get(cli_serial, TIMEOUT_NOBLOCK);
            ASSERT(val >= 0);
            cli_feed(val);
        } else if (active == gps_serial->rx_q) {
            int16_t val = serial_get(gps_serial, TIMEOUT_NOBLOCK);
            ASSERT(val >= 0);
            gps_byte_received(val);
            if (cfg.flags & FLAG_GPSOUT) {
                char tmp = val;
                serial_write(&Serial5, &tmp, 1);
            }
#if 0
        } else if (active == Serial5.rx_q) {
            char tmp = serial_get(&Serial5, TIMEOUT_NOBLOCK);
            serial_write(&Serial4, &tmp, 1);
#endif
        }
    }
}
Пример #9
0
/**
 * Returns 0 if the selected folder wasn't modified, or 1 if things changed and the updated status should be sent to the client. A -1
 * is used to indicate the update check encountered a problem and should be retried later.
 */
int_t imap_session_update(connection_t *con) {

	int_t result = 0;
	inx_cursor_t *cursor;
	meta_message_t *active;
	uint64_t recent = 0, exists = 0, checkpoint;

	// Check for the right state.
	if (con->imap.session_state != 1 || con->imap.user == NULL || con->imap.selected == 0) {
		return -1;
	}

	if ((checkpoint = serial_get(OBJECT_USER, con->imap.user->usernum)) != con->imap.user_checkpoint) {
		meta_user_wlock(con->imap.user);

		// Update the user preferences.
		if (checkpoint != con->imap.user->serials.user) {
			meta_user_update(con->imap.user, META_LOCKED);
		}

		// Store the new checkpoint.
		con->imap.user_checkpoint = con->imap.user->serials.user;
		meta_user_unlock(con->imap.user);
	}

	if ((checkpoint = serial_get(OBJECT_FOLDERS, con->imap.user->usernum)) != con->imap.folders_checkpoint) {
		meta_user_wlock(con->imap.user);

	   // Update the list of folders.
		if (checkpoint != con->imap.user->serials.folders) {
			meta_folders_update(con->imap.user, META_LOCKED);
		}

		// Store the new checkpoint.
		con->imap.folders_checkpoint = con->imap.user->serials.folders;
		meta_user_unlock(con->imap.user);
	}

	if ((checkpoint = serial_get(OBJECT_MESSAGES, con->imap.user->usernum)) != con->imap.messages_checkpoint) {
		meta_user_wlock(con->imap.user);

		if (checkpoint != con->imap.user->serials.messages) {
			meta_messages_update(con->imap.user, META_LOCKED);
		}

		// If there is a selected folder, scan the status.
		if ((cursor = inx_cursor_alloc(con->imap.user->messages))) {

			while ((active = inx_cursor_value_next(cursor))) {

				if (active->foldernum == con->imap.selected && (active->status & MAIL_STATUS_RECENT) == MAIL_STATUS_RECENT) {
					recent++;
					exists++;
				}
				else if (active->foldernum == con->imap.selected) {
					exists++;
				}

			}

			inx_cursor_free(cursor);
		}

		// If the folder has changed, output the current status.
		if (con->imap.messages_recent != recent || con->imap.messages_total != exists) {
			con->imap.messages_recent = recent;
			con->imap.messages_total = exists;
			result = 1;
		}

		// Store the new checkpoint.
		con->imap.messages_checkpoint = con->imap.user->serials.messages;

		meta_user_unlock(con->imap.user);
	}

	return result;
}
Пример #10
0
int main(void) {
  int itmp;

  ////////////////////////////////////////////////////////////////
  // Initialization

  main_init();
//  while(1);

  while(power_fail) {
    printf(".");
    timer2_wait(1000);
  }

  fpga_init();
  
  print_menu(0);

/*  fpga_put_eeprom_uint16(FPGA_COEFF_BASE, (uint16_t)(-12288));
  fpga_put_eeprom_uint16(FPGA_COEFF_BASE+2, 4096);
  fpga_put_eeprom_uint16(FPGA_COEFF_BASE+4, 16384);
  fpga_put_eeprom_uint16(FPGA_COEFF_BASE+6, 0);
  fpga_put_eeprom_uint16(FPGA_COEFF_BASE+8, 8192);
  fpga_put_eeprom_uint16(FPGA_COEFF_BASE+10, 0);
  fpga_put_eeprom_uint16(FPGA_COEFF_BASE+12, -16384);
  fpga_put_eeprom_uint16(FPGA_COEFF_BASE+14, 0);*/
  
  ////////////////////////////////////////////////////////////////
  // Main loop

  serial_set_echo(SERIAL_ECHO_OFF);

/*  while(1) {
    DDRG = 0xFF;
    PORTG = 0x00;
    PORTD |= (1<<PD7);
    timer2_wait(10000);
    PORTG = 0xFF;
    PORTD &= ~(1<<PD7);
    timer2_wait(10000);
  }*/

  itmp = -1;
  
//  while(1) {
  while(power_fail==0) {
    itmp = serial_get();
    if(fpga_check_cfg_done()==0) {
      printf("\r\nFPGA Configuring");
      while(fpga_check_cfg_done()==0) {
        printf(".");
	timer2_wait(500);
      }
      itmp=0;
    }
    if(itmp != -1) {
      print_menu((unsigned char)(itmp));
    }
    operation_power_check();
  }

  // Main loop exited with power failure
  PORTD &= ~(1<<PD5);
  PORTB &= ~((1<<PB6)|(1<<PB7)); // Power off
  printf(COLOR_RED"Power failed while operating (Code %x)! Shut down and abort!"COLOR_OFF, power_fail);
  power_error(power_fail);

  while(1) {
    timer2_wait(500);
    printf(".");
  }
  
  // We should never get to this point
  return 0;
}
Пример #11
0
void tick_monitor(void){	/*Determina si hi ha alguna ordre del supervisor per llegir. Les
				  ordres segueixen el protocol que s'ha explicat a l'apartat 2.1. Si
				  és el cas la llegeix i executa l'acció associada a l'ordre.*/	
  uint8_t char_order;	      	/*Declarem la variable per a enmagatzemar la lletra que rebem.*/
  if(serial_can_read()){	/*Si hi ha informació rebuda, llegeix-la. En cas contrari, salta
				  tot el procés.*/
    char_order = serial_get();	/*Rep l'irdre.*/
    if(char_order == 'E'){	/*Si hem rebut la "E" ves al procés d'emergencia.*/
      if (state!=Off){		/*Si el semafor está parat no facis el procés.*/
	state = Clear;		/*Posa en verd el semafor.*/
	semaphore_set(state);
	ticks_remaining = 40;	/*Reinicia el temps d'estar amb el semafor en verd.*/
	
	/*Enviem el missatge que indica que s'ha cambiat correctament el semafor*/				
	serial_put('E');
	serial_put('M');
	serial_put('E');
	serial_put('R');
	serial_put('G');
	serial_put('E');
	serial_put('N');
	serial_put('C');
	serial_put('Y');
	serial_put('\n');
      }
      else {			/*Si tenim el semafor parat, retorna una "N"*/
	serial_put('N');	
	serial_put('\n');
      }
    }
    
    else if(char_order == 'S'){	/*Si hem rebut la "S" ves al procés d'apagat.*/
      if(state != Off){		/*Si el semafor está parat no facis el procés.*/
	state=Off;		/*Posa en verd el semafor.*/
	semaphore_set(state);
	
	/*Enviem el missatge que indica que s'ha apagat correctament el semafor*/	
	serial_put('S');
	serial_put('H');
	serial_put('U');
	serial_put('T');
	serial_put('D');
	serial_put('O');
	serial_put('W');
	serial_put('N');
	serial_put('\n');
	
      }
      else{
	serial_put('J');
	serial_put('\n');
      }
    }
    else if(char_order == 'R'){	/*Si hem rebut la "R" ves al procés d'start.*/
      if(state == Off){		/*Si el semafor está parat fes el procés.*/
	state = Clear;		/*Posa en verd el semafor.*/
	semaphore_set(state);
	ticks_remaining = 40;	/*Reinicia el temps d'estar amb el semafor en verd.*/
	
	/*Enviem el missatge que indica que s'ha encés correctament el semafor*/	
	serial_put('R');
	serial_put('E');
	serial_put('S');
	serial_put('T');
	serial_put('A');
	serial_put('R');
	serial_put('T');
	serial_put('\n');
      }
      else{
	serial_put('J');
	serial_put('\n');
      }
    }
  }
}