AllWize Library
wize.cpp
Go to the documentation of this file.
1 /*
2 
3 WIZE MODULE
4 
5 */
6 
7 #include "wize.h"
8 #include "debug.h"
9 #include "forwarder.h"
10 #include "configuration.h"
11 
12 #include "AllWize.h"
13 
15 
16 double wizeFrequency(uint8_t channel) {
17  return allwize->getFrequency(channel);
18 }
19 
20 uint16_t wizeDataRateSpeed(uint8_t dr) {
21  return allwize->getDataRateSpeed(dr);
22 }
23 
24 void wizeSetup() {
25 
26  // Create and init AllWize object
28  allwize->begin();
29  if (!allwize->waitForReady()) {
30  DEBUG_MSG("[WIZE] Error connecting to the module, check your wiring!");
31  while (true);
32  }
33 
34  allwize->master();
37 
38  #if defined(DEBUG_PORT)
39  //allwize->dump(DEBUG_PORT);
40  #endif
41 
42  DEBUG_MSG("[WIZE] Listening... CH %d, DR %d\n", allwize->getChannel(), allwize->getDataRate());
43 
44 }
45 
47 
48  // Code to pretty-print the message
49  DEBUG_MSG(
50  "[WIZE] C: 0x%02X, MAN: %s, ADDR: 0x%02X%02X%02X%02X, TYPE: 0x%02X, VERSION: 0x%02X, CI: 0x%02X, RSSI: %3d, DATA: ",
51  message.c,
52  message.man,
53  message.address[0], message.address[1],
54  message.address[2], message.address[3],
55  message.type, message.version,
56  message.ci, (int16_t) message.rssi / -2
57  );
58 
59  for (uint8_t i=0; i<message.len; i++) {
60  DEBUG_MSG("%02x", message.data[i]);
61  }
62 
63  DEBUG_MSG("\n");
64 
65 }
66 
67 void wizeLoop() {
68 
69  if (allwize->available()) {
70 
71  // Get the message
72  allwize_message_t message = allwize->read();
73 
74  // Show it to console
75  wizeDebugMessage(message);
76 
77  // Forward it
78  forwarderMessage(message);
79 
80  }
81 
82 }
uint8_t getChannel()
Gets the channel stored in non-volatile memory.
Definition: AllWize.cpp:591
uint8_t rssi
Definition: AllWize.h:63
uint8_t data[RX_BUFFER_SIZE]
Definition: AllWize.h:62
double wizeFrequency(uint8_t channel)
Definition: wize.cpp:16
uint8_t version
Definition: AllWize.h:59
void wizeLoop()
Definition: wize.cpp:67
uint8_t len
Definition: AllWize.h:61
#define WIZE_CHANNEL
Definition: configuration.h:35
char man[4]
Definition: AllWize.h:57
void begin(uint8_t baudrate=MODEM_DEFAULT_BAUDRATE)
Inits the module communications.
Definition: AllWize.cpp:91
uint8_t address[4]
Definition: AllWize.h:60
void wizeDebugMessage(allwize_message_t message)
Definition: wize.cpp:46
#define DEBUG_MSG(...)
Definition: debug.h:12
void master()
Sets the module in master mode.
Definition: AllWize.cpp:234
bool available()
Returns true if a new message has been received and decoded This method has to be called in the main ...
Definition: AllWize.cpp:458
uint16_t wizeDataRateSpeed(uint8_t dr)
Definition: wize.cpp:20
void forwarderMessage(allwize_message_t message)
Definition: forwarder.cpp:82
uint8_t ci
Definition: AllWize.h:56
bool waitForReady(uint32_t timeout=DEFAULT_TIMEOUT)
Waits for timeout millis for the module to be ready.
Definition: AllWize.cpp:294
double getFrequency(uint8_t channel)
Returns the frequency for the given channel.
Definition: AllWize.cpp:1128
void setChannel(uint8_t channel, bool persist=false)
Sets the communications channel (for MBUS_MODE_R2 only)
Definition: AllWize.cpp:576
#define TX_PIN
Definition: configuration.h:29
uint8_t type
Definition: AllWize.h:58
#define RESET_PIN
Definition: configuration.h:27
#define WIZE_DATARATE
Definition: configuration.h:36
uint16_t getDataRateSpeed(uint8_t dr)
Returns the speed for te given datarate.
Definition: AllWize.cpp:1153
AllWize * allwize
Definition: wize.cpp:14
#define RX_PIN
Definition: configuration.h:28
void setDataRate(uint8_t dr)
Sets the data rate.
Definition: AllWize.cpp:621
uint8_t getDataRate()
Gets the data rate stored in non-volatile memory.
Definition: AllWize.cpp:646
allwize_message_t read()
Returns latest received message.
Definition: AllWize.cpp:504
void wizeSetup()
Definition: wize.cpp:24