void owchip_geteui(uint8_t* eui) { // >= 6000us uint8_t id[8]; int retry; int crc; uint8_t* byte; uint16_t oldTactl; retry = 5; memset(eui,0,8); // store current value of TACTL oldTactl = TACTL; // start timer in continuous mode at 1MHz TACTL = TASSEL_2 | ID_2 | MC_2; owpin_init(); while (retry-- > 0) { crc = 0; if(ow_reset()) { ow_write_byte(0x33); //read rom for(byte=id+7; byte>=id; byte--) { crc = crc8_byte( crc, *byte=ow_read_byte() ); } if(crc==0) { // CRC valid memcpy(eui,id,8); } } } // restore value of TACTL TACTL = oldTactl; }
/* * Returns: 0 on failure * 1 on success */ unsigned char send_packet(unsigned char to_addr, unsigned char *data, unsigned char data_len) { // TODO: Wait for timeout to tick down (in multi-station mode) // Too much data if (data_len > PACKET_DATA_MAX) { return 0; } unsigned char crc; crc8_init(0xFF); rfm12_EnableTx(); // TODO: turn on transmitter rfm12_Tx_Byte(0xAA); // Preamble for RFM12 rfm12_Tx_Byte(0xAA); rfm12_Tx_Byte(0xAA); rfm12_Tx_Byte(0x2D); // RFM12 sync pattern rfm12_Tx_Byte(0xD4); rfm12_Tx_Byte(HEADER_LENGTH + data_len); // Total packet length crc = crc8_byte(HEADER_LENGTH + data_len); rfm12_Tx_Byte(PACKET_MAGIC); // Magic identification bytes crc = crc8_byte(PACKET_MAGIC); rfm12_Tx_Byte(NODE_ADDRESS); // Sender ID crc = crc8_byte(NODE_ADDRESS); rfm12_Tx_Byte(to_addr); // Destination ID crc = crc8_byte(to_addr); rfm12_Tx_Byte(sequence_number); // Packet sequence number crc = crc8_byte(sequence_number); sequence_number++; rfm12_Tx_Byte(0); // Reserved for future use crc = crc8_byte(0); rfm12_Tx_Byte(0); // Reserved for future use crc = crc8_byte(0); for (int n = 0; n < data_len; n++) { rfm12_Tx_Byte(data[n]); crc = crc8_byte(data[n]); } rfm12_Tx_Byte(crc); // CRC rfm12_Tx_Byte(0xAA); // Trailer rfm12_Tx_Byte(0xAA); rfm12_DisableTx(); // Turn off Tx return 1; }
unsigned char _process_packet(unsigned char bytes_received) { unsigned char length = 0; unsigned char crc = 0; receive_count++; // Check for the start-of-packet byte if (packet_buffer[0] != PACKET_MAGIC) { return 0; } // Check that the packet is for us (or, in multicast mode, is for // the multicast address) #ifdef PACKET_MULTICAST if (packet_buffer[2] != NODE_ADDRESS && packet_buffer[2] != MULTICAST_ADDRESS) { #else if (packet_buffer[2] != NODE_ADDRESS) { #endif return 0; } // Extract the length length = packet_buffer[3]; // Calculate the CRC for the whole packet, minus the CRC // which is at the end crc8_init(0xff); for (int n = 0; n < length - 1; n++) { crc = crc8_byte(packet_buffer[n]); } // Check the CRC against the packet if (crc != packet_buffer[length - 1]) { return 0; } // Copy the data to the buffer for (int n = 0; n < length - HEADER_LENGTH; n++) { data_buffer[n] = packet_buffer[7 + n]; } data_arrived = length - HEADER_LENGTH; return 1; }
void eui64_get(uint8_t* addressToWrite) { // >= 6000us uint8_t id[8]; int retry; int crc; uint8_t* byte; uint16_t oldTactl; return;//poipoi retry = 5; memset(addressToWrite,0,8); // store current value of TACTL oldTactl = TACTL; // start timer in continuous mode at 1MHz TACTL = TASSEL_2 | ID_2 | MC_2; owpin_init(); while (retry-- > 0) { crc = 0; if(ow_reset()) { ow_write_byte(0x33); //read rom for(byte=id+7; byte>=id; byte--) { crc = crc8_byte( crc, *byte=ow_read_byte() ); } if(crc==0) { // CRC valid *(addressToWrite+0) = 0x14; *(addressToWrite+1) = 0x15; *(addressToWrite+2) = 0x92; memcpy(addressToWrite+3,id+1,5); } } } // restore value of TACTL TACTL = oldTactl; }