Esempio n. 1
0
//--------------------------------------------------------------------
void
ccreg(char *in)
{
  uint8_t hb, out;

  if(fromhex(in+1, &hb, 1)) {

    if(hb == 0x99) {
      for(uint8_t i = 0; i < 0x30; i++) {
        DH2(cc1100_readReg(i));
        if((i&7) == 7)
          DNL();
      }
    } else {
      out = cc1100_readReg(hb);
      DC('C');                    // prefix
      DH2(hb);                    // register number
      DS_P( PSTR(" = ") );
      DH2(out);                  // result, hex
      DS_P( PSTR(" / ") );
      DU(out,2);                  // result, decimal
      DNL();
    }

  }
}
Esempio n. 2
0
void
fht_display_buf(uint8_t ptr[])
{
#ifdef FHTDEBUG
#warning FHT USB DEBUGGING IS ACTIVE
  uint8_t odc = display_channel;
  display_channel = DISPLAY_USB;
  uint16_t *p = (uint16_t *)&ticks;
  DU(*p, 5);
  DC(' ');
  DH2(fht80b_state);
  DC(' ');
#else
  if(!(tx_report & REP_FHTPROTO))
    return;
#endif

  DC('T');
  for(uint8_t i = 0; i < 5; i++)
    DH2(ptr[i]);
  if(tx_report & REP_RSSI)
    DH2(250);
  DNL();
#ifdef FHTDEBUG
  display_channel = odc;
#endif
}
Esempio n. 3
0
void
moritz_sendAck(uint8_t* enc)
{
  uint8_t ackPacket[12];
  ackPacket[0] = 11; /* len*/
  ackPacket[1] = enc[1]; /* msgcnt */
  ackPacket[2] = 0; /* flag */
  ackPacket[3] = 2; /* type = Ack */
  for(int i=0;i<3;++i) /* src = enc_dst*/
    ackPacket[4+i] = enc[7+i];
  for(int i=0;i<3;++i) /* dst = enc_src */
    ackPacket[7+i] = enc[4+i];
  ackPacket[10] = 0; /* groupid */
  ackPacket[11] = 0; /* payload */

  my_delay_ms(20); /* by experiments */

  moritz_sendraw(ackPacket, 0);

  //Inform FHEM that we send an autoack
  DC('Z');
  for (uint8_t i=0; i < ackPacket[0]+1; i++)
    DH2( ackPacket[i] );
  if (tx_report & REP_RSSI)
    DH2( 0 ); //fake some rssi
  DNL();
}
Esempio n. 4
0
//--------------------------------------------------------------------
void
ccreg(char *in)
{
  uint8_t hb, out, addr;

  if(in[1] == 'w' && fromhex(in+2, &addr, 1) && fromhex(in+4, &hb, 1)) {
    cc1100_writeReg(addr, hb);
    ccStrobe( CC1100_SCAL );
    ccRX();
    DH2(addr); DH2(hb); DNL();

  } else if(fromhex(in+1, &hb, 1)) {

    if(hb == 0x99) {
      for(uint8_t i = 0; i < 0x30; i++) {
        DH2(cc1100_readReg(i));
        if((i&7) == 7)
          DNL();
      }
    } else {
      out = cc1100_readReg(hb);
      DC('C');                    // prefix
      DH2(hb);                    // register number
      DS_P( PSTR(" = ") );
      DH2(out);                  // result, hex
      DS_P( PSTR(" / ") );
      DU(out,2);                  // result, decimal
      DNL();
    }

  }
}
Esempio n. 5
0
File: dmx.c Progetto: Talustus/culfw
void dmx_func(char *in) {
  uint8_t hb[4], d = 0;

  if(in[1] == 'r') {                // print latest record
    memset( hb, 0, sizeof(hb) );
    d = fromhex(in+2, hb, 1);
    if(d) {
       DH2( dmx_get_level( hb[0] ));
       DNL();
    }

  } else if(in[1] == 'w') {

    memset( hb, 0, sizeof(hb) );
    d = fromhex(in+2, hb, 2);
    if(d == 2) {
       dmx_set_level( hb[0], hb[1] );
    }
    if(d > 0) {
       DH2( dmx_get_level( hb[0] ));
       DNL();
    }

  } else if(in[1] == 'c') {
       DU( channel_count, 3 );
       DNL();

  }
}
Esempio n. 6
0
void
rf_moritz_task(void)
{
  uint8_t enc[MAX_MORITZ_MSG];
  uint8_t rssi;

  if(!moritz_on)
    return;

  // see if a CRC OK pkt has been arrived
  if(bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
    //errata #1 does not affect us, because we wait until packet is completely received
    enc[0] = CC1100_READREG( CC1100_RXFIFO ) & 0x7f; // read len

    if (enc[0]>=MAX_MORITZ_MSG)
         enc[0] = MAX_MORITZ_MSG-1;

    CC1100_ASSERT;
    cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );

    for (uint8_t i=0; i<enc[0]; i++) {
         enc[i+1] = cc1100_sendbyte( 0 );
    }

    // RSSI is appended to RXFIFO
    rssi = cc1100_sendbyte( 0 );
    // And Link quality indicator, too
    /* LQI = */ cc1100_sendbyte( 0 );

    CC1100_DEASSERT;

    moritz_handleAutoAck(enc);

    if (tx_report & REP_BINTIME) {

      DC('z');
      for (uint8_t i=0; i<=enc[0]; i++)
      DC( enc[i] );
    } else {
      DC('Z');
      for (uint8_t i=0; i<=enc[0]; i++)
        DH2( enc[i] );
      if (tx_report & REP_RSSI)
        DH2(rssi);
      DNL();
    }

    return;
  }

  if(CC1100_READREG( CC1100_MARCSTATE ) == 17) {
    CCSTROBE( CC1100_SFRX  );
    CCSTROBE( CC1100_SIDLE );
    CCSTROBE( CC1100_SRX   );
  }
}
Esempio n. 7
0
void
gettime(char *unused)
{
  uint32_t actticks;
  get_timestamp(&actticks);
  uint8_t *p = (uint8_t *)&actticks;
  DH2(p[3]);
  DH2(p[2]);
  DH2(p[1]);
  DH2(p[0]);
  DNL();
}
Esempio n. 8
0
void native_func(char *in) {
  uint8_t mode = 0;

  if(in[1] == 'r') {                // Reception on
    
    // "Er<x>" - where <x> is mode
    if (in[2])
      fromdec(in+2, &mode);

    if (!mode || mode>MAX_MODES) {
      DS_P(PSTR("specify valid mode number\r\n"));
      return;
    }
    
    native_init(mode);

  } else if(in[1] == 'x') {        // Reception off

    if (native_on)
      ccStrobe( CC1100_SIDLE );
    
    native_on = 0;

  }

  DH2(native_on);
  DNL();
  
}
Esempio n. 9
0
void
dumpmem(uint8_t *addr, uint16_t len)
{
  for(uint16_t i = 0; i < len; i += 16) {
    uint8_t l = len;
    if(l > 16)
      l = 16;
    DH(i,4);
    DC(':'); DC(' ');
    for(uint8_t j = 0; j < l; j++) {
      DH2(addr[j]);
      if(j&1)
        DC(' ');
    }
    DC(' ');
    for(uint8_t j = 0; j < l; j++) {
      if(addr[j] >= ' ' && addr[j] <= '~')
        DC(addr[j]);
      else
        DC('.');
    }
    addr += 16;
    DNL();
  }
  DNL();
}
Esempio n. 10
0
static void
display_mac(uint8_t *a)
{
  uint8_t cnt = 6;
  while(cnt--) {
    DH2(*a++);
    if(cnt)
      DC(':');
  }
}
Esempio n. 11
0
static void
display_ee_bytes(uint8_t *a, uint8_t cnt)
{
  while(cnt--) {
    DH2(erb(a++));
    if(cnt)
      DC(':');
  }

}
Esempio n. 12
0
void
dumppkt(void)
{
  uint8_t *a = uip_buf;

  DC('e');DC(' ');
  DU(uip_len,5);

  display_channel &= ~DISPLAY_TCP;
  uint8_t ole = log_enabled;
  log_enabled = 0;
  DC(' '); DC('d'); DC(' '); display_mac(a); a+= sizeof(struct uip_eth_addr);
  DC(' '); DC('s'); DC(' '); display_mac(a); a+= sizeof(struct uip_eth_addr);
  DC(' '); DC('t'); DH2(*a++); DH2(*a++);
  DNL();

  if(eth_debug > 2)
    dumpmem(a, uip_len - sizeof(struct uip_eth_hdr));
  display_channel |= DISPLAY_TCP;
  log_enabled = ole;
}
Esempio n. 13
0
void
read_eeprom(char *in)
{
  uint8_t hb[2], d;
  uint16_t addr;

#ifdef HAS_ETHERNET
  if(in[1] == 'i') {
           if(in[2] == 'm') { display_ee_mac(EE_MAC_ADDR);
    } else if(in[2] == 'd') { DH2(erb(EE_USE_DHCP));
    } else if(in[2] == 'a') { display_ee_ip4(EE_IP4_ADDR);
    } else if(in[2] == 'n') { display_ee_ip4(EE_IP4_NETMASK);
    } else if(in[2] == 'g') { display_ee_ip4(EE_IP4_GATEWAY);
    } else if(in[2] == 'N') { display_ee_ip4(EE_IP4_NTPSERVER);
    } else if(in[2] == 'o') { DH2(erb(EE_IP4_NTPOFFSET));
    } else if(in[2] == 'p') {
      DU(eeprom_read_word((uint16_t *)EE_IP4_TCPLINK_PORT), 0);
    }
  } else 
#endif
  if(in[1] == 'M') { display_ee_mac(EE_DUDETTE_MAC); }  
  else if(in[1] == 'P') { display_ee_bytes(EE_DUDETTE_PUBL, 16); }  
  else {
    hb[0] = hb[1] = 0;
    d = fromhex(in+1, hb, 2);
    if(d == 2)
      addr = (hb[0] << 8) | hb[1];
    else
      addr = hb[0];

    d = erb((uint8_t *)addr);
    DC('R');                    // prefix
    DH(addr,4);                 // register number
    DS_P( PSTR(" = ") );
    DH2(d);                    // result, hex
    DS_P( PSTR(" / ") );
    DU(d,2);                    // result, decimal
  }
  DNL();
}
Esempio n. 14
0
void helios_task(void) {
	if (helios_next>ticks) 
		return;

	DC( 'F' );
	DS_P(PSTR(HELIOS_EMU_HC));
	DH2( 0 );

	switch (helios_power) {
		case 0x1:
			DH2( 0x1 );
			break;
		case 0x3:
			DH2( 0x3 );
			break;
		case 0x7:
			DH2( 0x5 );
			break;
		case 0xf:
			DH2( 0x7 );
			break;
		case 0x1f:
			DH2( 0x9 );
			break;
		case 0x3f:
			DH2( 0xb );
			break;
		case 0x7f:
			DH2( 0xd );
			break;
		case 0xff:
			DH2( 0xf );
			break;
	}

	DH2( 0xff ); // RSSI
	DNL();

	helios_next = ticks + 41000; // roughly 5 min
}
Esempio n. 15
0
void
set_txreport(char *in)
{
  if(in[1] == 0) {              // Report Value
    DH2(tx_report);
    DU(credit_10ms, 5);
    DNL();
    return;
  }

  fromhex(in+1, &tx_report, 1);
  set_txrestore();
}
Esempio n. 16
0
void
rf_router_func(char *in)
{
  if(in[1] == 0) {               // u: display id and router
    DH2(rf_router_myid);
    DH2(rf_router_target);
    DNL();
#ifdef RFR_DEBUG 
  } else if(in[1] == 'd') {     // ud: Debug
    DH((uint16_t)ticks, 4); DC('.');
    DH2(rf_router_sendtime);
    DNL();
  } else if(in[1] == 's') {     // us: Statistics
    DH(nr_t,1); DC('.');
    DH(nr_f,1); DC('.');
    DH(nr_e,1); DC('.');
    DH(nr_k,1); DC('.');
    DH(nr_h,1); DC('.');
    DH(nr_r,1); DC('.');
    DH(nr_plus,1);
    DNL();
#endif

  } else if(in[1] == 'i') {      // uiXXYY: set own id to XX and router id to YY
    fromhex(in+2, &rf_router_myid, 1);
    ewb(EE_RF_ROUTER_ID, rf_router_myid);
    fromhex(in+4, &rf_router_target, 1);
    ewb(EE_RF_ROUTER_ROUTER, rf_router_target);

  } else {                      // uYYDATA: send data to node with id YY
    rb_reset(&RFR_Buffer);
    while(*++in)
      rb_put(&RFR_Buffer, *in);
    rf_router_send(0);

  }
}
Esempio n. 17
0
static void
fht80b_print(uint8_t full)
{
  uint8_t *p = fht80b_buf;

  if(!p[0])
    DS_P( PSTR("N/A") );
  while(p[0] && (p < (fht80b_buf+FHTBUF_SIZE))) {
    if(p != fht80b_buf)
      DC(' ');
    uint8_t i = 1;
    DH2(p[i++]);
    DH2(p[i++]);
    if(full) {
      DC(':');
      while(i < p[0]) {
        if(i > 3 && (i&1))
          DC(',');
        DH2(p[i++]);
      }
    }
    p += p[0];
  }
}
Esempio n. 18
0
void
eth_func(char *in)
{
  if(in[1] == 'i') {
    ethernet_init();

  } else if(in[1] == 'c') {
    display_ip4((uint8_t *)uip_hostaddr); DC(' ');
    display_mac((uint8_t *)uip_ethaddr.addr);
    DNL();

  } else if(in[1] == 'd') {
    eth_debug = (eth_debug+1) & 0x3;
    DH2(eth_debug);
    DNL();

  } else if(in[1] == 'n') {
    ntp_sendpacket();

  }
}
Esempio n. 19
0
void
ntp_func(char *in)
{
  uint8_t hb[6], t;

  if(in == 0 || in[1] == 0) {
    t = 1, hb[0] = 7;
  } else  {
    t = fromhex(in+1, hb, 6);
  }

  if(t == 1) {
    t = hb[0];
    ntp_get(hb);
    if(t&1) {
      DH2(hb[0]); DC('-');
      DH2(hb[1]); DC('-');
      DH2(hb[2]);
    }
    if((t&3) == 3)
      DC(' ');

    if(t&2) {
      DH2(hb[3]); DC(':');
      DH2(hb[4]); DC(':');
      DH2(hb[5]);
    }

    if(t&4) {
      DC('.'); display_udec((uint16_t)(ntp_hsec*100)/125, 2, '0');
    }
    DNL();

  } else if(t == 6) {
    tm_t t;
    t.tm_year = bcd2dec(hb[0]);
    t.tm_mon  = bcd2dec(hb[1]);
    t.tm_mday = bcd2dec(hb[2]);
    t.tm_hour = bcd2dec(hb[3]);
    t.tm_min  = bcd2dec(hb[4]);
    t.tm_sec  = bcd2dec(hb[5]);
    ntp_sec = ntp_tm2sec(&t);

  }
}
Esempio n. 20
0
void helios_task(void) {
        char   sign = 0;
	int    temp = 0;
	double tempf = 0.0;
  
	if (helios_next>ticks) 
		return;

	DC( 'F' );
	DS_P(PSTR(HELIOS_EMU_HC));
	DH2( 0 );

	switch (helios_power) {
		case 0x1:
			DH2( 0x1 );
			break;
		case 0x3:
			DH2( 0x3 );
			break;
		case 0x7:
			DH2( 0x5 );
			break;
		case 0xf:
			DH2( 0x7 );
			break;
		case 0x1f:
			DH2( 0x9 );
			break;
		case 0x3f:
			DH2( 0xb );
			break;
		case 0x7f:
			DH2( 0xd );
			break;
		case 0xff:
			DH2( 0xf );
			break;
	}

	DH2( 0xff ); // RSSI
	DNL();

	for (uint8_t i=0;i<4;i++) {
	  
	  if (helios_temp[i]) {
	    tempf = (helios_temp[i]-100)/0.3;
	    temp  = (int) tempf;
	    sign  = (temp<0) ? '8' : '0';
	    
	    DC('H');
	    DH2(0x33);          //this needs to be coded more flexable
	    DH2(0x10+i);
	    DC(sign);		//Sign-Bit (needs to be 8 for negative
	    DC('1'); 		//HMS Type (only Temp)
	    //Temp under 10 degs
	    sign  =  (char) ( ( (uint8_t) ((temp / 10 ) % 10) )&0x0F ) + '0';
	    DC(sign);
	    //Degrees below 1  
	    sign  =  (char) ( ( (uint8_t)  (temp % 10 ) 	  )&0x0F ) + '0';
	    DC(sign);
	    DC('0');
	    //Temp over 9 degs
	    sign  =  (char) ( ( (uint8_t) ((temp / 100) % 10) )&0x0F ) + '0';
	    DC(sign);
	    DC('0');DC('0');DC('F');DC('F');                                            //Humidity & RSSI
	    DNL();
	  }
	}
	
	helios_next = ticks + 41000; // roughly 5 min
}
Esempio n. 21
0
// Transmitt data block for Kopp Free Control
// ------------------------------------------------------------------------------------------------------------------------------------------
void TransmittKoppBlk(uint8_t sendmsg01[15], uint8_t blkTXcode_i)

{

// Read Blockcounter from Config File Datei (RAMDISK) 
// --------------------------------------------------

   uint8_t blkcks = 0x0;


     
   int count = 0;
   int count2 = 1;
 
   //count2 = 1;														// each block / telegram will be written n times (n = 13 see below)
   sendmsg01[3] = blkctr;                                   		// Write BlockCounter (was incremented) and Transmitt Code (=Transmitter Key) to Array
   sendmsg01[4] = blkTXcode_i;                              		// -----------------------------------------------------------------------------------   

																
																


// Send Block via Transmitter Fifo
// --------------------------------
do {

   ccTX();															// initialize CC110x TX Mode?
   if(cc1100_readReg( CC1100_MARCSTATE ) != MARCSTATE_TX) 			// If Statemachine not MARCSTATE_TX -> error
   { 
    
	DS_P(PSTR("TX_INIT_ERR_"));

    DH2(cc1100_readReg( CC1100_MARCSTATE ));
    DNL();
    kopp_fc_init();
    return;
   }

   BlockStartTime = ticks;                           			// remember Start Time (1 tick=8msec, s.o.)
   blkcks=0xaa;                                                 // Checksumme initialisieren
   count=0;                                                    	//

   CC1100_ASSERT;												// Chip Select Activ
   cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);			// Burst Mode via Fifo 
                                                               

																// Now send !
   do {	                                                        // ===========
         cc1100_sendbyte(sendmsg01[count]);					    // write date to fifo (fifo is big enough)

          if (count <= 8)                                    	//
		  {
           blkcks=blkcks^sendmsg01[count];                    	//
           if (count==7) sendmsg01[8]=blkcks;               	// write ckecksum to Buffer as soon as calculated
           }                                                    //
																//
  	   count++;                                                	//
 	   } while(count < MAX_kopp_fc_MSG);  		                // Transmitt Byte 0 - AmountofBytes



  CC1100_DEASSERT;												 // Chip Select InActiv

  //Wait for sending to finish (CC1101 will go to RX state automatically

  uint8_t i;
  for(i=0; i< 200;++i) 
  {
//    if( cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_RX)		// Claus: After transmission we force idle, always, so RX will not happen
//      break; //now in RX, good
    if( cc1100_readReg( CC1100_MARCSTATE ) != MARCSTATE_TX)	
      break; //neither in RX nor TX, probably some error
    my_delay_ms(1);
  }

// Claus: Test shows i is ~ 0x36, but why so fast??, transmission should need about 25msec (15Bytes*8Bits*4800Bit/sec)
// may be reading status via SPI is also also slow?
 
//  DS_P(PSTR("variable i: "));										// For test only
//  DH((uint16_t) (i),4);											// For test only
//  DS_P(PSTR("\r\n"));												// For test only
 
  count2++;
  
	
 
 } while(count2 <= 13);        	                                // send same message 13x 


blkctr++;  												   			// increase Blockcounter

}
Esempio n. 22
0
/* longPreamble is necessary for unsolicited messages to wakeup the receiver */
void
moritz_sendraw(uint8_t *dec, int longPreamble)
{
  uint8_t hblen = dec[0]+1;
  //1kb/s = 1 bit/ms. we send 1 sec preamble + hblen*8 bits
  uint32_t sum = (longPreamble ? 100 : 0) + (hblen*8)/10;
  if (credit_10ms < sum) {
    DS_P(PSTR("LOVF\r\n"));
    return;
  }
  credit_10ms -= sum;

  // in Moritz mode already?
  if(!moritz_on) {
    rf_moritz_init();
  }

  if(CC1100_READREG( CC1100_MARCSTATE ) != MARCSTATE_RX) { //error
    DC('Z');
    DC('E');
    DC('R');
    DC('R');
    DC('1');
    DH2(CC1100_READREG( CC1100_MARCSTATE ));
    DNL();
    rf_moritz_init();
    return;
  }

  /* We have to keep at least 20 ms of silence between two sends
   * (found out by trial and error). ticks runs at 125 Hz (8 ms per tick),
   * so we wait for 3 ticks.
   * This looks a bit cumbersome but handles overflows of ticks gracefully.
   */
  if(lastSendingTicks)
    while(ticks == lastSendingTicks || ticks == lastSendingTicks+1)
      my_delay_ms(1);

  /* Enable TX. Perform calibration first if MCSM0.FS_AUTOCAL=1 (this is the case) (takes 809μs)
   * start sending - CC1101 will send preamble continuously until TXFIFO is filled.
   * The preamble will wake up devices. See http://e2e.ti.com/support/low_power_rf/f/156/t/142864.aspx
   * It will not go into TX mode instantly if channel is not clear (see CCA_MODE), thus ccTX tries multiple times */
#ifdef CC_ID
  do {
    CCSTROBE(CC1100_STX);
  } while (CC1100_READREG(CC1100_MARCSTATE) != MARCSTATE_TX);
#else
  ccTX();
#endif
  if(CC1100_READREG( CC1100_MARCSTATE ) != MARCSTATE_TX) { //error
    DC('Z');
    DC('E');
    DC('R');
    DC('R');
    DC('2');
    DH2(CC1100_READREG( CC1100_MARCSTATE ));
    DNL();
    rf_moritz_init();
    return;
  }

  if(longPreamble) {
    /* Send preamble for 1 sec. Keep in mind that waiting for too long may trigger the watchdog (2 seconds on CUL) */
    for(int i=0;i<10;++i)
      my_delay_ms(100); //arg is uint_8, so loop
  }

  // send
  CC1100_ASSERT;
  cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);

  for(uint8_t i = 0; i < hblen; i++) {
    cc1100_sendbyte(dec[i]);
  }

  CC1100_DEASSERT;

  //Wait for sending to finish (CC1101 will go to RX state automatically
  //after sending
  uint8_t i;
  for(i=0; i< 200;++i) {
    if( CC1100_READREG( CC1100_MARCSTATE ) == MARCSTATE_RX)
      break; //now in RX, good
    if( CC1100_READREG( CC1100_MARCSTATE ) != MARCSTATE_TX)
      break; //neither in RX nor TX, probably some error
    my_delay_ms(1);
  }

  if(CC1100_READREG( CC1100_MARCSTATE ) != MARCSTATE_RX) { //error
    DC('Z');
    DC('E');
    DC('R');
    DC('R');
    DC('3');
    DH2(CC1100_READREG( CC1100_MARCSTATE ));
    DNL();
    rf_moritz_init();
  }

  if(!moritz_on) {
    set_txrestore();
  }
  lastSendingTicks = ticks;
}
Esempio n. 23
0
void native_task(void) {
  uint8_t len, byte, i;

  if(!native_on)
    return;

  // wait for CC1100_FIFOTHR given bytes to arrive in FIFO:
  if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {

    // start over syncing
    ccStrobe( CC1100_SIDLE );

    len = cc1100_readReg( CC1100_RXBYTES ) & 0x7f; // read len, transfer RX fifo
    
    if (len) {
      
      CC1100_ASSERT;
      cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );

      DC( 'N' );
      DH2(native_on);

      for (i=0; i<len; i++) {
	byte = cc1100_sendbyte( 0 );

#if defined(LACROSSE_HMS_EMU)
	if (i<sizeof(payload))
	  payload[i] = byte;
#endif
	DH2( byte );
      }
      
      CC1100_DEASSERT;
      
      DNL();

#ifdef LACROSSE_HMS_EMU
      if (len>=5)
	dec2hms_lacrosse(payload);
#endif

    }

    return;
  }
       
  switch (cc1100_readReg( CC1100_MARCSTATE )) {
            
       // RX_OVERFLOW
  case 17:
       // IDLE
  case 1:
    ccStrobe( CC1100_SFRX  );
    ccStrobe( CC1100_SIDLE );
    ccStrobe( CC1100_SNOP  );
    ccStrobe( CC1100_SRX   );
    break;
       
  }

}
Esempio n. 24
0
void
it_func(char *in)
{
	if (in[1] == 't') {
			fromdec (in+2, (uint8_t *)&it_interval);
			DU(it_interval,0); DNL();
	} else if (in[1] == 's') {
			if (in[2] == 'r') {		// Modify Repetition-counter
				fromdec (in+3, (uint8_t *)&it_repetition);
				DU(it_repetition,0); DNL();
#ifdef HAS_HOMEEASY
      } else if (in[2] == 'h') {		// HomeEasy
        it_send (in, DATATYPE_HE);	
      } else if (in[2] == 'e') {		// HomeEasy EU
        it_send (in, DATATYPE_HEEU);	
#endif	
			} else {
				it_send (in, DATATYPE_IT);				// Sending real data
		} //sending real data
	} else if (in[1] == 'r') { // Start of "Set Frequency" (f)
		#ifdef HAS_ASKSIN
			if (asksin_on) {
				restore_asksin = 1;
				asksin_on = 0;
			}
		#endif
		#ifdef HAS_MORITZ
			if (moritz_on) {
				restore_moritz = 1;
				moritz_on = 0;
			}
		#endif
		it_tunein ();
		intertechno_on = 1;
	} else if (in[1] == 'f') { // Set Frequency
		  if (in[2] == '0' ) {
		  	it_frequency[0] = 0x10;
		  	it_frequency[1] = 0xb0;
		  	it_frequency[2] = 0x71;
		  } else {
				fromhex (in+2, it_frequency, 3);
			}
			DC('i');DC('f');DC(':');
		  DH2(it_frequency[0]);
		  DH2(it_frequency[1]);
		  DH2(it_frequency[2]);
		  DNL();
	} else if (in[1] == 'x') { 		                    // Reset Frequency back to Eeprom value
		if(0) { ;
		#ifdef HAS_ASKSIN
		} else if (restore_asksin) {
			restore_asksin = 0;
			rf_asksin_init();
			asksin_on = 1;
			ccRX();
		#endif
		#ifdef HAS_MORITZ
		} else if (restore_moritz) {
			restore_moritz = 0;
			rf_moritz_init();
		#endif
		} else {
			ccInitChip(EE_CC1100_CFG);										// Set back to Eeprom Values
			if(tx_report) {                               // Enable RX
				ccRX();
			} else {
				ccStrobe(CC1100_SIDLE);
			}
		}
		intertechno_on = 0;
	}
}
Esempio n. 25
0
int
main(void)
{

  led_init();

#ifdef LED_RGB
  led_off(LED_CHANNEL_GREEN);
  led_off(LED_CHANNEL_RED);
  led_off(LED_CHANNEL_BLUE);
#else
  LED_ON();
#endif


  spi_init();


  OCR0A  = 249;                            // Timer0: 0.008s = 8MHz/256/250 == 125Hz
  TCCR0B = _BV(CS02);
  TCCR0A = _BV(WGM01);
  TIMSK0 = _BV(OCIE0A);

  TCCR1A = 0;
  TCCR1B = _BV(CS11) | _BV(WGM12);         // Timer1: 1us = 8MHz/8

  clock_prescale_set(clock_div_1);

  MCUSR &= ~(1 << WDRF);                   // Enable the watchdog

  uart_init( UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU) );

  input_handle_func = analyze_ttydata;

  display_channel = DISPLAY_USB;

#ifdef LED_RGB
  my_delay_ms(200);
  led_on(LED_CHANNEL_RED);
  my_delay_ms(200);
  led_off(LED_CHANNEL_RED);
  led_on(LED_CHANNEL_GREEN);
  my_delay_ms(200);
  led_off(LED_CHANNEL_GREEN);
  led_on(LED_CHANNEL_BLUE);
  my_delay_ms(200);
  led_off(LED_CHANNEL_BLUE);
#else
  LED_OFF();
#endif

  sei();

  /* start moritz function */
  moritz_func("Zr\n");
  for(;;) {
	led_process(ticks);

    uart_task();
    Minute_Task();
    rf_asksin_task();
    rf_moritz_task();
    if (rf_moritz_data_available()) {
        DC('Z');
        uint8_t *rf_data = (uint8_t*) &max_data;
        for (uint8_t i=0; i<=*rf_data; i++) {
        	DH2( *rf_data++ );
        }
        DNL();
        DS("length: ");
        DU(max_data.length, 2);
        DNL();
        DS("msg count: ");
        DU(max_data.message_count, 2);
        DNL();
        DS("msg type: ");
        DU(max_data.message_type, 2);
        DNL();
    }
  }

}
Esempio n. 26
0
void
rf_asksin_task(void)
{
  uint8_t msg[MAX_ASKSIN_MSG];
  uint8_t this_enc, last_enc;
  uint8_t rssi;
  uint8_t l;

  if(!asksin_on)
    return;

  // see if a CRC OK pkt has been arrived
  if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
    msg[0] = CC1100_READREG( CC1100_RXFIFO ) & 0x7f; // read len

    if (msg[0] >= MAX_ASKSIN_MSG) {
      // Something went horribly wrong, out of sync?
      rf_asksin_reset_rx();
      return;
    }

    CC1100_ASSERT;
    cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
    
    for (uint8_t i=0; i<msg[0]; i++) {
         msg[i+1] = cc1100_sendbyte( 0 );
    }
    
    rssi = cc1100_sendbyte( 0 );
    /* LQI = */ cc1100_sendbyte( 0 );

    CC1100_DEASSERT;

    do {
      CCSTROBE(CC1100_SRX);
    } while (CC1100_READREG(CC1100_MARCSTATE) != MARCSTATE_RX);

    last_enc = msg[1];
    msg[1] = (~msg[1]) ^ 0x89;
    
    for (l = 2; l < msg[0]; l++) {
         this_enc = msg[l];
         msg[l] = (last_enc + 0xdc) ^ msg[l];
         last_enc = this_enc;
    }
    
    msg[l] = msg[l] ^ msg[2];
    
    if (tx_report & REP_BINTIME) {
      
      DC('a');
      for (uint8_t i=0; i<=msg[0]; i++)
      DC( msg[i] );
         
    } else {
      DC('A');
      
      for (uint8_t i=0; i<=msg[0]; i++)
        DH2( msg[i] );
      
      if (tx_report & REP_RSSI)
        DH2(rssi);
      
      DNL();
    }
  }

  switch(CC1100_READREG( CC1100_MARCSTATE )) {
    case MARCSTATE_RXFIFO_OVERFLOW:
      CCSTROBE( CC1100_SFRX  );
    case MARCSTATE_IDLE:
      CCSTROBE( CC1100_SIDLE );
      CCSTROBE( CC1100_SNOP  );
      CCSTROBE( CC1100_SRX   );
      break;
  }

#ifdef HAS_CC1101_RX_PLL_LOCK_CHECK_TASK_WAIT
  CC1101_RX_CHECK_PLL_WAIT_TASK();
#endif
}
Esempio n. 27
0
void
fhtsend(char *in)
{
  uint8_t hb[6], l;                    // Last byte needed for 8v checksum
  l = fromhex(in+1, hb, 5);

  if(l < 4) {

    if(hb[0] == 1) {                   // Set housecode, clear buffers
      if(l == 3) {
        ewb(EE_FHTID  , hb[1]);        // 1.st byte: 80b relevant
        ewb(EE_FHTID+1, hb[2]);        // 1.st+2.nd byte: 8v relevant
        fht_init();
        return;

      } else {
        DH2(fht_hc0);
        DH2(fht_hc1);
      }

#ifdef HAS_FHT_80b
    } else if(hb[0] == 2) {            // Return the 80b buffer
      fht80b_print(l==1 || hb[1]==1);

    } else if(hb[0] == 3) {            // Return the remaining fht buffer
#if FHTBUF_SIZE > 255
      DH(fht_bufspace(),4);
#else
      DH2(fht_bufspace());
#endif
#endif

#ifdef HAS_FHT_8v
    } else if(hb[0] == 0x10) {         // Return the 8v buffer

      uint8_t na=0;
      for(int i = 0; i < FHT_8V_NUM; i++) {
        if(fht8v_buf[2*i] == FHT_8V_DISABLED)
          continue;
        if(na)
          DC(' ');
        DH2(i);
        DC(':');
        DH2(fht8v_buf[2*i]);
        DH2(fht8v_buf[2*i+1]);
        na++;
      }

      if(na==0)
        DS_P( PSTR("N/A") );

    } else if(hb[0] == 0x11) {         // Return the next 8v timeout
      DH2(fht8v_timeout/125);
#endif

    }
    DNL();

  } else {

#ifdef HAS_FHT_8v
    if(hb[0]>=fht_hc0 &&
       hb[0]< fht_hc0+FHT_8V_NUM &&
       hb[1]==fht_hc1) {                 // FHT8v mode commands

      if(hb[3] == FHT8V_CMD_PAIR) {
        addParityAndSend(in, FHT_CSUM_START, 2);

      } else if(hb[3] == FHT8V_CMD_SYNC){// start syncprocess for _all_ 8v's
        fht8v_ctsync = hb[4];            // use it to shorten the sync-time
        fht8v_timeout=1;

        // Cheating on the 1%
        uint8_t cnt = 0;
        for(uint8_t i = 0 ; i < FHT_8V_NUM; i++ )
          if(fht8v_buf[2*i] != FHT_8V_DISABLED )
            cnt++;
        credit_10ms += (4*fht8v_ctsync);   // should be 3.75 = 75ms / 2 / 10
        
      } else {                           // Valve position
        uint8_t idx = (hb[0]-fht_hc0)*2;
        fht8v_buf[idx  ] = hb[3];        // Command or 0xff for disable this
        fht8v_buf[idx+1] = hb[4];        // slot (valve)

      }
      return;
    }
#endif

#ifdef HAS_FHT_80b
    if(!fht_addbuf(in))                  // FHT80b mode: Queue everything
      DS_P( PSTR("EOB\r\n") );
#endif

  }
}