Skip to content

Commit

Permalink
Merge pull request #61 from RobertGawron/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
RobertGawron authored Oct 24, 2020
2 parents 266fd8e + ab69093 commit 76ba7fd
Show file tree
Hide file tree
Showing 39 changed files with 158 additions and 83 deletions.
1 change: 1 addition & 0 deletions Software/HardwareDataLogger/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Software/NUCLEO-F091RC/Drivers/* linguist-vendored
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Static Code Analysis

on: [push]

jobs:
build_and_test:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v1
- name: install cppcheck and run tests
run: |
sudo apt-get install -y cppcheck
cd ./ContinousIntegration
chmod +x ./run_c_static_code_analysis.sh
ls run_c_static_code_analysis.sh
./run_c_static_code_analysis.sh
- uses: actions/checkout@v1
- name: install flake8 and run tests
if: always()
run: |
sudo pip install flake8 flake8-html
cd ./ContinousIntegration
chmod +x ./run_python_static_code_analysis.sh
ls
./run_python_static_code_analysis.sh
- name: Archive Python results
uses: actions/upload-artifact@v2
if: always()
with:
name: Report for Python sources
path: ./ContinousIntegration/python_lint_repport/

- name: Archive C results
uses: actions/upload-artifact@v2
if: always()
with:
name: Report for C sources
path: ./ContinousIntegration/C_Lint_*.txt
24 changes: 24 additions & 0 deletions Software/HardwareDataLogger/.github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Unit Tests

on: [push]

jobs:
build_and_test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Build and run tests
run: |
sudo pip install pytest pytest-html
cd ./ContinousIntegration
chmod +x ./run_unit_tests.sh
./run_unit_tests.sh
- name: Archive component test results
uses: actions/upload-artifact@v2
if: always()
with:
name: Report for Unit Tests
path: ./Test/UnitTest/test_*/*xml
3 changes: 3 additions & 0 deletions Software/HardwareDataLogger/ContinousIntegration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Continous Integration

This folder contains scripts run by GitHub continuous integration module. These scripts should be also run locally before pull request.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cppcheck --enable=all --inline-suppr --force --quiet --error-exitcode=1 ../Software/NUCLEO-F091RC/Inc ../Software/NUCLEO-F091RC/Src 2>C_Lint_ReportFull.txt

# look for errors in gm_* files (those are application files we are interested in)
# store them to separate log ans show them on stdout
grep -F '[../Software/NUCLEO-F091RC/Src/gm_' C_Lint_ReportFull.txt > C_Lint_ReportApplicationOnly.txt
cat C_Lint_ReportApplicationOnly.txt

# set exit code to ok if no errors were found in application files
if [ $(cat C_Lint_ReportApplicationOnly.txt | wc -l) -eq 0 ]; then
true
else
false
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flake8 --format=html --htmldir=python_lint_repport ../Simulation/FirmwarePCSimulator
18 changes: 18 additions & 0 deletions Software/HardwareDataLogger/ContinousIntegration/run_unit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cd ../Test/UnitTest && \
\
\
cd test_gm_circular_buffer && \
make clean && \
make -j12 && \
ls -l && \
./test_gm_circular_buffer --output=./test_gm_circular_buffer.xml &&
\
\
cd .. && \
\
\
cd test_gm_histogram && \
make clean && \
make -j12 && \
ls -l && \
./test_gm_histogram --output=./test_gm_histogram.xml
2 changes: 1 addition & 1 deletion Software/HardwareDataLogger/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HardwareDataLogger

---
[![Unit Tests](https://github.com/RobertGawron/HardwareDataLogger/workflows/Unit%20Tests/badge.svg)](https://github.com/RobertGawron/HardwareDataLogger/actions?query=workflow%3A%22Unit+Tests%22) [![Static Code Analysis](https://github.com/RobertGawron/HardwareDataLogger/workflows/Static%20Code%20Analysis/badge.svg)](https://github.com/RobertGawron/HardwareDataLogger/actions?query=workflow%3A%22Static+Code+Analysis%22)

## Summary

Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,68 @@
from ctypes import *
from ctypes.wintypes import *
import ctypes
import os.path


class DeviceUnderTest:
def __init__(self):
dll_name = "simulation.so"
dllabspath = os.path.dirname(os.path.abspath(os.path.abspath(__file__))) + os.path.sep +"..\\..\\Software" + os.path.sep + "NUCLEO-F091RC" + os.path.sep + dll_name
dllabspath = \
os.path.dirname(os.path.abspath(os.path.abspath(__file__))) \
+ os.path.sep + ".." + os.path.sep + ".." \
+ os.path.sep + "Software" + os.path.sep + "NUCLEO-F091RC" \
+ os.path.sep + dll_name

self.dut = ctypes.CDLL(dllabspath)
self.dut.Lib_Simulation_Init()


def generateGMPulse(self):
self.dut.Lib_GMMeasurementCalculator_OnGMPulseObserved()


def generateEndOfSampleCollecting(self):
self.dut.Lib_GMMeasurementCalculator_OnSamplingDone()


def getLoggedData(self):
self.dut.Lib_GMLoggerSIM_GetLoggedData.argtypes = [POINTER(POINTER(c_uint8)), POINTER(c_uint8)]
data = POINTER(c_uint8)()
size = c_uint8()
self.dut.Lib_GMLoggerSIM_GetLoggedData.argtypes = \
[ctypes.POINTER(ctypes.POINTER(ctypes.c_uint8)),
ctypes.POINTER(ctypes.c_uint8)]

data = ctypes.POINTER(ctypes.c_uint8)()
size = ctypes.c_uint8()

self.dut.Lib_GMLoggerSIM_GetLoggedData(byref(data), byref(size))
self.dut.Lib_GMLoggerSIM_GetLoggedData(
ctypes.byref(data), ctypes.byref(size))

logged_data = ""
for i in range(size.value):
logged_data += chr(data[i])

# it is expected that log end with new line,
# it is expected that log end with new line,
# this should be stripped application
return logged_data[:-3]


def pressKey(self):
self.dut.Lib_GMLoggerSIM_KeyPress()


def getDisplayLength(self):
self.dut.Lib_GMLoggerSIM_GetDisplayLength.restype = c_uint8
self.dut.Lib_GMLoggerSIM_GetDisplayLength.restype = ctypes.c_uint8
return self.dut.Lib_GMLoggerSIM_GetDisplayLength()


def getDisplayHeight(self):
self.dut.Lib_GMLoggerSIM_GetDisplayHeight.restype = c_uint8
self.dut.Lib_GMLoggerSIM_GetDisplayHeight.restype = ctypes.c_uint8
return self.dut.Lib_GMLoggerSIM_GetDisplayHeight()


def getDisplayData(self):
self.dut.Lib_GMLoggerSIM_GetDisplayContent.restype = POINTER(c_uint8)
self.dut.Lib_GMLoggerSIM_GetDisplayContent.restype =\
ctypes.POINTER(ctypes.c_uint8)

return self.dut.Lib_GMLoggerSIM_GetDisplayContent()

def getDisplayPixelValue(self, x, y):
# note: this is not optimal data is fetched multiple times

display_length = self.getDisplayLength()
display_height = self.getDisplayHeight()

self.dut.Lib_GMLoggerSIM_GetDisplayContent.restype = POINTER(c_uint8)
self.dut.Lib_GMLoggerSIM_GetDisplayContent.restype =\
ctypes.POINTER(ctypes.c_uint8)
display_data = self.dut.Lib_GMLoggerSIM_GetDisplayContent()

# formula from SSD1306_DrawPixel()
Expand All @@ -67,5 +71,3 @@ def getDisplayPixelValue(self, x, y):
value = cell & (1 << (y % 8))

return value


32 changes: 13 additions & 19 deletions Software/HardwareDataLogger/Simulation/FirmwarePCSimulator/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys
from datetime import datetime
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets, QtGui, QtCore, uic
from PyQt5.QtWidgets import QApplication, QMainWindow, \
QPushButton, QTextBrowser, QLabel
from PyQt5 import QtCore, QtGui, uic
from device_under_test import DeviceUnderTest


Expand All @@ -18,11 +19,12 @@ def __init__(self):
def setupWidgets(self):
uic.loadUi("gui.ui", self)

self.WidgetGenerateGMPulse = self.findChild(QPushButton, "WidgetGenerateGMPulse")
self.WidgetPushHWKey= self.findChild(QPushButton, "WidgetPushHWKey")
self.WidgetGenerateGMPulse = \
self.findChild(QPushButton, "WidgetGenerateGMPulse")
self.WidgetPushHWKey = self.findChild(QPushButton, "WidgetPushHWKey")
self.WidgetLogger = self.findChild(QTextBrowser, "WidgetLogger")
self.WidgetHWDisplay= self.findChild(QLabel, "WidgetHWDisplay")
self.WidgetHWDisplay = self.findChild(QLabel, "WidgetHWDisplay")

self.WidgetGenerateGMPulse.clicked.connect(self.onGenerateGMPulse)
self.WidgetPushHWKey.clicked.connect(self.onPressHWKey)

Expand All @@ -32,42 +34,34 @@ def startTimers(self):
self.dutTimer.timeout.connect(self.onTimer)
self.dutTimer.start()


def onGenerateGMPulse(self):
self.dut.generateGMPulse()


def onTimer(self):
self.dut.generateEndOfSampleCollecting()
self.onNewLoggedData()
self.onHWDisplayUpdate()


def onNewLoggedData(self):
logged_data = self.dut.getLoggedData()
local_timestamp = datetime.now()
data_with_timestamp = "{}: {}".format(local_timestamp, logged_data)
self.WidgetLogger.append (data_with_timestamp)

self.WidgetLogger.append(data_with_timestamp)

def onPressHWKey(self):
self.dut.pressKey()
self.onHWDisplayUpdate()


def onHWDisplayUpdate(self):
display_pixel_on_color = "#6df8fc"
display_pixel_off_color ="#14182b"
display_pixel_off_color = "#14182b"

display_data = self.dut.getDisplayData()
display_length = self.dut.getDisplayLength()
display_height = self.dut.getDisplayHeight()

canvas = QtGui.QPixmap(display_length, display_height)
# clean canvas, otherwise image is black
# see https://stackoverflow.com/questions/63269098/qpixmap-qpainter-showing-black-window-background
canvas.fill(QtGui.QColor(display_pixel_off_color))

self.WidgetHWDisplay.setPixmap(canvas)

painter = QtGui.QPainter(self.WidgetHWDisplay.pixmap())
Expand All @@ -76,14 +70,14 @@ def onHWDisplayUpdate(self):

for y in range(display_height):
for x in range(display_length):
if(self.dut.getDisplayPixelValue(x,y)):
if(self.dut.getDisplayPixelValue(x, y)):
pen.setColor(QtGui.QColor(display_pixel_on_color))
painter.setPen(pen)
else:
pen.setColor(QtGui.QColor(display_pixel_off_color))
painter.setPen(pen)
painter.drawPoint(x, y)

painter.end()


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GMCircularBuffer_GetElementStatus_t GMCircularBuffer_GetElement(GMMeasurement_Va
}
else
{
element = 0;
*element = 0;
retValue = GMCIRCULARBUFFER_GETELEMENT_INDEX_OUT_OF_RANGE;
}

Expand Down Expand Up @@ -97,8 +97,8 @@ GMCircularBuffer_GetMinMaxElementStatus_t GMCircularBuffer_GetMinMaxElement(GMMe
else
{
// no elements in buffer, so counting max element is pointless
minElement = 0;
maxElement = 0;
*minElement = 0;
*maxElement = 0;
retValue = GMCIRCULARBUFFER_GETMINMAXELEMENT_NO_MEASSUREMENTS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ static GMDisplayUpdater_ViewSelector_t GMDisplayUpdater_ViewSelector = {

void GMDisplayUpdater_Init()
{
GMDisplayHW_Init();

for(uint8_t i = 0u; i < GMDisplayUpdater_ViewSelector.viewsAmount; i++)
{
(GMDisplayUpdater_ViewSelector.views[i].GMDisplayUpdater_Init)();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ uint8_t txBuffer[TX_BUFFER_SIZE];

void GMLogger_Init()
{

GMLoggerHW_Init();
}

void GMLogger_LogMeasurement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "gm_view_bargraph.h"
#include "gm_display_hw.h"
#include "gm_display_labels.h"
#include "gm_dose_counter.h"
#include "gm_measurement.h"
#include "gm_circular_buffer.h"

Expand Down Expand Up @@ -76,14 +75,6 @@ void GMViewBargraph_ShowDoseLabel()

stringOffset = strlen(labelDose);
strcpy(&labelDose[stringOffset], labelMinuteCounter);
#if 0
uint16_t dosage = GMDoseCounter_Calculate();
stringOffset = strlen(labelDose);
itoa(dosage, &labelDose[stringOffset], base);

stringOffset = strlen(labelDose);
strcpy(&labelDose[stringOffset], labelDosageUnit);
#endif
}
else
{
Expand Down
Loading

0 comments on commit 76ba7fd

Please sign in to comment.