.idea
archive
arduino
automation
bsp_egse
bsp_hosted
bsp_linux_board
bsp_q7s
bsp_te0720_1cfa
cmake
common
doc
dummies
fsfw
generators
hooks
linux
misc
mission
cfdp
config
controller
core
csp
devices
devicedefinitions
BpxBatteryDefinitions.h
CMakeLists.txt
GPSDefinitions.h
GomSpacePackets.h
GomspaceDefinitions.h
GyroADIS1650XDefinitions.h
GyroL3GD20Definitions.h
Max31865Definitions.h
RadSensorDefinitions.h
ScexDefinitions.cpp
ScexDefinitions.h
SpBase.h
SusDefinitions.h
SyrlinksDefinitions.h
Tmp1075Definitions.h
gomspaceDefines.h
imtqHelpers.cpp
imtqHelpers.h
payloadPcduDefinitions.h
powerDefinitions.h
rwHelpers.cpp
rwHelpers.h
ACUHandler.cpp
ACUHandler.h
BpxBatteryHandler.cpp
BpxBatteryHandler.h
CMakeLists.txt
GPSHyperionHandler.cpp
GPSHyperionHandler.h
GomspaceDeviceHandler.cpp
GomspaceDeviceHandler.h
GyroADIS1650XHandler.cpp
GyroADIS1650XHandler.h
HeaterHandler.cpp
HeaterHandler.h
ImtqHandler.cpp
ImtqHandler.h
Max31865EiveHandler.cpp
Max31865EiveHandler.h
Max31865PT1000Handler.cpp
Max31865PT1000Handler.h
P60DockHandler.cpp
P60DockHandler.h
PDU1Handler.cpp
PDU1Handler.h
PDU2Handler.cpp
PDU2Handler.h
PayloadPcduHandler.cpp
PayloadPcduHandler.h
PcduHandler.cpp
PcduHandler.h
RadiationSensorHandler.cpp
RadiationSensorHandler.h
RwHandler.cpp
RwHandler.h
ScexDeviceHandler.cpp
ScexDeviceHandler.h
SolarArrayDeploymentHandler.cpp
SolarArrayDeploymentHandler.h
SusHandler.cpp
SusHandler.h
SyrlinksHandler.cpp
SyrlinksHandler.h
Tmp1075Handler.cpp
Tmp1075Handler.h
max1227.cpp
max1227.h
memory
system
tmtc
utility
CMakeLists.txt
acsDefs.cpp
acsDefs.h
comDefs.h
mission.mk
trace.cpp
trace.h
scripts
test
thirdparty
tmtc
unittest
watchdog
.clang-format
.dockerignore
.gitignore
.gitmodules
CHANGELOG.md
CMakeLists.txt
Justfile
LICENSE
NOTICE
README.md
clone-submodules-no-privlibs.sh
docker-compose.yml
q7s-env-em.sh
q7s-env.sh
release_checklist.md
36 lines
1.4 KiB
C++
36 lines
1.4 KiB
C++
#include "ScexDefinitions.h"
|
|
|
|
#include <fsfw/globalfunctions/CRC.h>
|
|
|
|
#include <cstring>
|
|
|
|
uint8_t scex::createCmdByte(Cmds cmd, bool tempCheck) {
|
|
return (IDLE_BIT_0_DEF_STATE << 7) | (IDLE_BIT_1_DEF_STATE << 6) | (cmd << 1) | tempCheck;
|
|
}
|
|
|
|
ReturnValue_t scex::prepareScexCmd(Cmds cmd, std::pair<uint8_t*, size_t> cmdBufPair, size_t& cmdLen,
|
|
std::pair<const uint8_t*, size_t> usrDataPair, bool tempCheck) {
|
|
using namespace scex;
|
|
uint8_t* cmdBuf = cmdBufPair.first;
|
|
const uint8_t* userData = usrDataPair.first;
|
|
// Send command
|
|
if (cmdBuf == nullptr or (cmdBufPair.second < usrDataPair.second + HEADER_LEN + CRC_LEN) or
|
|
(usrDataPair.second > 0 and userData == nullptr)) {
|
|
cmdLen = 0;
|
|
return returnvalue::FAILED;
|
|
}
|
|
cmdBuf[0] = createCmdByte(cmd, tempCheck);
|
|
// These two fields are the packet counter and the total packet count. Those are 1 and 1 for each
|
|
// telecommand so far
|
|
cmdBuf[1] = 1;
|
|
cmdBuf[2] = 1;
|
|
cmdBuf[3] = (usrDataPair.second >> 8) & 0xff;
|
|
cmdBuf[4] = usrDataPair.second & 0xff;
|
|
std::memcpy(cmdBuf + HEADER_LEN, userData, usrDataPair.second);
|
|
uint16_t crc = CRC::crc16ccitt(cmdBuf, usrDataPair.second + HEADER_LEN);
|
|
cmdBuf[usrDataPair.second + HEADER_LEN] = (crc >> 8) & 0xff;
|
|
cmdBuf[usrDataPair.second + HEADER_LEN + 1] = crc & 0xff;
|
|
cmdLen = usrDataPair.second + HEADER_LEN + CRC_LEN;
|
|
return returnvalue::OK;
|
|
}
|