B Lập trình chương trình sử lý trên máy tính
4.4.8. Phương hướng phát triển đề tà
Nếu số lượng nút mạng có đủ và có đầu đo nồng độ oxy cũng như độ PH trong nước và các nút có thể họa động được trong môi trường nước thì sẽ tiến hành làm ứng dụng trong nuôi trồng thủy sản. Khi đó hệ thống sẽ có ý nghĩa rất lớn trong thực tiễn để nâng cao năng suất trong việc nuôi trồng thủy sản.
[1] Thiết kế chế tạo, vận hành và đo thử nghiệm mạng cảm nhận không dây- Nguyễn Thế Sơn.
[2]. Hòa Quang Dự , Phần mềm nhúng cho vi điều khiển CC1010 và phưong thức giải quyết vấn đề truyền dữ liệu không dây trên khoảng cách xa đến nơi nhận, Luận văn Cao học, Trường ĐHDL Hải Phòng.
[3]. Vương Đạo Vy, Trần Thanh Hải, Phạm Đình Tuấn, Trần Anh Tuấn, Hòa Quang Dự, Phùng Công Phi Khanh, Mạng cảm nhận không dây thu thập dữ liệu môi trường sử dụng vi điều khiển Chipcon CC1010, Khoa Điện tử - Viễn thông, Trường Đại học Công nghệ, ĐHQGHN
Tiếng anh
[4] wireless sensor networks: a survey I.F. Akyildiz, W. Su*, Y.
Sankarasubramaniam, E. Cayirci
[5] Broadband and Wireless Networking Laboratory, School of Electrical and Computer Engineering, Georgia Institute of Technology,
Atlanta, GA 30332, USA.
[6]. Sensor Network Protocols – Deborah
[7] Guoliang Xing, Xiaorui Wang, Yuanfang Zhang, Chenyang Lu, Robert Pless, and Christopher D. Gill.
Integrated coverage and connectivity configuration for energy conservation in sensor networks.
ACM Transactions on Sensor Networks, 1(1), 2005.
[8]. Chipcon, CC1010IDE Manual (2003), www.Chipcon.com
[9].http://nesl.ee.ucla.edu
PHỤ LỤC
/************************************************************* Chuong trinh truyen nhiet do di xa o muc nut don. O muc nay` khoang cach truyen
toi da la 300m ngoai troi, 150m trong nha
*************************************************************/ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <chipcon/reg1010.h> #include <chipcon/cc1010eb.h> #include <chipcon/hal.h> #include <chipcon/cul.h> #include <chipcon/vt100.h> // Temperature packet:
#define TBC_NODE_ID_LENGTH 2 // word #define TBC_NODE_NAME_LENGTH 20
#define TBC_TEMP_OFFSET (TBC_NODE_ID_LENGTH + TBC_NODE_NAME_LENGTH)
#define TBC_TEMP_LENGTH 2
#define TBC_DATA_LEN (TBC_NODE_ID_LENGTH + TBC_NODE_NAME_LENGTH + TBC_TEMP_LENGTH) // Radio related: #define TBC_MY_SPP_ADDRESS 1 #define TBC_RX_INTERVAL 50 #define TBC_PREAMBLE_COUNT 4 // Node registration #define TBC_INVALID_NODE_INDEX 255 #define TBC_UNUSED_NODE_ID 0x0000 // Speed related
byte xdata waitMultiplier; // The temperature "table":
byte xdata nodeNames[TBC_MAX_NODE_COUNT] [TBC_NODE_NAME_LENGTH];
word xdata nodeTemps[TBC_MAX_NODE_COUNT]; word xdata nodeLastT[TBC_MAX_NODE_COUNT]; // SPP variables
SPP_SETTINGS xdata sppSettings; SPP_RX_INFO xdata RXI;
SPP_TX_INFO xdata TXI;
byte xdata rxDataBuffer[TBC_DATA_LEN]; byte xdata txDataBuffer[TBC_DATA_LEN]; // Function prototypes
void tbcWaitRandom (void); void tbcTransmit (void); void tbcReceive (void); void tbcPrintTable (void); // Unit name, stored in Flash
byte code flashUnitName[TBC_NODE_NAME_LENGTH]; // RAM buffer for Flash copy
byte xdata ramBufNonAligned[128];
//--- // MAIN PROGRAM
//--- void main (void) {
byte xdata n; byte xdata m;
RF_RXTXPAIR_SETTINGS code RF_SETTINGS = { 0xA3, 0x2F, 0x15, // Modem 0, 1 and 2
0x75, 0xA0, 0x00, // Freq A 0x58, 0x32, 0x8D, // Freq B 0x01, 0xAB, // FSEP 1 and 0 0x40, // PLL_RX 0x30, // PLL_TX 0x6C, // CURRENT_RX 0xF3, // CURRENT_TX 0x32, // FREND 0xFF, // PA_POW
0x00, // MATCH 0x00, // PRESCALER };
// Calibration data
RF_RXTXPAIR_CALDATA xdata RF_CALDATA; // Initialize peripherals WDT_ENABLE(FALSE); RLED_OE(TRUE); YLED_OE(TRUE); GLED_OE(TRUE); BLED_OE(TRUE);
// Startup macros for speed and low power consumption MEM_NO_WAIT_STATES();
FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS); // Seed the random generator:
halRandomNumberGen(&n, 1); halRandomNumberGen(&m, 1); srand((n << 8) + m); waitMultiplier = 1; // ADC setup halConfigADC(ADC_MODE_SINGLE | ADC_REFERENCE_INTERNAL_1_25, CC1010EB_CLKFREQ, 0); ADC_SELECT_INPUT(ADC_INPUT_AD1); ADC_POWER(TRUE); // RF/SPP setup
sppSetupRF(&RF_SETTINGS, &RF_CALDATA, TRUE); sppSettings.myAddress = TBC_MY_SPP_ADDRESS; sppSettings.rxTimeout = TBC_RX_INTERVAL;
sppSettings.txAckTimeout = TBC_PREAMBLE_COUNT;
TXI.destination = SPP_BROADCAST; TXI.flags = 0x00;
TXI.pDataBuffer = txDataBuffer; TXI.dataLen = TBC_DATA_LEN; // Initialize the SPP timer
sppStartTimer(CC1010EB_CLKFREQ); SPP_INIT_TIMEOUTS();
// Reset the node IDs
for (n = 0; n < TBC_MAX_NODE_COUNT; n++) { nodeIDs[n] = TBC_UNUSED_NODE_ID;
}
// Reset our name buffer
for (n = 0; n < TBC_NODE_NAME_LENGTH; n++) { nodeNames[0][n] = 0x00;
}
// Setup UART0 for polled I/O
UART0_SETUP(57600, CC1010EB_CLKFREQ, UART_NO_PARITY | UART_RX_TX | UART_POLLED);
// Get our name
VT100_CLEAR_SCREEN(); VT100_GO_TOP_LEFT(); // Load name from Flash memcpy(&nodeNames[0]
[0],flashUnitName,TBC_NODE_NAME_LENGTH); // Get our ID from CRC16(our name)
nodeIDs[0] = TBC_MY_SPP_ADDRESS; // Prepare the id+name part of the packet txDataBuffer[0] = (nodeIDs[0] >> 8) & 0xFF; txDataBuffer[1] = nodeIDs[0] & 0xFF;
for (n = 0; n < TBC_NODE_NAME_LENGTH; n++) {
txDataBuffer[n + TBC_NODE_ID_LENGTH] = nodeNames[0][n]; }
// Loop forever while (TRUE) {
tbcTransmit(); tbcWaitRandom(); }
} // main
void tbcWaitRandom (void) { byte xdata time;
byte xdata n; time = rand();
for (n = 0; n < waitMultiplier; n++) { halWait (time, CC1010EB_CLKFREQ); }
} // tbcWaitRandom void tbcTransmit (void) { word xdata temp; // Indicate transmission RLED = LED_ON; YLED = LED_ON;
// Power up the ADC and sample the temperature ADC_SAMPLE_SINGLE();
temp = ADC_GET_SAMPLE_10BIT();
// Update the TX buffer and the table with the new temperature txDataBuffer[TBC_TEMP_OFFSET] = (temp >> 8) & 0xFF; txDataBuffer[TBC_TEMP_OFFSET + 1] = temp & 0xFF; nodeTemps[0] = temp;
nodeLastT[0] = (int) sppGetTime(); YLED = LED_OFF;
// Transmit the temperature sppSend(&TXI);
do { } while (sppStatus() != SPP_IDLE_MODE); RLED = LED_OFF;
} // tbcTransmit
**************************************************************/ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <chipcon/reg1010.h> #include <chipcon/cc1010eb.h> #include <chipcon/hal.h> #include <chipcon/cul.h> #include <chipcon/vt100.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <chipcon/reg1010.h> #include <chipcon/cc1010eb.h> #include <chipcon/hal.h> #include <chipcon/cul.h> #include <chipcon/vt100.h> // Temperature packet:
#define TBC_NODE_ID_LENGTH 2 // word #define TBC_NODE_NAME_LENGTH 20
#define TBC_TEMP_OFFSET (TBC_NODE_ID_LENGTH + TBC_NODE_NAME_LENGTH)
#define TBC_TEMP_LENGTH 2
#define TBC_DATA_LEN (TBC_NODE_ID_LENGTH + TBC_NODE_NAME_LENGTH + TBC_TEMP_LENGTH)
// Radio related:
#define TBC_MY_SPP_ADDRESS 2 #define TBC_RX_INTERVAL 50 #define TBC_PREAMBLE_COUNT 4
// Node registration
#define TBC_INVALID_NODE_INDEX 255 #define TBC_UNUSED_NODE_ID 0x0000 // Speed related
byte xdata waitMultiplier; // The temperature "table":
#define TBC_MAX_NODE_COUNT 16
word xdata nodeIDs[TBC_MAX_NODE_COUNT]; byte xdata nodeNames[TBC_MAX_NODE_COUNT] [TBC_NODE_NAME_LENGTH];
word xdata nodeTemps[TBC_MAX_NODE_COUNT]; word xdata nodeLastT[TBC_MAX_NODE_COUNT]; // SPP variables
SPP_SETTINGS xdata sppSettings; SPP_RX_INFO xdata RXI;
SPP_TX_INFO xdata TXI;
byte xdata rxDataBuffer[TBC_DATA_LEN]; byte xdata txDataBuffer[TBC_DATA_LEN]; // Function prototypes
void tbcWaitRandom (void); void tbcTransmit (void); void tbcReceive (void); void tbcPrintTable (void); // Unit name, stored in Flash
byte code flashUnitName[TBC_NODE_NAME_LENGTH]; // RAM buffer for Flash copy
byte xdata ramBufNonAligned[128];
//--- // MAIN PROGRAM
//--- void main (void) {
byte xdata m;
RF_RXTXPAIR_SETTINGS code RF_SETTINGS = { 0xA3, 0x2F, 0x15, // Modem 0, 1 and 2
0x75, 0xA0, 0x00, // Freq A 0x58, 0x32, 0x8D, // Freq B 0x01, 0xAB, // FSEP 1 and 0 0x40, // PLL_RX 0x30, // PLL_TX 0x6C, // CURRENT_RX 0xF3, // CURRENT_TX 0x32, // FREND 0xFF, // PA_POW 0x00, // MATCH 0x00, // PRESCALER }; // Calibration data
RF_RXTXPAIR_CALDATA xdata RF_CALDATA; // Initialize peripherals WDT_ENABLE(FALSE); RLED_OE(TRUE); YLED_OE(TRUE); GLED_OE(TRUE); BLED_OE(TRUE);
// Startup macros for speed and low power consumption MEM_NO_WAIT_STATES();
FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS); // Seed the random generator:
halRandomNumberGen(&n, 1); halRandomNumberGen(&m, 1); srand((n << 8) + m);
waitMultiplier = 1; // RF/SPP setup
sppSetupRF(&RF_SETTINGS, &RF_CALDATA, TRUE); sppSettings.myAddress = TBC_MY_SPP_ADDRESS; sppSettings.rxTimeout = TBC_RX_INTERVAL; sppSettings.txAckTimeout = TBC_PREAMBLE_COUNT; sppSettings.txPreambleByteCount = TBC_PREAMBLE_COUNT; RXI.maxDataLen = TBC_DATA_LEN; RXI.pDataBuffer = rxDataBuffer; TXI.destination = SPP_BROADCAST; TXI.flags = 0x00; TXI.pDataBuffer = txDataBuffer; TXI.dataLen = TBC_DATA_LEN; // Initialize the SPP timer
sppStartTimer(CC1010EB_CLKFREQ); SPP_INIT_TIMEOUTS();
// Reset the node IDs
for (n = 0; n < TBC_MAX_NODE_COUNT; n++) { nodeIDs[n] = TBC_UNUSED_NODE_ID;
}
// Reset our name buffer
for (n = 0; n < TBC_NODE_NAME_LENGTH; n++) { nodeNames[0][n] = 0x00;
}
// Setup UART0 for polled I/O
UART0_SETUP(57600, CC1010EB_CLKFREQ, UART_NO_PARITY | UART_RX_TX | UART_POLLED);
// Get our name
VT100_CLEAR_SCREEN(); VT100_GO_TOP_LEFT(); // Load name from Flash memcpy(&nodeNames[0]
[0],flashUnitName,TBC_NODE_NAME_LENGTH);
// Prepare the id+name part of the packet txDataBuffer[0] = (nodeIDs[0] >> 8) & 0xFF; txDataBuffer[1] = nodeIDs[0] & 0xFF;
for (n = 0; n < TBC_NODE_NAME_LENGTH; n++) {
txDataBuffer[n + TBC_NODE_ID_LENGTH] = nodeNames[0][n]; }
// Loop forever while (TRUE) {
tbcReceive();
// Tien hanh truyen goi tin nhan duoc tbcTransmit();
tbcWaitRandom(); }
} // main
void tbcWaitRandom (void) { byte xdata time;
byte xdata n; time = rand();
for (n = 0; n < waitMultiplier; n++) { halWait (time, CC1010EB_CLKFREQ); }
} // tbcWaitRandom void tbcTransmit (void) { word xdata temp;
int m,n; // Indicate transmission RLED = LED_ON; YLED = LED_ON; for (n = 0; n <= TBC_MAX_NODE_COUNT; n++) { if (nodeIDs[n] == TBC_UNUSED_NODE_ID) { continue; } // Node name: for (m = 0; m < TBC_NODE_NAME_LENGTH; m++) {
UART0_WAIT_AND_SEND(nodeNames[n][m]); } if(nodeIDs[n]==1){ // Temperature: temp = nodeTemps[n]; break; } } // temp=30;
// Update the TX buffer and the table with the new temperature txDataBuffer[TBC_TEMP_OFFSET] = (temp >> 8) & 0xFF; txDataBuffer[TBC_TEMP_OFFSET + 1] = temp & 0xFF; nodeTemps[0] = temp;
nodeLastT[0] = (int) sppGetTime(); YLED = LED_OFF;
// Transmit the temperature sppSend(&TXI);
do { /*nothing*/ } while (sppStatus() != SPP_IDLE_MODE); RLED = LED_OFF;
} // tbcTransmit
void tbcReceive (void) { byte xdata n,m,o; byte xdata nodeIndex; word xdata nodeID;
// Throw out "old" nodes (no updates during the last 3 seconds) for (n = 0; n < TBC_MAX_NODE_COUNT; n++) {
if (((int) sppGetTime() - nodeLastT[n]) > 300) {
// Re-organize the list (by moving the remaining nodes up one index) for (m = n; m < (TBC_MAX_NODE_COUNT - 1); m++) {
nodeIDs[m] = nodeIDs[m + 1];
for (o = 0; o < TBC_NODE_NAME_LENGTH; o++) { nodeNames[m][o] = nodeNames[m + 1][o];
}
nodeTemps[m] = nodeTemps[m + 1]; nodeLastT[m] = nodeLastT[m + 1];
}
// Receive the packet (if any) YLED = LED_ON;
sppReceive(&RXI);
do { /*nothing*/ } while (sppStatus() != SPP_IDLE_MODE); YLED = LED_OFF;
// Process the packet
if (RXI.status == SPP_RX_FINISHED) { GLED = LED_ON;
// Get the node ID
nodeID = (rxDataBuffer[0] << 8) + rxDataBuffer[1]; // Get the node's index in the temperature table
for (n = 0; n < TBC_MAX_NODE_COUNT; n++) { if (nodeIDs[n] == nodeID) {
nodeIndex = n; break;
} else if (nodeIDs[n] == TBC_UNUSED_NODE_ID) { nodeIndex = n; break; } else { nodeIndex = TBC_INVALID_NODE_INDEX; } }
// Update the table
if (nodeIndex != TBC_INVALID_NODE_INDEX) { nodeIDs[nodeIndex] = nodeID; for (n = 0; n < TBC_NODE_NAME_LENGTH; n++) { nodeNames[nodeIndex][n] = rxDataBuffer[n + TBC_NODE_ID_LENGTH]; } nodeTemps[nodeIndex] = (rxDataBuffer[TBC_TEMP_OFFSET] << 8) + rxDataBuffer[TBC_TEMP_OFFSET + 1];
nodeLastT[nodeIndex] = (int) sppGetTime(); }
} else {
}
} // tbcReceive
Mã nguồn chương trình nạp vàp chíp nối trực tiếp với máy tính
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <chipcon/reg1010.h> #include <chipcon/cc1010eb.h> #include <chipcon/hal.h> #include <chipcon/cul.h> #include <chipcon/vt100.h> //LCD define #define LCDPORT P2 sbit _RS=LCDPORT^0; sbit _RW=LCDPORT^1; sbit _E =LCDPORT^2; #include "lcd.h" // Temperature packet:
#define TBC_NODE_ID_LENGTH 2 // word #define TBC_NODE_NAME_LENGTH 20
#define TBC_TEMP_OFFSET (TBC_NODE_ID_LENGTH + TBC_NODE_NAME_LENGTH)
#define TBC_TEMP_LENGTH 2
#define TBC_DATA_LEN (TBC_NODE_ID_LENGTH + TBC_NODE_NAME_LENGTH + TBC_TEMP_LENGTH) // Radio related: #define TBC_MY_SPP_ADDRESS 3 #define TBC_RX_INTERVAL 50 #define TBC_PREAMBLE_COUNT 4 // Node registration #define TBC_INVALID_NODE_INDEX 255 #define TBC_UNUSED_NODE_ID 0x0000
// The temperature "table":
#define TBC_MAX_NODE_COUNT 16
word xdata nodeIDs[TBC_MAX_NODE_COUNT]; byte xdata nodeNames[TBC_MAX_NODE_COUNT] [TBC_NODE_NAME_LENGTH];
word xdata nodeTemps[TBC_MAX_NODE_COUNT]; word xdata nodeLastT[TBC_MAX_NODE_COUNT]; // SPP variables
SPP_SETTINGS xdata sppSettings; SPP_RX_INFO xdata RXI;
SPP_TX_INFO xdata TXI;
byte xdata rxDataBuffer[TBC_DATA_LEN]; byte xdata txDataBuffer[TBC_DATA_LEN]; // Function prototypes
void tbcWaitRandom (void); void tbcTransmit (void); void tbcReceive (void); void tbcPrintTable (void); void delayy(int ms);
// Unit name, stored in Flash
byte code flashUnitName[TBC_NODE_NAME_LENGTH]; // RAM buffer for Flash copy
byte xdata ramBufNonAligned[128];
//--- // MAIN PROGRAM
//--- void main (void) {
byte xdata n; byte xdata m;
float xdata fTemp; char so[15];
RF_RXTXPAIR_SETTINGS code RF_SETTINGS = { 0xA3, 0x2F, 0x15, // Modem 0, 1 and 2
0x75, 0xA0, 0x00, // Freq A 0x58, 0x32, 0x8D, // Freq B 0x01, 0xAB, // FSEP 1 and 0 0x40, // PLL_RX 0x30, // PLL_TX 0x6C, // CURRENT_RX 0xF3, // CURRENT_TX 0x32, // FREND 0xFF, // PA_POW 0x00, // MATCH 0x00, // PRESCALER }; // Calibration data
RF_RXTXPAIR_CALDATA xdata RF_CALDATA; // Initialize peripherals WDT_ENABLE(FALSE); RLED_OE(TRUE); YLED_OE(TRUE); GLED_OE(TRUE); BLED_OE(TRUE);
// Startup macros for speed and low power consumption MEM_NO_WAIT_STATES();
FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS); // Seed the random generator:
halRandomNumberGen(&n, 1); halRandomNumberGen(&m, 1); srand((n << 8) + m);
sppSettings.myAddress = TBC_MY_SPP_ADDRESS; sppSettings.rxTimeout = TBC_RX_INTERVAL; sppSettings.txAckTimeout = TBC_PREAMBLE_COUNT; sppSettings.txPreambleByteCount = TBC_PREAMBLE_COUNT; RXI.maxDataLen = TBC_DATA_LEN; RXI.pDataBuffer = rxDataBuffer; TXI.destination = SPP_BROADCAST; TXI.flags = 0x00; TXI.pDataBuffer = txDataBuffer; TXI.dataLen = TBC_DATA_LEN; // Initialize the SPP timer
sppStartTimer(CC1010EB_CLKFREQ); SPP_INIT_TIMEOUTS();
// Reset the node IDs
for (n = 0; n < TBC_MAX_NODE_COUNT; n++) { nodeIDs[n] = TBC_UNUSED_NODE_ID;
}
// Reset our name buffer
for (n = 0; n < TBC_NODE_NAME_LENGTH; n++) { nodeNames[0][n] = 0x00;
}
// Setup UART0 for polled I/O
UART0_SETUP(57600, CC1010EB_CLKFREQ, UART_NO_PARITY | UART_RX_TX | UART_POLLED);
// Get our name
VT100_CLEAR_SCREEN(); VT100_GO_TOP_LEFT(); // Load name from Flash memcpy(&nodeNames[0]
[0],flashUnitName,TBC_NODE_NAME_LENGTH);
// Get our ID from CRC16(our name) nodeIDs[0] = TBC_MY_SPP_ADDRESS; // Prepare the id+name part of the packet txDataBuffer[0] = (nodeIDs[0] >> 8) & 0xFF;
txDataBuffer[1] = nodeIDs[0] & 0xFF;
for (n = 0; n < TBC_NODE_NAME_LENGTH; n++) {
txDataBuffer[n + TBC_NODE_ID_LENGTH] = nodeNames[0][n]; }
// Dat P2 o che do out du lieu P2DIR = 0X00; // Loop forever while (TRUE) { delay(2000); tbcReceive(); for (n = 0; n <= TBC_MAX_NODE_COUNT; n++) { if (nodeIDs[n] == TBC_UNUSED_NODE_ID) { continue; } // Node name: for (m = 0; m < TBC_NODE_NAME_LENGTH; m++) { UART0_WAIT_AND_SEND(nodeNames[n][m]); } if(nodeIDs[n]==2){ // Temperature: fTemp = nodeTemps[n]; fTemp -= 492; fTemp /= 8.192; sprintf(so,"%2.3f",fTemp);
// Phan doan tinh` trang he thong: if(fTemp<70){
printf("Nhiet tai nut 1: %2.3f\n",fTemp); printf("Tinh trang nut 1: An toan\n"); delayy(10000);
} else{
} }
else{
printf("Hien tai chua co du lieu\n"); }
} } } // main
void tbcWaitRandom (void) { byte xdata time;
byte xdata n; time = rand();
for (n = 0; n < waitMultiplier; n++) { halWait (time, CC1010EB_CLKFREQ); }
} // tbcWaitRandom void tbcReceive (void) { byte xdata n,m,o; byte xdata nodeIndex; word xdata nodeID;
// Throw out "old" nodes (no updates during the last 3 seconds) for (n = 0; n < TBC_MAX_NODE_COUNT; n++) {
if (((int) sppGetTime() - nodeLastT[n]) > 300) {
// Re-organize the list (by moving the remaining nodes up one index) for (m = n; m < (TBC_MAX_NODE_COUNT - 1); m++) {
nodeIDs[m] = nodeIDs[m + 1];
for (o = 0; o < TBC_NODE_NAME_LENGTH; o++) { nodeNames[m][o] = nodeNames[m + 1][o];
} nodeTemps[m] = nodeTemps[m + 1]; nodeLastT[m] = nodeLastT[m + 1]; } } }
// Receive the packet (if any) YLED = LED_ON;
sppReceive(&RXI);
do { /*nothing*/ } while (sppStatus() != SPP_IDLE_MODE); YLED = LED_OFF;
// Process the packet
if (RXI.status == SPP_RX_FINISHED) { GLED = LED_ON;
// Get the node ID
nodeID = (rxDataBuffer[0] << 8) + rxDataBuffer[1]; // Get the node's index in the temperature table
for (n = 0; n < TBC_MAX_NODE_COUNT; n++) { if (nodeIDs[n] == nodeID) {
nodeIndex = n; break;
} else if (nodeIDs[n] == TBC_UNUSED_NODE_ID) { nodeIndex = n; break; } else { nodeIndex = TBC_INVALID_NODE_INDEX; } }
// Update the table
if (nodeIndex != TBC_INVALID_NODE_INDEX) { nodeIDs[nodeIndex] = nodeID; for (n = 0; n < TBC_NODE_NAME_LENGTH; n++) { nodeNames[nodeIndex][n] = rxDataBuffer[n + TBC_NODE_ID_LENGTH]; } nodeTemps[nodeIndex] = (rxDataBuffer[TBC_TEMP_OFFSET] << 8) + rxDataBuffer[TBC_TEMP_OFFSET + 1];
nodeLastT[nodeIndex] = (int) sppGetTime(); }
} else {
// --- // ham delayy // ---