WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Examples
  4. Messaging
Mission NodeSDK 6.1PawnnetworkProject Included

Messaging

Network messaging As we know, WOWCube consists of eight modules, and each module is a separate independent micro computer with its own processor, memory and ...

Examples / SDK 6.1 / Pawn / network

Network messaging

As we know, WOWCube consists of eight modules, and each module is a separate independent micro-computer with its own processor, memory and storage space. Obviously, the modules must be able to interact and transfer information to each other, how else can we possibly create really high-quality games?

Such a connection between modules certainly exists.

In much the same way as in the case of a conventional network, computers are connected with network cables, the WOWCube modules are connected by UART channels.

Without much digging into technical details, UART, or universal asynchronous receiver-transmitter, is a device-to-device communication protocol, one of the most used ones too.

By definition, UART is a hardware communication protocol that uses asynchronous serial communication with configurable speed. Asynchronous means there is no clock signal to synchronize the output bits from the transmitting device going to the receiving end.

The purpose of a transmitter and receiver channel for each device is to transmit and receive serial data intended for serial communication.

So as you can see, the analogy with ordinary network is pretty close. The modules are connected via UART channels, these connections form an internal "network" inside WOWCube device. The only difference is, each module has three adjoined modules, therefore each module must have three UART channels to be able to talk to all its neighbours.

The example

In this example we actually want to do rather simple, but very important thing which takes an essential part in the architecture of many WOWCube games - we want to send a message from one module to the other. I mean, once you know how to do that, you know how to send many more messages wherever and whenever you need to, right?

So let's begin.

Firstly, we define commands we want to be able to send from one module to the other:

Messaging
PAWN
1const e_Commands:
2{
3 cmd_paintGreen = 0,
4 cmd_paintBlue = 1,
5 cmd_paintRed = 2
6}
7
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.

This is more for convenience really. Nothing stops us from sending of some raw data, some decimal number or floats. But the code would look tidier if you just give a bit of a human readable description to these values.

So yeah, we've defined three commands.

But how to use them? What exactly to command?

The answer is, we will command one module from the other one. One module asks to do something - the other does it. One module sends commands - the other one receives them.

Simple.

How the commanding module knows it should send the command? Even simple, it will do that on tap. You tap it - and it sends the command to use another color.

In order to handle screen taps, ON_Tap(const count, const display, const bool:opposite) callback function is used:

Messaging
PAWN
1public ON_Tap(const count, const display, const bool:opposite)
2{
3 if (SELF_ID == 0)
4 {
5 //When device is tapped, module 0 will broadcast commands to all neighbouring modules
6 sendDataToNeighbours();
7 }
8 else
9 {
10 }
11}
12
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.

and the sendDataToNeighbours() function is called to broadcast current command to the adjoined modules.

Messaging
PAWN
1sendDataToNeighbours()
2{
3 new data[1];
4 new const type[3] = [cmd_paintBlue, cmd_paintGreen, cmd_paintRed];
5
6 broadcastPacket(type[Application.counter], data); // broadcast data over UART
7
8 if(Application.counter<2) Application.counter++; else Application.counter = 0;
9}
10
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.

Now, to receive the message, ON_Packet(type, size, const pkt[]) callback is used. It gets called every time when WOWCube module receives data over UART channels.

Messaging
PAWN
1public ON_Packet(type, size, const pkt[])
2{
3 if(SELF_ID!=0)
4 {
5 switch (type)
6 {
7 case cmd_paintBlue:
8 {
9 Application.currentColor = Colors.blue;
10 }
11 case cmd_paintGreen:
12 {
13 Application.currentColor = Colors.green;
14 }
15 case cmd_paintRed:
16 {
17 Application.currentColor = Colors.red;
18 }
19
20 }
21 }
22}
23
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.

And finally, in order for us to know that the message has been sent and received successfully, let's give some visual feedback:

Messaging
PAWN
1public ON_Render()
2{
3 for(new screenNumber = 0; screenNumber<3; screenNumber++)
4 {
5 GFX_setRenderTarget(screenNumber);
6
7 if(SELF_ID==0)
8 {
9 GFX_clear(Colors.red);
10
11 GFX_drawText([ 120,80 ], TEXT_SIZE, 0, 0, TEXT_ALIGN_CENTER, Colors.white, "TAP");
12 GFX_drawText([ 120,160 ], TEXT_SIZE, 0, 0, TEXT_ALIGN_CENTER, Colors.white, "ME");
13 }
14 else
15 {
16 GFX_clear(Application.currentColor);
17 }
18
19 GFX_render();
20 }
21}
22
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

main.pwn
project/src/main.pwn
wowcubeapp-build.json
project/wowcubeapp-build.json
Jump Grid

On This Page

Network messagingThe example
Context Rail

Related nodes

info.json
Examples / SDK 6.1 / Pawn / network / Messaging
main.pwn
Examples / SDK 6.1 / Pawn / network / Messaging / project / src
wowcubeapp-build.json
Examples / SDK 6.1 / Pawn / network / Messaging / project
Messaging
Examples / SDK 6.1 / C++ / network
Previous Node
wowcubeapp-build.json
Examples / SDK 6.1 / Pawn / getting all together / Butterflies - The Game / project
Next Node
info.json
Examples / SDK 6.1 / Pawn / network / Messaging