Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b0f715a87 |
134
.gitignore
vendored
134
.gitignore
vendored
@ -1,67 +1,67 @@
|
|||||||
# These are some examples of commonly ignored file patterns.
|
# These are some examples of commonly ignored file patterns.
|
||||||
# You should customize this list as applicable to your project.
|
# You should customize this list as applicable to your project.
|
||||||
# Learn more about .gitignore:
|
# Learn more about .gitignore:
|
||||||
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
|
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
|
||||||
|
|
||||||
# config files
|
# config files
|
||||||
/src/wifiConf.h
|
/src/wifiConf.h
|
||||||
|
|
||||||
# ccs artifact files
|
# ccs artifact files
|
||||||
/.settings
|
/.settings
|
||||||
/targetConfigs
|
/targetConfigs
|
||||||
/.ccs*
|
/.ccs*
|
||||||
/.cproject
|
/.cproject
|
||||||
/.project
|
/.project
|
||||||
*.cmd
|
*.cmd
|
||||||
/*.c
|
/*.c
|
||||||
/*.h
|
/*.h
|
||||||
/.launches
|
/.launches
|
||||||
/Debug
|
/Debug
|
||||||
|
|
||||||
# Node artifact files
|
# Node artifact files
|
||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
# VS Code artifact files
|
# VS Code artifact files
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
|
|
||||||
# Compiled Java class files
|
# Compiled Java class files
|
||||||
*.class
|
*.class
|
||||||
|
|
||||||
# Compiled Python bytecode
|
# Compiled Python bytecode
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
||||||
# Log files
|
# Log files
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
# Package files
|
# Package files
|
||||||
*.jar
|
*.jar
|
||||||
|
|
||||||
# Maven
|
# Maven
|
||||||
target/
|
target/
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
# JetBrains IDE
|
# JetBrains IDE
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# Unit test reports
|
# Unit test reports
|
||||||
TEST*.xml
|
TEST*.xml
|
||||||
|
|
||||||
# Generated by MacOS
|
# Generated by MacOS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# Generated by Windows
|
# Generated by Windows
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# Applications
|
# Applications
|
||||||
*.app
|
*.app
|
||||||
*.exe
|
*.exe
|
||||||
*.war
|
*.war
|
||||||
|
|
||||||
# Large media files
|
# Large media files
|
||||||
*.mp4
|
*.mp4
|
||||||
*.tiff
|
*.tiff
|
||||||
*.avi
|
*.avi
|
||||||
*.flv
|
*.flv
|
||||||
*.mov
|
*.mov
|
||||||
*.wmv
|
*.wmv
|
||||||
|
|||||||
@ -9,23 +9,17 @@
|
|||||||
* Import the modules used in this configuration.
|
* Import the modules used in this configuration.
|
||||||
*/
|
*/
|
||||||
const DriverLib = scripting.addModule("/ti/devices/DriverLib");
|
const DriverLib = scripting.addModule("/ti/devices/DriverLib");
|
||||||
const Display = scripting.addModule("/ti/display/Display");
|
|
||||||
const Display1 = Display.addInstance();
|
|
||||||
const Board = scripting.addModule("/ti/drivers/Board");
|
const Board = scripting.addModule("/ti/drivers/Board");
|
||||||
const Crypto = scripting.addModule("/ti/drivers/Crypto");
|
|
||||||
const Crypto1 = Crypto.addInstance();
|
|
||||||
const DMA = scripting.addModule("/ti/drivers/DMA");
|
const DMA = scripting.addModule("/ti/drivers/DMA");
|
||||||
const GPIO = scripting.addModule("/ti/drivers/GPIO", {}, false);
|
const GPIO = scripting.addModule("/ti/drivers/GPIO", {}, false);
|
||||||
const GPIO1 = GPIO.addInstance();
|
const GPIO1 = GPIO.addInstance();
|
||||||
const I2C = scripting.addModule("/ti/drivers/I2C", {}, false);
|
const I2C = scripting.addModule("/ti/drivers/I2C", {}, false);
|
||||||
const I2C1 = I2C.addInstance();
|
const I2C1 = I2C.addInstance();
|
||||||
|
const PWM = scripting.addModule("/ti/drivers/PWM", {}, false);
|
||||||
|
const PWM1 = PWM.addInstance();
|
||||||
const Power = scripting.addModule("/ti/drivers/Power");
|
const Power = scripting.addModule("/ti/drivers/Power");
|
||||||
const SPI = scripting.addModule("/ti/drivers/SPI");
|
const SPI = scripting.addModule("/ti/drivers/SPI");
|
||||||
const SPI1 = SPI.addInstance();
|
const SPI1 = SPI.addInstance();
|
||||||
const Timer = scripting.addModule("/ti/drivers/Timer");
|
|
||||||
const Timer1 = Timer.addInstance();
|
|
||||||
const Timer2 = Timer.addInstance();
|
|
||||||
const Timer3 = Timer.addInstance();
|
|
||||||
const Watchdog = scripting.addModule("/ti/drivers/Watchdog");
|
const Watchdog = scripting.addModule("/ti/drivers/Watchdog");
|
||||||
const Watchdog1 = Watchdog.addInstance();
|
const Watchdog1 = Watchdog.addInstance();
|
||||||
const SimpleLinkWifi = scripting.addModule("/ti/drivers/net/wifi/SimpleLinkWifi");
|
const SimpleLinkWifi = scripting.addModule("/ti/drivers/net/wifi/SimpleLinkWifi");
|
||||||
@ -35,24 +29,15 @@ const SlNet1 = SlNet.addInstance();
|
|||||||
/**
|
/**
|
||||||
* Write custom configuration values to the imported modules.
|
* Write custom configuration values to the imported modules.
|
||||||
*/
|
*/
|
||||||
Display1.$name = "CONFIG_Display_0";
|
|
||||||
Display1.$hardware = system.deviceData.board.components.XDS110UART;
|
|
||||||
Display1.uart.$name = "CONFIG_UART_0";
|
|
||||||
Display1.uart.useDMA = true;
|
|
||||||
Display1.uart.uart.$assign = "UART0";
|
|
||||||
Display1.uart.uart.txPin.$assign = "GP01";
|
|
||||||
Display1.uart.uart.rxPin.$assign = "GP02";
|
|
||||||
Display1.uart.uart.txDmaChannel.$assign = "UDMA_CH9";
|
|
||||||
Display1.uart.uart.rxDmaChannel.$assign = "UDMA_CH8";
|
|
||||||
|
|
||||||
Crypto1.$name = "CONFIG_Crypto_0";
|
|
||||||
|
|
||||||
GPIO1.$name = "CONFIG_LED_R";
|
GPIO1.$name = "CONFIG_LED_R";
|
||||||
GPIO1.$hardware = system.deviceData.board.components.LED_RED;
|
GPIO1.$hardware = system.deviceData.board.components.LED_RED;
|
||||||
|
|
||||||
I2C1.$hardware = system.deviceData.board.components.LP_I2C;
|
I2C1.$hardware = system.deviceData.board.components.LP_I2C;
|
||||||
I2C1.$name = "CONFIG_I2C";
|
I2C1.$name = "CONFIG_I2C";
|
||||||
|
|
||||||
|
PWM1.$name = "CONFIG_PWM_0";
|
||||||
|
PWM1.timer.pwmPin.$assign = "boosterpack.13";
|
||||||
|
|
||||||
Power.ioRetentionShutdown = ["GRP_1"];
|
Power.ioRetentionShutdown = ["GRP_1"];
|
||||||
Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0";
|
Power.parkPins.$name = "ti_drivers_power_PowerCC32XXPins0";
|
||||||
|
|
||||||
@ -67,16 +52,6 @@ SPI1.spi.ssPin.$assign = "boosterpack.18";
|
|||||||
SPI1.spi.dmaRxChannel.$assign = "UDMA_CH6";
|
SPI1.spi.dmaRxChannel.$assign = "UDMA_CH6";
|
||||||
SPI1.spi.dmaTxChannel.$assign = "UDMA_CH7";
|
SPI1.spi.dmaTxChannel.$assign = "UDMA_CH7";
|
||||||
|
|
||||||
Timer1.$name = "CONFIG_TIMER_0";
|
|
||||||
Timer1.timerType = "32 Bits";
|
|
||||||
Timer1.timer.$assign = "Timer0";
|
|
||||||
|
|
||||||
Timer2.$name = "CONFIG_TIMER_1";
|
|
||||||
Timer2.timer.$assign = "Timer1";
|
|
||||||
|
|
||||||
Timer3.$name = "CONFIG_TIMER_2";
|
|
||||||
Timer3.timer.$assign = "Timer1";
|
|
||||||
|
|
||||||
Watchdog1.$name = "CONFIG_WATCHDOG_0";
|
Watchdog1.$name = "CONFIG_WATCHDOG_0";
|
||||||
Watchdog1.watchdog.$assign = "WATCHDOG0";
|
Watchdog1.watchdog.$assign = "WATCHDOG0";
|
||||||
|
|
||||||
@ -92,3 +67,4 @@ GPIO1.gpioPin.$suggestSolution = "boosterpack.29";
|
|||||||
I2C1.i2c.$suggestSolution = "I2C0";
|
I2C1.i2c.$suggestSolution = "I2C0";
|
||||||
I2C1.i2c.sdaPin.$suggestSolution = "boosterpack.10";
|
I2C1.i2c.sdaPin.$suggestSolution = "boosterpack.10";
|
||||||
I2C1.i2c.sclPin.$suggestSolution = "boosterpack.9";
|
I2C1.i2c.sclPin.$suggestSolution = "boosterpack.9";
|
||||||
|
PWM1.timer.$suggestSolution = "Timer1";
|
||||||
|
|||||||
@ -1,35 +1,35 @@
|
|||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>c00d3363-b79d-4e9e-be8e-6206aff6b78d</ProjectGuid>
|
<ProjectGuid>c00d3363-b79d-4e9e-be8e-6206aff6b78d</ProjectGuid>
|
||||||
<ProjectHome>.</ProjectHome>
|
<ProjectHome>.</ProjectHome>
|
||||||
<StartupFile>EMS20_Groep_5_UDP_Server.py</StartupFile>
|
<StartupFile>EMS20_Groep_5_UDP_Server.py</StartupFile>
|
||||||
<SearchPath>
|
<SearchPath>
|
||||||
</SearchPath>
|
</SearchPath>
|
||||||
<WorkingDirectory>.</WorkingDirectory>
|
<WorkingDirectory>.</WorkingDirectory>
|
||||||
<OutputPath>.</OutputPath>
|
<OutputPath>.</OutputPath>
|
||||||
<Name>EMS20_Groep-5_UDP-Server</Name>
|
<Name>EMS20_Groep-5_UDP-Server</Name>
|
||||||
<RootNamespace>EMS20_Groep-5_UDP-Server</RootNamespace>
|
<RootNamespace>EMS20_Groep-5_UDP-Server</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="EMS20_Groep_5_UDP_Server.py" />
|
<Compile Include="EMS20_Groep_5_UDP_Server.py" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
|
||||||
<!-- Uncomment the CoreCompile target to enable the Build command in
|
<!-- Uncomment the CoreCompile target to enable the Build command in
|
||||||
Visual Studio and specify your pre- and post-build commands in
|
Visual Studio and specify your pre- and post-build commands in
|
||||||
the BeforeBuild and AfterBuild targets below. -->
|
the BeforeBuild and AfterBuild targets below. -->
|
||||||
<!--<Target Name="CoreCompile" />-->
|
<!--<Target Name="CoreCompile" />-->
|
||||||
<Target Name="BeforeBuild">
|
<Target Name="BeforeBuild">
|
||||||
</Target>
|
</Target>
|
||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
@ -1,16 +1,16 @@
|
|||||||
import socket
|
import socket
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
UDP_IP = '0.0.0.0' # IP van de gebruiker
|
UDP_IP = '0.0.0.0' # IP van de gebruiker
|
||||||
UDP_PORT = 0 # Port van de UDP server
|
UDP_PORT = 12345 # Port van de UDP server
|
||||||
|
|
||||||
cooleSokken = socket.socket(socket.AF_INET, # Internet
|
cooleSokken = socket.socket(socket.AF_INET, # Internet
|
||||||
socket.SOCK_DGRAM) # UDP
|
socket.SOCK_DGRAM) # UDP
|
||||||
cooleSokken.bind((UDP_IP, UDP_PORT))
|
cooleSokken.bind((UDP_IP, UDP_PORT))
|
||||||
|
|
||||||
def recvUDP():
|
def recvUDP():
|
||||||
data = cooleSokken.recv(1024)
|
data = cooleSokken.recv(1024)
|
||||||
return str(data)
|
return str(data)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print(recvUDP())
|
print(recvUDP())
|
||||||
|
|||||||
@ -1,37 +1,37 @@
|
|||||||
import socket
|
import socket
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
UDP_IP = '0.0.0.0' # IP van de gebruiker
|
UDP_IP = '0.0.0.0' # IP van de gebruiker
|
||||||
UDP_PORT = 0 # Port van de UDP server
|
UDP_PORT = 0 # Port van de UDP server
|
||||||
|
|
||||||
cooleSokken = socket.socket(socket.AF_INET, # Internet
|
cooleSokken = socket.socket(socket.AF_INET, # Internet
|
||||||
socket.SOCK_DGRAM) # UDP
|
socket.SOCK_DGRAM) # UDP
|
||||||
cooleSokken.bind((UDP_IP, UDP_PORT))
|
cooleSokken.bind((UDP_IP, UDP_PORT))
|
||||||
|
|
||||||
def recvUDP():
|
def recvUDP():
|
||||||
data = cooleSokken.recv(1024)
|
data = cooleSokken.recv(1024)
|
||||||
return str(data)
|
return str(data)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = recvUDP()
|
data = recvUDP()
|
||||||
if data == 'Handdruk aangeboden':
|
if data == 'Handdruk aangeboden':
|
||||||
wachtEventjes = 0
|
wachtEventjes = 0
|
||||||
while wachtEventjes != 10:
|
while wachtEventjes != 10:
|
||||||
wachtEventjes += 0.1
|
wachtEventjes += 0.1
|
||||||
data = recvUDP()
|
data = recvUDP()
|
||||||
if (data != 0) & (data != 'Handdruk aangeboden'):
|
if (data != 0) & (data != 'Handdruk aangeboden'):
|
||||||
print(data, " heeft je hand geschud :D")
|
print(data, " heeft je hand geschud :D")
|
||||||
break
|
break
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|
||||||
elif data != 0:
|
elif data != 0:
|
||||||
wachtEventjes = 0
|
wachtEventjes = 0
|
||||||
aanbieder = data
|
aanbieder = data
|
||||||
print(data + " bied je een handdruk aan")
|
print(data + " bied je een handdruk aan")
|
||||||
while wachtEventjes != 10:
|
while wachtEventjes != 10:
|
||||||
wachtEventjes += 0.1
|
wachtEventjes += 0.1
|
||||||
data = recvUDP()
|
data = recvUDP()
|
||||||
if data == 'Handdruk aangeboden':
|
if data == 'Handdruk aangeboden':
|
||||||
print("Je hebt de hand geaccepteerd van ", aanbieder, " :D")
|
print("Je hebt de hand geaccepteerd van ", aanbieder, " :D")
|
||||||
break
|
break
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|||||||
162
src/gsensor.c
162
src/gsensor.c
@ -1,81 +1,81 @@
|
|||||||
/*
|
/*
|
||||||
* Accelerometer op de launchpad gekoppeld aan de I2C
|
* Accelerometer op de launchpad gekoppeld aan de I2C
|
||||||
* Beweging 2: achter-voor op de x-as
|
* Beweging 2: achter-voor op de x-as
|
||||||
*
|
*
|
||||||
* 0971472 - Bram Bleij
|
* 0971472 - Bram Bleij
|
||||||
* 0964590 - Mats van Reenen
|
* 0964590 - Mats van Reenen
|
||||||
*
|
*
|
||||||
* Begonnen op 13/10/2020
|
* Begonnen op 13/10/2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// I2C drivers
|
// I2C drivers
|
||||||
#include <ti/drivers/I2C.h>
|
#include <ti/drivers/I2C.h>
|
||||||
#include <ti/drivers/i2c/I2CCC32XX.h>
|
#include <ti/drivers/i2c/I2CCC32XX.h>
|
||||||
#include <mqueue.h>
|
#include <mqueue.h>
|
||||||
|
|
||||||
extern void MQTTPublish(char * topic, char * payload);
|
extern void MQTTPublish(char * topic, char * payload);
|
||||||
|
|
||||||
#define SPEEDYBOI_ADDR 0x18
|
#define SPEEDYBOI_ADDR 0x18
|
||||||
#define ACCD_X_MSB 0x03
|
#define ACCD_X_MSB 0x03
|
||||||
|
|
||||||
char mqtt_topic[] = "top_pik";
|
char mqtt_topic[] = "top_pik";
|
||||||
|
|
||||||
extern mqd_t gsensorQueue;
|
extern mqd_t gsensorQueue;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
enum {Vooruit, Achteruit} richting;
|
enum {Vooruit, Achteruit} richting;
|
||||||
double timestamp;
|
double timestamp;
|
||||||
int8_t g;
|
int8_t g;
|
||||||
} gsensorMsgQueue;
|
} gsensorMsgQueue;
|
||||||
//typedef struct {
|
//typedef struct {
|
||||||
// enum {Vooruit, Achteruit} richting;
|
// enum {Vooruit, Achteruit} richting;
|
||||||
// double timestamp;
|
// double timestamp;
|
||||||
// int8_t g;
|
// int8_t g;
|
||||||
//} pakketje;
|
//} pakketje;
|
||||||
|
|
||||||
void * GSensorTask(void *args) {
|
void * GSensorTask(void *args) {
|
||||||
|
|
||||||
I2C_Handle speedyBoy;
|
I2C_Handle speedyBoy;
|
||||||
|
|
||||||
speedyBoy = I2C_open(0, NULL);
|
speedyBoy = I2C_open(0, NULL);
|
||||||
|
|
||||||
// buffer create
|
// buffer create
|
||||||
int8_t buffer_rcv;
|
int8_t buffer_rcv;
|
||||||
uint8_t buffer_send = ACCD_X_MSB;
|
uint8_t buffer_send = ACCD_X_MSB;
|
||||||
|
|
||||||
double timer = 0;
|
double timer = 0;
|
||||||
uint32_t sleeper;
|
uint32_t sleeper;
|
||||||
|
|
||||||
I2C_Transaction RW_Trans;
|
I2C_Transaction RW_Trans;
|
||||||
RW_Trans.slaveAddress = SPEEDYBOI_ADDR;
|
RW_Trans.slaveAddress = SPEEDYBOI_ADDR;
|
||||||
RW_Trans.writeBuf = &buffer_send;
|
RW_Trans.writeBuf = &buffer_send;
|
||||||
RW_Trans.writeCount = 1;
|
RW_Trans.writeCount = 1;
|
||||||
RW_Trans.readBuf = &buffer_rcv;
|
RW_Trans.readBuf = &buffer_rcv;
|
||||||
RW_Trans.readCount = 1;
|
RW_Trans.readCount = 1;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
bool success = I2C_transfer(speedyBoy, &RW_Trans);
|
bool success = I2C_transfer(speedyBoy, &RW_Trans);
|
||||||
if (success == false) {
|
if (success == false) {
|
||||||
while(1); // als een connectie niet kan worden gemaakt, blijf hier
|
while(1); // als een connectie niet kan worden gemaakt, blijf hier
|
||||||
}
|
}
|
||||||
// publish read into mailbox (defined in mqtt.c)
|
// publish read into mailbox (defined in mqtt.c)
|
||||||
timer += 0.1;
|
timer += 0.1;
|
||||||
|
|
||||||
gsensorMsgQueue pakket;
|
gsensorMsgQueue pakket;
|
||||||
pakket.richting = (buffer_rcv < 0) ? Achteruit : Vooruit;
|
pakket.richting = (buffer_rcv < 0) ? Achteruit : Vooruit;
|
||||||
pakket.timestamp = timer;
|
pakket.timestamp = timer;
|
||||||
pakket.g = abs(buffer_rcv);
|
pakket.g = abs(buffer_rcv);
|
||||||
|
|
||||||
mq_send(gsensorQueue, (const char*)&pakket, sizeof(gsensorMsgQueue), 0);
|
mq_send(gsensorQueue, (const char*)&pakket, sizeof(gsensorMsgQueue), 0);
|
||||||
|
|
||||||
// char payload[150];
|
// char payload[150];
|
||||||
//
|
//
|
||||||
// sprintf(&payload, "handshake (richting: %s; timestamp: %.1f; g: %d)", (buffer_rcv < 0) ? "Achteruit" : "Vooruit", timer, abs(buffer_rcv));
|
// sprintf(&payload, "handshake (richting: %s; timestamp: %.1f; g: %d)", (buffer_rcv < 0) ? "Achteruit" : "Vooruit", timer, abs(buffer_rcv));
|
||||||
//
|
//
|
||||||
// MQTTPublish(&mqtt_topic, &payload);
|
// MQTTPublish(&mqtt_topic, &payload);
|
||||||
// MQTTPublish(pakket);
|
// MQTTPublish(pakket);
|
||||||
|
|
||||||
usleep(100000U);
|
usleep(100000U);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
292
src/handshake.c
292
src/handshake.c
@ -1,143 +1,149 @@
|
|||||||
/*
|
/*
|
||||||
* handshake.c
|
* handshake.c
|
||||||
*
|
*
|
||||||
* Created on: 29 Oct 2020
|
* Created on: 29 Oct 2020
|
||||||
* Author: MReenen
|
* Author: MReenen
|
||||||
*/
|
*/
|
||||||
#include <mqueue.h>
|
#include <mqueue.h>
|
||||||
#include <ti/drivers/GPIO.h>
|
#include <ti/drivers/GPIO.h>
|
||||||
#include "ti_drivers_config.h"
|
#include "ti_drivers_config.h"
|
||||||
|
|
||||||
#define TIME_BETWEEN_DIRECTION_CHANGE 1.0
|
#define TIME_BETWEEN_DIRECTION_CHANGE 1.0
|
||||||
#define TIME_TO_RESPAN_ON_REQUEST 10.0
|
#define TIME_TO_RESPAN_ON_REQUEST 10.0
|
||||||
#define G_THUSHOLD 10
|
#define G_THUSHOLD 10
|
||||||
#define TIMEOUT_DURATION 11
|
#define TIMEOUT_DURATION 11
|
||||||
|
|
||||||
const char yourName[] = "Mats";
|
const char yourName[] = "Mats";
|
||||||
#define YOUR_STUDENTNUMBER "0964590"
|
#define YOUR_STUDENTNUMBER "0964590"
|
||||||
|
|
||||||
#define REPLY_TOPIC(n) "ems20/handshake/" n "/reply"
|
#define REPLY_TOPIC(n) "ems20/handshake/" n "/reply"
|
||||||
#define REQUEST_TOPIC(n) "ems20/handshake/" n "/request"
|
#define REQUEST_TOPIC(n) "ems20/handshake/" n "/request"
|
||||||
|
|
||||||
mqd_t gsensorQueue;
|
mqd_t gsensorQueue;
|
||||||
bool replyListen = false;
|
bool replyListen = false;
|
||||||
bool requestListen = true;
|
bool requestListen = true;
|
||||||
|
|
||||||
double timestamp = 0;
|
double timestamp = 0;
|
||||||
double requestTimeout = -TIME_TO_RESPAN_ON_REQUEST - 1;
|
double requestTimeout = -TIME_TO_RESPAN_ON_REQUEST - 1;
|
||||||
double lastBack = -TIME_BETWEEN_DIRECTION_CHANGE - 1;
|
double lastBack = -TIME_BETWEEN_DIRECTION_CHANGE - 1;
|
||||||
|
|
||||||
char requestFrom[6];
|
char requestFrom[7];
|
||||||
|
char requestFromName[50];
|
||||||
char requestTopic[] = "ems20/handshake/0964590/request";
|
|
||||||
|
char requestTopic[] = "ems20/handshake/0964590/request";
|
||||||
typedef struct {
|
|
||||||
enum {Vooruit, Achteruit} richting;
|
typedef struct {
|
||||||
double timestamp;
|
enum {Vooruit, Achteruit} richting;
|
||||||
int8_t g;
|
double timestamp;
|
||||||
} gsensorMsgQueue;
|
int8_t g;
|
||||||
|
} gsensorMsgQueue;
|
||||||
|
|
||||||
extern void MQTTPublish(char * topic, char * payload);
|
|
||||||
extern void MQTTSubscribe(char* topic, void *cb(char* topic, char* payload));
|
extern void MQTTPublish(char * topic, char * payload);
|
||||||
|
extern void MQTTSubscribe(char* topic, void *cb(char* topic, char* payload));
|
||||||
extern void UDPSend (char msg[128], int len);
|
|
||||||
|
extern void UDPSend (char msg[128], int len);
|
||||||
void MQTTCB_reply(char* topic, char* payload){
|
|
||||||
char msg[50];
|
void MQTTCB_reply(char* topic, char* payload){
|
||||||
|
char msg[50];
|
||||||
if(!replyListen)
|
|
||||||
return;
|
if(!replyListen)
|
||||||
|
return;
|
||||||
sprintf(&msg, "%s heeft je hand geschud.", payload);
|
|
||||||
UDPSend(msg, strlen(msg));
|
sprintf(&msg, "%s heeft je hand geschud.", payload);
|
||||||
}
|
UDPSend(msg, strlen(msg));
|
||||||
|
}
|
||||||
void MQTTCB_request(char* topic, char* payload){
|
|
||||||
char msg[50];
|
void MQTTCB_request(char* topic, char* payload){
|
||||||
uint8_t i;
|
char msg[128];
|
||||||
|
uint8_t i;
|
||||||
if(!requestListen)
|
|
||||||
return;
|
if(!requestListen)
|
||||||
|
return;
|
||||||
// get student number from topic
|
|
||||||
if(strlen(topic) < 16+6){
|
// get student number from topic
|
||||||
return; //ERROR invalid topic
|
if(strlen(topic) < 16+7){
|
||||||
}
|
return; //ERROR invalid topic
|
||||||
for(i=0; i<6; i++){
|
}
|
||||||
requestFrom[i] = topic[i+16];
|
for(i=0; i<7; i++){
|
||||||
}
|
requestFrom[i] = topic[i+16];
|
||||||
|
}
|
||||||
requestTimeout = timestamp + TIME_TO_RESPAN_ON_REQUEST;
|
for(i=0; i<strlen(payload); i++){
|
||||||
sprintf(&msg, "%s bied je een handdruk aan.", payload);
|
requestFromName[i] = payload[i];
|
||||||
UDPSend(msg, strlen(msg));
|
}
|
||||||
}
|
|
||||||
|
requestTimeout = timestamp + TIME_TO_RESPAN_ON_REQUEST;
|
||||||
void handshake(){
|
sprintf(&msg, "%s bied je een handdruk aan.", payload);
|
||||||
if(requestTimeout > timestamp){
|
UDPSend(msg, strlen(msg));
|
||||||
// replyed to request
|
}
|
||||||
requestTimeout = 0;
|
|
||||||
|
void handshake(){
|
||||||
replyListen = false;
|
if(requestTimeout > timestamp){
|
||||||
requestListen = true; //?? direct luisteren naar requests na
|
// reply to request
|
||||||
|
requestTimeout = 0;
|
||||||
char topic[128];
|
|
||||||
sprintf(&topic, "ems20/handshake/$s/reply", requestFrom);
|
replyListen = false;
|
||||||
MQTTPublish(&topic[0], &yourName[0]);
|
requestListen = true;
|
||||||
}else{ // send request
|
|
||||||
replyListen = true;
|
char topic[128];
|
||||||
requestListen = false;
|
sprintf(&topic, "ems20/handshake/%s/reply", requestFrom);
|
||||||
GPIO_write(CONFIG_LED_R, 1);
|
MQTTPublish(&topic[0], &yourName[0]);
|
||||||
MQTTPublish(&requestTopic[0], &yourName[0]);
|
char msg[128];
|
||||||
}
|
sprintf(&msg, "Je hebt de hand geschud van %s.", requestFromName);
|
||||||
UDPSend("Handshake aangeboden", strlen("Handshake aangeboden"));
|
UDPSend(msg, strlen(msg));
|
||||||
}
|
}else{ // send request
|
||||||
|
// replyListen = true;
|
||||||
void * handshakeTask(void *arg0){
|
// requestListen = false;
|
||||||
// create massage queue
|
GPIO_write(CONFIG_LED_R, 1);
|
||||||
mq_attr attr;
|
MQTTPublish(&requestTopic[0], &yourName[0]);
|
||||||
attr.mq_maxmsg = 10;
|
UDPSend("Handshake aangeboden", strlen("Handshake aangeboden"));
|
||||||
attr.mq_msgsize = sizeof(gsensorMsgQueue);
|
}
|
||||||
gsensorQueue = mq_open("gsensorQueue", O_CREAT, 0, &attr);
|
}
|
||||||
if(((int)gsensorQueue) <= 0){
|
|
||||||
while(1);
|
void * handshakeTask(void *arg0){
|
||||||
}
|
// create massage queue
|
||||||
|
mq_attr attr;
|
||||||
GPIO_write(CONFIG_LED_R, 0);
|
attr.mq_maxmsg = 10;
|
||||||
|
attr.mq_msgsize = sizeof(gsensorMsgQueue);
|
||||||
gsensorMsgQueue queueElement;
|
gsensorQueue = mq_open("gsensorQueue", O_CREAT, 0, &attr);
|
||||||
double replyTimeout = -1;
|
if(((int)gsensorQueue) <= 0){
|
||||||
|
while(1);
|
||||||
while(1){
|
}
|
||||||
mq_receive(gsensorQueue, (char*)&queueElement, sizeof(gsensorMsgQueue), NULL);
|
|
||||||
|
GPIO_write(CONFIG_LED_R, 0);
|
||||||
timestamp = queueElement.timestamp;
|
|
||||||
|
gsensorMsgQueue queueElement;
|
||||||
if(replyTimeout >= timestamp){
|
double replyTimeout = -1;
|
||||||
if(replyTimeout <= timestamp + 1){
|
|
||||||
replyListen = false;
|
while(1){
|
||||||
GPIO_write(CONFIG_LED_R, 0);
|
mq_receive(gsensorQueue, (char*)&queueElement, sizeof(gsensorMsgQueue), NULL);
|
||||||
}
|
|
||||||
requestListen = true;
|
timestamp = queueElement.timestamp;
|
||||||
continue;
|
|
||||||
}
|
if(replyTimeout >= timestamp){
|
||||||
|
if(replyTimeout <= timestamp + 1){
|
||||||
if(requestTimeout > timestamp){
|
replyListen = false;
|
||||||
uint32_t a = timestamp*2;
|
GPIO_write(CONFIG_LED_R, 0);
|
||||||
GPIO_write(CONFIG_LED_R, a & 0x01);
|
}
|
||||||
}else{
|
requestListen = true;
|
||||||
GPIO_write(CONFIG_LED_R, 0);
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(queueElement.g > G_THUSHOLD){
|
if(requestTimeout > timestamp){
|
||||||
if(queueElement.richting == Vooruit && timestamp - lastBack < TIME_BETWEEN_DIRECTION_CHANGE){
|
GPIO_write(CONFIG_LED_R, 0x01 & (uint32_t)(timestamp*2));
|
||||||
replyTimeout = timestamp + TIMEOUT_DURATION;
|
}else{
|
||||||
handshake();
|
GPIO_write(CONFIG_LED_R, 0);
|
||||||
} else if(queueElement.richting == Achteruit){
|
}
|
||||||
lastBack = timestamp;
|
|
||||||
}
|
if(queueElement.g > G_THUSHOLD){
|
||||||
}
|
if(queueElement.richting == Vooruit && timestamp - lastBack < TIME_BETWEEN_DIRECTION_CHANGE){
|
||||||
}
|
replyTimeout = timestamp + TIMEOUT_DURATION;
|
||||||
}
|
handshake();
|
||||||
|
} else if(queueElement.richting == Achteruit){
|
||||||
|
lastBack = timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,142 +1,142 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Texas Instruments Incorporated
|
* Copyright (c) 2016, Texas Instruments Incorporated
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* * Neither the name of Texas Instruments Incorporated nor the names of
|
* * Neither the name of Texas Instruments Incorporated nor the names of
|
||||||
* its contributors may be used to endorse or promote products derived
|
* its contributors may be used to endorse or promote products derived
|
||||||
* from this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ======== main_tirtos.c ========
|
* ======== main_tirtos.c ========
|
||||||
*/
|
*/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* POSIX Header files */
|
/* POSIX Header files */
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
/* RTOS header files */
|
/* RTOS header files */
|
||||||
#include <ti/sysbios/BIOS.h>
|
#include <ti/sysbios/BIOS.h>
|
||||||
|
|
||||||
/* TI-RTOS Header files */
|
/* TI-RTOS Header files */
|
||||||
#include <ti/drivers/GPIO.h>
|
#include <ti/drivers/GPIO.h>
|
||||||
|
|
||||||
/* TI-DRIVERS Header files */
|
/* TI-DRIVERS Header files */
|
||||||
|
|
||||||
#include "ti_drivers_config.h"
|
#include "ti_drivers_config.h"
|
||||||
|
|
||||||
extern void * GSensorTask(void *arg0);
|
extern void * GSensorTask(void *arg0);
|
||||||
extern void * MQTTTask(void *arg0);
|
extern void * MQTTTask(void *arg0);
|
||||||
extern void * handshakeTask(void *arg0);
|
extern void * handshakeTask(void *arg0);
|
||||||
extern void * UDPClientTask(void *arg0);
|
extern void * UDPClientTask(void *arg0);
|
||||||
|
|
||||||
/* Stack size in bytes */
|
/* Stack size in bytes */
|
||||||
#define BIGOLTHREADSTACK 4096
|
#define BIGOLTHREADSTACK 4096
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ======== main ========
|
* ======== main ========
|
||||||
*/
|
*/
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
pthread_attr_t attrs;
|
pthread_attr_t attrs;
|
||||||
struct sched_param priParam;
|
struct sched_param priParam;
|
||||||
int retc;
|
int retc;
|
||||||
|
|
||||||
/* Call board init functions */
|
/* Call board init functions */
|
||||||
Board_init();
|
Board_init();
|
||||||
I2C_init();
|
I2C_init();
|
||||||
GPIO_init();
|
GPIO_init();
|
||||||
|
|
||||||
/* Initialize the attributes structure with default values */
|
/* Initialize the attributes structure with default values */
|
||||||
pthread_attr_init(&attrs);
|
pthread_attr_init(&attrs);
|
||||||
|
|
||||||
/* Set priority, detach state, and stack size attributes */
|
/* Set priority, detach state, and stack size attributes */
|
||||||
priParam.sched_priority = 1;
|
priParam.sched_priority = 1;
|
||||||
retc = pthread_attr_setschedparam(&attrs, &priParam);
|
retc = pthread_attr_setschedparam(&attrs, &priParam);
|
||||||
retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
|
retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
|
||||||
retc |= pthread_attr_setstacksize(&attrs, BIGOLTHREADSTACK);
|
retc |= pthread_attr_setstacksize(&attrs, BIGOLTHREADSTACK);
|
||||||
if (retc != 0) {
|
if (retc != 0) {
|
||||||
// LOG_CRITICAL("main(): failed to set tread attributes");
|
// LOG_CRITICAL("main(): failed to set tread attributes");
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===============================================
|
/* ===============================================
|
||||||
=== thread for G sensor =======================
|
=== thread for G sensor =======================
|
||||||
===============================================
|
===============================================
|
||||||
*/
|
*/
|
||||||
pthread_t GSensorThread;
|
pthread_t GSensorThread;
|
||||||
retc = pthread_create(&GSensorThread, &attrs, GSensorTask, NULL);
|
retc = pthread_create(&GSensorThread, &attrs, GSensorTask, NULL);
|
||||||
if (retc != 0) {
|
if (retc != 0) {
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===============================================
|
/* ===============================================
|
||||||
=== thread for MQTT ===========================
|
=== thread for MQTT ===========================
|
||||||
===============================================
|
===============================================
|
||||||
*/
|
*/
|
||||||
pthread_t MQTTThread;
|
pthread_t MQTTThread;
|
||||||
retc = pthread_create(&MQTTThread, &attrs, MQTTTask, NULL);
|
retc = pthread_create(&MQTTThread, &attrs, MQTTTask, NULL);
|
||||||
if (retc != 0) {
|
if (retc != 0) {
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===============================================
|
/* ===============================================
|
||||||
=== thread for Handshake ======================
|
=== thread for Handshake ======================
|
||||||
===============================================
|
===============================================
|
||||||
*/
|
*/
|
||||||
pthread_t HandshakeThread;
|
pthread_t HandshakeThread;
|
||||||
retc = pthread_create(&HandshakeThread, &attrs, handshakeTask, NULL);
|
retc = pthread_create(&HandshakeThread, &attrs, handshakeTask, NULL);
|
||||||
if (retc != 0) {
|
if (retc != 0) {
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===============================================
|
/* ===============================================
|
||||||
* == thread for UDP =============================
|
* == thread for UDP =============================
|
||||||
* ===============================================
|
* ===============================================
|
||||||
*/
|
*/
|
||||||
pthread_t UDPClientThread;
|
pthread_t UDPClientThread;
|
||||||
retc = pthread_create(&UDPClientThread, &attrs, UDPClientTask, NULL);
|
retc = pthread_create(&UDPClientThread, &attrs, UDPClientTask, NULL);
|
||||||
if (retc != 0) {
|
if (retc != 0) {
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BIOS_start();
|
BIOS_start();
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ======== dummyOutput ========
|
* ======== dummyOutput ========
|
||||||
* Dummy SysMin output function needed for benchmarks and size comparison
|
* Dummy SysMin output function needed for benchmarks and size comparison
|
||||||
* of FreeRTOS and TI-RTOS solutions.
|
* of FreeRTOS and TI-RTOS solutions.
|
||||||
*/
|
*/
|
||||||
void dummyOutput(void)
|
void dummyOutput(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
150
src/udp_client.c
150
src/udp_client.c
@ -1,75 +1,75 @@
|
|||||||
/*
|
/*
|
||||||
* udp_client.c
|
* udp_client.c
|
||||||
*
|
*
|
||||||
* Created on: 6 Nov 2020
|
* Created on: 6 Nov 2020
|
||||||
* Author: BramB
|
* Author: BramB
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ti/display/Display.h>
|
#include <ti/display/Display.h>
|
||||||
#include <ti/drivers/net/wifi/slnetifwifi.h>
|
#include <ti/drivers/net/wifi/slnetifwifi.h>
|
||||||
#include <mqueue.h>
|
#include <mqueue.h>
|
||||||
|
|
||||||
Display_Handle lookielookie;
|
Display_Handle lookielookie;
|
||||||
mqd_t UDPQueue;
|
mqd_t UDPQueue;
|
||||||
|
|
||||||
#define UDP_PORT sl_Htons(12345) // Port gedefineerd in de UDP server
|
#define UDP_PORT sl_Htons(12345) // Port gedefineerd in de UDP server
|
||||||
#define UDP_IP sl_Htonl(SL_IPV4_VAL(10, 2, 0, 2)) // IP gedefineerd in de UDP server
|
#define UDP_IP sl_Htonl(SL_IPV4_VAL(10, 2, 0, 2)) // IP gedefineerd in de UDP server
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
_u8 buffboi[128];
|
_u8 buffboi[128];
|
||||||
_u8 len;
|
_u8 len;
|
||||||
} UDPMsgQueue;
|
} UDPMsgQueue;
|
||||||
|
|
||||||
void UDPSend (char msg[128], int len) {
|
void UDPSend (char msg[128], int len) {
|
||||||
UDPMsgQueue Msg;
|
UDPMsgQueue Msg;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for(i=0; i<128; i++){
|
for(i=0; i<128; i++){
|
||||||
Msg.buffboi[i] = msg[i];
|
Msg.buffboi[i] = msg[i];
|
||||||
}
|
}
|
||||||
Msg.len = len;
|
Msg.len = len;
|
||||||
mq_send(UDPQueue, (const char*)&Msg.buffboi, sizeof(UDPMsgQueue), 0);
|
mq_send(UDPQueue, (const char*)&Msg.buffboi, sizeof(UDPMsgQueue), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* UDPClientTask(void *args) {
|
void* UDPClientTask(void *args) {
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
|
||||||
_i16 sokken = sl_Socket(SL_AF_INET, SL_SOCK_DGRAM, SL_IPPROTO_UDP);
|
_i16 sokken = sl_Socket(SL_AF_INET, SL_SOCK_DGRAM, SL_IPPROTO_UDP);
|
||||||
if (sokken < 0) {
|
if (sokken < 0) {
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SlSockAddrIn_t clientAddress = {SL_AF_INET, UDP_PORT, sl_Htonl(SL_INADDR_ANY)};
|
SlSockAddrIn_t clientAddress = {SL_AF_INET, UDP_PORT, sl_Htonl(SL_INADDR_ANY)};
|
||||||
SlSockAddrIn_t serverAddress = {SL_AF_INET, UDP_PORT, UDP_IP};
|
SlSockAddrIn_t serverAddress = {SL_AF_INET, UDP_PORT, UDP_IP};
|
||||||
|
|
||||||
_i16 error = sl_Connect(sokken, (SlSockAddr_t *)&serverAddress, sizeof(serverAddress));
|
_i16 error = sl_Connect(sokken, (SlSockAddr_t *)&serverAddress, sizeof(serverAddress));
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
_u8 buffering[100];
|
_u8 buffering[100];
|
||||||
|
|
||||||
// _i16 sokkenAan = sl_Recv(sokken, &buffering, 100, 0);
|
// _i16 sokkenAan = sl_Recv(sokken, &buffering, 100, 0);
|
||||||
// if (error < 0) {
|
// if (error < 0) {
|
||||||
// while(1);
|
// while(1);
|
||||||
// }
|
// }
|
||||||
Display_printf(lookielookie, 0, 0, "Ontvangen van server: %s", buffering);
|
Display_printf(lookielookie, 0, 0, "Ontvangen van server: %s", buffering);
|
||||||
|
|
||||||
mq_attr attr;
|
mq_attr attr;
|
||||||
attr.mq_maxmsg = 10;
|
attr.mq_maxmsg = 10;
|
||||||
attr.mq_msgsize = sizeof(UDPMsgQueue);
|
attr.mq_msgsize = sizeof(UDPMsgQueue);
|
||||||
UDPQueue = mq_open("UDPQueue", O_CREAT, 0, &attr);
|
UDPQueue = mq_open("UDPQueue", O_CREAT, 0, &attr);
|
||||||
if(((int)UDPQueue) <= 0){
|
if(((int)UDPQueue) <= 0){
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
UDPMsgQueue queueElement;
|
UDPMsgQueue queueElement;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
mq_receive(UDPQueue, (char*)&queueElement, sizeof(UDPMsgQueue), NULL);
|
mq_receive(UDPQueue, (char*)&queueElement, sizeof(UDPMsgQueue), NULL);
|
||||||
|
|
||||||
error = sl_Send(sokken, &queueElement.buffboi, queueElement.len, NULL);
|
error = sl_Send(sokken, &queueElement.buffboi, queueElement.len, NULL);
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* wifiConf.h
|
* wifiConf.h
|
||||||
*
|
*
|
||||||
* Created on: 28 Oct 2020
|
* Created on: 28 Oct 2020
|
||||||
* Author: MReenen
|
* Author: MReenen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRC_WIFICONF_H_
|
#ifndef SRC_WIFICONF_H_
|
||||||
#define SRC_WIFICONF_H_
|
#define SRC_WIFICONF_H_
|
||||||
|
|
||||||
/* AP SSID */
|
/* AP SSID */
|
||||||
#define SSID_NAME "<ssid>"
|
#define SSID_NAME "<ssid>"
|
||||||
/* Security type (OPEN or WEP or WPA) */
|
/* Security type (OPEN or WEP or WPA) */
|
||||||
#define SECURITY_TYPE SL_WLAN_SEC_TYPE_WPA_WPA2
|
#define SECURITY_TYPE SL_WLAN_SEC_TYPE_WPA_WPA2
|
||||||
//#define SECURITY_TYPE SL_WLAN_SEC_TYPE_OPEN
|
//#define SECURITY_TYPE SL_WLAN_SEC_TYPE_OPEN
|
||||||
/* Password of the secured AP */
|
/* Password of the secured AP */
|
||||||
#define SECURITY_KEY "<password"
|
#define SECURITY_KEY "<password"
|
||||||
|
|
||||||
#endif /* SRC_WIFICONF_H_ */
|
#endif /* SRC_WIFICONF_H_ */
|
||||||
Loading…
x
Reference in New Issue
Block a user