diff --git a/FSW-rtems/FSW-rtems.cbp b/FSW-rtems/FSW-rtems.cbp
--- a/FSW-rtems/FSW-rtems.cbp
+++ b/FSW-rtems/FSW-rtems.cbp
@@ -7,20 +7,20 @@
-
-
+
+
-
+
-
-
+
+
-
-
+
+
@@ -34,11 +34,16 @@
-
-
+
+
+
+
-
+
+
+
+
diff --git a/FSW-rtems/FSW-rtems.depend b/FSW-rtems/FSW-rtems.depend
--- a/FSW-rtems/FSW-rtems.depend
+++ b/FSW-rtems/FSW-rtems.depend
@@ -1,4 +1,4 @@
-# depslib dependency file v1.0
+# depslib dependency file v1.0
1355231335 source:e:\missions\solo\dev_ple\src\fsw-rtems.c
@@ -13,25 +13,67 @@ 1355231335 source:e:\missions\solo\dev_p
-
+
+1355231335 -processing.h>
+
1350983928 source:e:\missions\solo\dev_ple\src\grspw.c
<..\header\grspw.h>
-
+
+1354190601
+
1350983928 e:\missions\solo\dev_ple\header\grspw.h
-
+
1351173364 source:e:\missions\solo\dev_ple\src\fsw-config.c
-
+
+1354190602 bapp_bus.h>
+
1354190602 e:\missions\solo\dev_ple\src\fsw-config.c
-
+
1354190602 source:e:\missions\solo\dev_ple\src\fsw-rtems-processing.c
-
+
1354190601 e:\missions\solo\dev_ple\header\fsw-rtems-processing.h
-
+
+1358144203 source:/opt/DEV_PLE/src/FSW-rtems-processing.c
+
+
+
+
+
+1358144202 /opt/DEV_PLE/header/FSW-rtems-processing.h
+
+
+1358441917 source:/opt/DEV_PLE/src/FSW-rtems.c
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1358144203 /opt/DEV_PLE/src/FSW-config.c
+
+
+1358441070 source:/opt/DEV_PLE/src/TC_handler.c
+
+
+1358435124 /opt/DEV_PLE/header/TC_handler.h
+
+
+1358440633 /opt/DEV_PLE/header/ccsds_types.h
+
diff --git a/FSW-rtems/FSW-rtems.layout b/FSW-rtems/FSW-rtems.layout
--- a/FSW-rtems/FSW-rtems.layout
+++ b/FSW-rtems/FSW-rtems.layout
@@ -1,13 +1,22 @@
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
diff --git a/header/TC_handler.h b/header/TC_handler.h
--- a/header/TC_handler.h
+++ b/header/TC_handler.h
@@ -1,8 +1,22 @@
#ifndef TC_HANDLER_H_INCLUDED
#define TC_HANDLER_H_INCLUDED
-#include <..\header\ccsds_types.h>
+#include
+
+unsigned char currentTC_LEN_RCV[2]; // SHALL be equal to the current TC packet estimated packet length field
+unsigned char currentTC_COMPUTED_CRC[2];
+unsigned int currentTC_LEN_RCV_AsUnsignedInt;
+unsigned int currentTM_length;
+ccsdsTelemetryPacket_t currentTM;
+ccsdsTelecommandPacket_t currentTC;
+unsigned char currentTC_processedFlag;
+
+unsigned int lookUpTableForCRC[256];
+void InitLookUpTableForCRC();
+void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
-char TM_checker(ccsdsTelecommandSourcePacketHeader_t * TMPacket);
+unsigned char TM_checker(ccsdsTelecommandPacket_t * TMPacket);
+unsigned char TM_acceptance_generator(ccsdsTelecommandPacket_t * TCPacket, unsigned int code, ccsdsTelemetryPacket_t * TMPacket);
+unsigned char TM_not_implemented_generator(ccsdsTelecommandPacket_t * TCPacket, ccsdsTelemetryPacket_t * TMPacket);
#endif // TC_HANDLER_H_INCLUDED
diff --git a/header/ccsds_types.h b/header/ccsds_types.h
--- a/header/ccsds_types.h
+++ b/header/ccsds_types.h
@@ -1,68 +1,63 @@
#ifndef CCSDS_H_INCLUDED
#define CCSDS_H_INCLUDED
-#define CCSDS_TELEMETRY_HEADER_LENGTH 16+4
+#define CCSDS_TELEMETRY_HEADER_LENGTH 16+4
+#define CCSDS_TM_PKT_MAX_SIZE 4412
#define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4
-#define CCSDS_TELECOMMAND_MAX_PACKET_LENGTH 248
-#define CCSDS_PROCESS_ID 11
-#define CCSDS_PACKET_CATEGORY 12
-
-#define CCSDS_ERR_PID -1
-#define CCSDS_ERR_CAT -2
-#define CCSDS_ERR_LENGTH -3
-#define CCSDS_ERR_TYPE -4
-#define CCSDS_ERR_SUBTYPE -5
-#define CCSDS_ERR_SRC -6
-#define CCSDS_ERR_CRC -7
-#define CCSDS_TM_VALID 1
+#define CCSDS_TC_PKT_MAX_SIZE 248
+#define CCSDS_TC_TM_PACKET_OFFSET 7
+#define CCSDS_PROCESS_ID 76
+#define CCSDS_PACKET_CATEGORY 12
+#define CCSDS_DESTINATION_ID 0x21
+
+#define SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED 24
+#define SIZE_TM_LFR_TC_EXE_CORRUPTED 32
-struct ccsdsTelemetrySourcePacketHeader_str
-{
- unsigned char targetLogicalAddress;
- unsigned char protocolIdentifier;
- unsigned char reserved;
- unsigned char userApplication;
- unsigned char packetID[2];
- unsigned char packetSequenceControl[2];
- unsigned char packetLength[2];
- unsigned char dataFieldHeader[10];
-};
-typedef struct ccsdsTelemetrySourcePacketHeader_str ccsdsTelemetrySourcePacketHeader_t;
+#define ILLEGAL_APID 0
+#define WRONG_LEN_PACKET 1
+#define INCOR_CHECKSUM 2
+#define ILL_TYPE 3
+#define ILL_SUBTYPE 4
+#define WRONG_APP_DATA 5
+#define WRONG_CMD_CODE 6
+#define CCSDS_TM_VALID 7
+//
+#define TC_NOT_EXE 40000
+#define WRONG_SRC_ID 40001
+#define FUNCT_NOT_IMPL 40002
+#define FAIL_DETECTED 40003
+#define NOT_ALLOWED 40004
+#define CORRUPTED 40005
+//
+#define CCSDS_ERR_SRC 8
+#define CCSDS_ERR_CAT 9
-struct ccsdsTelecommandSourcePacketHeader_str
+struct ccsdsTelemetryPacket_str
{
- unsigned char targetLogicalAddress;
- unsigned char protocolIdentifier;
- unsigned char reserved;
- unsigned char userApplication;
- unsigned char packetID[2];
- unsigned char packetSequenceControl[2];
- unsigned char packetLength[2];
- unsigned char dataFieldHeader[4];
+ volatile unsigned char targetLogicalAddress;
+ volatile unsigned char protocolIdentifier;
+ volatile unsigned char reserved;
+ volatile unsigned char userApplication;
+ volatile unsigned char packetID[2];
+ volatile unsigned char packetSequenceControl[2];
+ volatile unsigned char packetLength[2];
+ volatile unsigned char dataFieldHeader[10];
+ volatile unsigned char data[CCSDS_TM_PKT_MAX_SIZE-16];
};
-typedef struct ccsdsTelemetrySourcePacketHeader_str ccsdsTelecommandSourcePacketHeader_t;
+typedef struct ccsdsTelemetryPacket_str ccsdsTelemetryPacket_t;
-// initialize the ccsds telemetry header
-ccsdsTelemetrySourcePacketHeader_t ccsdsTelemetryHeader;
-#define INIT_CCSDS_TELEMETRY_HEADER ccsdsTelemetryHeader.targetLogicalAddress = 0x21; \
-ccsdsTelemetryHeader.protocolIdentifier = 0x02; \
-ccsdsTelemetryHeader.reserved = 0x00; \
-ccsdsTelemetryHeader.userApplication = 0x00; \
-ccsdsTelemetryHeader.packetID[0] = 0x08; \
-ccsdsTelemetryHeader.packetID[1] = 0xbc; \
-ccsdsTelemetryHeader.packetSequenceControl[0] = 0xc0; \
-ccsdsTelemetryHeader.packetSequenceControl[1] = 0x00; \
-ccsdsTelemetryHeader.packetLength[0] = 0x00; \
-ccsdsTelemetryHeader.packetLength[1] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[0] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[1] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[2] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[3] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[4] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[5] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[6] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[7] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[8] = 0x00; \
-ccsdsTelemetryHeader.dataFieldHeader[9] = 0x00;
+struct ccsdsTelecommandPacket_str
+{
+ //unsigned char targetLogicalAddress;
+ volatile unsigned char protocolIdentifier;
+ volatile unsigned char reserved;
+ volatile unsigned char userApplication;
+ volatile unsigned char packetID[2];
+ volatile unsigned char packetSequenceControl[2];
+ volatile unsigned char packetLength[2];
+ volatile unsigned char dataFieldHeader[4];
+ volatile unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10];
+};
+typedef struct ccsdsTelecommandPacket_str ccsdsTelecommandPacket_t;
#endif // CCSDS_H_INCLUDED
diff --git a/src/FSW-rtems.c b/src/FSW-rtems.c
--- a/src/FSW-rtems.c
+++ b/src/FSW-rtems.c
@@ -2,20 +2,18 @@
// GPL reminder to be added
//*************************
-#define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions
+//#define PRINT_MESSAGES_ON_CONSOLE // enable or disable the printf instructions
#ifdef PRINT_MESSAGES_ON_CONSOLE
#define PRINTF(x) printf(x);
#define PRINTF1(x,y) printf(x,y);
#define PRINTF2(x,y,z) printf(x,y,z);
#else
-#define PRINTF(x)
-#define PRINTF1(x,y)
-#define PRINTF2(x,y,z)
+#define PRINTF(x) ;
+#define PRINTF1(x,y) ;
+#define PRINTF2(x,y,z) ;
#endif
-#define CCSDS_TC_PKT_MAX_SIZE 500 // 248
-#define CCSDS_TM_PKT_MAX_SIZE 4412
-#define OFFSET_COARSE_TIME 4+10-1 // -1 => the receiver suppressed the target logical address
+#define OFFSET_COARSE_TIME 4+10-1 // -1 => the receiver suppresses the target logical address
#define OFFSET_FINE_TIME OFFSET_COARSE_TIME+4
#define TC_FIFO_SIZE 5
@@ -71,8 +69,23 @@
#include
#include
-#include
+#include
+#include
#include
+
+char *errorCCSDSMsg[8] = { "ILLEGAL_APID 0",
+ "WRONG_LEN_PACKET 1",
+ "INCOR_CHECKSUM 2",
+ "ILL_TYPE 3",
+ "ILL_SUBTYPE 4",
+ "WRONG_APP_DATA 5",
+ "WRONG_CMD_CODE 6",
+ "CCSDS_TM_VALID 7"
+};
+
+char *tmGeneratorMsg[2] = { "NOTHING_TO_DO",
+ "TM_GENERATED"
+};
rtems_task Init( rtems_task_argument argument); /* forward declaration needed */
rtems_task spw_recv_task(rtems_task_argument argument);
@@ -124,8 +137,7 @@ rtems_id sem_tc_fifo_id;
rtems_task Init( rtems_task_argument ignored ) {
rtems_status_code status;
- struct apbuart_regs_str *apbuart_regs;
- int i;
+ //struct apbuart_regs_str *apbuart_regs;
rtems_isr_entry old_isr_handler;
Task_name[1] = rtems_build_name( 'R', 'E', 'C', 'V' );
@@ -190,28 +202,19 @@ rtems_task Init( rtems_task_argument ign
//********************************************
// Send the console outputs on the serial port
- apbuart_regs = (struct apbuart_regs_str *) ADDRESS_APBUART_REGISTERS;
- apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB;
- PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
+ //apbuart_regs = (struct apbuart_regs_str *) ADDRESS_APBUART_REGISTERS;
+ //apbuart_regs->ctrl = apbuart_regs->ctrl & APBUART_CTRL_REG_MASK_DB;
+ //PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
//
//********************************************
configure_spw_link();
- for (i = 0; i -3 is for Prot ID, Reserved and User App bytes
+ status = rtems_event_send( Task_id[2], RTEMS_EVENT_0 ); // sending an event to the task TCCK
+ if (status == RTEMS_INVALID_ID) PRINTF("IN TASK RECV *** invalid task id when sending RTEMS_EVENT_0\n")
+ }
+ }
+
+ close(fdSPW);
}
rtems_task spw_tcck_task( rtems_task_argument unused ) {
rtems_status_code status;
- rtems_event_set event_out;
+ rtems_event_set event_out;
+ unsigned char result;
+ unsigned int code;
PRINTF("In TCCK ***\n")
while(1){
- status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out);
+ status = rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an event to process a TC packet
if (status == RTEMS_SUCCESSFUL)
- {
- while(tc_being_processed->ready==1){
- printf("In TCCK *** COARSE TIME 0x%x 0x%x 0x%x 0x%x FINE_TIME 0x%x 0x%x\n",
- tc_being_processed->tc_pkt[OFFSET_COARSE_TIME],
- tc_being_processed->tc_pkt[OFFSET_COARSE_TIME+1],
- tc_being_processed->tc_pkt[OFFSET_COARSE_TIME+2],
- tc_being_processed->tc_pkt[OFFSET_COARSE_TIME+3],
- tc_being_processed->tc_pkt[OFFSET_FINE_TIME],
- tc_being_processed->tc_pkt[OFFSET_FINE_TIME+1]);
- tc_being_processed->ready = 0;
- tc_being_processed = tc_being_processed->next;
- }
- }
+ {
+ GetCRCAsTwoBytes((unsigned char*)currentTC.packetID, currentTC_COMPUTED_CRC, currentTC_LEN_RCV_AsUnsignedInt + 5);
+ code = TM_checker(¤tTC);
+ PRINTF1(" %s\n", errorCCSDSMsg[code])
+ if (code == 7){ // if the TC is valid, the TM_LFR_TC_EXE_NOT_IMPLEMENTED packet is sent
+ result = TM_not_implemented_generator(¤tTC, ¤tTM);
+ PRINTF1(" %s\n", tmGeneratorMsg[result])
+ result = write( fdSPW, (char*)¤tTM, currentTM_length );
+ if (result==-1) printf("IN TCCK *** error sending TM of size: %d\n", currentTM_length);
+ }
+ else{ // if the TC is not valid, the TM_LFR_TC_EXE_CORRUPTED is sent
+ result = TM_acceptance_generator(¤tTC, code, ¤tTM);
+ PRINTF1(" %s\n", tmGeneratorMsg[result])
+ result = write( fdSPW, (char*)¤tTM, currentTM_length );
+ if (result==-1) printf("IN TCCK *** error sending TM of size: %d\n", currentTM_length);
+ }
+
+ currentTC_processedFlag = 1;
+ }
}
}
@@ -373,15 +418,23 @@ int configure_spw_link()
// sets a few parameters of the link
status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RMAPEN, 1); // sets the RMAP enable bit
- if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
- ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
- if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
- ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a
- if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
- ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
- if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
- ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
- if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
+ if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RMAPEN\n")
+ //
+ status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
+ if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
+ //
+ status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[3]); // sets the task ID to which an event is sent when a
+ if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
+ //
+ status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 1); // automatic link-disabling due to link-error interrupts
+ if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
+ //
+ status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
+ if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
+ //
+ //status = ioctl(fdSPW, SPACEWIRE_IOCTRL_SET_DESTKEY, CCSDS_DESTINATION_ID); // sets the destinatino key
+ //if (status!=RTEMS_SUCCESSFUL) PRINTF("In RECV *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
+ //
PRINTF("In configure_spw_link *** "GRSPW_DEVICE_NAME" configured successfully\n")
return RTEMS_SUCCESSFUL;
diff --git a/src/TC_handler.c b/src/TC_handler.c
--- a/src/TC_handler.c
+++ b/src/TC_handler.c
@@ -1,74 +1,207 @@
-#include <..\header\TC_handler.h>
-
-char TM_checker(ccsdsTelecommandSourcePacketHeader_t * TMPacket)
+#include
+
+unsigned int Crc_opt( unsigned char D, unsigned int Chk)
+{
+ return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
+}
+
+void InitLookUpTableForCRC()
+{
+ unsigned int i, tmp;
+ for (i=0; i<256; i++)
+ {
+ tmp = 0;
+ if((i & 1) != 0) tmp = tmp ^ 0x1021;
+ if((i & 2) != 0) tmp = tmp ^ 0x2042;
+ if((i & 4) != 0) tmp = tmp ^ 0x4084;
+ if((i & 8) != 0) tmp = tmp ^ 0x8108;
+ if((i & 16) != 0) tmp = tmp ^ 0x1231;
+ if((i & 32) != 0) tmp = tmp ^ 0x2462;
+ if((i & 64) != 0) tmp = tmp ^ 0x48c4;
+ if((i & 128) != 0) tmp = tmp ^ 0x9188;
+ lookUpTableForCRC[i] = tmp;
+ }
+}
+
+void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData){
+ unsigned int Chk;
+ int j;
+ Chk = 0xffff; // reset the syndrom to all ones
+ for (j=0; j> 8);
+ crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
+}
+
+unsigned char TM_checker(ccsdsTelecommandPacket_t * TMPacket)
{
unsigned char pid = 0;
unsigned char category = 0;
- unsigned int length = 0;
+ unsigned int length = 0;
+ unsigned char packetType = 0;
+ unsigned char packetSubtype = 0;
+ unsigned char * CCSDSContent;
// APID check *** APID on 2 bytes
pid = ((TMPacket->packetID[0] & 0x07)<<4) + ( (TMPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
category = (TMPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
- if (pid!=CCSDS_PROCESS_ID) return CCSDS_ERR_PID;
- if (category!=CCSDS_PACKET_CATEGORY) return CCSDS_ERR_CAT;
+ if (pid!=CCSDS_PROCESS_ID) return ILLEGAL_APID;
+ if (category!=CCSDS_PACKET_CATEGORY) return ILLEGAL_APID;
// packet length check
- length = TMPacket->packetLength[1] + TMPacket->packetLength[0] * 256;
- if (category<=CCSDS_TELECOMMAND_MAX_PACKET_LENGTH) return CCSDS_ERR_LENGTH; // check that the packet does not exceed the MAX size
-
- // service type, subtype and packet length check
- switch(TMPacket->dataFieldHeader[1]) { // service type, authorized values are 181 and 9
- case 181:
- switch(TMPacket->dataFieldHeader[2]){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
- case 3:
- if (length!=12) return CCSDS_ERR_LENGTH;
- break;
- case 20:
- if (length!=14) return CCSDS_ERR_LENGTH;
- break;
- case 21:
- if (length!=20) return CCSDS_ERR_LENGTH;
- break;
- case 24:
- if (length!=14) return CCSDS_ERR_LENGTH;
- break;
- case 27:
- if (length!=14) return CCSDS_ERR_LENGTH;
- break;
- case 28:
- if (length!=14) return CCSDS_ERR_LENGTH;
- break;
- case 30:
- if (length!=12) return CCSDS_ERR_LENGTH;
- break;
- case 40:
- if (length!=20) return CCSDS_ERR_LENGTH;
- break;
- case 50:
- if (length!=50) return CCSDS_ERR_LENGTH;
- break;
- case 60:
- if (length!=12) return CCSDS_ERR_LENGTH;
- break;
- case 61:
- if (length!=12) return CCSDS_ERR_LENGTH;
- break;
- default:
- return CCSDS_ERR_SUBTYPE;
- break;
- }
- case 9:
- if (TMPacket->dataFieldHeader[2]==129) return CCSDS_ERR_SUBTYPE;
- if (length!=18) return CCSDS_ERR_LENGTH;
- break;
- default:
- return CCSDS_ERR_TYPE;
- break;
- }
+ length = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
+ if (length != (currentTC_LEN_RCV[0] * 256 + currentTC_LEN_RCV[1]) ) return WRONG_LEN_PACKET; // LEN RCV != SIZE FIELD
+ if (length >= CCSDS_TC_PKT_MAX_SIZE) return WRONG_LEN_PACKET; // check that the packet does not exceed the MAX size
+
+ packetType = TMPacket->dataFieldHeader[1];
+ packetSubtype = TMPacket->dataFieldHeader[2];
+ // service type, subtype and packet length check
+ if (packetType == 181){
+ switch(packetSubtype){ //subtype, autorized values are 3, 20, 21, 24, 27, 28, 30, 40, 50, 60, 61
+ case 3:
+ if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 20:
+ if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 21:
+ if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 24:
+ if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 27:
+ if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 28:
+ if (length!=(14-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 30:
+ if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 40:
+ if (length!=(20-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 50:
+ if (length!=(50-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 60:
+ if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ case 61:
+ if (length!=(12-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ break;
+ default:
+ return ILL_SUBTYPE;
+ break;
+ }
+ }
+ else if (packetType == 9){
+ if (packetSubtype!=129) return ILL_SUBTYPE;
+ if (length!=(18-CCSDS_TC_TM_PACKET_OFFSET)) return WRONG_LEN_PACKET;
+ }
+ else return ILL_TYPE;
// source ID check // Source ID not documented in the ICD
- // packet error control, CRC check
+ // packet error control, CRC check
+ CCSDSContent = (unsigned char*) TMPacket->packetID;
+ GetCRCAsTwoBytes(CCSDSContent, currentTC_COMPUTED_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
+ if (currentTC_COMPUTED_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) return INCOR_CHECKSUM;
+ if (currentTC_COMPUTED_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) return INCOR_CHECKSUM;
return CCSDS_TM_VALID;
}
+
+unsigned char TM_acceptance_generator(ccsdsTelecommandPacket_t * TCPacket, unsigned int code, ccsdsTelemetryPacket_t * TMPacket)
+{
+ unsigned int packetLength = 0;
+ packetLength = TMPacket->packetLength[0] * 256 + TMPacket->packetLength[1];
+ if ( (code == 0) | (code == 1) | (code == 2)
+ | (code == 3) | (code == 4) | (code == 5) )
+ { // generated TM_LFR_TC_EXE_CORRUPTED
+ TMPacket->targetLogicalAddress = CCSDS_DESTINATION_ID;
+ TMPacket->protocolIdentifier = 0x02;
+ TMPacket->reserved = 0x00;
+ TMPacket->userApplication = 0x00;
+ //
+ TMPacket->packetID[0] = 0x0c;
+ TMPacket->packetID[1] = 0xc1;
+ TMPacket->packetSequenceControl[0] = 0xc0;
+ TMPacket->packetSequenceControl[1] = 0x00;
+ TMPacket->packetLength[0] = 0x00;
+ TMPacket->packetLength[1] = SIZE_TM_LFR_TC_EXE_CORRUPTED-CCSDS_TC_TM_PACKET_OFFSET;
+ //
+ TMPacket->dataFieldHeader[0] = 0x10;
+ TMPacket->dataFieldHeader[1] = 0x01; // service type
+ TMPacket->dataFieldHeader[2] = 0x08; // service subtype
+ TMPacket->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
+ TMPacket->dataFieldHeader[4] = 0x00; // time
+ TMPacket->dataFieldHeader[5] = 0x00; // time
+ TMPacket->dataFieldHeader[6] = 0x00; // time
+ TMPacket->dataFieldHeader[7] = 0x00; // time
+ TMPacket->dataFieldHeader[8] = 0x00; // time
+ TMPacket->dataFieldHeader[9] = 0x00; // time
+ //
+ TMPacket->data[0] = 0x9c; // failure code
+ TMPacket->data[1] = 0x45; // failure code
+ TMPacket->data[2] = TCPacket->packetID[0];
+ TMPacket->data[3] = TCPacket->packetID[1];
+ TMPacket->data[4] = TCPacket->packetSequenceControl[0];
+ TMPacket->data[5] = TCPacket->packetSequenceControl[1];
+ TMPacket->data[6] = TCPacket->dataFieldHeader[1]; // type
+ TMPacket->data[7] = TCPacket->dataFieldHeader[2]; // subtype
+ TMPacket->data[8] = currentTC_LEN_RCV[0];
+ TMPacket->data[9] = currentTC_LEN_RCV[1];
+ TMPacket->data[10] = TCPacket->packetLength[0];
+ TMPacket->data[11] = TCPacket->packetLength[1];
+ TMPacket->data[12] = TCPacket->dataAndCRC[packetLength];
+ TMPacket->data[13] = TCPacket->dataAndCRC[packetLength+1];
+ TMPacket->data[14] = currentTC_COMPUTED_CRC[0];
+ TMPacket->data[15] = currentTC_COMPUTED_CRC[1];
+ //
+ currentTM_length = SIZE_TM_LFR_TC_EXE_CORRUPTED-CCSDS_TC_TM_PACKET_OFFSET;
+ }
+ else return 0;
+ return 1;
+}
+
+unsigned char TM_not_implemented_generator(ccsdsTelecommandPacket_t * TCPacket, ccsdsTelemetryPacket_t * TMPacket)
+{
+ TMPacket->targetLogicalAddress = CCSDS_DESTINATION_ID;
+ TMPacket->protocolIdentifier = 0x02;
+ TMPacket->reserved = 0x00;
+ TMPacket->userApplication = 0x00;
+ //
+ TMPacket->packetID[0] = 0x0c;
+ TMPacket->packetID[1] = 0xc1;
+ TMPacket->packetSequenceControl[0] = 0xc0;
+ TMPacket->packetSequenceControl[1] = 0x00;
+ TMPacket->packetLength[0] = 0x00;
+ TMPacket->packetLength[1] = SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED-CCSDS_TC_TM_PACKET_OFFSET;
+ //
+ TMPacket->dataFieldHeader[0] = 0x10;
+ TMPacket->dataFieldHeader[1] = 0x01; // service type
+ TMPacket->dataFieldHeader[2] = 0x08; // service subtype
+ TMPacket->dataFieldHeader[3] = CCSDS_DESTINATION_ID;
+ TMPacket->dataFieldHeader[4] = 0x00; // time
+ TMPacket->dataFieldHeader[5] = 0x00; // time
+ TMPacket->dataFieldHeader[6] = 0x00; // time
+ TMPacket->dataFieldHeader[7] = 0x00; // time
+ TMPacket->dataFieldHeader[8] = 0x00; // time
+ TMPacket->dataFieldHeader[9] = 0x00; // time
+ //
+ TMPacket->data[0] = 0x9c; // failure code
+ TMPacket->data[1] = 0x42; // failure code
+ TMPacket->data[2] = TCPacket->packetID[0];
+ TMPacket->data[3] = TCPacket->packetID[1];
+ TMPacket->data[4] = TCPacket->packetSequenceControl[0];
+ TMPacket->data[5] = TCPacket->packetSequenceControl[1];
+ TMPacket->data[6] = TCPacket->dataFieldHeader[1]; // type
+ TMPacket->data[7] = TCPacket->dataFieldHeader[2]; // subtype
+ //
+ currentTM_length = SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED-CCSDS_TC_TM_PACKET_OFFSET;
+
+ return 1;
+}