diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..d03417e3 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -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 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..195842c2 --- /dev/null +++ b/.vscode/launch.json @@ -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 + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..9f79b26d --- /dev/null +++ b/.vscode/tasks.json @@ -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 + } + } + ] +} \ No newline at end of file diff --git a/CISLibrary/components/communications/Frame.h b/CISLibrary/components/communications/Frame.h index 23c70322..e803060b 100644 --- a/CISLibrary/components/communications/Frame.h +++ b/CISLibrary/components/communications/Frame.h @@ -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 @@ -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_ */ \ No newline at end of file diff --git a/CISLibrary/components/communications/IQSource/IQSource.h b/CISLibrary/components/communications/IQSource/IQSource.h index a3fe207d..bebaee97 100644 --- a/CISLibrary/components/communications/IQSource/IQSource.h +++ b/CISLibrary/components/communications/IQSource/IQSource.h @@ -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 @@ -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 * @@ -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_ */ \ No newline at end of file diff --git a/CISLibrary/components/communications/Packet.h b/CISLibrary/components/communications/Packet.h index e69de29b..d22966f8 100644 --- a/CISLibrary/components/communications/Packet.h +++ b/CISLibrary/components/communications/Packet.h @@ -0,0 +1,150 @@ +#include +#include + +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= 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()); +} diff --git a/CougSat1-Ground/source/main.cpp b/CougSat1-Ground/source/main.cpp index 5f179b33..376f0d99 100644 --- a/CougSat1-Ground/source/main.cpp +++ b/CougSat1-Ground/source/main.cpp @@ -8,10 +8,12 @@ #include +#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 @@ -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;