##// END OF EJS Templates
Removed commented code
jeandet -
r376:30b34f0fbdfa No PWD scrub with... draft
parent child
Show More
@@ -1,112 +1,112
1 cmake_minimum_required (VERSION 2.6)
1 cmake_minimum_required (VERSION 2.6)
2 project (fsw)
2 project (fsw)
3
3
4 include(sparc-rtems)
4 include(sparc-rtems)
5 include(cppcheck)
5 include(cppcheck)
6
6
7 include_directories("../header"
7 include_directories("../header"
8 "../header/lfr_common_headers"
8 "../header/lfr_common_headers"
9 "../header/processing"
9 "../header/processing"
10 "../LFR_basic-parameters"
10 "../LFR_basic-parameters"
11 "../src")
11 "../src")
12
12
13 set(SOURCES wf_handler.c
13 set(SOURCES wf_handler.c
14 tc_handler.c
14 tc_handler.c
15 fsw_misc.c
15 fsw_misc.c
16 fsw_init.c
16 fsw_init.c
17 fsw_globals.c
17 fsw_globals.c
18 fsw_spacewire.c
18 fsw_spacewire.c
19 tc_load_dump_parameters.c
19 tc_load_dump_parameters.c
20 tm_lfr_tc_exe.c
20 tm_lfr_tc_exe.c
21 tc_acceptance.c
21 tc_acceptance.c
22 processing/fsw_processing.c
22 processing/fsw_processing.c
23 processing/avf0_prc0.c
23 processing/avf0_prc0.c
24 processing/avf1_prc1.c
24 processing/avf1_prc1.c
25 processing/avf2_prc2.c
25 processing/avf2_prc2.c
26 lfr_cpu_usage_report.c
26 lfr_cpu_usage_report.c
27 ${LFR_BP_SRC}
27 ${LFR_BP_SRC}
28 ../header/wf_handler.h
28 ../header/wf_handler.h
29 ../header/tc_handler.h
29 ../header/tc_handler.h
30 ../header/grlib_regs.h
30 ../header/grlib_regs.h
31 ../header/fsw_misc.h
31 ../header/fsw_misc.h
32 ../header/fsw_init.h
32 ../header/fsw_init.h
33 ../header/fsw_spacewire.h
33 ../header/fsw_spacewire.h
34 ../header/tc_load_dump_parameters.h
34 ../header/tc_load_dump_parameters.h
35 ../header/tm_lfr_tc_exe.h
35 ../header/tm_lfr_tc_exe.h
36 ../header/tc_acceptance.h
36 ../header/tc_acceptance.h
37 ../header/processing/fsw_processing.h
37 ../header/processing/fsw_processing.h
38 ../header/processing/avf0_prc0.h
38 ../header/processing/avf0_prc0.h
39 ../header/processing/avf1_prc1.h
39 ../header/processing/avf1_prc1.h
40 ../header/processing/avf2_prc2.h
40 ../header/processing/avf2_prc2.h
41 ../header/fsw_params_wf_handler.h
41 ../header/fsw_params_wf_handler.h
42 ../header/lfr_cpu_usage_report.h
42 ../header/lfr_cpu_usage_report.h
43 ../header/lfr_common_headers/ccsds_types.h
43 ../header/lfr_common_headers/ccsds_types.h
44 ../header/lfr_common_headers/fsw_params.h
44 ../header/lfr_common_headers/fsw_params.h
45 ../header/lfr_common_headers/fsw_params_nb_bytes.h
45 ../header/lfr_common_headers/fsw_params_nb_bytes.h
46 ../header/lfr_common_headers/fsw_params_processing.h
46 ../header/lfr_common_headers/fsw_params_processing.h
47 ../header/lfr_common_headers/tm_byte_positions.h
47 ../header/lfr_common_headers/tm_byte_positions.h
48 ../LFR_basic-parameters/basic_parameters.h
48 ../LFR_basic-parameters/basic_parameters.h
49 ../LFR_basic-parameters/basic_parameters_params.h
49 ../LFR_basic-parameters/basic_parameters_params.h
50 ../header/GscMemoryLPP.hpp
50 ../header/GscMemoryLPP.hpp
51 )
51 )
52
52
53
53
54 option(FSW_verbose "Enable verbose LFR" OFF)
54 option(FSW_verbose "Enable verbose LFR" OFF)
55 option(FSW_boot_messages "Enable LFR boot messages" OFF)
55 option(FSW_boot_messages "Enable LFR boot messages" OFF)
56 option(FSW_debug_messages "Enable LFR debug messages" OFF)
56 option(FSW_debug_messages "Enable LFR debug messages" OFF)
57 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
57 option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF)
58 option(FSW_stack_report "Enable LFR stack report" OFF)
58 option(FSW_stack_report "Enable LFR stack report" OFF)
59 option(FSW_vhdl_dev "?" OFF)
59 option(FSW_vhdl_dev "?" OFF)
60 option(FSW_lpp_dpu_destid "Set to debug at LPP" OFF)
60 option(FSW_lpp_dpu_destid "Set to debug at LPP" OFF)
61 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
61 option(FSW_debug_watchdog "Enable debug watchdog" OFF)
62 option(FSW_debug_tch "?" OFF)
62 option(FSW_debug_tch "?" OFF)
63
63
64 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
64 set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE)
65 set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE)
65 set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE)
66 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
66 set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE)
67 set(SW_VERSION_N4 "15" CACHE STRING "Choose N4 FSW Version." FORCE)
67 set(SW_VERSION_N4 "16" CACHE STRING "Choose N4 FSW Version." FORCE)
68
68
69 if(FSW_verbose)
69 if(FSW_verbose)
70 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
70 add_definitions(-DPRINT_MESSAGES_ON_CONSOLE)
71 endif()
71 endif()
72 if(FSW_boot_messages)
72 if(FSW_boot_messages)
73 add_definitions(-DBOOT_MESSAGES)
73 add_definitions(-DBOOT_MESSAGES)
74 endif()
74 endif()
75 if(FSW_debug_messages)
75 if(FSW_debug_messages)
76 add_definitions(-DDEBUG_MESSAGES)
76 add_definitions(-DDEBUG_MESSAGES)
77 endif()
77 endif()
78 if(FSW_cpu_usage_report)
78 if(FSW_cpu_usage_report)
79 add_definitions(-DPRINT_TASK_STATISTICS)
79 add_definitions(-DPRINT_TASK_STATISTICS)
80 endif()
80 endif()
81 if(FSW_stack_report)
81 if(FSW_stack_report)
82 add_definitions(-DPRINT_STACK_REPORT)
82 add_definitions(-DPRINT_STACK_REPORT)
83 endif()
83 endif()
84 if(FSW_vhdl_dev)
84 if(FSW_vhdl_dev)
85 add_definitions(-DVHDL_DEV)
85 add_definitions(-DVHDL_DEV)
86 endif()
86 endif()
87 if(FSW_lpp_dpu_destid)
87 if(FSW_lpp_dpu_destid)
88 add_definitions(-DLPP_DPU_DESTID)
88 add_definitions(-DLPP_DPU_DESTID)
89 endif()
89 endif()
90 if(FSW_debug_watchdog)
90 if(FSW_debug_watchdog)
91 add_definitions(-DDEBUG_WATCHDOG)
91 add_definitions(-DDEBUG_WATCHDOG)
92 endif()
92 endif()
93 if(FSW_debug_tch)
93 if(FSW_debug_tch)
94 add_definitions(-DDEBUG_TCH)
94 add_definitions(-DDEBUG_TCH)
95 endif()
95 endif()
96
96
97 add_definitions(-DMSB_FIRST_TCH)
97 add_definitions(-DMSB_FIRST_TCH)
98
98
99 add_definitions(-DSWVERSION=-1-0)
99 add_definitions(-DSWVERSION=-1-0)
100 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
100 add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1})
101 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
101 add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2})
102 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
102 add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3})
103 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
103 add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4})
104
104
105 add_executable(fsw ${SOURCES})
105 add_executable(fsw ${SOURCES})
106
106
107 if(fix-b2bst)
107 if(fix-b2bst)
108 check_b2bst(fsw ${CMAKE_CURRENT_BINARY_DIR})
108 check_b2bst(fsw ${CMAKE_CURRENT_BINARY_DIR})
109 endif()
109 endif()
110
110
111 add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE)
111 add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE)
112
112
@@ -1,514 +1,512
1 /** Functions to send TM packets related to TC parsing and execution.
1 /** Functions to send TM packets related to TC parsing and execution.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to send appropriate TM packets after parsing and execution:
6 * A group of functions to send appropriate TM packets after parsing and execution:
7 * - TM_LFR_TC_EXE_SUCCESS
7 * - TM_LFR_TC_EXE_SUCCESS
8 * - TM_LFR_TC_EXE_INCONSISTENT
8 * - TM_LFR_TC_EXE_INCONSISTENT
9 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
9 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
10 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
10 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
11 * - TM_LFR_TC_EXE_ERROR
11 * - TM_LFR_TC_EXE_ERROR
12 * - TM_LFR_TC_EXE_CORRUPTED
12 * - TM_LFR_TC_EXE_CORRUPTED
13 *
13 *
14 */
14 */
15
15
16 #include "tm_lfr_tc_exe.h"
16 #include "tm_lfr_tc_exe.h"
17
17
18 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
18 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
19 {
19 {
20 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
20 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
21 *
21 *
22 * @param TC points to the TeleCommand packet that is being processed
22 * @param TC points to the TeleCommand packet that is being processed
23 * @param queue_id is the id of the queue which handles TM
23 * @param queue_id is the id of the queue which handles TM
24 *
24 *
25 * @return RTEMS directive status code:
25 * @return RTEMS directive status code:
26 * - RTEMS_SUCCESSFUL - message sent successfully
26 * - RTEMS_SUCCESSFUL - message sent successfully
27 * - RTEMS_INVALID_ID - invalid queue id
27 * - RTEMS_INVALID_ID - invalid queue id
28 * - RTEMS_INVALID_SIZE - invalid message size
28 * - RTEMS_INVALID_SIZE - invalid message size
29 * - RTEMS_INVALID_ADDRESS - buffer is NULL
29 * - RTEMS_INVALID_ADDRESS - buffer is NULL
30 * - RTEMS_UNSATISFIED - out of message buffers
30 * - RTEMS_UNSATISFIED - out of message buffers
31 * - RTEMS_TOO_MANY - queue s limit has been reached
31 * - RTEMS_TOO_MANY - queue s limit has been reached
32 *
32 *
33 */
33 */
34
34
35 rtems_status_code status;
35 rtems_status_code status;
36 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
36 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
37 unsigned char messageSize;
37 unsigned char messageSize;
38
38
39 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
39 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
40 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
40 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
41 TM.reserved = DEFAULT_RESERVED;
41 TM.reserved = DEFAULT_RESERVED;
42 TM.userApplication = CCSDS_USER_APP;
42 TM.userApplication = CCSDS_USER_APP;
43 // PACKET HEADER
43 // PACKET HEADER
44 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
44 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
45 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
45 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
46 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
46 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
47 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> SHIFT_1_BYTE);
47 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> SHIFT_1_BYTE);
48 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
48 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
49 // DATA FIELD HEADER
49 // DATA FIELD HEADER
50 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
50 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
51 TM.serviceType = TM_TYPE_TC_EXE;
51 TM.serviceType = TM_TYPE_TC_EXE;
52 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
52 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
53 TM.destinationID = TC->sourceID;
53 TM.destinationID = TC->sourceID;
54 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
54 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
55 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
55 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
56 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
56 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
57 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
57 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
58 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
58 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
59 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
59 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
60 //
60 //
61 TM.telecommand_pkt_id[0] = TC->packetID[0];
61 TM.telecommand_pkt_id[0] = TC->packetID[0];
62 TM.telecommand_pkt_id[1] = TC->packetID[1];
62 TM.telecommand_pkt_id[1] = TC->packetID[1];
63 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
63 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
64 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
64 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
65
65
66 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
66 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
67
67
68 // SEND DATA
68 // SEND DATA
69 status = rtems_message_queue_send( queue_id, &TM, messageSize);
69 status = rtems_message_queue_send( queue_id, &TM, messageSize);
70 if (status != RTEMS_SUCCESSFUL) {
70 if (status != RTEMS_SUCCESSFUL) {
71 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
71 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
72 }
72 }
73
73
74 // UPDATE HK FIELDS
74 // UPDATE HK FIELDS
75 update_last_TC_exe( TC, TM.time );
75 update_last_TC_exe( TC, TM.time );
76
76
77 return status;
77 return status;
78 }
78 }
79
79
80 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
80 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
81 unsigned char byte_position, unsigned char rcv_value )
81 unsigned char byte_position, unsigned char rcv_value )
82 {
82 {
83 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
83 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
84 *
84 *
85 * @param TC points to the TeleCommand packet that is being processed
85 * @param TC points to the TeleCommand packet that is being processed
86 * @param queue_id is the id of the queue which handles TM
86 * @param queue_id is the id of the queue which handles TM
87 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
87 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
88 * @param rcv_value is the value of the LSB of the parameter that has been detected as inconsistent
88 * @param rcv_value is the value of the LSB of the parameter that has been detected as inconsistent
89 *
89 *
90 * @return RTEMS directive status code:
90 * @return RTEMS directive status code:
91 * - RTEMS_SUCCESSFUL - message sent successfully
91 * - RTEMS_SUCCESSFUL - message sent successfully
92 * - RTEMS_INVALID_ID - invalid queue id
92 * - RTEMS_INVALID_ID - invalid queue id
93 * - RTEMS_INVALID_SIZE - invalid message size
93 * - RTEMS_INVALID_SIZE - invalid message size
94 * - RTEMS_INVALID_ADDRESS - buffer is NULL
94 * - RTEMS_INVALID_ADDRESS - buffer is NULL
95 * - RTEMS_UNSATISFIED - out of message buffers
95 * - RTEMS_UNSATISFIED - out of message buffers
96 * - RTEMS_TOO_MANY - queue s limit has been reached
96 * - RTEMS_TOO_MANY - queue s limit has been reached
97 *
97 *
98 */
98 */
99
99
100 rtems_status_code status;
100 rtems_status_code status;
101 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
101 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
102 unsigned char messageSize;
102 unsigned char messageSize;
103
103
104 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
104 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
105 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
105 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
106 TM.reserved = DEFAULT_RESERVED;
106 TM.reserved = DEFAULT_RESERVED;
107 TM.userApplication = CCSDS_USER_APP;
107 TM.userApplication = CCSDS_USER_APP;
108 // PACKET HEADER
108 // PACKET HEADER
109 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
109 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
110 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
110 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
111 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
111 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
112 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> SHIFT_1_BYTE);
112 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> SHIFT_1_BYTE);
113 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
113 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
114 // DATA FIELD HEADER
114 // DATA FIELD HEADER
115 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
115 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
116 TM.serviceType = TM_TYPE_TC_EXE;
116 TM.serviceType = TM_TYPE_TC_EXE;
117 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
117 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
118 TM.destinationID = TC->sourceID;
118 TM.destinationID = TC->sourceID;
119 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
119 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
120 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
120 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
121 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
121 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
122 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
122 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
123 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
123 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
124 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
124 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
125 //
125 //
126 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> SHIFT_1_BYTE);
126 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> SHIFT_1_BYTE);
127 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
127 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
128 TM.telecommand_pkt_id[0] = TC->packetID[0];
128 TM.telecommand_pkt_id[0] = TC->packetID[0];
129 TM.telecommand_pkt_id[1] = TC->packetID[1];
129 TM.telecommand_pkt_id[1] = TC->packetID[1];
130 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
130 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
131 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
131 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
132 TM.tc_service = TC->serviceType; // type of the rejected TC
132 TM.tc_service = TC->serviceType; // type of the rejected TC
133 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
133 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
134 TM.byte_position = byte_position;
134 TM.byte_position = byte_position;
135 TM.rcv_value = (unsigned char) rcv_value;
135 TM.rcv_value = (unsigned char) rcv_value;
136
136
137 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
137 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
138
138
139 // SEND DATA
139 // SEND DATA
140 status = rtems_message_queue_send( queue_id, &TM, messageSize);
140 status = rtems_message_queue_send( queue_id, &TM, messageSize);
141 if (status != RTEMS_SUCCESSFUL) {
141 if (status != RTEMS_SUCCESSFUL) {
142 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
142 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
143 }
143 }
144
144
145 // UPDATE HK FIELDS
145 // UPDATE HK FIELDS
146 update_last_TC_rej( TC, TM.time );
146 update_last_TC_rej( TC, TM.time );
147
147
148 return status;
148 return status;
149 }
149 }
150
150
151 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
151 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
152 {
152 {
153 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
153 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
154 *
154 *
155 * @param TC points to the TeleCommand packet that is being processed
155 * @param TC points to the TeleCommand packet that is being processed
156 * @param queue_id is the id of the queue which handles TM
156 * @param queue_id is the id of the queue which handles TM
157 *
157 *
158 * @return RTEMS directive status code:
158 * @return RTEMS directive status code:
159 * - RTEMS_SUCCESSFUL - message sent successfully
159 * - RTEMS_SUCCESSFUL - message sent successfully
160 * - RTEMS_INVALID_ID - invalid queue id
160 * - RTEMS_INVALID_ID - invalid queue id
161 * - RTEMS_INVALID_SIZE - invalid message size
161 * - RTEMS_INVALID_SIZE - invalid message size
162 * - RTEMS_INVALID_ADDRESS - buffer is NULL
162 * - RTEMS_INVALID_ADDRESS - buffer is NULL
163 * - RTEMS_UNSATISFIED - out of message buffers
163 * - RTEMS_UNSATISFIED - out of message buffers
164 * - RTEMS_TOO_MANY - queue s limit has been reached
164 * - RTEMS_TOO_MANY - queue s limit has been reached
165 *
165 *
166 */
166 */
167
167
168 rtems_status_code status;
168 rtems_status_code status;
169 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
169 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
170 unsigned char messageSize;
170 unsigned char messageSize;
171
171
172 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
172 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
173 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
173 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
174 TM.reserved = DEFAULT_RESERVED;
174 TM.reserved = DEFAULT_RESERVED;
175 TM.userApplication = CCSDS_USER_APP;
175 TM.userApplication = CCSDS_USER_APP;
176 // PACKET HEADER
176 // PACKET HEADER
177 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
177 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
178 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
178 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
179 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
179 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
180 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> SHIFT_1_BYTE);
180 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> SHIFT_1_BYTE);
181 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
181 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
182 // DATA FIELD HEADER
182 // DATA FIELD HEADER
183 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
183 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
184 TM.serviceType = TM_TYPE_TC_EXE;
184 TM.serviceType = TM_TYPE_TC_EXE;
185 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
185 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
186 TM.destinationID = TC->sourceID; // default destination id
186 TM.destinationID = TC->sourceID; // default destination id
187 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
187 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
188 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
188 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
189 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
189 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
190 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
190 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
191 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
191 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
192 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
192 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
193 //
193 //
194 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> SHIFT_1_BYTE);
194 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> SHIFT_1_BYTE);
195 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
195 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
196 TM.telecommand_pkt_id[0] = TC->packetID[0];
196 TM.telecommand_pkt_id[0] = TC->packetID[0];
197 TM.telecommand_pkt_id[1] = TC->packetID[1];
197 TM.telecommand_pkt_id[1] = TC->packetID[1];
198 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
198 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
199 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
199 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
200 TM.tc_service = TC->serviceType; // type of the rejected TC
200 TM.tc_service = TC->serviceType; // type of the rejected TC
201 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
201 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
202 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
202 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
203 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
203 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
204
204
205 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
205 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
206
206
207 // SEND DATA
207 // SEND DATA
208 status = rtems_message_queue_send( queue_id, &TM, messageSize);
208 status = rtems_message_queue_send( queue_id, &TM, messageSize);
209 if (status != RTEMS_SUCCESSFUL) {
209 if (status != RTEMS_SUCCESSFUL) {
210 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
210 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
211 }
211 }
212
212
213 // UPDATE HK FIELDS
213 // UPDATE HK FIELDS
214 update_last_TC_rej( TC, TM.time );
214 update_last_TC_rej( TC, TM.time );
215
215
216 return status;
216 return status;
217 }
217 }
218
218
219 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
219 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
220 {
220 {
221 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
221 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
222 *
222 *
223 * @param TC points to the TeleCommand packet that is being processed
223 * @param TC points to the TeleCommand packet that is being processed
224 * @param queue_id is the id of the queue which handles TM
224 * @param queue_id is the id of the queue which handles TM
225 *
225 *
226 * @return RTEMS directive status code:
226 * @return RTEMS directive status code:
227 * - RTEMS_SUCCESSFUL - message sent successfully
227 * - RTEMS_SUCCESSFUL - message sent successfully
228 * - RTEMS_INVALID_ID - invalid queue id
228 * - RTEMS_INVALID_ID - invalid queue id
229 * - RTEMS_INVALID_SIZE - invalid message size
229 * - RTEMS_INVALID_SIZE - invalid message size
230 * - RTEMS_INVALID_ADDRESS - buffer is NULL
230 * - RTEMS_INVALID_ADDRESS - buffer is NULL
231 * - RTEMS_UNSATISFIED - out of message buffers
231 * - RTEMS_UNSATISFIED - out of message buffers
232 * - RTEMS_TOO_MANY - queue s limit has been reached
232 * - RTEMS_TOO_MANY - queue s limit has been reached
233 *
233 *
234 */
234 */
235
235
236 rtems_status_code status;
236 rtems_status_code status;
237 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
237 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
238 unsigned char messageSize;
238 unsigned char messageSize;
239
239
240 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
240 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
241 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
241 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
242 TM.reserved = DEFAULT_RESERVED;
242 TM.reserved = DEFAULT_RESERVED;
243 TM.userApplication = CCSDS_USER_APP;
243 TM.userApplication = CCSDS_USER_APP;
244 // PACKET HEADER
244 // PACKET HEADER
245 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
245 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
246 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
246 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
247 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
247 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
248 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> SHIFT_1_BYTE);
248 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> SHIFT_1_BYTE);
249 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
249 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
250 // DATA FIELD HEADER
250 // DATA FIELD HEADER
251 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
251 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
252 TM.serviceType = TM_TYPE_TC_EXE;
252 TM.serviceType = TM_TYPE_TC_EXE;
253 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
253 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
254 TM.destinationID = TC->sourceID; // default destination id
254 TM.destinationID = TC->sourceID; // default destination id
255 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
255 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
256 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
256 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
257 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
257 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
258 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
258 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
259 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
259 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
260 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
260 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
261 //
261 //
262 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> SHIFT_1_BYTE);
262 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> SHIFT_1_BYTE);
263 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
263 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
264 TM.telecommand_pkt_id[0] = TC->packetID[0];
264 TM.telecommand_pkt_id[0] = TC->packetID[0];
265 TM.telecommand_pkt_id[1] = TC->packetID[1];
265 TM.telecommand_pkt_id[1] = TC->packetID[1];
266 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
266 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
267 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
267 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
268 TM.tc_service = TC->serviceType; // type of the rejected TC
268 TM.tc_service = TC->serviceType; // type of the rejected TC
269 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
269 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
270
270
271 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
271 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
272
272
273 // SEND DATA
273 // SEND DATA
274 status = rtems_message_queue_send( queue_id, &TM, messageSize);
274 status = rtems_message_queue_send( queue_id, &TM, messageSize);
275 if (status != RTEMS_SUCCESSFUL) {
275 if (status != RTEMS_SUCCESSFUL) {
276 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
276 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
277 }
277 }
278
278
279 // UPDATE HK FIELDS
279 // UPDATE HK FIELDS
280 update_last_TC_rej( TC, TM.time );
280 update_last_TC_rej( TC, TM.time );
281
281
282 return status;
282 return status;
283 }
283 }
284
284
285 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
285 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
286 {
286 {
287 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
287 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
288 *
288 *
289 * @param TC points to the TeleCommand packet that is being processed
289 * @param TC points to the TeleCommand packet that is being processed
290 * @param queue_id is the id of the queue which handles TM
290 * @param queue_id is the id of the queue which handles TM
291 *
291 *
292 * @return RTEMS directive status code:
292 * @return RTEMS directive status code:
293 * - RTEMS_SUCCESSFUL - message sent successfully
293 * - RTEMS_SUCCESSFUL - message sent successfully
294 * - RTEMS_INVALID_ID - invalid queue id
294 * - RTEMS_INVALID_ID - invalid queue id
295 * - RTEMS_INVALID_SIZE - invalid message size
295 * - RTEMS_INVALID_SIZE - invalid message size
296 * - RTEMS_INVALID_ADDRESS - buffer is NULL
296 * - RTEMS_INVALID_ADDRESS - buffer is NULL
297 * - RTEMS_UNSATISFIED - out of message buffers
297 * - RTEMS_UNSATISFIED - out of message buffers
298 * - RTEMS_TOO_MANY - queue s limit has been reached
298 * - RTEMS_TOO_MANY - queue s limit has been reached
299 *
299 *
300 */
300 */
301
301
302 rtems_status_code status;
302 rtems_status_code status;
303 Packet_TM_LFR_TC_EXE_ERROR_t TM;
303 Packet_TM_LFR_TC_EXE_ERROR_t TM;
304 unsigned char messageSize;
304 unsigned char messageSize;
305
305
306 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
306 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
307 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
307 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
308 TM.reserved = DEFAULT_RESERVED;
308 TM.reserved = DEFAULT_RESERVED;
309 TM.userApplication = CCSDS_USER_APP;
309 TM.userApplication = CCSDS_USER_APP;
310 // PACKET HEADER
310 // PACKET HEADER
311 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
311 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
312 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
312 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
313 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
313 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
314 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> SHIFT_1_BYTE);
314 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> SHIFT_1_BYTE);
315 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
315 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
316 // DATA FIELD HEADER
316 // DATA FIELD HEADER
317 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
317 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
318 TM.serviceType = TM_TYPE_TC_EXE;
318 TM.serviceType = TM_TYPE_TC_EXE;
319 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
319 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
320 TM.destinationID = TC->sourceID; // default destination id
320 TM.destinationID = TC->sourceID; // default destination id
321 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
321 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
322 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
322 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
323 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
323 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
324 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
324 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
325 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
325 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
326 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
326 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
327 //
327 //
328 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> SHIFT_1_BYTE);
328 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> SHIFT_1_BYTE);
329 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
329 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
330 TM.telecommand_pkt_id[0] = TC->packetID[0];
330 TM.telecommand_pkt_id[0] = TC->packetID[0];
331 TM.telecommand_pkt_id[1] = TC->packetID[1];
331 TM.telecommand_pkt_id[1] = TC->packetID[1];
332 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
332 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
333 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
333 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
334 TM.tc_service = TC->serviceType; // type of the rejected TC
334 TM.tc_service = TC->serviceType; // type of the rejected TC
335 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
335 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
336
336
337 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
337 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
338
338
339 // SEND DATA
339 // SEND DATA
340 status = rtems_message_queue_send( queue_id, &TM, messageSize);
340 status = rtems_message_queue_send( queue_id, &TM, messageSize);
341 if (status != RTEMS_SUCCESSFUL) {
341 if (status != RTEMS_SUCCESSFUL) {
342 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
342 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
343 }
343 }
344
344
345 // UPDATE HK FIELDS
345 // UPDATE HK FIELDS
346 update_last_TC_rej( TC, TM.time );
346 update_last_TC_rej( TC, TM.time );
347
347
348 return status;
348 return status;
349 }
349 }
350
350
351 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
351 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
352 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
352 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
353 unsigned char destinationID )
353 unsigned char destinationID )
354 {
354 {
355 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
355 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
356 *
356 *
357 * @param TC points to the TeleCommand packet that is being processed
357 * @param TC points to the TeleCommand packet that is being processed
358 * @param queue_id is the id of the queue which handles TM
358 * @param queue_id is the id of the queue which handles TM
359 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
359 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
360 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
360 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
361 *
361 *
362 * @return RTEMS directive status code:
362 * @return RTEMS directive status code:
363 * - RTEMS_SUCCESSFUL - message sent successfully
363 * - RTEMS_SUCCESSFUL - message sent successfully
364 * - RTEMS_INVALID_ID - invalid queue id
364 * - RTEMS_INVALID_ID - invalid queue id
365 * - RTEMS_INVALID_SIZE - invalid message size
365 * - RTEMS_INVALID_SIZE - invalid message size
366 * - RTEMS_INVALID_ADDRESS - buffer is NULL
366 * - RTEMS_INVALID_ADDRESS - buffer is NULL
367 * - RTEMS_UNSATISFIED - out of message buffers
367 * - RTEMS_UNSATISFIED - out of message buffers
368 * - RTEMS_TOO_MANY - queue s limit has been reached
368 * - RTEMS_TOO_MANY - queue s limit has been reached
369 *
369 *
370 */
370 */
371
371
372 rtems_status_code status;
372 rtems_status_code status;
373 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
373 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
374 unsigned char messageSize;
374 unsigned char messageSize;
375 unsigned int packetLength;
375 unsigned int packetLength;
376 unsigned int estimatedPacketLength;
376 unsigned int estimatedPacketLength;
377 unsigned char *packetDataField;
377 unsigned char *packetDataField;
378
378
379 packetLength = (TC->packetLength[0] * CONST_256) + TC->packetLength[1]; // compute the packet length parameter written in the TC
379 packetLength = (TC->packetLength[0] * CONST_256) + TC->packetLength[1]; // compute the packet length parameter written in the TC
380 estimatedPacketLength = (unsigned int) ((currentTC_LEN_RCV[0] * CONST_256) + currentTC_LEN_RCV[1]);
380 estimatedPacketLength = (unsigned int) ((currentTC_LEN_RCV[0] * CONST_256) + currentTC_LEN_RCV[1]);
381 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
381 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
382
382
383 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
383 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
384 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
384 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
385 TM.reserved = DEFAULT_RESERVED;
385 TM.reserved = DEFAULT_RESERVED;
386 TM.userApplication = CCSDS_USER_APP;
386 TM.userApplication = CCSDS_USER_APP;
387 // PACKET HEADER
387 // PACKET HEADER
388 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
388 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
389 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
389 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
390 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
390 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
391 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> SHIFT_1_BYTE);
391 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> SHIFT_1_BYTE);
392 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
392 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
393 // DATA FIELD HEADER
393 // DATA FIELD HEADER
394 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
394 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
395 TM.serviceType = TM_TYPE_TC_EXE;
395 TM.serviceType = TM_TYPE_TC_EXE;
396 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
396 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
397 TM.destinationID = destinationID;
397 TM.destinationID = destinationID;
398 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
398 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
399 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
399 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
400 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
400 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
401 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
401 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
402 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
402 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
403 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
403 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
404 //
404 //
405 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> SHIFT_1_BYTE);
405 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> SHIFT_1_BYTE);
406 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
406 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
407 TM.telecommand_pkt_id[0] = TC->packetID[0];
407 TM.telecommand_pkt_id[0] = TC->packetID[0];
408 TM.telecommand_pkt_id[1] = TC->packetID[1];
408 TM.telecommand_pkt_id[1] = TC->packetID[1];
409 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
409 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
410 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
410 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
411 TM.tc_service = TC->serviceType; // type of the rejected TC
411 TM.tc_service = TC->serviceType; // type of the rejected TC
412 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
412 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
413 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
413 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
414 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
414 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
415 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
415 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
416 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
416 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
417 // TM.rcv_crc[0] = packetDataField[ packetLength - 1 ];
418 // TM.rcv_crc[1] = packetDataField[ packetLength ];
419 TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ];
417 TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ];
420 TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ];
418 TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ];
421 TM.computed_crc[0] = computed_CRC[0];
419 TM.computed_crc[0] = computed_CRC[0];
422 TM.computed_crc[1] = computed_CRC[1];
420 TM.computed_crc[1] = computed_CRC[1];
423
421
424 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
422 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
425
423
426 // SEND DATA
424 // SEND DATA
427 status = rtems_message_queue_send( queue_id, &TM, messageSize);
425 status = rtems_message_queue_send( queue_id, &TM, messageSize);
428 if (status != RTEMS_SUCCESSFUL) {
426 if (status != RTEMS_SUCCESSFUL) {
429 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
427 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
430 }
428 }
431
429
432 // UPDATE HK FIELDS
430 // UPDATE HK FIELDS
433 update_last_TC_rej( TC, TM.time );
431 update_last_TC_rej( TC, TM.time );
434
432
435 return status;
433 return status;
436 }
434 }
437
435
438 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
436 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
439 {
437 {
440 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
438 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
441 *
439 *
442 * @param packet_sequence_control points to the packet sequence control which will be incremented
440 * @param packet_sequence_control points to the packet sequence control which will be incremented
443 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
441 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
444 *
442 *
445 * If the destination ID is not known, a dedicated counter is incremented.
443 * If the destination ID is not known, a dedicated counter is incremented.
446 *
444 *
447 */
445 */
448
446
449 unsigned short sequence_cnt;
447 unsigned short sequence_cnt;
450 unsigned short segmentation_grouping_flag;
448 unsigned short segmentation_grouping_flag;
451 unsigned short new_packet_sequence_control;
449 unsigned short new_packet_sequence_control;
452 unsigned char i;
450 unsigned char i;
453
451
454 switch (destination_id)
452 switch (destination_id)
455 {
453 {
456 case SID_TC_GROUND:
454 case SID_TC_GROUND:
457 i = GROUND;
455 i = GROUND;
458 break;
456 break;
459 case SID_TC_MISSION_TIMELINE:
457 case SID_TC_MISSION_TIMELINE:
460 i = MISSION_TIMELINE;
458 i = MISSION_TIMELINE;
461 break;
459 break;
462 case SID_TC_TC_SEQUENCES:
460 case SID_TC_TC_SEQUENCES:
463 i = TC_SEQUENCES;
461 i = TC_SEQUENCES;
464 break;
462 break;
465 case SID_TC_RECOVERY_ACTION_CMD:
463 case SID_TC_RECOVERY_ACTION_CMD:
466 i = RECOVERY_ACTION_CMD;
464 i = RECOVERY_ACTION_CMD;
467 break;
465 break;
468 case SID_TC_BACKUP_MISSION_TIMELINE:
466 case SID_TC_BACKUP_MISSION_TIMELINE:
469 i = BACKUP_MISSION_TIMELINE;
467 i = BACKUP_MISSION_TIMELINE;
470 break;
468 break;
471 case SID_TC_DIRECT_CMD:
469 case SID_TC_DIRECT_CMD:
472 i = DIRECT_CMD;
470</