Compare commits

...

1 Commits

Author SHA1 Message Date
9b0f715a87
found this code is some old backup 2024-06-15 22:31:38 +02:00
11 changed files with 1163 additions and 1248 deletions

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

@ -2,7 +2,7 @@ import socket
from time import sleep
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
socket.SOCK_DGRAM) # UDP

View File

@ -27,7 +27,8 @@ double timestamp = 0;
double requestTimeout = -TIME_TO_RESPAN_ON_REQUEST - 1;
double lastBack = -TIME_BETWEEN_DIRECTION_CHANGE - 1;
char requestFrom[6];
char requestFrom[7];
char requestFromName[50];
char requestTopic[] = "ems20/handshake/0964590/request";
@ -54,19 +55,22 @@ void MQTTCB_reply(char* topic, char* payload){
}
void MQTTCB_request(char* topic, char* payload){
char msg[50];
char msg[128];
uint8_t i;
if(!requestListen)
return;
// get student number from topic
if(strlen(topic) < 16+6){
if(strlen(topic) < 16+7){
return; //ERROR invalid topic
}
for(i=0; i<6; i++){
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);
@ -75,23 +79,26 @@ void MQTTCB_request(char* topic, char* payload){
void handshake(){
if(requestTimeout > timestamp){
// replyed to request
// reply to request
requestTimeout = 0;
replyListen = false;
requestListen = true; //?? direct luisteren naar requests na
requestListen = true;
char topic[128];
sprintf(&topic, "ems20/handshake/$s/reply", requestFrom);
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;
// 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
@ -123,8 +130,7 @@ void * handshakeTask(void *arg0){
}
if(requestTimeout > timestamp){
uint32_t a = timestamp*2;
GPIO_write(CONFIG_LED_R, a & 0x01);
GPIO_write(CONFIG_LED_R, 0x01 & (uint32_t)(timestamp*2));
}else{
GPIO_write(CONFIG_LED_R, 0);
}

View File

@ -53,8 +53,6 @@
#include <ti/drivers/net/wifi/slnetifwifi.h>
#include <ti/drivers/SPI.h>
// #include <ti/drivers/GPIO.h>
// #include <ti/drivers/Timer.h>
#include <ti/net/mqtt/mqttclient.h>
@ -154,7 +152,6 @@ MQTT_IF_ClientParams_t mqttClientParams =
&mqttWillParams // will parameters
};
#ifndef MQTT_SECURE_CLIENT
MQTTClient_ConnParams mqttConnParams =
{
MQTT_CONNECTION_FLAGS, // connection flags
@ -165,66 +162,6 @@ MQTTClient_ConnParams mqttConnParams =
0, // number of files for secure connection
NULL // secure files
};
#else
/*
* In order to connect to an MQTT broker securely, the MQTTCLIENT_NETCONN_SEC flag,
* method for secure socket, cipher, secure files, number of secure files must be set
* and the certificates must be programmed to the file system.
*
* The first parameter is a bit mask which configures the server address type and security mode.
* Server address type: IPv4, IPv6 and URL must be declared with the corresponding flag.
* All flags can be found in mqttclient.h.
*
* The flag MQTTCLIENT_NETCONN_SEC enables the security (TLS) which includes domain name
* verification and certificate catalog verification. Those verifications can be skipped by
* adding to the bit mask: MQTTCLIENT_NETCONN_SKIP_DOMAIN_NAME_VERIFICATION and
* MQTTCLIENT_NETCONN_SKIP_CERTIFICATE_CATALOG_VERIFICATION.
*
* Note: The domain name verification requires URL Server address type otherwise, this
* verification will be disabled.
*
* Secure clients require time configuration in order to verify the server certificate validity (date)
*/
/* Day of month (DD format) range 1-31 */
#define DAY 1
/* Month (MM format) in the range of 1-12 */
#define MONTH 5
/* Year (YYYY format) */
#define YEAR 2020
/* Hours in the range of 0-23 */
#define HOUR 4
/* Minutes in the range of 0-59 */
#define MINUTES 00
/* Seconds in the range of 0-59 */
#define SEC 00
char *MQTTClient_secureFiles[1] = {"ca-cert.pem"};
MQTTClient_ConnParams mqttConnParams =
{
MQTT_CONNECTION_FLAGS, // connection flags
MQTT_CONNECTION_ADDRESS, // server address
MQTT_CONNECTION_PORT_NUMBER, // port number of MQTT server
SLNETSOCK_SEC_METHOD_SSLv3_TLSV1_2, // method for secure socket
SLNETSOCK_SEC_CIPHER_FULL_LIST, // cipher for secure socket
1, // number of files for secure connection
MQTTClient_secureFiles // secure files
};
void setTime(){
SlDateTime_t dateTime = {0};
dateTime.tm_day = (uint32_t)DAY;
dateTime.tm_mon = (uint32_t)MONTH;
dateTime.tm_year = (uint32_t)YEAR;
dateTime.tm_hour = (uint32_t)HOUR;
dateTime.tm_min = (uint32_t)MINUTES;
dateTime.tm_sec = (uint32_t)SEC;
sl_DeviceSet(SL_DEVICE_GENERAL, SL_DEVICE_GENERAL_DATE_TIME,
sizeof(SlDateTime_t), (uint8_t *)(&dateTime));
}
#endif
//*****************************************************************************
//!
@ -467,10 +404,6 @@ void MQTTPublish(char * topic, char * payload){
int res = mq_send(appQueue, (const char*)&queueElement, sizeof(struct msgQueue), 0);
}
// void MQTTSubscribe(char* topic, void *cb(char* topic, char* payload)){
// uint8_t ret = MQTT_IF_Subscribe(0, topic, MQTT_QOS_2, cb);
// }
void MQTTTask(void * args){
int32_t ret;