void main(void) { uint8_t err; Status_Payload status_payload; TEMP_HUM_Payload temp_hum_payload; memset(&temp_hum_payload,0,sizeof(TEMP_HUM_Payload)); temp_hum_payload.header.msg_id = TEMP_HUM_DATA; temp_hum_payload.header.nodeId = NODE_ID; memset(&status_payload,0,sizeof(Status_Payload)); status_payload.header.msg_id = STATUS_DATA; status_payload.header.nodeId = NODE_ID; status_payload.sw_version = SW_VERSION; /* set all pins to input to save power. */ TRISC = 0xffffff; TRISA = 0xffffff; TRISB = 0xffffff; RF_PWR_PIN_DIR = 0; peripheral_pwr(false); // never works first time, so dummy call... measure_power(); LED_RED_DIR = 0; LED_GRN_DIR = 0; LED_RED = 0b0; LED_GRN = 0b0; /* Configure the oscillator for the device */ ConfigureOscillator(); /* Initialize I/O and Peripherals for application */ InitApp(); /* Check payload size */ if ((temp_hum_payload_size != sizeof (TEMP_HUM_Payload)) || (status_payload_size != sizeof (Status_Payload))) { while (1) { LED_RED = 0b1; LED_GRN = 0b1; sleep(WDT_256_MS); LED_RED = 0b0; LED_GRN = 0b0; sleep(WDT_256_MS); } } sleep(WDT_1_SEC); LED_RED = 0b1; LED_GRN = 0b1; sleep(WDT_256_MS); LED_RED = 0b0; LED_GRN = 0b0; /* Main loop */ while (1) { peripheral_pwr(true); //wait for settling time sleep(WDT_32_MS); err = getTH(&temp_hum_payload.humidity,&temp_hum_payload.temperature); if (err){ status_payload.sensor_err++; } temp_hum_payload.header.count++; wl_module_tx_config(wl_module_TX_NR_0); err = wl_module_send((unsigned char *) &temp_hum_payload, sizeof (temp_hum_payload)); if (err){ status_payload.rf_error++; } if (temp_hum_payload.header.count % 12 == 1) { /* send long payload */ status_payload.millivolts = measure_power(); status_payload.header.count++; err |= wl_module_send((unsigned char *) &status_payload, sizeof (status_payload)); } peripheral_pwr(false); if (err){ LED_RED = 0b1; sleep(WDT_1_MS); LED_RED = 0b0; }else{ LED_GRN = 0b1; sleep(WDT_1_MS); LED_GRN = 0b0; } LED_RED = 0b0; LED_GRN = 0b0; sleep(WDT_256_SEC); sleep(WDT_32_SEC); } }
// Send given payload of length. // // Commentary // // From datasheet p. 29: With static payload length all packets // between a transmitter and a receiver have the same length. Static // payload length is set by the RX_PW_Px registers on the receiver // side. The payload length on the transmitter side is set by the // number of bytes clocked into the TX_FIFO and must equal the value // in the RX_PW_Px register on the receiver side. void wlhl_send_payload(uint8_t *payload, uint8_t len) { // Be sure to send the correct amount of bytes as configured as // payload on the receiver. wl_module_send(payload, len); }