map<string, CanVariable> CanIdTranslator::translateData(int commandId, string moduleName, string dataHex) { vector<XmlNode> commandNodes = xmlNode.findChild("commands").getChildren(); for (int n = 0; n < commandNodes.size(); n++) { map<string, string> attributes = commandNodes[n].getAttributes(); bool correct = false; if (commandId >= 128) { if (stoi(attributes["id"]) == commandId && attributes["module"] == moduleName) { correct = true; } } else if (stoi(attributes["id"]) == commandId) { correct = true; } if (correct) { XmlNode varablesNode = commandNodes[n].findChild("variables"); return translateData(varablesNode.getChildren(), dataHex); } } map<string, CanVariable> variables; return variables; }
map<string, CanVariable> CanIdTranslator::translateNMTData(int commandId, string dataHex) { vector<XmlNode> commandNodes = xmlNode.findChild("nmt_messages").getChildren(); for (int n = 0; n < commandNodes.size(); n++) { map<string, string> attributes = commandNodes[n].getAttributes(); if (stoi(attributes["id"]) == commandId) { XmlNode varablesNode = commandNodes[n].findChild("variables"); return translateData(varablesNode.getChildren(), dataHex); } } map<string, CanVariable> variables; return variables; }
/* Function that translates every code and data segment. * This function returns ASM_OK if everything went good */ int translateCode(t_translation_infos *infos, FILE *fp) { int instruction_counter; t_list *current_instruction; void *instruction_or_data; int errorcode; /* unchecked preconditions: pf and infos are different from NULL */ if (infos->code == NULL) return ASM_CODE_NOT_PRESENT; /* initialize the instruction_counter */ instruction_counter = 0; current_instruction = infos->code; errorcode = ASM_OK; /* translate the instruction segment */ while (instruction_counter < infos->codesize) { instruction_or_data = LDATA(current_instruction); assert(instruction_or_data != NULL); /* translate every single instruction */ errorcode = translateInstruction (infos, (t_asm_instruction *) instruction_or_data, fp); /* verify the errorcode */ if (errorcode != ASM_OK) return errorcode; /* update the instruction counter and the current instruction data */ instruction_counter++; current_instruction = LNEXT(current_instruction); } #ifndef NDEBUG fprintf(stderr, "\n"); #endif /* translate the data segment */ while (current_instruction != NULL) { instruction_or_data = LDATA(current_instruction); assert(instruction_or_data != NULL); /* translate every single element of data */ #ifndef NDEBUG fprintf(stderr, "Adding data into the data segment [datatype == %s \t; " , dataType_toString(((t_asm_data *)instruction_or_data)->dataType) ); fprintf(stderr, "value == 0x%08x] \n" , ((t_asm_data *)instruction_or_data)->value); #endif errorcode = translateData(infos, (t_asm_data *) instruction_or_data, fp); /* verify the errorcode */ if (errorcode != ASM_OK) return errorcode; current_instruction = LNEXT(current_instruction); } #ifndef NDEBUG fprintf(stderr, "\n"); #endif return ASM_OK; }