Commit 69061608 authored by Lindenberg, Arthur-Vincent's avatar Lindenberg, Arthur-Vincent
Browse files

Initial Commit:

--Clone of Git CoSA/Tools/Redpitaya/MqttClient_mosquitto.
- Repo contains the C_code to flash RedPitayas for Mqtt remote management.
parent e36a89a9
set ip="169.254.208.214"
For /f "tokens=1-3 delims=/." %%a in ('date /t') do (set mydate=%%c%%b%%a)
For /f "tokens=1-2 delims=/ " %%a in ('echo %mydate%') do (set mydate=%%a%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a:%%b)
plink.exe -ssh root@%ip% -pw root date +%%Y%%m%%d -s '%mydate%'
plink.exe -ssh root@%ip% -pw root date +%%T -s '%mytime%:00'
putty.exe -ssh root@%ip% -pw root -m compileAndRunPre.txt -t
pscp -P 22 -pw root -p -r * root@%ip%:/RedPitaya/dev/mqttclient/
putty.exe -ssh root@%ip% -pw root -m compileAndRun.txt -t
\ No newline at end of file
CFLAGS = -std=gnu99 -Wall -Werror -g
CFLAGS += -I/opt/redpitaya/include -I/RedPitaya/dev/mqttclient/includes/src
LDFLAGS = -L/opt/redpitaya/lib -L$(LIB)
LDLIBS = -lm -pthread -lrp -lrp_cosa -lini
SRC=.
INC=include
LIB=.
AR=ar
CCFLAGS=-I$(INC) -I/opt/redpitaya/include -Wall -O
GCC=gcc
SRCS=$(wildcard *.c)
OBJS=$(SRCS:.c=)
#all: acquire_trigger_posedge.o
# $(CC) $(LDFLAGS) $(LDLIBS) acquire_trigger_posedge.o -o acquire_trigger_posedge
.PHONY: all
#all: $(OBJS)
all: libemqtt.a libmqttwrapper.a libini.a librp_cosa.a
$(CC) $(CFLAGS) $(LDFLAGS) acquire_trigger_posedge.c $(LDLIBS) -o acquire_trigger_posedge
oscilloscope: libini.a librp_cosa.a
$(CC) $(CFLAGS) $(LDFLAGS) oscilloscope.c $(LDLIBS) -o oscilloscope ./lib/libmosquitto.so.1
sig-gen: libemqtt.a libmqttwrapper.a libini.a librp_cosa.a
$(CC) $(CFLAGS) $(LDFLAGS) sig-gen.c $(LDLIBS) -o sig-gen
%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
libemqtt.a: libemqtt.o
$(AR) rcs libemqtt.a libemqtt.o
libmqttwrapper.a: libmqttwrapper.o
$(AR) rcs libmqttwrapper.a libmqttwrapper.o
libini.a: libini.o
$(AR) rcs libini.a libini.o
librp_cosa.a: librp_cosa.o
$(AR) rcs librp_cosa.a librp_cosa.o
libemqtt.o: $(SRC)/libemqtt.c $(INC)/libemqtt.h
$(GCC) $(CCFLAGS) -c $(SRC)/libemqtt.c -o libemqtt.o
libmqttwrapper.o: $(SRC)/mqttwrapper.c $(INC)/mqttwrapper.h
$(GCC) $(CCFLAGS) -c $(SRC)/mqttwrapper.c -o libmqttwrapper.o
libini.o: $(SRC)/ini.c $(INC)/ini.h
$(GCC) $(CCFLAGS) -c $(SRC)/ini.c -o libini.o
librp_cosa.o: $(SRC)/librp_cosa.c $(INC)/librp_cosa.h
$(GCC) $(CCFLAGS) -c $(SRC)/librp_cosa.c -o librp_cosa.o
../mosquitto/lib/libmosquitto.so.${SOVERSION} :
$(MAKE) -C ../mosquitto/lib
clean:
$(RM) *.a
$(RM) *.o
$(RM) $(OBJS)
#cc -std=gnu99 -Wall -Werror -I/opt/redpitaya/include -L/opt/redpitaya/lib acquire_trigger_posedge.c -lm -pthread -lrp -o acquire_trigger_posedge
#cc -L/opt/redpitaya/lib -lm -pthread -lrp -c -std=gnu99 -Wall -Werror -I/opt/redpitaya/include acquire_trigger_posedge.c -o acquire_trigger_posedge
\ No newline at end of file
cd /RedPitaya/dev/mqttclient
export LD_LIBRARY_PATH=/opt/redpitaya/lib
export LDFLAGS=/opt/redpitaya/lib
make clean
# make sig-gen
make oscilloscope
cat /opt/redpitaya/fpga/fpga_0.94.bit > /dev/xdevcfg
#read -p "Press Enter to Quit" variable1
# cat /opt/redpitaya/fpga/fpga_0.94.bit > /dev/xdevcfg
# LD_LIBRARY_PATH=/opt/redpitaya/lib:/RedPitaya/dev/mqttclient/lib /RedPitaya/dev/mqttclient/oscilloscope
# read -p "Press Enter to Quit" variable1
#
# mv mqtt-sig-gen.service /etc/systemd/system/
mv mqtt-oscilloscope.service /etc/systemd/system/
cd /etc/systemd/system
systemctl daemon-reload
# systemctl enable mqtt-sig-gen
systemctl enable mqtt-oscilloscope
systemctl daemon-reload
# systemctl start mqtt-sig-gen
systemctl start mqtt-oscilloscope
systemctl daemon-reload
read -p "Press Enter to Quit" variable1
systemctl stop mqtt-sig-gen
systemctl stop mqtt-oscilloscope
systemctl daemon-reload
systemctl disable mqtt-sig-gen
systemctl disable mqtt-oscilloscope
systemctl daemon-reload
cd /etc/systemd/system
rm mqtt-sig-gen.service
rm mqtt-oscilloscope.service
systemctl daemon-reload
mkdir -p /RedPitaya/dev/mqttclient
cd /RedPitaya/dev
rm -r mqttclient
mkdir mqttclient
[mqtt]
broker_ip=169.254.249.197
root_topic=RP2
/* inih -- simple .INI file parser
SPDX-License-Identifier: BSD-3-Clause
Copyright (C) 2009-2020, Ben Hoyt
inih is released under the New BSD license (see LICENSE.txt). Go to the project
home page for more info:
https://github.com/benhoyt/inih
*/
#ifndef INI_H
#define INI_H
/* Make this header file easier to include in C++ code */
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
/* Nonzero if ini_handler callback should accept lineno parameter. */
#ifndef INI_HANDLER_LINENO
#define INI_HANDLER_LINENO 0
#endif
/* Typedef for prototype of handler function. */
#if INI_HANDLER_LINENO
typedef int (*ini_handler)(void* user, const char* section,
const char* name, const char* value,
int lineno);
#else
typedef int (*ini_handler)(void* user, const char* section,
const char* name, const char* value);
#endif
/* Typedef for prototype of fgets-style reader function. */
typedef char* (*ini_reader)(char* str, int num, void* stream);
/* Parse given INI-style file. May have [section]s, name=value pairs
(whitespace stripped), and comments starting with ';' (semicolon). Section
is "" if name=value pair parsed before any section heading. name:value
pairs are also supported as a concession to Python's configparser.
For each name=value pair parsed, call handler function with given user
pointer as well as section, name, and value (data only valid for duration
of handler call). Handler should return nonzero on success, zero on error.
Returns 0 on success, line number of first error on parse error (doesn't
stop on first error), -1 on file open error, or -2 on memory allocation
error (only when INI_USE_STACK is zero).
*/
int ini_parse(const char* filename, ini_handler handler, void* user);
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
close the file when it's finished -- the caller must do that. */
int ini_parse_file(FILE* file, ini_handler handler, void* user);
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
filename. Used for implementing custom or string-based I/O (see also
ini_parse_string). */
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
void* user);
/* Same as ini_parse(), but takes a zero-terminated string with the INI data
instead of a file. Useful for parsing INI data from a network socket or
already in memory. */
int ini_parse_string(const char* string, ini_handler handler, void* user);
/* Nonzero to allow multi-line value parsing, in the style of Python's
configparser. If allowed, ini_parse() will call the handler with the same
name for each subsequent line parsed. */
#ifndef INI_ALLOW_MULTILINE
#define INI_ALLOW_MULTILINE 1
#endif
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
the file. See https://github.com/benhoyt/inih/issues/21 */
#ifndef INI_ALLOW_BOM
#define INI_ALLOW_BOM 1
#endif
/* Chars that begin a start-of-line comment. Per Python configparser, allow
both ; and # comments at the start of a line by default. */
#ifndef INI_START_COMMENT_PREFIXES
#define INI_START_COMMENT_PREFIXES ";#"
#endif
/* Nonzero to allow inline comments (with valid inline comment characters
specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
Python 3.2+ configparser behaviour. */
#ifndef INI_ALLOW_INLINE_COMMENTS
#define INI_ALLOW_INLINE_COMMENTS 1
#endif
#ifndef INI_INLINE_COMMENT_PREFIXES
#define INI_INLINE_COMMENT_PREFIXES ";"
#endif
/* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */
#ifndef INI_USE_STACK
#define INI_USE_STACK 1
#endif
/* Maximum line length for any line in INI file (stack or heap). Note that
this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */
#ifndef INI_MAX_LINE
#define INI_MAX_LINE 200
#endif
/* Nonzero to allow heap line buffer to grow via realloc(), zero for a
fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is
zero. */
#ifndef INI_ALLOW_REALLOC
#define INI_ALLOW_REALLOC 0
#endif
/* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK
is zero. */
#ifndef INI_INITIAL_ALLOC
#define INI_INITIAL_ALLOC 200
#endif
/* Stop parsing on first error (default is to keep parsing). */
#ifndef INI_STOP_ON_FIRST_ERROR
#define INI_STOP_ON_FIRST_ERROR 0
#endif
/* Nonzero to call the handler at the start of each new section (with
name and value NULL). Default is to only call the handler on
each name=value pair. */
#ifndef INI_CALL_HANDLER_ON_NEW_SECTION
#define INI_CALL_HANDLER_ON_NEW_SECTION 0
#endif
/* Nonzero to allow a name without a value (no '=' or ':' on the line) and
call the handler with value NULL in this case. Default is to treat
no-value lines as an error. */
#ifndef INI_ALLOW_NO_VALUE
#define INI_ALLOW_NO_VALUE 0
#endif
#ifdef __cplusplus
}
#endif
#endif /* INI_H */
/*
Author: Fabian John
Company: Technische Hochschule Lübeck - CoSA
(C) 2020
Description: Basic functionalities used by RedPitaya C programs
*/
#include <time.h>
#include <rp.h>
#include "mosquitto.h"
#ifndef __LIBRP_COSA_H__
#define __LIBRP_COSA_H__
char* mqtt_root_topic_base;
char* mqtt_client_name;
char rp_mac_name[14];
struct mosquitto *my_mosq;
typedef struct
{
const char* mqtt_borker_ip;
const char* root_topic;
} configuration_t;
typedef struct
{
int decimation;
int trigger_delay;
float trigger_level;
rp_channel_t trigger_ch;
rp_acq_trig_src_t trigger_src;
} osc_configuration_start_t;
int sleep_advanced(struct timespec ts);
int cfg_handler(void* user, const char* section, const char* name, const char* value);
int osc_handler(void* user, const char* section, const char* name, const char* value);
int process_lb(char* dest, const char* src, int32_t len);
int init_mqtt(void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *));
char *append_topic_str(const char * root, const char * appending);
#endif //__LIBRP_COSA_H__
\ No newline at end of file
This diff is collapsed.
/*
Copyright (c) 2009-2020 Roger Light <roger@atchoo.org>
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
and Eclipse Distribution License v1.0 which accompany this distribution.
The Eclipse Public License is available at
https://www.eclipse.org/legal/epl-2.0/
and the Eclipse Distribution License is available at
http://www.eclipse.org/org/documents/edl-v10.php.
SPDX-License-Identifier: EPL-2.0 OR EDL-1.0
Contributors:
Roger Light - initial implementation and documentation.
*/
/*
* File: mosquitto_broker.h
*
* This header contains functions for use by plugins.
*/
#ifndef MOSQUITTO_BROKER_H
#define MOSQUITTO_BROKER_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(WIN32) && defined(mosquitto_EXPORTS)
# define mosq_EXPORT __declspec(dllexport)
#else
# define mosq_EXPORT
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
struct mosquitto;
typedef struct mqtt5__property mosquitto_property;
enum mosquitto_protocol {
mp_mqtt,
mp_mqttsn,
mp_websockets
};
/* =========================================================================
*
* Section: Register callbacks.
*
* ========================================================================= */
/* Callback events */
enum mosquitto_plugin_event {
MOSQ_EVT_RELOAD = 1,
MOSQ_EVT_ACL_CHECK = 2,
MOSQ_EVT_BASIC_AUTH = 3,
MOSQ_EVT_EXT_AUTH_START = 4,
MOSQ_EVT_EXT_AUTH_CONTINUE = 5,
MOSQ_EVT_CONTROL = 6,
MOSQ_EVT_MESSAGE = 7,
MOSQ_EVT_PSK_KEY = 8,
MOSQ_EVT_TICK = 9,
MOSQ_EVT_DISCONNECT = 10,
};
/* Data for the MOSQ_EVT_RELOAD event */
struct mosquitto_evt_reload {
void *future;
struct mosquitto_opt *options;
int option_count;
void *future2[4];
};
/* Data for the MOSQ_EVT_ACL_CHECK event */
struct mosquitto_evt_acl_check {
void *future;
struct mosquitto *client;
const char *topic;
const void *payload;
mosquitto_property *properties;
int access;
uint32_t payloadlen;
uint8_t qos;
bool retain;
void *future2[4];
};
/* Data for the MOSQ_EVT_BASIC_AUTH event */
struct mosquitto_evt_basic_auth {
void *future;
struct mosquitto *client;
char *username;
char *password;
void *future2[4];
};
/* Data for the MOSQ_EVT_PSK_KEY event */
struct mosquitto_evt_psk_key {
void *future;
struct mosquitto *client;
const char *hint;
const char *identity;
char *key;
int max_key_len;
void *future2[4];
};
/* Data for the MOSQ_EVT_EXTENDED_AUTH event */
struct mosquitto_evt_extended_auth {
void *future;
struct mosquitto *client;
const void *data_in;
void *data_out;
uint16_t data_in_len;
uint16_t data_out_len;
void *future2[4];
};
/* Data for the MOSQ_EVT_CONTROL event */
struct mosquitto_evt_control {
void *future;
struct mosquitto *client;
const char *topic;
const void *payload;
const mosquitto_property *properties;
char *reason_string;
uint32_t payloadlen;
uint8_t qos;
uint8_t reason_code;
bool retain;
void *future2[4];
};
/* Data for the MOSQ_EVT_MESSAGE event */
struct mosquitto_evt_message {
void *future;
struct mosquitto *client;
char *topic;
void *payload;
mosquitto_property *properties;
char *reason_string;
uint32_t payloadlen;
uint8_t qos;
uint8_t reason_code;
bool retain;
void *future2[4];
};
/* Data for the MOSQ_EVT_TICK event */
struct mosquitto_evt_tick {
void *future;
long now_ns;
long next_ns;
int now_s;
int next_s;
void *future2[4];
};
/* Data for the MOSQ_EVT_DISCONNECT event */
struct mosquitto_evt_disconnect {
void *future;
struct mosquitto *client;
int reason;
void *future2[4];
};
/* Callback definition */
typedef int (*MOSQ_FUNC_generic_callback)(int, void *, void *);
typedef struct mosquitto_plugin_id_t mosquitto_plugin_id_t;
/*
* Function: mosquitto_callback_register
*
* Register a callback for an event.
*
* Parameters:
* identifier - the plugin identifier, as provided by <mosquitto_plugin_init>.
* event - the event to register a callback for. Can be one of:
* * MOSQ_EVT_RELOAD
* * MOSQ_EVT_ACL_CHECK
* * MOSQ_EVT_BASIC_AUTH
* * MOSQ_EVT_EXT_AUTH_START
* * MOSQ_EVT_EXT_AUTH_CONTINUE
* * MOSQ_EVT_CONTROL
* * MOSQ_EVT_MESSAGE
* * MOSQ_EVT_PSK_KEY
* * MOSQ_EVT_TICK
* * MOSQ_EVT_DISCONNECT
* cb_func - the callback function
* event_data - event specific data
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if cb_func is NULL
* MOSQ_ERR_NOMEM - on out of memory
* MOSQ_ERR_ALREADY_EXISTS - if cb_func has already been registered for this event
* MOSQ_ERR_NOT_SUPPORTED - if the event is not supported
*/
mosq_EXPORT int mosquitto_callback_register(
mosquitto_plugin_id_t *identifier,
int event,
MOSQ_FUNC_generic_callback cb_func,
const void *event_data,
void *userdata);
/*
* Function: mosquitto_callback_unregister
*
* Unregister a previously registered callback function.
*
* Parameters:
* identifier - the plugin identifier, as provided by <mosquitto_plugin_init>.
* event - the event to register a callback for. Can be one of:
* * MOSQ_EVT_RELOAD
* * MOSQ_EVT_ACL_CHECK
* * MOSQ_EVT_BASIC_AUTH
* * MOSQ_EVT_EXT_AUTH_START
* * MOSQ_EVT_EXT_AUTH_CONTINUE
* * MOSQ_EVT_CONTROL
* * MOSQ_EVT_MESSAGE
* * MOSQ_EVT_PSK_KEY
* * MOSQ_EVT_TICK
* * MOSQ_EVT_DISCONNECT
* cb_func - the callback function
* event_data - event specific data
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if cb_func is NULL
* MOSQ_ERR_NOT_FOUND - if cb_func was not registered for this event
* MOSQ_ERR_NOT_SUPPORTED - if the event is not supported
*/
mosq_EXPORT int mosquitto_callback_unregister(
mosquitto_plugin_id_t *identifier,
int event,
MOSQ_FUNC_generic_callback cb_func,
const void *event_data);
/* =========================================================================
*
* Section: Memory allocation.
*
* Use these functions when allocating or freeing memory to have your memory
* included in the memory tracking on the broker.
*
* ========================================================================= */
/*
* Function: mosquitto_calloc
*/
mosq_EXPORT void *mosquitto_calloc(size_t nmemb, size_t size);
/*
* Function: mosquitto_free
*/
mosq_EXPORT void mosquitto_free(void *mem);
/*
* Function: mosquitto_malloc
*/
mosq_EXPORT void *mosquitto_malloc(size_t size);
/*
* Function: mosquitto_realloc
*/
mosq_EXPORT void *mosquitto_realloc(void *ptr, size_t size);
/*
* Function: mosquitto_strdup
*/
mosq_EXPORT char *mosquitto_strdup(const char *s);
/* =========================================================================
*
* Section: Utility Functions
*
* Use these functions from within your plugin.
*
* ========================================================================= */
/*
* Function: mosquitto_log_printf
*
* Write a log message using the broker configured logging.
*
* Parameters:
* level - Log message priority. Can currently be one of:
*