void rf_router_task(void) { if(rf_router_status == RF_ROUTER_INACTIVE) return; uint8_t hsec = (uint8_t)ticks; if(rf_router_status == RF_ROUTER_GOT_DATA) { uint8_t len = cc1100_readReg(CC1100_RXFIFO); uint8_t proto = 0; if(len > 5) { rb_reset(&TTY_Rx_Buffer); CC1100_ASSERT; cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO ); proto = cc1100_sendbyte(0); while(--len) rb_put(&TTY_Rx_Buffer, cc1100_sendbyte(0)); CC1100_DEASSERT; } set_txrestore(); rf_router_status = RF_ROUTER_INACTIVE; if(proto == RF_ROUTER_PROTO_ID) { uint8_t id; if(fromhex(TTY_Rx_Buffer.buf, &id, 1) == 1 && // it is for us id == rf_router_myid) { if(TTY_Rx_Buffer.buf[4] == 'U') { // "Display" the data while(TTY_Rx_Buffer.nbytes) // downlink: RFR->CUL DC(rb_get(&TTY_Rx_Buffer)); DNL(); } else { // uplink: CUL->RFR TTY_Rx_Buffer.nbytes -= 4; // Skip dest/src bytes TTY_Rx_Buffer.getoff = 4; rb_put(&TTY_Rx_Buffer, '\n'); input_handle_func(DISPLAY_RFROUTER); // execute the command } } else { rb_reset(&TTY_Rx_Buffer); } } } else if(rf_router_status == RF_ROUTER_DATA_WAIT) { uint8_t diff = hsec - rf_router_hsec; if(diff > 7) { // 3 (delay above) + 3 ( ((4+64)*8)/250kBaud ) set_txrestore(); rf_router_status = RF_ROUTER_INACTIVE; } } else if(rf_router_status == RF_ROUTER_SYNC_RCVD) { ccInitChip(EE_FASTRF_CFG); ccRX(); rf_router_status = RF_ROUTER_DATA_WAIT; rf_router_hsec = hsec; } }
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(); } } }
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(); }
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; } }
// 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 }