Skip to content

Commit f132eea

Browse files
committed
Initial version
0 parents  commit f132eea

31 files changed

+1459
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

.vscode/Workspace.code-workspace

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"folders": [
3+
{
4+
"name": "BattleShip",
5+
"path": "C:\\Users\\ThomasSchissler\\source\\repos\\tschissler\\Arduino\\battleship-embedded\\BattleShip"
6+
}
7+
],
8+
"settings": {
9+
"terminal.integrated.env.windows": {
10+
"PATH": "C:\\Users\\ThomasSchissler\\.platformio\\penv\\Scripts;C:\\Users\\ThomasSchissler\\.platformio\\penv;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\VC\\VCPackages;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\bin\\Roslyn;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Team Tools\\Performance Tools;C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Common\\VSPerfCollectionTools\\vs2019\\;C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.7.2 Tools\\;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\FSharp\\;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\\\MSBuild\\Current\\Bin;C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\Tools\\;C:\\ProgramData\\DockerDesktop\\version-bin;C:\\Program Files\\Docker\\Docker\\Resources\\bin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Users\\ThomasSchissler\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Users\\ThomasSchissler\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\VC\\VCPackages;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\bin\\Roslyn;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Team Tools\\Performance Tools;C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Common\\VSPerfCollectionTools\\vs2019\\;C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.7.2 Tools\\;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\FSharp\\;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\\\MSBuild\\Current\\Bin;C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\Tools\\;C:\\ProgramData\\DockerDesktop\\version-bin;C:\\Program Files\\Docker\\Docker\\Resources\\bin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Users\\ThomasSchissler\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Users\\ThomasSchissler\\AppData\\Local\\Programs\\Microsoft VS Code\\bin",
11+
"PLATFORMIO_CALLER": "vscode"
12+
}
13+
}
14+
}

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"platformio.platformio-ide"
6+
]
7+
}

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"terminal.integrated.env.windows": {
3+
"PATH": "C:\\Users\\ThomasSchissler\\.platformio\\penv\\Scripts;C:\\Users\\ThomasSchissler\\.platformio\\penv;C:\\ProgramData\\DockerDesktop\\version-bin;C:\\Program Files\\Docker\\Docker\\Resources\\bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI2\\wbin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\nodejs\\;C:\\Program Files\\Terraform;C:\\Program Files (x86)\\Microsoft SQL Server\\150\\DTS\\Binn\\;C:\\MinGW\\bin;C:\\Program Files\\PuTTY\\;C:\\Users\\ThomasSchissler\\AppData\\Local\\Programs\\Python\\Python37\\Scripts\\;C:\\Users\\ThomasSchissler\\AppData\\Local\\Programs\\Python\\Python37\\;C:\\Users\\ThomasSchissler\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Users\\ThomasSchissler\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\ThomasSchissler\\AppData\\Roaming\\npm;C:\\Users\\ThomasSchissler\\.dotnet\\tools;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps;C:\\ProgramData\\DockerDesktop\\version-bin;C:\\Program Files\\Docker\\Docker\\Resources\\bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI2\\wbin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\nodejs\\;C:\\Program Files\\Terraform;C:\\Program Files (x86)\\Microsoft SQL Server\\150\\DTS\\Binn\\;C:\\MinGW\\bin;C:\\Program Files\\PuTTY\\;C:\\Users\\ThomasSchissler\\AppData\\Local\\Programs\\Python\\Python37\\Scripts\\;C:\\Users\\ThomasSchissler\\AppData\\Local\\Programs\\Python\\Python37\\;C:\\Users\\ThomasSchissler\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Users\\ThomasSchissler\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\ThomasSchissler\\AppData\\Roaming\\npm;C:\\Users\\ThomasSchissler\\.dotnet\\tools;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps",
4+
"PLATFORMIO_CALLER": "vscode"
5+
}
6+
}

_deploy/TestResult2.xml

1.35 KB
Binary file not shown.

_deploy/TestResults.xml

1.35 KB
Binary file not shown.

_deploy/TestResultsParser.py

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import string
2+
import re
3+
import sys
4+
from xml.sax.saxutils import escape
5+
6+
def createXML(testData, outputfilepath):
7+
template_testsuites = string.Template("""<?xml version="1.0" encoding="UTF-8"?>
8+
<test-results>
9+
<test-suite>
10+
<results>
11+
${successtestcases}
12+
${failingtestcases}
13+
</results>
14+
</test-suite>
15+
</test-results>""")
16+
17+
template_successtestcase = string.Template(""" <test-case classname="${classname}" name="${name}" result="${result}" time=""/>""")
18+
template_failingtestcase = string.Template(""" <test-case classname="${classname}" name="${name}" result="${result}" time="">
19+
<failure>
20+
<message>${message}</message>
21+
</failure>
22+
</test-case>""")
23+
24+
contents_successtestcase = [template_successtestcase.substitute(id=id, classname=classname, name=name, result=result) for (id, classname, name, result, message) in testData if result != "Failed"]
25+
contents_failingtestcase = [template_failingtestcase.substitute(id=id, classname=classname, name=name, result=result, message=message) for (id, classname, name, result, message) in testData if result == "Failed"]
26+
result = template_testsuites.substitute(successtestcases='\n'.join(contents_successtestcase), failingtestcases='\n'.join(contents_failingtestcase))
27+
#print (result)
28+
with open(outputfilepath, 'w') as outputfile:
29+
outputfile.write(result)
30+
31+
print("Finished converting data, result written to " + outputfilepath)
32+
33+
def readFileContent(inputfilepath, outputfile):
34+
TestBlock = False
35+
print (" Reading testresults from file " + inputfilepath)
36+
with open(inputfilepath, 'r') as inputfile:
37+
testData = []
38+
39+
for line in inputfile:
40+
line = line.replace("FAIL:", "FAIL->").strip().replace("[FAILED]", "Failed").replace("[PASSED]", "Success")
41+
#print (line)
42+
if line.strip() == "" and TestBlock == True:
43+
TestBlock = False
44+
print (" End of testing block")
45+
if TestBlock == True:
46+
parts = re.split(":|\t", line)
47+
print (" Found Test Case: " + str(parts))
48+
if (len(parts) > 4):
49+
testData.append((parts[1], parts[0], parts[2], parts[4], parts[3]))
50+
else:
51+
testData.append((parts[1], parts[0], parts[2], parts[3], ''))
52+
if line.__contains__("Testing...") == True:
53+
TestBlock = True
54+
print (" Found testing block - start reading test cases")
55+
print (" Found " + str(len(testData)) + " Test Cases, exporting them now to output file")
56+
createXML(testData, outputfile)
57+
58+
print ("#################################################################################################")
59+
print ("# Test Results Parser 1.0 by @tschissler")
60+
print ("#################################################################################################")
61+
print ()
62+
print ("This tool is parsing test results from PlatformIO unit tests and converting into NUnit format")
63+
print ()
64+
print ("Usage: TestResultsParser.py <inputfile> <outputfile>")
65+
print ()
66+
67+
print (sys.argv)
68+
if (len(sys.argv) != 3):
69+
print ("Wrong number of parameters [" + str(len(sys.argv)) + "], expecting 2 parameters")
70+
sys.exit([-1])
71+
72+
print (" -- Starting conversion process --")
73+
readFileContent(sys.argv[1], sys.argv[2])
74+
75+
76+
77+
78+
79+
80+
#<?xml version="1.0" encoding="UTF-8"?>
81+
#<testsuites disabled="" errors="" failures="" name="" tests="" time="">
82+
# <testsuite disabled="" errors="" failures="" hostname="" id=""
83+
# name="" package="" skipped="" tests="" time="" timestamp="">
84+
# <properties>
85+
# <property name="" value=""/>
86+
# </properties>
87+
# <testcase assertions="" classname="" name="" status="" time="">
88+
# <skipped/>
89+
# <error message="" type=""/>
90+
# <failure message="" type=""/>
91+
# <system-out/>
92+
# <system-err/>
93+
# </testcase>
94+
# <system-out/>
95+
# <system-err/>
96+
# </testsuite>
97+
#</testsuites>

_deploy/docker.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker run -i -t -v ${PWD}:/battleship infinitecoding/platformio-for-ci /bin/bash

_deploy/flash.ps1

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#param (
2+
# [Parameter(Mandatory=$true)]
3+
# [String] $binPath
4+
#)
5+
6+
#esptool.py --chip esp32 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 C:\Users\ThomasSchissler\.platformio\packages\framework-arduinoespressif32\tools\sdk\bin\bootloader_dio_40m.bin 0x8000 $binPath\partitions.bin 0xe000 C:\Users\ThomasSchissler\.platformio\packages\framework-arduinoespressif32\tools\partitions\boot_app0.bin 0x10000 $binPath\firmware.bin
7+
8+
param (
9+
[Parameter(Mandatory=$true)]
10+
[String] $binPath
11+
)
12+
13+
esptool.py `
14+
--chip esp32 `
15+
--before default_reset `
16+
--after hard_reset `
17+
write_flash `
18+
-z `
19+
--flash_mode dio `
20+
--flash_freq 40m `
21+
--flash_size detect `
22+
0x8000 $binPath/partitions.bin `
23+
0x10000 $binPath/firmware.bin
24+
25+
# 0x1000 $binPath\bootloader_dio_40m.bin `
26+
# 0xe000 $binPath\boot_app0.bin `
27+

include/README

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <DisplayManager.h>
2+
using namespace std;
3+
4+
DisplayManager::DisplayManager(){
5+
}
6+
7+
int DisplayManager::AddPage(Page page){
8+
OutputBuffer.insert(OutputBuffer.end(), page);
9+
CurrentPage++;
10+
}
11+
12+
Page & DisplayManager::GetLastPage(){
13+
return OutputBuffer.back();
14+
}
15+
16+
Page & DisplayManager::GetCurrentPage(){
17+
return OutputBuffer.at(CurrentPage-1);
18+
}
19+
20+
Page & DisplayManager::GetPage(int index){
21+
return OutputBuffer.at(index-1);
22+
}
23+
24+
bool DisplayManager::IsCurrentPageLastPage() {
25+
return CurrentPage == OutputBuffer.size();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <vector>
4+
#include <Page.h>
5+
using namespace std;
6+
7+
#ifndef DisplayManager_h
8+
#define DisplayManager_h
9+
class DisplayManager {
10+
public:
11+
vector<Page> OutputBuffer;
12+
int CurrentPage=0;
13+
14+
public:
15+
DisplayManager();
16+
int AddPage(Page page);
17+
Page & GetLastPage();
18+
Page & GetCurrentPage();
19+
Page & GetPage(int index);
20+
bool IsCurrentPageLastPage();
21+
};
22+
#endif

lib/Battleship.DisplayManager/Page.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <iostream>
2+
#include <string>
3+
using namespace std;
4+
5+
#ifndef Page_h
6+
#define Page_h
7+
class Page {
8+
public:
9+
string Line1;
10+
string Line2;
11+
string Line3;
12+
string Line4;
13+
};
14+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "GameController.h"
2+
3+
bool GameController::CheckIsHit(list<Ship> &ships, Position shot)
4+
{
5+
6+
if (&ships == nullptr)
7+
throw std::invalid_argument(std::string("argument 'ships' is invalid"));
8+
9+
for(Ship ship: ships) {
10+
for(Position position: ship.Positions) {
11+
if (position.Column == shot.Column && position.Row == shot.Row) {
12+
return true;
13+
}
14+
}
15+
}
16+
return false;
17+
}
18+
19+
Letters GameController::CharToLetter(char input){
20+
return Letters(input-'A');
21+
}
22+
23+
char GameController::LetterToChar(Letters input){
24+
return input+'A';
25+
}
26+
27+
list<Ship> GameController::InitializeShips(){
28+
list<Ship> ships;
29+
ships.insert(ships.end(), Ship("Aircraft Carrier",5 ,44));
30+
ships.insert(ships.end(), Ship("Battleship", 4, 41));
31+
ships.insert(ships.end(), Ship("Submarine", 3, 42));
32+
ships.insert(ships.end(), Ship("Destroyer", 3, 43));
33+
ships.insert(ships.end(), Ship("Patrol Boat", 2, 45));
34+
return ships;
35+
}
36+
37+
Position GameController::GetRandomPosition(int size) {
38+
srand((unsigned int) time(NULL));
39+
Letters lColumn = (Letters)(rand() % size);
40+
int nRow = (rand() % size);
41+
42+
Position position(lColumn, nRow);
43+
return position;
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <Letters.h>
2+
#include <iostream>
3+
#include <string>
4+
#include <Ship.h>
5+
#include <list>
6+
#include <algorithm>
7+
#include <time.h>
8+
9+
#ifndef GamesController_h
10+
#define GamesController_h
11+
class GameController {
12+
public:
13+
static bool CheckIsHit(list<Ship> &ships, Position shot);
14+
static Letters CharToLetter(char letter);
15+
static char LetterToChar(Letters letter);
16+
static list<Ship> InitializeShips();
17+
static Position GetRandomPosition(int size);
18+
};
19+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <Letters.h>
4+
using namespace std;
5+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <iostream>
2+
#include <string>
3+
using namespace std;
4+
5+
#ifndef Letters_h
6+
#define Letters_h
7+
enum Letters{
8+
A,
9+
B,
10+
C,
11+
D,
12+
E,
13+
F,
14+
G,
15+
H
16+
};
17+
18+
#endif
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <Position.h>
2+
#include <sstream>
3+
namespace std {
4+
template<typename T>
5+
std::string to_string(const T &n) {
6+
std::ostringstream s;
7+
s << n;
8+
return s.str();
9+
}
10+
}
11+
12+
enum Letters Column;
13+
int Row;
14+
15+
Position::Position() {
16+
17+
}
18+
19+
Position::Position(Letters column, int row) {
20+
Column = column;
21+
Row = row;
22+
}
23+
24+
string Position::toString() {
25+
char letter = Column + 'A';
26+
return letter + std::to_string(Row);
27+
}

0 commit comments

Comments
 (0)