Skip to content
Snippets Groups Projects
Commit 1cbc2ccf authored by DAsamhan's avatar DAsamhan
Browse files

squash from main

parent f87797ec
Branches
1 merge request!6Implement main application
......@@ -4,9 +4,9 @@
"version": "2.0.0",
"tasks": [
{
"label": "Build app posix",
"label": "Build app native",
"type": "shell",
"command": "./scripts/docker_run.sh west build -b native_sim debug-app/app --build-dir .build-debug-app-native",
"command": "./scripts/docker_run.sh west build -b native_sim debug-app/app --build-dir .build-debug-app-native -- -DCONF_FILE=\"prj.conf ../boards/overlay.conf\"",
"problemMatcher": [
"$gcc"
],
......@@ -48,21 +48,21 @@
"clear": true
}
},
// {
// "label": "Run Posix",
// "type": "shell",
// "command": " ./scripts/docker_run.sh west build -t run --build-dir .build-debug-app-qemu",
// "problemMatcher": [
// "$gcc"
// ],
// "group": {
// "kind": "build",
// "isDefault": true
// },
// "presentation": {
// "clear": true
// }
// },
{
"label": "Debug native",
"type": "shell",
"command": "./scripts/docker_run.sh ./scripts/run_debug.sh",
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"clear": true
}
},
{
"label": "Clean",
"type": "shell",
......
......@@ -9,10 +9,11 @@ CONFIG_NEWLIB_LIBC=y
# Zephyr
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_HEAP_MEM_POOL_SIZE=512
CONFIG_HEAP_MEM_POOL_SIZE=65535
CONFIG_THREAD_NAME=y
CONFIG_ASSERT=y
CONFIG_NO_OPTIMIZATIONS=n
CONFIG_DEBUG=n
CONFIG_BOOT_BANNER=n
# Peripheral
# CONFIG_ADC=y
......@@ -61,6 +62,7 @@ CONFIG_NET_L2_ETHERNET=y
# CONFIG_PM_DEVICE=y
# CONFIG_PM_DEVICE_RUNTIME=y
# Log
CONFIG_LOG=y
CONFIG_LOG_PROCESS_THREAD=y
......
......@@ -2,13 +2,16 @@
#include <zephyr/logging/log.h>
#include <zephyr/zbus/zbus.h>
#include "utilities.h"
#include "main-handler.h"
#include "debug-handler.h"
#include "driver-hook.h"
#include "ble-scanner.h"
#include "device-parser.h"
#if !defined(CONFIG_SOC_POSIX)
#include "ble-scanner.h"
#include "wifi-controller.h"
#include "utilities.h"
#endif
LOG_MODULE_REGISTER(main);
......@@ -51,11 +54,13 @@ ZBUS_CHAN_DEFINE(stateChannel, /* Name */
int main()
{
#if !defined(CONFIG_SOC_POSIX)
WifiController wifiController;
BleScanner bleScanner;
#endif
DebugHandler debugHanddler;
MainHandler mainHandler;
DriverHook driverHook;
DebugHandler debugHanddler;
BleScanner bleScanner;
DeviceParser deviceParser;
while(true) {
......
#ble
CONFIG_BT=n
CONFIG_BT_OBSERVER=n
#networking
CONFIG_WIFI=n
CONFIG_NETWORKING=n
#zephyr
CONFIG_NO_OPTIMIZATIONS=y
CONFIG_DEBUG=y
CONFIG_BOOT_BANNER=y
add_subdirectory(ble-scanner)
add_subdirectory(wifi-controller)
add_subdirectory_ifndef(CONFIG_SOC_POSIX ble-scanner)
add_subdirectory_ifndef(CONFIG_SOC_POSIX wifi-controller)
add_subdirectory(ir-driver)
add_subdirectory(servo-driver)
add_subdirectory(led-driver)
\ No newline at end of file
......@@ -2,7 +2,9 @@
#include <zephyr/logging/log.h>
#include <zephyr/zbus/zbus.h>
#ifndef CONFIG_SOC_POSIX
#include <zephyr/net/socket.h>
#endif
#include <stdio.h>
#include <string.h>
......@@ -32,6 +34,11 @@ int serv;
int client;
bool isDebugMode = false;
// Debug Client
bool isDriverAvailable = false;
bool isBleAvailable = false;
DebugMessage_t debugData;
ZBUS_LISTENER_DEFINE(debugDriverListener, context->DriverResponseListener);
ZBUS_LISTENER_DEFINE(stateListener, context->StateListener);
ZBUS_LISTENER_DEFINE(bleListener, context->BleListener);
......@@ -56,6 +63,7 @@ int DebugHandler::Deinit(){
}
void DebugHandler::DebugThread(DebugHandler *context){
#ifndef CONFIG_SOC_POSIX
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(PORT);
......@@ -118,6 +126,37 @@ void DebugHandler::DebugThread(DebugHandler *context){
isDebugMode = false;
LOG_INF("Connection to %s close", addr_str);
}
#else
while(1){
std::vector<uint8_t> driverData;
std::vector<uint8_t> bleData;
uint8_t bleArray[128];
uint8_t driverArray[128];
uint16_t bleLen = 0;
uint16_t driverLen = 0;
if(isDriverAvailable){
driverData.insert(driverData.end(), &driverArray[0], &driverArray[driverLen]);
DriverMessage_t sentMessage = {
.number = (DriverNumb_e)0, //temporary
.value = driverData
};
zbus_chan_pub(&driverResponseChannel, &sentMessage, K_MSEC(200));
isDriverAvailable = false;
}
if(isBleAvailable){
bleData.insert(bleData.end(), &bleArray[0], &bleArray[bleLen]);
BleData_t sentMessage = {
.address = std::string(""), //temporary
.data = bleData
};
zbus_chan_pub(&bleScanChannel, &sentMessage, K_MSEC(200));
isBleAvailable = false;
}
k_msleep(100);
}
#endif
}
void DebugHandler::DriverResponseListener(const struct zbus_channel *chan){
......@@ -165,6 +204,7 @@ void DebugHandler::BleListener(const struct zbus_channel *chan){
}
int DebugHandler::SendPacket(uint8_t *buf, uint16_t size){
#ifndef CONFIG_SOC_POSIX
int sentlength, recvLength;
recvLength = size;
do {
......@@ -177,4 +217,7 @@ int DebugHandler::SendPacket(uint8_t *buf, uint16_t size){
recvLength-= sentlength;
} while (recvLength);
return recvLength;
#else
return 0;
#endif
}
\ No newline at end of file
#!/usr/bin/env python
import socket
import select
import gdb
import rpyc
TCP_IP = '192.168.8.149'
TCP_PORT = 12345
BUFFER_SIZE = 1024
MESSAGE = b'ABC'
received = 0
c = rpyc.connect("localhost", 18080)
def GetState():
return c.root.getState()
def GetBle():
return c.root.getBle()
def GetDriver():
return c.root.getDriver()
class StateBp(gdb.Breakpoint):
def __init__(self):
gdb.Breakpoint.__init__(self, "main-handler.cpp:69")
def stop(self):
# SocketStart()
state = GetState()
if state >= 0:
print('set var currentState = ' + str(state))
gdb.execute('set var currentState = ' + str(state))
return False
class DriverBp(gdb.Breakpoint):
def __init__(self):
gdb.Breakpoint.__init__(self, "debug-handler.cpp:136")
def stop(self):
bleData = GetBle()
driverData = GetDriver()
if len(bleData) > 0:
gdb.execute('set var bleLen = ' + str(len(bleData)))
gdb.execute('set var isBleAvailable = true')
# gdb.execute('print bleLen')
# gdb.execute('print isBleAvailable')
print(bleData)
for i, data in enumerate(bleData):
gdb.execute('set var bleArray[' +str(i) + '] =' + str(data))
# gdb.execute('print bleArray')
if len(driverData) > 0:
gdb.execute('set var driverLen = ' + str(len(driverData)))
gdb.execute('set var isDriverAvailable = true')
for i, data in enumerate(driverData):
gdb.execute('set var driverArray[' +str(i) + '] =' + str(data))
return False
def SocketStart():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.setblocking(False)
s.send(MESSAGE)
inputs = [s]
outputs = [s]
while inputs:
readable,writable,exceptional = select.select(inputs,outputs,inputs,1)
data = []
for s in readable:
data = s.recv(1024)
# logging.info(f'Non Blocking - data: {len(data)}')
# logging.info(f'Non Blocking - closing...')
if(len(data) >0):
if(data[0]==0):
global received
received = data[3]
print(received)
break
s.close()
bp1 = StateBp()
bp2 = DriverBp()
\ No newline at end of file
#!/usr/bin/env python
import rpyc
c = rpyc.connect("localhost", 18080)
c.root.socketStart()
\ No newline at end of file
#!/usr/bin/env python
import socket
import select
import rpyc
from rpyc.utils.server import ThreadedServer
TCP_IP = '192.168.8.149'
TCP_PORT = 12345
BUFFER_SIZE = 1024
MESSAGE = b'ABC'
received = 0
stateData = []
bleData = []
driverData = []
class DebugService(rpyc.Service):
def on_connect(self,conn):
print("connected")
# SocketStart()
def on_disconnect(self,conn):
pass
def parser(self, packet):
FLAG_BYTE = 0
LENGTH_MSB = 1
LENGTH_LSB = 2
PAYLOAD_BYTE = 3
STATE_DATA = 0
BLE_DATA = 1
DRIVER_DATA = 2
dataType = FLAG_BYTE
dataLength = 0
dataFlag = 0
index = 0
while index < len(packet):
dataLength = ((packet[index + 1] << 8) + packet[index + 2])
if(packet[index] == STATE_DATA):
stateData.append(packet[index+3])
elif(packet[index] == BLE_DATA):
bleData.append(packet[index+3 : index + 3 + dataLength])
elif(packet[index] == DRIVER_DATA):
driverData.append(packet[index+3 : index + 3 + dataLength])
index += (3+dataLength)
def exposed_socketStart(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.setblocking(False)
s.send(MESSAGE)
inputs = [s]
outputs = [s]
while inputs:
readable,writable,exceptional = select.select(inputs,outputs,inputs,1)
data = []
for s in readable:
data = s.recv(1024)
self.parser(data)
def exposed_getState(self):
if len(stateData) > 0:
return stateData.pop(0)
else:
return -1
def exposed_getDriver(self):
if len(driverData) > 0:
return driverData.pop(0)
else :
return []
def exposed_getBle(self):
if len(bleData) > 0:
return bleData.pop(0)
else :
return []
def SocketStart():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.setblocking(False)
s.send(MESSAGE)
inputs = [s]
outputs = [s]
while inputs:
readable,writable,exceptional = select.select(inputs,outputs,inputs,1)
data = []
for s in readable:
data = s.recv(1024)
# logging.info(f'Non Blocking - data: {len(data)}')
# logging.info(f'Non Blocking - closing...')
if(len(data) >0):
if(data[0]==0):
print(data)
global received
received = data[3]
ts = ThreadedServer(DebugService,port=18080)
print('Service started on port 18080')
ts.start()
\ No newline at end of file
......@@ -8,10 +8,11 @@ DOCKER_ARGS="--privileged \
--rm=true \
--user="$(id --user):$(id --group)" \
-e ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-0.16.4 \
-e CCACHE_DIR=$(pwd)/.ccache \
-e CCACHE_DIR=$(pwd)/.ccache
-v $(pwd):$(pwd) \
-v /dev/bus/usb:/dev/bus/usb \
-w $(pwd)"
DOCKER_IMAGE=zephyrprojectrtos/ci:v0.26.6
-w $(pwd) \
-it"
DOCKER_IMAGE=zephyrprojectrtos/ci:v0.26.6-t
docker run $DOCKER_ARGS $DOCKER_IMAGE "$@"
#!/bin/bash
python debug-python/socket-run.py&
python debug-python/helper.py&
gdb --command debug-python/debug.py .build-debug-app-native/zephyr/zephyr.exe
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment