Skip to content

Commit

Permalink
wip: message format in example app
Browse files Browse the repository at this point in the history
  • Loading branch information
everedero committed Jan 5, 2024
1 parent 09c39a9 commit 440175c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/alice.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ CONFIG_NRF24L01_TRIGGER=y

CONFIG_LOG=y
CONFIG_APP_LOG_LEVEL_INF=y
CONFIG_NRF24L01_LOG_LEVEL_ERR=y

CONFIG_ROLE=0
1 change: 1 addition & 0 deletions app/bob.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ CONFIG_NRF24L01_TRIGGER=y

CONFIG_LOG=y
CONFIG_APP_LOG_LEVEL_INF=y
CONFIG_NRF24L01_LOG_LEVEL_ERR=y

CONFIG_ROLE=1
1 change: 1 addition & 0 deletions app/eve.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ CONFIG_NRF24L01_TRIGGER=y

CONFIG_LOG=y
CONFIG_APP_LOG_LEVEL_INF=y
CONFIG_NRF24L01_LOG_LEVEL_ERR=y

CONFIG_ROLE=2
32 changes: 18 additions & 14 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ int main(void)
uint8_t buffer[16] = {0};
#ifndef TRIGGER
int i;
#endif // CONFIG_NRF24L01_TRIGGER
#endif // TRIGGER

if (!device_is_ready(nrf24)) {
LOG_ERR("Sensor not ready");
return 0;
}
LOG_INF("Device ready");
#ifdef TRIGGER
LOG_DBG("Trigger mode activated");
#endif //TRIGGER

#ifdef ALICE
printk("I am Alice!\n");
LOG_WRN("I am Alice!");
while (true) {
strncpy(buffer, "I am Alice, hi!", 16);
#ifdef TRIGGER
printk("Trigger mode!\n");
while (nrf24_write(nrf24, buffer, data_len))
{
k_sleep(K_MSEC(10));
Expand All @@ -57,33 +59,33 @@ int main(void)
nrf24_write(nrf24, buffer, data_len);
k_sleep(K_MSEC(10));
}
#endif // CONFIG_NRF24L01_TRIGGER
printk("Switch to read");
#endif // TRIGGER
LOG_HEXDUMP_INF(buffer, data_len, "Sent: ");
LOG_DBG("Switch to read");
#ifdef TRIGGER
while (nrf24_read(nrf24, buffer, data_len));
#else
nrf24_read(nrf24, buffer, data_len);
#endif // CONFIG_NRF24L01_TRIGGER
#endif // TRIGGER
LOG_HEXDUMP_INF(buffer, data_len, "Received: ");
k_sleep(K_MSEC(1000));
printk("Switch to write\n");
LOG_DBG("Switch to write");
}
#endif // ALICE

#ifdef BOB
printk("I am Bob!\n");
LOG_WRN("I am Bob!");
while (true) {
#ifdef TRIGGER
while (nrf24_read(nrf24, buffer, data_len));
#else
nrf24_read(nrf24, buffer, data_len);
#endif // CONFIG_NRF24L01_TRIGGER
#endif // TRIGGER
LOG_HEXDUMP_INF(buffer, data_len, "Received: ");
printk("Switch to write\n");
LOG_DBG("Switch to write");
strncpy(buffer, "Hi Alice Im Bob", 16);
k_sleep(K_MSEC(1000));
#ifdef TRIGGER
printk("Trigger mode!\n");
while (nrf24_write(nrf24, buffer, data_len))
{
k_sleep(K_MSEC(10));
Expand All @@ -94,19 +96,21 @@ int main(void)
nrf24_write(nrf24, buffer, data_len);
k_sleep(K_MSEC(10));
}
#endif // CONFIG_NRF24L01_TRIGGER
#endif // TRIGGER
LOG_HEXDUMP_INF(buffer, data_len, "Sent: ");
LOG_DBG("Switch to read");
}
#endif // BOB

#ifdef EVE
printk("I am Eve!\n");
LOG_WRN("I am Eve!");
while (true) {
#ifdef TRIGGER
while (nrf24_read(nrf24, buffer, data_len));
#else
strncpy(buffer, " ", 16);
nrf24_read(nrf24, buffer, data_len);
#endif // CONFIG_NRF24L01_TRIGGER
#endif // TRIGGER
LOG_HEXDUMP_INF(buffer, data_len, "I spied: ");
}
#endif // EVE
Expand Down

0 comments on commit 440175c

Please sign in to comment.