2013-11-15 14:42:41 +07:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
#include <avr/io.h>
|
|
|
|
|
#include <stdio.h>
|
2013-12-11 13:34:53 +07:00
|
|
|
|
#include <string.h>
|
2013-11-15 14:42:41 +07:00
|
|
|
|
#include <avr/interrupt.h>
|
2013-12-09 21:06:29 +07:00
|
|
|
|
#include <util/delay.h>
|
2013-12-11 13:34:53 +07:00
|
|
|
|
#include <avr/eeprom.h>
|
|
|
|
|
#include "nrf24l01/nrf24l01.h"
|
|
|
|
|
#include "onewire/onewire.h"
|
2013-11-15 14:42:41 +07:00
|
|
|
|
|
2013-12-11 13:34:53 +07:00
|
|
|
|
typedef struct t_data{
|
|
|
|
|
uint8_t from;
|
|
|
|
|
uint8_t to;
|
|
|
|
|
char cmd[5];
|
|
|
|
|
uint8_t value[25];
|
|
|
|
|
}t_data;
|
2013-11-15 14:42:41 +07:00
|
|
|
|
|
2013-12-11 13:34:53 +07:00
|
|
|
|
uint8_t* address_at_eeprom_location = (uint8_t*)0;
|
|
|
|
|
|
|
|
|
|
uint8_t getid(void){
|
|
|
|
|
uint8_t result = 0;
|
|
|
|
|
if ( eeprom_read_byte(address_at_eeprom_location) == 0xdf ){
|
|
|
|
|
result = eeprom_read_byte(address_at_eeprom_location+1);
|
|
|
|
|
}else{
|
|
|
|
|
result =0x00;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getListDevices(t_data data){
|
|
|
|
|
uint8_t i;
|
|
|
|
|
uint8_t id[OW_ROMCODE_SIZE];
|
|
|
|
|
uint8_t diff;
|
|
|
|
|
|
|
|
|
|
ow_reset();
|
|
|
|
|
diff = OW_SEARCH_FIRST;
|
|
|
|
|
while ( diff != OW_LAST_DEVICE) {
|
|
|
|
|
diff = ow_rom_search( diff, &id[0] );
|
|
|
|
|
if ( diff != OW_PRESENCE_ERR && diff != OW_DATA_ERR) {
|
|
|
|
|
for ( i=0; i < OW_ROMCODE_SIZE; i++ ){
|
|
|
|
|
data.value[i] = id[i];
|
|
|
|
|
}
|
|
|
|
|
data.value[OW_ROMCODE_SIZE] = 0x00;
|
|
|
|
|
}
|
|
|
|
|
if (nrf24l01_write((uint8_t*) &data)){
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t mac[NRF24L01_ADDRSIZE] = {0xF0, 0xF0, 0xF0, 0xF0, 0xF0};
|
2013-11-15 14:42:41 +07:00
|
|
|
|
|
2013-11-17 21:26:03 +07:00
|
|
|
|
int main(void){
|
2013-12-11 13:34:53 +07:00
|
|
|
|
|
|
|
|
|
uint8_t id = getid();
|
|
|
|
|
nrf24l01_init();
|
2013-11-17 21:26:03 +07:00
|
|
|
|
sei();
|
2013-12-09 21:06:29 +07:00
|
|
|
|
|
2013-12-11 13:34:53 +07:00
|
|
|
|
nrf24l01_setrxaddr(0, mac);
|
|
|
|
|
mac[4] = 0xF0 & ( 0x0F & id);
|
|
|
|
|
nrf24l01_settxaddr(mac);
|
|
|
|
|
|
|
|
|
|
t_data data;
|
2013-11-18 21:27:01 +07:00
|
|
|
|
|
|
|
|
|
while(1){
|
2013-12-11 13:34:53 +07:00
|
|
|
|
if(nrf24l01_readready(&id)){
|
|
|
|
|
nrf24l01_read((uint8_t*) &data);
|
|
|
|
|
if (data.to==id && data.from==0x00){ // <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD> <20> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (strcmp(data.cmd, "ld")==0){ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
data.from = id;
|
|
|
|
|
data.to = 0x00;
|
|
|
|
|
getListDevices(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-09 21:06:29 +07:00
|
|
|
|
}
|
2013-11-15 14:42:41 +07:00
|
|
|
|
}
|
|
|
|
|
}
|