found this code is some old backup

This commit is contained in:
Laila van Reenen 2024-06-15 22:31:38 +02:00
parent 820f6e5106
commit 9b0f715a87
Signed by: LailaTheElf
GPG Key ID: 1F4E6EE3E6DDF769
11 changed files with 1163 additions and 1248 deletions

134
.gitignore vendored
View File

@ -1,67 +1,67 @@
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
# config files
/src/wifiConf.h
# ccs artifact files
/.settings
/targetConfigs
/.ccs*
/.cproject
/.project
*.cmd
/*.c
/*.h
/.launches
/Debug
# Node artifact files
node_modules/
dist/
# VS Code artifact files
*.code-workspace
# Compiled Java class files
*.class
# Compiled Python bytecode
*.py[cod]
# Log files
*.log
# Package files
*.jar
# Maven
target/
dist/
# JetBrains IDE
.idea/
# Unit test reports
TEST*.xml
# Generated by MacOS
.DS_Store
# Generated by Windows
Thumbs.db
# Applications
*.app
*.exe
*.war
# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
# config files
/src/wifiConf.h
# ccs artifact files
/.settings
/targetConfigs
/.ccs*
/.cproject
/.project
*.cmd
/*.c
/*.h
/.launches
/Debug
# Node artifact files
node_modules/
dist/
# VS Code artifact files
*.code-workspace
# Compiled Java class files
*.class
# Compiled Python bytecode
*.py[cod]
# Log files
*.log
# Package files
*.jar
# Maven
target/
dist/
# JetBrains IDE
.idea/
# Unit test reports
TEST*.xml
# Generated by MacOS
.DS_Store
# Generated by Windows
Thumbs.db
# Applications
*.app
*.exe
*.war
# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv

View File

@ -9,23 +9,17 @@
* Import the modules used in this configuration.
*/
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 Crypto = scripting.addModule("/ti/drivers/Crypto");
const Crypto1 = Crypto.addInstance();
const DMA = scripting.addModule("/ti/drivers/DMA");
const GPIO = scripting.addModule("/ti/drivers/GPIO", {}, false);
const GPIO1 = GPIO.addInstance();
const I2C = scripting.addModule("/ti/drivers/I2C", {}, false);
const I2C1 = I2C.addInstance();
const PWM = scripting.addModule("/ti/drivers/PWM", {}, false);
const PWM1 = PWM.addInstance();
const Power = scripting.addModule("/ti/drivers/Power");
const SPI = scripting.addModule("/ti/drivers/SPI");
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 Watchdog1 = Watchdog.addInstance();
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.
*/
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.$hardware = system.deviceData.board.components.LED_RED;
I2C1.$hardware = system.deviceData.board.components.LP_I2C;
I2C1.$name = "CONFIG_I2C";
PWM1.$name = "CONFIG_PWM_0";
PWM1.timer.pwmPin.$assign = "boosterpack.13";
Power.ioRetentionShutdown = ["GRP_1"];
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.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.watchdog.$assign = "WATCHDOG0";
@ -92,3 +67,4 @@ GPIO1.gpioPin.$suggestSolution = "boosterpack.29";
I2C1.i2c.$suggestSolution = "I2C0";
I2C1.i2c.sdaPin.$suggestSolution = "boosterpack.10";
I2C1.i2c.sclPin.$suggestSolution = "boosterpack.9";
PWM1.timer.$suggestSolution = "Timer1";

View File

@ -1,35 +1,35 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>c00d3363-b79d-4e9e-be8e-6206aff6b78d</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>EMS20_Groep_5_UDP_Server.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<Name>EMS20_Groep-5_UDP-Server</Name>
<RootNamespace>EMS20_Groep-5_UDP-Server</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="EMS20_Groep_5_UDP_Server.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in
the BeforeBuild and AfterBuild targets below. -->
<!--<Target Name="CoreCompile" />-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>c00d3363-b79d-4e9e-be8e-6206aff6b78d</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>EMS20_Groep_5_UDP_Server.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<Name>EMS20_Groep-5_UDP-Server</Name>
<RootNamespace>EMS20_Groep-5_UDP-Server</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="EMS20_Groep_5_UDP_Server.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in
the BeforeBuild and AfterBuild targets below. -->
<!--<Target Name="CoreCompile" />-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
</Project>

View File

@ -1,16 +1,16 @@
import socket
from time import sleep
UDP_IP = '0.0.0.0' # IP van de gebruiker
UDP_PORT = 0 # Port van de UDP server
cooleSokken = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
cooleSokken.bind((UDP_IP, UDP_PORT))
def recvUDP():
data = cooleSokken.recv(1024)
return str(data)
while True:
print(recvUDP())
import socket
from time import sleep
UDP_IP = '0.0.0.0' # IP van de gebruiker
UDP_PORT = 12345 # Port van de UDP server
cooleSokken = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
cooleSokken.bind((UDP_IP, UDP_PORT))
def recvUDP():
data = cooleSokken.recv(1024)
return str(data)
while True:
print(recvUDP())

View File

@ -1,37 +1,37 @@
import socket
from time import sleep
UDP_IP = '0.0.0.0' # IP van de gebruiker
UDP_PORT = 0 # Port van de UDP server
cooleSokken = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
cooleSokken.bind((UDP_IP, UDP_PORT))
def recvUDP():
data = cooleSokken.recv(1024)
return str(data)
while True:
data = recvUDP()
if data == 'Handdruk aangeboden':
wachtEventjes = 0
while wachtEventjes != 10:
wachtEventjes += 0.1
data = recvUDP()
if (data != 0) & (data != 'Handdruk aangeboden'):
print(data, " heeft je hand geschud :D")
break
sleep(0.1)
elif data != 0:
wachtEventjes = 0
aanbieder = data
print(data + " bied je een handdruk aan")
while wachtEventjes != 10:
wachtEventjes += 0.1
data = recvUDP()
if data == 'Handdruk aangeboden':
print("Je hebt de hand geaccepteerd van ", aanbieder, " :D")
break
sleep(0.1)
import socket
from time import sleep
UDP_IP = '0.0.0.0' # IP van de gebruiker
UDP_PORT = 0 # Port van de UDP server
cooleSokken = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
cooleSokken.bind((UDP_IP, UDP_PORT))
def recvUDP():
data = cooleSokken.recv(1024)
return str(data)
while True:
data = recvUDP()
if data == 'Handdruk aangeboden':
wachtEventjes = 0
while wachtEventjes != 10:
wachtEventjes += 0.1
data = recvUDP()
if (data != 0) & (data != 'Handdruk aangeboden'):
print(data, " heeft je hand geschud :D")
break
sleep(0.1)
elif data != 0:
wachtEventjes = 0
aanbieder = data
print(data + " bied je een handdruk aan")
while wachtEventjes != 10:
wachtEventjes += 0.1
data = recvUDP()
if data == 'Handdruk aangeboden':
print("Je hebt de hand geaccepteerd van ", aanbieder, " :D")
break
sleep(0.1)

View File

@ -1,81 +1,81 @@
/*
* Accelerometer op de launchpad gekoppeld aan de I2C
* Beweging 2: achter-voor op de x-as
*
* 0971472 - Bram Bleij
* 0964590 - Mats van Reenen
*
* Begonnen op 13/10/2020
*/
// I2C drivers
#include <ti/drivers/I2C.h>
#include <ti/drivers/i2c/I2CCC32XX.h>
#include <mqueue.h>
extern void MQTTPublish(char * topic, char * payload);
#define SPEEDYBOI_ADDR 0x18
#define ACCD_X_MSB 0x03
char mqtt_topic[] = "top_pik";
extern mqd_t gsensorQueue;
typedef struct {
enum {Vooruit, Achteruit} richting;
double timestamp;
int8_t g;
} gsensorMsgQueue;
//typedef struct {
// enum {Vooruit, Achteruit} richting;
// double timestamp;
// int8_t g;
//} pakketje;
void * GSensorTask(void *args) {
I2C_Handle speedyBoy;
speedyBoy = I2C_open(0, NULL);
// buffer create
int8_t buffer_rcv;
uint8_t buffer_send = ACCD_X_MSB;
double timer = 0;
uint32_t sleeper;
I2C_Transaction RW_Trans;
RW_Trans.slaveAddress = SPEEDYBOI_ADDR;
RW_Trans.writeBuf = &buffer_send;
RW_Trans.writeCount = 1;
RW_Trans.readBuf = &buffer_rcv;
RW_Trans.readCount = 1;
while(1) {
bool success = I2C_transfer(speedyBoy, &RW_Trans);
if (success == false) {
while(1); // als een connectie niet kan worden gemaakt, blijf hier
}
// publish read into mailbox (defined in mqtt.c)
timer += 0.1;
gsensorMsgQueue pakket;
pakket.richting = (buffer_rcv < 0) ? Achteruit : Vooruit;
pakket.timestamp = timer;
pakket.g = abs(buffer_rcv);
mq_send(gsensorQueue, (const char*)&pakket, sizeof(gsensorMsgQueue), 0);
// char payload[150];
//
// sprintf(&payload, "handshake (richting: %s; timestamp: %.1f; g: %d)", (buffer_rcv < 0) ? "Achteruit" : "Vooruit", timer, abs(buffer_rcv));
//
// MQTTPublish(&mqtt_topic, &payload);
// MQTTPublish(pakket);
usleep(100000U);
}
return 0;
}
/*
* Accelerometer op de launchpad gekoppeld aan de I2C
* Beweging 2: achter-voor op de x-as
*
* 0971472 - Bram Bleij
* 0964590 - Mats van Reenen
*
* Begonnen op 13/10/2020
*/
// I2C drivers
#include <ti/drivers/I2C.h>
#include <ti/drivers/i2c/I2CCC32XX.h>
#include <mqueue.h>
extern void MQTTPublish(char * topic, char * payload);
#define SPEEDYBOI_ADDR 0x18
#define ACCD_X_MSB 0x03
char mqtt_topic[] = "top_pik";
extern mqd_t gsensorQueue;
typedef struct {
enum {Vooruit, Achteruit} richting;
double timestamp;
int8_t g;
} gsensorMsgQueue;
//typedef struct {
// enum {Vooruit, Achteruit} richting;
// double timestamp;
// int8_t g;
//} pakketje;
void * GSensorTask(void *args) {
I2C_Handle speedyBoy;
speedyBoy = I2C_open(0, NULL);
// buffer create
int8_t buffer_rcv;
uint8_t buffer_send = ACCD_X_MSB;
double timer = 0;
uint32_t sleeper;
I2C_Transaction RW_Trans;
RW_Trans.slaveAddress = SPEEDYBOI_ADDR;
RW_Trans.writeBuf = &buffer_send;
RW_Trans.writeCount = 1;
RW_Trans.readBuf = &buffer_rcv;
RW_Trans.readCount = 1;
while(1) {
bool success = I2C_transfer(speedyBoy, &RW_Trans);
if (success == false) {
while(1); // als een connectie niet kan worden gemaakt, blijf hier
}
// publish read into mailbox (defined in mqtt.c)
timer += 0.1;
gsensorMsgQueue pakket;
pakket.richting = (buffer_rcv < 0) ? Achteruit : Vooruit;
pakket.timestamp = timer;
pakket.g = abs(buffer_rcv);
mq_send(gsensorQueue, (const char*)&pakket, sizeof(gsensorMsgQueue), 0);
// char payload[150];
//
// sprintf(&payload, "handshake (richting: %s; timestamp: %.1f; g: %d)", (buffer_rcv < 0) ? "Achteruit" : "Vooruit", timer, abs(buffer_rcv));
//
// MQTTPublish(&mqtt_topic, &payload);
// MQTTPublish(pakket);
usleep(100000U);
}
return 0;
}

View File

@ -1,143 +1,149 @@
/*
* handshake.c
*
* Created on: 29 Oct 2020
* Author: MReenen
*/
#include <mqueue.h>
#include <ti/drivers/GPIO.h>
#include "ti_drivers_config.h"
#define TIME_BETWEEN_DIRECTION_CHANGE 1.0
#define TIME_TO_RESPAN_ON_REQUEST 10.0
#define G_THUSHOLD 10
#define TIMEOUT_DURATION 11
const char yourName[] = "Mats";
#define YOUR_STUDENTNUMBER "0964590"
#define REPLY_TOPIC(n) "ems20/handshake/" n "/reply"
#define REQUEST_TOPIC(n) "ems20/handshake/" n "/request"
mqd_t gsensorQueue;
bool replyListen = false;
bool requestListen = true;
double timestamp = 0;
double requestTimeout = -TIME_TO_RESPAN_ON_REQUEST - 1;
double lastBack = -TIME_BETWEEN_DIRECTION_CHANGE - 1;
char requestFrom[6];
char requestTopic[] = "ems20/handshake/0964590/request";
typedef struct {
enum {Vooruit, Achteruit} richting;
double timestamp;
int8_t g;
} gsensorMsgQueue;
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);
void MQTTCB_reply(char* topic, char* payload){
char msg[50];
if(!replyListen)
return;
sprintf(&msg, "%s heeft je hand geschud.", payload);
UDPSend(msg, strlen(msg));
}
void MQTTCB_request(char* topic, char* payload){
char msg[50];
uint8_t i;
if(!requestListen)
return;
// get student number from topic
if(strlen(topic) < 16+6){
return; //ERROR invalid topic
}
for(i=0; i<6; i++){
requestFrom[i] = topic[i+16];
}
requestTimeout = timestamp + TIME_TO_RESPAN_ON_REQUEST;
sprintf(&msg, "%s bied je een handdruk aan.", payload);
UDPSend(msg, strlen(msg));
}
void handshake(){
if(requestTimeout > timestamp){
// replyed to request
requestTimeout = 0;
replyListen = false;
requestListen = true; //?? direct luisteren naar requests na
char topic[128];
sprintf(&topic, "ems20/handshake/$s/reply", requestFrom);
MQTTPublish(&topic[0], &yourName[0]);
}else{ // send request
replyListen = true;
requestListen = false;
GPIO_write(CONFIG_LED_R, 1);
MQTTPublish(&requestTopic[0], &yourName[0]);
}
UDPSend("Handshake aangeboden", strlen("Handshake aangeboden"));
}
void * handshakeTask(void *arg0){
// create massage queue
mq_attr attr;
attr.mq_maxmsg = 10;
attr.mq_msgsize = sizeof(gsensorMsgQueue);
gsensorQueue = mq_open("gsensorQueue", O_CREAT, 0, &attr);
if(((int)gsensorQueue) <= 0){
while(1);
}
GPIO_write(CONFIG_LED_R, 0);
gsensorMsgQueue queueElement;
double replyTimeout = -1;
while(1){
mq_receive(gsensorQueue, (char*)&queueElement, sizeof(gsensorMsgQueue), NULL);
timestamp = queueElement.timestamp;
if(replyTimeout >= timestamp){
if(replyTimeout <= timestamp + 1){
replyListen = false;
GPIO_write(CONFIG_LED_R, 0);
}
requestListen = true;
continue;
}
if(requestTimeout > timestamp){
uint32_t a = timestamp*2;
GPIO_write(CONFIG_LED_R, a & 0x01);
}else{
GPIO_write(CONFIG_LED_R, 0);
}
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;
}
}
}
}
/*
* handshake.c
*
* Created on: 29 Oct 2020
* Author: MReenen
*/
#include <mqueue.h>
#include <ti/drivers/GPIO.h>
#include "ti_drivers_config.h"
#define TIME_BETWEEN_DIRECTION_CHANGE 1.0
#define TIME_TO_RESPAN_ON_REQUEST 10.0
#define G_THUSHOLD 10
#define TIMEOUT_DURATION 11
const char yourName[] = "Mats";
#define YOUR_STUDENTNUMBER "0964590"
#define REPLY_TOPIC(n) "ems20/handshake/" n "/reply"
#define REQUEST_TOPIC(n) "ems20/handshake/" n "/request"
mqd_t gsensorQueue;
bool replyListen = false;
bool requestListen = true;
double timestamp = 0;
double requestTimeout = -TIME_TO_RESPAN_ON_REQUEST - 1;
double lastBack = -TIME_BETWEEN_DIRECTION_CHANGE - 1;
char requestFrom[7];
char requestFromName[50];
char requestTopic[] = "ems20/handshake/0964590/request";
typedef struct {
enum {Vooruit, Achteruit} richting;
double timestamp;
int8_t g;
} gsensorMsgQueue;
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);
void MQTTCB_reply(char* topic, char* payload){
char msg[50];
if(!replyListen)
return;
sprintf(&msg, "%s heeft je hand geschud.", payload);
UDPSend(msg, strlen(msg));
}
void MQTTCB_request(char* topic, char* payload){
char msg[128];
uint8_t i;
if(!requestListen)
return;
// get student number from topic
if(strlen(topic) < 16+7){
return; //ERROR invalid topic
}
for(i=0; i<7; i++){
requestFrom[i] = topic[i+16];
}
for(i=0; i<strlen(payload); i++){
requestFromName[i] = payload[i];
}
requestTimeout = timestamp + TIME_TO_RESPAN_ON_REQUEST;
sprintf(&msg, "%s bied je een handdruk aan.", payload);
UDPSend(msg, strlen(msg));
}
void handshake(){
if(requestTimeout > timestamp){
// reply to request
requestTimeout = 0;
replyListen = false;
requestListen = true;
char topic[128];
sprintf(&topic, "ems20/handshake/%s/reply", requestFrom);
MQTTPublish(&topic[0], &yourName[0]);
char msg[128];
sprintf(&msg, "Je hebt de hand geschud van %s.", requestFromName);
UDPSend(msg, strlen(msg));
}else{ // send request
// replyListen = true;
// requestListen = false;
GPIO_write(CONFIG_LED_R, 1);
MQTTPublish(&requestTopic[0], &yourName[0]);
UDPSend("Handshake aangeboden", strlen("Handshake aangeboden"));
}
}
void * handshakeTask(void *arg0){
// create massage queue
mq_attr attr;
attr.mq_maxmsg = 10;
attr.mq_msgsize = sizeof(gsensorMsgQueue);
gsensorQueue = mq_open("gsensorQueue", O_CREAT, 0, &attr);
if(((int)gsensorQueue) <= 0){
while(1);
}
GPIO_write(CONFIG_LED_R, 0);
gsensorMsgQueue queueElement;
double replyTimeout = -1;
while(1){
mq_receive(gsensorQueue, (char*)&queueElement, sizeof(gsensorMsgQueue), NULL);
timestamp = queueElement.timestamp;
if(replyTimeout >= timestamp){
if(replyTimeout <= timestamp + 1){
replyListen = false;
GPIO_write(CONFIG_LED_R, 0);
}
requestListen = true;
continue;
}
if(requestTimeout > timestamp){
GPIO_write(CONFIG_LED_R, 0x01 & (uint32_t)(timestamp*2));
}else{
GPIO_write(CONFIG_LED_R, 0);
}
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;
}
}
}
}

View File

@ -1,142 +1,142 @@
/*
* Copyright (c) 2016, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== main_tirtos.c ========
*/
#include <stdint.h>
/* POSIX Header files */
#include <pthread.h>
/* RTOS header files */
#include <ti/sysbios/BIOS.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
/* TI-DRIVERS Header files */
#include "ti_drivers_config.h"
extern void * GSensorTask(void *arg0);
extern void * MQTTTask(void *arg0);
extern void * handshakeTask(void *arg0);
extern void * UDPClientTask(void *arg0);
/* Stack size in bytes */
#define BIGOLTHREADSTACK 4096
/*
* ======== main ========
*/
int main(void)
{
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
/* Call board init functions */
Board_init();
I2C_init();
GPIO_init();
/* Initialize the attributes structure with default values */
pthread_attr_init(&attrs);
/* Set priority, detach state, and stack size attributes */
priParam.sched_priority = 1;
retc = pthread_attr_setschedparam(&attrs, &priParam);
retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
retc |= pthread_attr_setstacksize(&attrs, BIGOLTHREADSTACK);
if (retc != 0) {
// LOG_CRITICAL("main(): failed to set tread attributes");
while(1);
}
/* ===============================================
=== thread for G sensor =======================
===============================================
*/
pthread_t GSensorThread;
retc = pthread_create(&GSensorThread, &attrs, GSensorTask, NULL);
if (retc != 0) {
while(1);
}
/* ===============================================
=== thread for MQTT ===========================
===============================================
*/
pthread_t MQTTThread;
retc = pthread_create(&MQTTThread, &attrs, MQTTTask, NULL);
if (retc != 0) {
while(1);
}
/* ===============================================
=== thread for Handshake ======================
===============================================
*/
pthread_t HandshakeThread;
retc = pthread_create(&HandshakeThread, &attrs, handshakeTask, NULL);
if (retc != 0) {
while(1);
}
/* ===============================================
* == thread for UDP =============================
* ===============================================
*/
pthread_t UDPClientThread;
retc = pthread_create(&UDPClientThread, &attrs, UDPClientTask, NULL);
if (retc != 0) {
while(1);
}
BIOS_start();
return (0);
}
/*
* ======== dummyOutput ========
* Dummy SysMin output function needed for benchmarks and size comparison
* of FreeRTOS and TI-RTOS solutions.
*/
void dummyOutput(void)
{
}
/*
* Copyright (c) 2016, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== main_tirtos.c ========
*/
#include <stdint.h>
/* POSIX Header files */
#include <pthread.h>
/* RTOS header files */
#include <ti/sysbios/BIOS.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
/* TI-DRIVERS Header files */
#include "ti_drivers_config.h"
extern void * GSensorTask(void *arg0);
extern void * MQTTTask(void *arg0);
extern void * handshakeTask(void *arg0);
extern void * UDPClientTask(void *arg0);
/* Stack size in bytes */
#define BIGOLTHREADSTACK 4096
/*
* ======== main ========
*/
int main(void)
{
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
/* Call board init functions */
Board_init();
I2C_init();
GPIO_init();
/* Initialize the attributes structure with default values */
pthread_attr_init(&attrs);
/* Set priority, detach state, and stack size attributes */
priParam.sched_priority = 1;
retc = pthread_attr_setschedparam(&attrs, &priParam);
retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
retc |= pthread_attr_setstacksize(&attrs, BIGOLTHREADSTACK);
if (retc != 0) {
// LOG_CRITICAL("main(): failed to set tread attributes");
while(1);
}
/* ===============================================
=== thread for G sensor =======================
===============================================
*/
pthread_t GSensorThread;
retc = pthread_create(&GSensorThread, &attrs, GSensorTask, NULL);
if (retc != 0) {
while(1);
}
/* ===============================================
=== thread for MQTT ===========================
===============================================
*/
pthread_t MQTTThread;
retc = pthread_create(&MQTTThread, &attrs, MQTTTask, NULL);
if (retc != 0) {
while(1);
}
/* ===============================================
=== thread for Handshake ======================
===============================================
*/
pthread_t HandshakeThread;
retc = pthread_create(&HandshakeThread, &attrs, handshakeTask, NULL);
if (retc != 0) {
while(1);
}
/* ===============================================
* == thread for UDP =============================
* ===============================================
*/
pthread_t UDPClientThread;
retc = pthread_create(&UDPClientThread, &attrs, UDPClientTask, NULL);
if (retc != 0) {
while(1);
}
BIOS_start();
return (0);
}
/*
* ======== dummyOutput ========
* Dummy SysMin output function needed for benchmarks and size comparison
* of FreeRTOS and TI-RTOS solutions.
*/
void dummyOutput(void)
{
}

File diff suppressed because it is too large Load Diff

View File

@ -1,75 +1,75 @@
/*
* udp_client.c
*
* Created on: 6 Nov 2020
* Author: BramB
*/
#include <ti/display/Display.h>
#include <ti/drivers/net/wifi/slnetifwifi.h>
#include <mqueue.h>
Display_Handle lookielookie;
mqd_t UDPQueue;
#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
typedef struct {
_u8 buffboi[128];
_u8 len;
} UDPMsgQueue;
void UDPSend (char msg[128], int len) {
UDPMsgQueue Msg;
uint8_t i;
for(i=0; i<128; i++){
Msg.buffboi[i] = msg[i];
}
Msg.len = len;
mq_send(UDPQueue, (const char*)&Msg.buffboi, sizeof(UDPMsgQueue), 0);
}
void* UDPClientTask(void *args) {
sleep(2);
_i16 sokken = sl_Socket(SL_AF_INET, SL_SOCK_DGRAM, SL_IPPROTO_UDP);
if (sokken < 0) {
while(1);
}
SlSockAddrIn_t clientAddress = {SL_AF_INET, UDP_PORT, sl_Htonl(SL_INADDR_ANY)};
SlSockAddrIn_t serverAddress = {SL_AF_INET, UDP_PORT, UDP_IP};
_i16 error = sl_Connect(sokken, (SlSockAddr_t *)&serverAddress, sizeof(serverAddress));
if (error < 0) {
while(1);
}
_u8 buffering[100];
// _i16 sokkenAan = sl_Recv(sokken, &buffering, 100, 0);
// if (error < 0) {
// while(1);
// }
Display_printf(lookielookie, 0, 0, "Ontvangen van server: %s", buffering);
mq_attr attr;
attr.mq_maxmsg = 10;
attr.mq_msgsize = sizeof(UDPMsgQueue);
UDPQueue = mq_open("UDPQueue", O_CREAT, 0, &attr);
if(((int)UDPQueue) <= 0){
while(1);
}
UDPMsgQueue queueElement;
while(1) {
mq_receive(UDPQueue, (char*)&queueElement, sizeof(UDPMsgQueue), NULL);
error = sl_Send(sokken, &queueElement.buffboi, queueElement.len, NULL);
if (error < 0) {
while(1);
}
}
}
/*
* udp_client.c
*
* Created on: 6 Nov 2020
* Author: BramB
*/
#include <ti/display/Display.h>
#include <ti/drivers/net/wifi/slnetifwifi.h>
#include <mqueue.h>
Display_Handle lookielookie;
mqd_t UDPQueue;
#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
typedef struct {
_u8 buffboi[128];
_u8 len;
} UDPMsgQueue;
void UDPSend (char msg[128], int len) {
UDPMsgQueue Msg;
uint8_t i;
for(i=0; i<128; i++){
Msg.buffboi[i] = msg[i];
}
Msg.len = len;
mq_send(UDPQueue, (const char*)&Msg.buffboi, sizeof(UDPMsgQueue), 0);
}
void* UDPClientTask(void *args) {
sleep(2);
_i16 sokken = sl_Socket(SL_AF_INET, SL_SOCK_DGRAM, SL_IPPROTO_UDP);
if (sokken < 0) {
while(1);
}
SlSockAddrIn_t clientAddress = {SL_AF_INET, UDP_PORT, sl_Htonl(SL_INADDR_ANY)};
SlSockAddrIn_t serverAddress = {SL_AF_INET, UDP_PORT, UDP_IP};
_i16 error = sl_Connect(sokken, (SlSockAddr_t *)&serverAddress, sizeof(serverAddress));
if (error < 0) {
while(1);
}
_u8 buffering[100];
// _i16 sokkenAan = sl_Recv(sokken, &buffering, 100, 0);
// if (error < 0) {
// while(1);
// }
Display_printf(lookielookie, 0, 0, "Ontvangen van server: %s", buffering);
mq_attr attr;
attr.mq_maxmsg = 10;
attr.mq_msgsize = sizeof(UDPMsgQueue);
UDPQueue = mq_open("UDPQueue", O_CREAT, 0, &attr);
if(((int)UDPQueue) <= 0){
while(1);
}
UDPMsgQueue queueElement;
while(1) {
mq_receive(UDPQueue, (char*)&queueElement, sizeof(UDPMsgQueue), NULL);
error = sl_Send(sokken, &queueElement.buffboi, queueElement.len, NULL);
if (error < 0) {
while(1);
}
}
}

View File

@ -1,19 +1,19 @@
/*
* wifiConf.h
*
* Created on: 28 Oct 2020
* Author: MReenen
*/
#ifndef SRC_WIFICONF_H_
#define SRC_WIFICONF_H_
/* AP SSID */
#define SSID_NAME "<ssid>"
/* Security type (OPEN or WEP or WPA) */
#define SECURITY_TYPE SL_WLAN_SEC_TYPE_WPA_WPA2
//#define SECURITY_TYPE SL_WLAN_SEC_TYPE_OPEN
/* Password of the secured AP */
#define SECURITY_KEY "<password"
/*
* wifiConf.h
*
* Created on: 28 Oct 2020
* Author: MReenen
*/
#ifndef SRC_WIFICONF_H_
#define SRC_WIFICONF_H_
/* AP SSID */
#define SSID_NAME "<ssid>"
/* Security type (OPEN or WEP or WPA) */
#define SECURITY_TYPE SL_WLAN_SEC_TYPE_WPA_WPA2
//#define SECURITY_TYPE SL_WLAN_SEC_TYPE_OPEN
/* Password of the secured AP */
#define SECURITY_KEY "<password"
#endif /* SRC_WIFICONF_H_ */