/** * This functions handles an incoming ECSS packet. * If the ECSS packet is part of a large data transfer consisting from * several sequential ECSS packets, it handles them automatically. * * In other words, there is no need to explicitly check for a fragmented data * transfer. * * @param payload the received payload * @param payload_size the size of the payload * @return SATR_OK if all went ok or appropriate error code */ SAT_returnState rx_ecss (uint8_t *payload, const uint16_t payload_size) { SAT_returnState ret; tc_tm_pkt *pkt; pkt = get_pkt (payload_size); if (!C_ASSERT(pkt != NULL)) { return SATR_ERROR; } if (unpack_pkt (payload, pkt, payload_size) == SATR_OK) { ret = route_pkt (pkt); } TC_TM_app_id dest = 0; if(pkt->type == TC) { dest = pkt->app_id; } else if(pkt->type == TM) { dest = pkt->dest_id; } if(dest == SYSTEM_APP_ID) { free_pkt(pkt); } return ret; }
int main() { /*unpack_pkt UT*/ struct tc_tm_pkt res, in; uint16_t size; size = 16; /*TC*/ in.type = TC; in.app_id = 0x01; in.seq_flags = 3; in.seq_count = 0xB9; /*data_hdr+data-1*/ in.len = 5+5-1; in.ack = 0; in.ser_type = 8; in.ser_subtype = 1; in.dest_id = 0xC9; route_pkt(&in); return 0; }
SAT_returnState hk_app(tc_tm_pkt *pkt) { if(!C_ASSERT(pkt != NULL && pkt->data != NULL) == true) { return SATR_ERROR; } if(!C_ASSERT(pkt->ser_subtype == TC_HK_REPORT_PARAMETERS || pkt->ser_subtype == TM_HK_PARAMETERS_REPORT) == true) {return SATR_ERROR; } if(pkt->ser_subtype == TC_HK_REPORT_PARAMETERS) { tc_tm_pkt *temp_pkt = 0; HK_struct_id sid = (HK_struct_id)pkt->data[0]; hk_crt_empty_pkt_TM(&temp_pkt, (TC_TM_app_id)pkt->dest_id, sid); if(!C_ASSERT(temp_pkt != NULL) == true) { return SATR_ERROR; } route_pkt(temp_pkt); } else if(pkt->ser_subtype == TM_HK_PARAMETERS_REPORT) { const SAT_returnState res = hk_parameters_report(pkt->app_id, (HK_struct_id)pkt->data[0], pkt->data, pkt->len); if(res == SATR_OK) { pkt->verification_state = SATR_OK; } } return SATR_OK; }