Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base class code and test code #347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${C:/Users/Kendrick Mitchell/Documents/GitHub/CougSat1-Software/CougSat1-Comms/src}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "install",
"path": "CougSat1-Ground/lib/ehbanana/lib/rapidjson/",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
17 changes: 17 additions & 0 deletions CISLibrary/components/communications/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Frame {
bool isDone();

uint8_t getNextTXByte();
uint8_t GetPayloadData(int index);
uint8_t SetPayloadData(int index, uint8_t data);

private:
static const size_t MAX_PAYLOAD = 1024 + 2; // Packet + packet header
Expand All @@ -25,6 +27,21 @@ class Frame {
// TODO add CRC field
};

uint8_t Frame::GetPayloadData(int i) {
if (i > 0 && i < MAX_PAYLOAD) {
return payloadData[i];
}
return 0;
}

uint8_t Frame::SetPayloadData(int index, uint8_t data) {
if (index > -1 && index < MAX_PAYLOAD) {
payloadData[index] = data;
return 1;
}
return 0;
}

} // namespace Communications

#endif /* _LIBRARY_COMPONENT_COMMUNICATIONS_FRAME_H_ */
49 changes: 48 additions & 1 deletion CISLibrary/components/communications/IQSource/IQSource.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _LIBRARY_COMPONENT_COMMUNICATIONS_IQ_SOURCE_H_
#define _LIBRARY_COMPONENT_COMMUNICATIONS_IQ_SOURCE_H_

#include "Frame.h"
#include "Packet.h"
#include "tools/CircularBuffer.h"
#include <stdint.h>

Expand All @@ -9,6 +11,13 @@ namespace IQSource {

class IQSource {
public:
Packet Lv2_3Ascend(Frame F); // I'm assuming all checks have been completed
Frame Lv3_2Descent(Packet P); // No checks are needed here
bool IsEquivalent2_3(
Frame & F, Packet & P, int size); // This will test the equivlenace of
// packets and frame payload data
bool Test2_3Ascend(Frame & F);
bool Test2_3Descend(Packet & P);
/**
* @brief Construct a new IQSource object
*
Expand Down Expand Up @@ -41,7 +50,45 @@ class IQSource {
const uint32_t sampleFrequency;
};

Packet IQSource::Lv2_3Ascend(
Frame F) { // I'm assuming all safety tests have been passed.
int i = 0;
Packet P;
for (i = 0; F.GetPayloadData(i);
i++) { // Assuming "unoccupied" indexes will be zeroed out.
P.OverwriteData(F.GetPayloadData(i), i);
}
return P;
}

Frame IQSource::Lv3_2Descent(Packet P) {
Frame F;
int i = 0;
for (i = 0; P.GetData(i); i++) {
F.SetPayloadData(P.GetData(i), i);
}
}
bool IQSource::IsEquivalent2_3(Frame & F, Packet & P,
int size) { // Just test for equivalence in the 1026 data.
for (int i = 0; i < size; i++) { // Size will be provided
if (F.GetPayloadData(i) != P.GetData(i)) {
return false;
}
}
return true;
}

bool IQSource::Test2_3Ascend(Frame & F) { //
Packet P = Lv2_3Ascend(F);
int i = P.GetLength();
return IsEquivalent2_3(F, P, i);
}
bool IQSource::Test2_3Descend(Packet & P) {
int i = P.GetLength();
Frame F = Lv3_2Descent(P);
return IsEquivalent2_3(F, P, i);
}
} // namespace IQSource
} // namespace Communications

// I assume the SRC facilitates data ascension
#endif /* _LIBRARY_COMPONENT_COMMUNICATIONS_IQ_SOURCE_H_ */
150 changes: 150 additions & 0 deletions CISLibrary/components/communications/Packet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#include <stdio.h>
#include <stdlib.h>

typedef unsigned char u8;
typedef unsigned int u32;

// Remake the program to use big endian. So Vibes
class Packet {
private:
const static u32 headersize = 2;
const static u32 maxdata_size = 1024;
const static u32 Maxsize = maxdata_size + headersize;
u8 Data[Maxsize]; // Payload is 1024bytes max
u32 length; // Length is 10bits
u32 sender;
u32 recipient; // Combined Sender and recipient IDs are 3 bytes each

public:
Packet(u32 sender, u32 recipient, u32 length);
Packet();
~Packet();
void SetSender(u32 S);
u32 GetSender();

void SetRecipient(u32 R);
u32 GetRecipient();

void SetLength(u32 L);
u32 GetLength();

void OverwriteData(u8 Input, u32 Index);
u8 GetData(u32 Index);
void IncrementData(u8 Inout); // Work on it.
// What form should I expect ascending descending data to be in?
};

Packet::Packet(u32 sender, u32 recipient, u32 length) {
for (int i = 0; i < Maxsize; i++) {
Data[i] = 0;
}
}

Packet::Packet() {
for (int i = 0; i < Maxsize; i++) {
Data[i] = 0;
}
}

/*
Packet::Packet(FrameSource F)
{
for(int i=0;i<Maxsize & F.loadPayloadData(i);i++)
{
Data[i]=F.loadPayloadData(i);
}
}*/

Packet::~Packet() {}

void Packet::SetSender(u32 S) {
if (S >= 8) {
return;
}

Data[0] = Data[0] && 31; // Zero out sender in data
S = S << 5; // Push up s to the right position
Data[0] = Data[0] | S;
} // Big endian

u32 Packet::GetSender() {
u32 S = 0;
S = (Data[0] >> 5) & 0x07;
return S;
} // Big Endian

void Packet::SetRecipient(u32 R) {
/// check recipient value.
if (R > 7) {
return;
}
Data[0] = Data[0] & 227;
R = R << 2;
Data[0] = Data[0] & R;
} // big endian

u32 Packet::GetRecipient() {
u32 R = 0;
R = (Data[0] >> 2) & 0x07; // Get three bits out.
return R;
} // big endian

u32 Packet::GetLength() {
u32 Product = 0;
Product = (Data[0]) & 0x03; // Grab lowest two bits.
Product <<= 8; // Push most important bits up.
Product |= Data[1]; // Grab 8 lowest bits.
return Product;
} // big endian

void Packet::SetLength(u32 L) {
if (L > maxdata_size) {
return; // Data can only be 1024 at most
}
length = L;
Data[1] = 0; // zero out lowest 8 bits.
Data[0] = Data[0] & 252; // zero out the 2 most important bits.

Data[1] = Data[1] | L;
L = L >> 8;
Data[0] = Data[0] & L;
// Big endian
}

void Packet::OverwriteData(u8 Input, u32 Index) {
if (Index >= Maxsize || Index < 0) {
return; /// Error out of bounds
}
Data[Index] = 0;
Data[Index] = Input;
}

u8 Packet::GetData(u32 Index) {
if (Index >= Maxsize) {
return 0;
}
return Data[Index];
}

class Testpacket { // This is just for independent functions.
private:
Packet P;

public:
Testpacket(/* args */);
~Testpacket();
void Test(u32 recipient, u32 sender, u32 length);
};

Testpacket::Testpacket(/* args */) {}

Testpacket::~Testpacket() {}

void Testpacket::Test(u32 recipient, u32 sender, u32 length) {
P.SetLength(length);
P.SetRecipient(recipient);
P.SetSender(sender);
u8 C = P.GetData(3);
printf("Recipient %d Sender %d Length %d", P.GetRecipient(), P.GetSender(),
P.GetLength());
}
28 changes: 16 additions & 12 deletions CougSat1-Ground/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#include <Windows.h>

#include "Frame.h"
#include "communications/Radio.h"
#include "gui/GUI.h"
#include "gui/Radio.h"

//#include "IQSource.h"
/**
* @brief Logger callback
* Prints the message string to the destination stream, default: stdout
Expand Down Expand Up @@ -86,25 +88,27 @@ void configureLogging(
}

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
try {
configureLogging("log.log", true, true);
spdlog::info("Cougs in Space Ground starting");
EBSetLogger(logEhbanana);
try { /*
configureLogging("log.log", true, true);
spdlog::info("Cougs in Space Ground starting");
EBSetLogger(logEhbanana);

GUI::GUI::init();
Communications::Radio::setConstellationCallback(
GUI::Radio::addConstellationIQ);
Communications::Radio::start();
//GUI::GUI::init();
Communications::Radio::setConstellationCallback(
GUI::Radio::addConstellationIQ);
Communications::Radio::start();

GUI::GUI::run();
GUI::GUI::run();

Communications::Radio::stop();
GUI::GUI::deinit();
Communications::Radio::stop();
GUI::GUI::deinit(); */
} catch (const std::exception & e) {
spdlog::error(e.what());
return -1;
}

/*
//Testing separate systems will occur here.
*///Use F5 to compile and run code.
spdlog::info("Cougs in Space Ground complete");
spdlog::default_logger()->flush();
return 0;
Expand Down