예제 #1
0
static void
rf_router_send(uint8_t addAddr)
{
#ifdef RFR_DEBUG
       if(RFR_Buffer.buf[5] == 'T') nr_t++;
  else if(RFR_Buffer.buf[5] == 'F') nr_f++;
  else if(RFR_Buffer.buf[5] == 'E') nr_e++;
  else if(RFR_Buffer.buf[5] == 'K') nr_k++;
  else if(RFR_Buffer.buf[5] == 'H') nr_h++;
  else                              nr_r++;
#endif

  uint8_t buf[7], l = 1;
  buf[0] = RF_ROUTER_PROTO_ID;
  if(addAddr) {
    tohex(rf_router_target, buf+1);
    tohex(rf_router_myid,   buf+3),
    buf[5] = 'U';
    l = 6;
  }
  rf_router_ping();           // 15ms
  ccInitChip(EE_FASTRF_CFG);  // 1.6ms
  my_delay_ms(3);             // 3ms: Found by trial and error

  CC1100_ASSERT;
  cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
#ifdef RFR_USBECHO
  uint8_t nbuf = RFR_Buffer.nbytes;
#endif
  cc1100_sendbyte(RFR_Buffer.nbytes+l);
  for(uint8_t i = 0; i < l; i++)
    cc1100_sendbyte(buf[i]);
  while(RFR_Buffer.nbytes)
    cc1100_sendbyte(rb_get(&RFR_Buffer));
  CC1100_DEASSERT;
  ccTX();
  rb_reset(&RFR_Buffer); // needed by FHT_compress

  // Wait for the data to be sent
  uint8_t maxwait = 20;        // max 20ms
  while((cc1100_readReg(CC1100_TXBYTES) & 0x7f) && maxwait--)
    my_delay_ms(1);
  set_txrestore();
#ifdef RFR_USBECHO
#warning RFR USB DEBUGGING IS ACTIVE
  uint8_t odc = display_channel;
  display_channel = DISPLAY_USB;
  DC('.'); DU(nbuf, 2); DNL();
  display_channel = odc;
#endif
}
예제 #2
0
// Duration is 15ms, more than one tick!
static void
rf_router_ping(void)
{
  set_ccon();           // 1.7ms
  ccTX();               // 4.8ms

  // Sync               // 8.5ms
  for(uint8_t i = 0; i < 6; i++) {
    sethigh(RF_ROUTER_ZERO_HIGH);
    setlow(RF_ROUTER_ZERO_LOW);
  }
  sethigh(RF_ROUTER_ONE_HIGH);
  setlow(RF_ROUTER_ONE_LOW);
  sethigh(RF_ROUTER_ONE_LOW);
  CC1100_CLEAR_OUT;
}
예제 #3
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;
}
예제 #4
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

}
예제 #5
0
파일: belfox.c 프로젝트: Diggen85/a-culfw
void
send_belfox(char *msg)
{

  uint8_t repeat=BELFOX_REPEAT;
  uint8_t len=strnlen(msg,BELFOX_LEN+2)-1;
  
  // assert if length incorrect
  if (len != BELFOX_LEN) return;
  
  LED_ON();

#if defined (HAS_IRRX) || defined (HAS_IRTX) // Block IR_Reception
  cli();
#endif

#ifdef USE_RF_MODE
  change_RF_mode(RF_mode_slow);
#else

#ifdef HAS_MORITZ
  uint8_t restore_moritz = 0;
  if(moritz_on) {
    restore_moritz = 1;
    moritz_on = 0;
    set_txreport("21");
  }
#endif

  if(!cc_on)
    set_ccon();
#endif
  ccTX();                                       // Enable TX 
  do {
    send_sync();                                // sync

    for(int i = 1; i <= BELFOX_LEN; i++)        // loop input, for example 'L111001100110'
      send_bit(msg[i] == '1');

    CC1100_OUT_PORT &= ~_BV(CC1100_OUT_PIN);    // final low to complete last bit
        
    my_delay_ms(BELFOX_PAUSE);                  // pause

  } while(--repeat > 0);

  if(TX_REPORT) {                               // Enable RX
    ccRX();
  } else {
    ccStrobe(CC1100_SIDLE);
  }

#if defined (HAS_IRRX) || defined (HAS_IRTX) // Activate IR_Reception
  sei(); 
#endif

#ifdef USE_RF_MODE
  restore_RF_mode();
#else
#ifdef HAS_MORITZ
  if(restore_moritz)
    rf_moritz_init();
#endif
#endif
  LED_OFF();
}
예제 #6
0
static void
it_send (char *in, uint8_t datatype) {	

    //while (rf_isreceiving()) {
      //_delay_ms(1);
    //}
	  int8_t i, j, k;

		LED_ON();

    #if defined (HAS_IRRX) || defined (HAS_IRTX) //Blockout IR_Reception for the moment
      cli(); 
    #endif
  
	// If NOT InterTechno mode
	if(!intertechno_on)  {
	#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();
	my_delay_ms(3);             // 3ms: Found by trial and error
    }
  	ccStrobe(CC1100_SIDLE);
  	ccStrobe(CC1100_SFRX );
  	ccStrobe(CC1100_SFTX );

	  ccTX();                       // Enable TX 
	
    int8_t sizeOfPackage = strlen(in)-1; // IT-V1 = 14, IT-V3 = 33, IT-V3-Dimm = 37
	  int8_t mode = 0; // IT V1
    //DU(sizeOfPackage, 3);
    if (sizeOfPackage == 33 || sizeOfPackage == 37) { 
      mode = 1; // IT V3
      
    }
		for(i = 0; i < it_repetition; i++)  {
      if (datatype == DATATYPE_IT) {
        if (mode == 1) {    
          send_IT_sync_V3();  
          send_IT_latch_V3();
        } else {
          // Sync-Bit for IT V1 send before package
          CC1100_SET_OUT;         // High
          my_delay_us(it_interval);
          CC1100_CLEAR_OUT;       // Low
          for(k = 0; k < 31; k++)  {
            my_delay_us(it_interval);
          }
        }
#ifdef HAS_HOMEEASY
      } else if (datatype == DATATYPE_HE) {
        send_IT_sync_HE(DATATYPE_HE);
      } else if (datatype == DATATYPE_HEEU) {
        send_IT_sync_HE(DATATYPE_HEEU);
#endif
      }
      uint8_t startCount = 1;
#ifdef HAS_HOMEEASY
      if (datatype == DATATYPE_HE || datatype == DATATYPE_HEEU) {
        startCount = 2;
      } 
#endif
		  for(j = startCount; j < sizeOfPackage; j++)  {
			  if(in[j+1] == '0') {
          if (datatype == DATATYPE_IT) {
            if (mode == 1) {
					    send_IT_bit_V3(0);
            } else {
					    send_IT_bit(0);
            }      
#ifdef HAS_HOMEEASY
          } else {
            send_IT_bit_HE(0, datatype);
#endif
          }
				} else if (in[j+1] == '1') {
          if (datatype == DATATYPE_IT) {
            if (mode == 1) {
					    send_IT_bit_V3(1);
            } else {
					    send_IT_bit(1);
            }
#ifdef HAS_HOMEEASY
          } else {
            send_IT_bit_HE(1, datatype);
#endif
          }
        } else if (in[j+1] == '2') {
          send_IT_bit_V3(2);
				} else {
          if (mode == 1) {
					  send_IT_bit_V3(3);
				  } else {
					  send_IT_bit(2);
				  }
			  }
			}
      //if (mode == 1) {  
      //  send_IT_sync_V3();
      //}
		} //Do it n Times
	
  	if(intertechno_on) {
			if(tx_report) {                               // Enable RX
	    	ccRX();
	  	} else {
		  	ccStrobe(CC1100_SIDLE);
			}
  	} 
  	#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 {
    	set_txrestore();
  	}	

    #if defined (HAS_IRRX) || defined (HAS_IRTX) //Activate IR_Reception again
      sei(); 
    #endif		  

		LED_OFF();
	
		DC('i');DC('s');
#ifdef HAS_HOMEEASY
    if (datatype == DATATYPE_HE) {
      DC('h');
    } else if (datatype == DATATYPE_HEEU) {
      DC('e');
    }
#endif
		for(j = 1; j < sizeOfPackage; j++)  {
		 	if(in[j+1] == '0') {
				DC('0');
			} else if (in[j+1] == '1') {
				DC('1');
			} else if (in[j+1] == '2') {
				DC('2');
			} else {
        if (datatype == DATATYPE_IT) {
          if (mode == 1) {  
     				DC('D');
          } else {
				    DC('F');
          }
        }
			}
		}
		DNL();
}