Esempio n. 1
0
/*
 * Read the serial number from the 1-wire bus and return it.
 * Returns 0 if successful.
 * Returns non-zero if not successful.
 */
 int ds2401_get_number( unsigned char id[6] )
 {
	 int ii, result;
	 unsigned char crc;
	 unsigned char buf[8];
	 ds2401_init();

	 result = ds2401_reset();
	 if (result != 0)
		 return 2;

	 ds2401_write_byte(DS2401_CMD_READ_ROM); /* send read rom command */

	 /*
	  * read 8 bytes:
	  * buf[0]       - family code (0x01)
	  * buf[1..6]    - serial number
	  * buf[7]       - CRC
	  */
	 for (ii = 0; ii < 8; ii++)
		 buf[ii] = ds2401_read_byte();

	 /*
	  * calculate the 8-bit Dallas CRC
	  */
	 crc = ds2401_calc_crc8( buf, 7 );

	 if ( crc != buf[7] )
		 return 1;

	 for (ii = 0; ii < 6; ii++)
		 id[ii] = buf[ii + 1];

	 return 0;
 }
Esempio n. 2
0
int
main(void)
{

  leds_init();

  leds_on(LEDS_RED);

  /* Initialize USART */
  init_usart();
  
  /* Clock */
  clock_init();

  leds_on(LEDS_GREEN);

  ds2401_init();

  random_init(0);

  rtimer_init();

  /* Process subsystem */
  process_init();

  process_start(&etimer_process, NULL);

  ctimer_init();

  leds_on(LEDS_YELLOW);

  init_net();

  node_id_restore();
  
  printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n"),
                                                       node_id, rime_mac->name);
  printf_P(PSTR("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n"),
	 ds2401_id[0], ds2401_id[1], ds2401_id[2], ds2401_id[3],
	 ds2401_id[4], ds2401_id[5], ds2401_id[6], ds2401_id[7]);

  leds_off(LEDS_ALL);

  /* Autostart processes */
  autostart_start(autostart_processes);

  /* Main scheduler loop */
  do {

    process_run();

  }while(1);

  return 0;
}
Esempio n. 3
0
/*---------------------------------------------------------------------------*/
int
main(void)
{

  leds_init();

  leds_on(LEDS_RED);

  /* Initialize USART */
  init_usart();
  
  /* Clock */
  clock_init();

  leds_on(LEDS_GREEN);

  ds2401_init();
  
  node_id_restore();

  random_init(ds2401_id[0] + node_id);

  rtimer_init();

  /* Process subsystem */
  process_init();

  process_start(&etimer_process, NULL);

  ctimer_init();

  leds_on(LEDS_YELLOW);
  
  init_net();
  
  printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u\n"), node_id);

  leds_off(LEDS_ALL);

  /* Autostart processes */
  autostart_start(autostart_processes);

  mmem_init();
  /* Main scheduler loop */
  do {

    process_run();

  }while(1);

  return 0;
}
Esempio n. 4
0
 void init_ds2401(void)
 {
	 ds2401_init();
 }
/*------Done in a subroutine to keep main routine stack usage small--------*/
void
initialize(void)
{
#ifdef BUZZER
  buzz_id();
#endif

  watchdog_init();
  watchdog_start();

  clock_init();

  PRINTD("\n\nChecking MCUSR...\n");
  if(MCUSR & (1<<PORF )) PRINTD("Power-on reset.\n");
  if(MCUSR & (1<<EXTRF)) PRINTD("External reset!\n");
  if(MCUSR & (1<<BORF )) PRINTD("Brownout reset!\n");
  if(MCUSR & (1<<WDRF )) PRINTD("Watchdog reset!\n");
  if(MCUSR & (1<<JTRF )) PRINTD("JTAG reset!\n");
  MCUSR = 0;

  PRINTD("CLOCK_SECOND %d\n",CLOCK_SECOND);
  PRINTD("RTIMER_ARCH_SECOND %lu\n",RTIMER_ARCH_SECOND);
  PRINTD("F_CPU %lu\n",F_CPU);

#if STACKMONITOR
  /* Simple stack pointer highwater monitor. Checks for magic numbers in the main
   * loop. In conjuction with PERIODICPRINTS, never-used stack will be printed
   * every STACKMONITOR seconds.
   */
{
extern uint16_t __bss_end;
uint16_t p=(uint16_t)&__bss_end;
    do {
      *(uint16_t *)p = 0x4242;
      p+=10;
    } while (p<SP-10); //don't overwrite our own stack
}
#endif

/* Calibrate internal mcu clock against external 32768Hz watch crystal */
#define CONF_CALIBRATE_OSCCAL 0
#if CONF_CALIBRATE_OSCCAL
void calibrate_rc_osc_32k();
{
extern uint8_t osccal_calibrated;
uint8_t i;
  PRINTD("\nBefore calibration OSCCAL=%x\n",OSCCAL);
  for (i=0;i<10;i++) {
    calibrate_rc_osc_32k();
    PRINTD("Calibrated=%x\n",osccal_calibrated);
//#include <util/delay_basic.h>
//#define delay_us( us )   ( _delay_loop_2(1+(us*F_CPU)/4000000UL) )
//   delay_us(50000);
 }
   clock_init();
}
#endif 

  PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);

  leds_init();
  leds_on(LEDS_RED);

  /* Initialize USART */
#ifdef CAMERA_INTERFACE
  camera_init();
#else
  init_usart();
#endif

/* rtimers needed for radio cycling */
  rtimer_init();

 /* Initialize process subsystem */
  process_init();
 /* etimers must be started before ctimer_init */
  process_start(&etimer_process, NULL);

#if RF2XXBB
  ds2401_init();
  node_id_restore();

  /* Get a random seed for the 802.15.4 packet sequence number.
   * Some layers will ignore duplicates found in a history (e.g. Contikimac)
   * causing the initial packets to be ignored after a short-cycle restart.
   */
  random_init(rng_get_uint8());

  ctimer_init();

  init_net();
#else /* !RF2XXBB */
/* Original RF230 combined mac/radio driver */
/* mac process must be started before tcpip process! */
  process_start(&mac_process, NULL);
  process_start(&tcpip_process, NULL);
#endif /* RF2XXBB */

  /* Autostart other processes */
  autostart_start(autostart_processes);

  /*---If using coffee file system create initial web content if necessary---*/
#if COFFEE_FILES
  int fa = cfs_open( "/index.html", CFS_READ);
  if (fa<0) {     //Make some default web content
    PRINTA("No index.html file found, creating upload.html!\n");
    PRINTA("Formatting FLASH file system for coffee...");
    cfs_coffee_format();
    PRINTA("Done!\n");
    fa = cfs_open( "/index.html", CFS_WRITE);
    int r = cfs_write(fa, &"It works!", 9);
    if (r<0) PRINTA("Can''t create /index.html!\n");
    cfs_close(fa);
//  fa = cfs_open("upload.html"), CFW_WRITE);
// <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html>
  }
#endif /* COFFEE_FILES */

/* Add addresses for testing */
#if 0
{
  uip_ip6addr_t ipaddr;
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
//  uip_ds6_prefix_add(&ipaddr,64,0);
}
#endif

/*--------------------------Announce the configuration---------------------*/
#if ANNOUNCE_BOOT
{
#if AVR_WEBSERVER
  uint8_t i;
  char buf1[40],buf[40];
  unsigned int size;

  for (i=0;i<UIP_DS6_ADDR_NB;i++) {
	if (uip_ds6_if.addr_list[i].isused) {
	   httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf);
       PRINTA("IPv6 Address: %s\n",buf);
	}
  }
   cli();
   eeprom_read_block (buf1,eemem_server_name, sizeof(eemem_server_name));
   eeprom_read_block (buf,eemem_domain_name, sizeof(eemem_domain_name));
   sei();
   buf1[sizeof(eemem_server_name)]=0;
   PRINTA("%s",buf1);
   buf[sizeof(eemem_domain_name)]=0;
   size=httpd_fs_get_size();
#ifndef COFFEE_FILES
   PRINTA(".%s online with fixed %u byte web content\n",buf,size);
#elif COFFEE_FILES==1
   PRINTA(".%s online with static %u byte EEPROM file system\n",buf,size);
#elif COFFEE_FILES==2
   PRINTA(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10);
#elif COFFEE_FILES==3
   PRINTA(".%s online with static %u byte program memory file system\n",buf,size);
#elif COFFEE_FILES==4
   PRINTA(".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
#endif /* COFFEE_FILES */

#else
   PRINTA("Online\n");
#endif /* AVR_WEBSERVER */

#endif /* ANNOUNCE_BOOT */
}
}
Esempio n. 6
0
/*-------------------------------------------------------------------------------------------*/
PROCESS_THREAD(test_process, ev, data)
{
	           user.userID=1;
	           uip_ipaddr_t ipaddr;

	           ds2401_init();
	          int ii;
	           for (ii = 0; ii < 7; ii++) {
	             printf("%02x:", ds2401_id[ii]);
	           }
	           printf("%02x\n", ds2401_id[7]);
				static struct etimer timer;

				struct udp_tx *udp_tx_info = (udp_tx*) malloc(sizeof(udp_tx));

				PROCESS_BEGIN();

			   uip_ip6addr(&ipaddr, ipv6_addr[0], ipv6_addr[1],ipv6_addr[2],ipv6_addr[3],
						                          ipv6_addr[4],ipv6_addr[5],ipv6_addr[6],ipv6_addr[7]);

			   server_conn = udp_new(NULL,UIP_HTONS(0), NULL);
			   server_conn2 = udp_new(&ipaddr,UIP_HTONS(3007), NULL);

			   udp_bind(server_conn, uip_htons(3001));
			   udp_bind(server_conn2, uip_htons(3005));
				memset(udp_tx_info, 0, sizeof(udp_tx));

			   while(1)
				{
/*--------------------------------------------------------------------------------------------*/
				   if(Sendonce_flag == 0){
					   etimer_set(&timer, CLOCK_SECOND*5);
					   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
					   udp_send_register(udp_tx_info);
					 //  udp_send_data(udp_tx_info);
					   PRINTF("udp_tx_info->len = %d\r\n",udp_tx_info->len);
					   server_conn2->rport=uip_htons(3007);
					   uip_udp_packet_send(server_conn2, &udp_tx_info->buf[0], udp_tx_info->len);
					   server_conn2->rport=0;
					   Sendonce_flag = 1;
					  			printf("Send once!\n");
					  			leds_toggle(LEDS_GREEN);
				   }
  /*--------------------------------------------------------------------------------------------*/
			       if(Sample_begin_flag==1)
			       {
			    	   etimer_set(&timer, CLOCK_SECOND*Sample_Interval);
			    	   printf("Sample_Interval:%d\n",Sample_Interval);
			    	  do{
			                   PROCESS_WAIT_EVENT();
			             	 if (ev == PROCESS_EVENT_TIMER)
			             	 {
			             		 printf("data send lym 001\n");
			             		udp_send_data(udp_tx_info);
			             	    PRINTF("udp_tx_info->len = %d\r\n",udp_tx_info->len);
			             	    uip_udp_packet_send(server_conn2, &udp_tx_info->buf[0], udp_tx_info->len);
			             		 printf("wait\n");
			             		 etimer_reset(&timer);
			             		leds_toggle(LEDS_GREEN);
			             	 }
			             	 else if(ev == tcpip_event)
			             	 {
			             		 tcpip_handler(udp_tx_info);
			             	 }
			    	     }
			    	  while(Sample_begin_flag==1);
			       }
/*--------------------------------------------------------------------------------------------*/
				   PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
				   tcpip_handler(udp_tx_info);
			    }
			    PROCESS_END();
}