//Sets the minimum values to a fastqEntry void initializeFastqEntry (fastqEntry *newEntry) { initializeString (&newEntry->title); initializeString (&newEntry->sequence); initializeString (&newEntry->quality); newEntry->next = NULL; return; }
//Create a new node on a fasta entry list void createFastaEntry (fastaEntry **newEntry) { *newEntry = malloc (sizeof (**newEntry)); initializeString (&(*newEntry)->title); initializeString (&(*newEntry)->seq); initializeString (&(*newEntry)->output); (*newEntry)->next = NULL; return; }
//(Re)Sets a node to empty values void initializeNode (node *newNode) { initializeString (&newNode->title); initializeString (&newNode->sequence); initializeString (&newNode->quality); newNode->left = NULL; newNode->right = NULL; newNode->height = -1; return; }
void initializePatient(PatientT * patient) { initializeString(patient->firstName, 30); initializeString(patient->lastName, 30); initializeString(patient->race, 30); initializeString(patient->gender, 30); initializeString(patient->uuid, 33); initializeString(patient->ssn, 10); initializeString(patient->dateOfBirth, 11); patient->age = 0; patient->smokes = 0; patient->insurance = malloc(sizeof(InsuranceT)); initializeString(patient->insurance->name, 40); initializeString(patient->insurance->name, 30); patient->immunizations = malloc(sizeof(ImmunizationListT)); patient->immunizations->next = NULL; patient->immunizations->item = NULL; patient->medications = malloc(sizeof(MedicationListT)); patient->medications->next = NULL; patient->medications->item = NULL; patient->visits = malloc(sizeof(VisitListT)); patient->visits->next = NULL; patient->visits->item = NULL; patient->testResults = malloc(sizeof(TestResultListT)); patient->testResults->next = NULL; patient->testResults->item = NULL; }
//Prints the nodes void printNodeList (node *firstNode, FILE *outFile) { //Local variables node *curNode = firstNode; string curScaff; initializeString (&curScaff); copyString (&firstNode->scaffold, &curScaff); fprintf (outFile, "##gff-version 3\n"); //One loop while (curNode != NULL) { //If it's a new scaffold print a "###" breaker line if (strcmp (curNode->scaffold.str, curScaff.str) != 0) { fprintf (outFile, "###\n"); copyString (&curNode->scaffold, &curScaff); } fprintf (outFile, "%s\n", curNode->entry.str); curNode = curNode->next; free (firstNode->entry.str); free (firstNode->scaffold.str); free (firstNode); firstNode = curNode; } free (curScaff.str); fprintf (outFile, "###"); return; }
int main() { PString *p = initializeString(30); strcpy(p->chars, "Hello"); printf("%d\n", p->length(p)); return 0; }
//Check buffer with a particular. always stops at $ boolean WiFlyRNXV::checkBufferResponse(String compareValue,int timeout){ //NULL case boolean noCase=false; if(compareValue==NULL) noCase=true; initializeString(responseBuffer,LONG_STRING); //Variables //char* responseBuffer; //Buffer for response boolean bufRead = true; //Finish Reading int bufpos = 0; //Buffer position char chResponse = 'A'; //Initial character response boolean compareSuccess=false; //Compare Success //Fill the buffer unsigned long startTime = millis(); while(bufRead){ //Start getting values if(uart.available()){ chResponse = uart.read(); //Serial.print(chResponse); //Keep reading until $ seen if(noCase){ if(chResponse=='$'){ compareSuccess=true; break; } } //Place into String if(bufpos<100){ responseBuffer[bufpos]=chResponse; bufpos++; }else{ Serial.println("Overflow"); bufpos=0; } } //Check for existence of the comparison string, or if timeout stop if(checkForString(compareValue,responseBuffer) && noCase==false){ compareSuccess=true; bufRead=false; }else if((millis()-startTime)>timeout){ compareSuccess=false; bufRead=false; } } uart.flush(); //if(compareSuccess)Serial.println("Found: "+compareValue); //else Serial.println("Not found: "+compareValue); return compareSuccess; }
//main () int main (int argc, char *argv[]) { //Call syntax check if (argc != 3) { printf ("Usage: %s Title_list_filename Sequence_list_filename\n", argv[0]); exit (1); } //Main variables string title, sequence; FILE *titleInFile = NULL, *sequenceInFile = NULL, *outFile = NULL; int count = 0; //File creation and checks printf ("Opening files..\n"); createFile (&titleInFile, argv[1], 'r'); createFile (&sequenceInFile, argv[2], 'r'); createFile (&outFile, "Combined.fasta", 'w'); //Combine entries printf ("File opened. Combining...\n"); initializeString (&title); initializeString (&sequence); while (1) { //Load the data, break the loop if either list runs out loadString (&title, titleInFile); loadString (&sequence, sequenceInFile); if ((title.str == NULL) || (sequence.str == NULL)) { break; } //Print the new fasta entry and reset for the next set fprintf (outFile, ">%s\n%s\n", title.str, sequence.str); reinitializeString (&title); reinitializeString (&sequence); //A counter so the user has some idea of how long it will take if (++count % 1000000 == 0) { printf ("%d entries combined...\n", count); } } //Close everything and free memory printf ("%d entries combined. Closing files and freeing memory...\n", count); free (title.str); free (sequence.str); fclose (titleInFile); fclose (sequenceInFile); fclose (outFile); return 0; }
int main(int argc, char* argv[]) { bool running = true; struct SudokuBoard board = { 0 }; struct SudokuCommandInput commandInput = { 0 }; const struct SudokuCommand *command = NULL; SudokuCommandResult status = SUDOKU_COMMAND_SUCCESS; initializeSudokuBoard(&board); initializeString(&commandInput.string); puts("========== Sudoku Game =========="); puts(showAllCommandsPrompt); putchar('\n'); // if one argument was provided, go ahead and load sudoku board from textfile if (argc > 1) { // if filename provided by argument cannot be found/read, loadSudokuBoard will // print an error statement, and execution will continue with a blank board loadSudokuBoard(argv[1], &board); } printSudokuBoard(&board); while (running) { // put extra space between previous output and command prompt putchar('\n'); command = getCommand(&commandInput); status = command->commandFunction(&board, &commandInput); if (status == SUDOKU_COMMAND_USAGE) { printf("Usage: '%s'\n", command->usagePrompt); } else if (status == SUDOKU_COMMAND_EXIT) { running = false; } } freeHistory(&board.history); return 0; }
//ResponseBuffer will be updated uint8_t WiFlyRNXV::sendTCPString(String data,uint8_t command){ bool status=false; uint8_t resp=0; initializeString(responseBuffer,LONG_STRING); Serial.print("SEND:"); Serial.println(data); if(!inCommandMode) EnterCommandMode(); delay(500); uart.println("open"); if(checkBufferResponse("*OPEN*",5000)){ delay(300); uart.print(command,DEC); uart.print(":"); uart.println(data); } if(checkBufferResponse("*CLOS*",5000)){ Serial.print("RESP:"); //Serial.println("TEST: "+responseBuffer); resp=processResponse(false); Serial.println(resp,DEC); Serial.print("RECV:"); Serial.println(responseBuffer); status=true; }else{ status=false; } //delete data; inCommandMode=false; return resp; }
void WiFlyRNXV::EnterAdHoc(){ initializeString(ipValue,SHORT_STRING); int delayW=500; if(!inCommandMode) EnterCommandMode(); delay(1000); // Setup adhoc network Serial.println("set ip address 169.254.1.1"); uart.flush(); uart.println("set ip address 169.254.1.1"); delay(delayW); Serial.println("set ip netmask 255.255.0.0"); uart.flush(); uart.println("set ip netmask 255.255.0.0"); delay(delayW); Serial.println("set ip dhcp 0"); uart.flush(); uart.println("set ip dhcp 0"); delay(delayW); Serial.println("set ip proto 2"); uart.flush(); uart.println("set ip proto 2"); delay(delayW); Serial.println("set wlan ssid WiRED"); uart.flush(); uart.println("set wlan ssid WiRED"); delay(delayW); Serial.println("set wlan channel 1"); uart.flush(); uart.println("set wlan channel 1"); delay(delayW); // Create adhoc network Serial.println("set wlan join 4"); uart.flush(); uart.println("set wlan join 4"); delay(delayW); Serial.println("save"); uart.flush(); uart.println("save"); delay(delayW); Serial.println("reboot"); uart.flush(); uart.println("reboot"); delay(delayW); delay(2000); inCommandMode=false; uart.flush(); Serial.println("Done AdHoc"); }
//Resets a used string to an empty status void reinitializeString (string *string) { free (string->str); initializeString (&(*string)); return; }
//main () int main (int argc, char *argv[]) { //Call syntax check if (argc != 2) { printf ("Usage: %s Input_filename\n", argv[0]); exit (1); } //Main variables FILE *inFile = NULL; string source, type; char in; int maker_count = 0, augustus_count = 0, snap_count = 0, genemark_count = 0, blastn_count = 0, blastx_count = 0, est2genome_count = 0, protein2genome_count = 0, repeatmasker_count = 0, repeatrunner_count = 0, LTRharvest_count = 0, LTRfinder_count = 0, TRF_count = 0, tRNAscan_count = 0, gene_count = 0, TE_count = 0, count = 0; //File creation and checks printf ("Opening files...\n"); createFile (&inFile, argv[1], 'r'); //Collect stats printf ("Files opened. Parsing stats...\n"); initializeString (&source); initializeString (&type); in = fgetc (inFile); //Automate the rest while (1) { //Skip the title while (in != '\t') { if (((ferror (inFile)) || (feof (inFile)))) { source.str = NULL; break; } in = fgetc (inFile); } //Stop the loop if the list is done if (source.str == NULL) { break; } //Read the source in = fgetc (inFile); while (in != '\t') { readValueToString (&source, in); in = fgetc (inFile); } //Read the type in = fgetc (inFile); while (in != '\t') { readValueToString (&type, in); in = fgetc (inFile); } //Burn the rest of the line and reset the strings while (in != '\n') { in = fgetc (inFile); } //Increase the counts as they appear /*ADD NEW SOURCES HERE */ if ((strcmp (source.str, "maker") == 0) && (strcmp (type.str, "gene") == 0)) { maker_count++; } else if ((strcmp (source.str, "augustus_masked") == 0) && (strcmp (type.str, "match") == 0)) { augustus_count++; } else if ((strcmp (source.str, "snap_masked") == 0) && (strcmp (type.str, "match") == 0)) { snap_count++; } else if ((strcmp (source.str, "genemark_masked") == 0) && (strcmp (type.str, "match") == 0)) { genemark_count++; } else if ((strcmp (source.str, "blastn") == 0) && (strcmp (type.str, "expressed_sequence_match") == 0)) { blastn_count++; } else if ((strcmp (source.str, "blastx") == 0) && (strcmp (type.str, "protein_match") == 0)) { blastx_count++; } else if ((strcmp (source.str, "est2genome") == 0) && (strcmp (type.str, "expressed_sequence_match") == 0)) { est2genome_count++; } else if ((strcmp (source.str, "protein2genome") == 0) && (strcmp (type.str, "protein_match") == 0)) { protein2genome_count++; } else if ((strcmp (source.str, "repeatmasker") == 0) && (strcmp (type.str, "match") == 0)) { repeatmasker_count++; } else if ((strcmp (source.str, "repeatrunner") == 0) && (strcmp (type.str, "protein_match") == 0)) { repeatrunner_count++; } else if ((strcmp (source.str, "LTRharvest") == 0) && (strcmp (type.str, "repeat_region") == 0)) { LTRharvest_count++; } else if ((strcmp (source.str, "LTRfinder") == 0) && (strcmp (type.str, "repeat_region") == 0)) { LTRfinder_count++; } else if ((strcmp (source.str, "TRF") == 0) && (strcmp (type.str, "repeat_region") == 0)) { TRF_count++; } else if ((strcmp (source.str, "tRNAscan") == 0) && (strcmp (type.str, "tRNA") == 0)) { tRNAscan_count++; } else if (strcmp (type.str, "gene") == 0) { gene_count++; } else if (strcmp (type.str, "transposable_element") == 0) { TE_count++; } //A counter so the user has some idea of how long it will take if (++count % 100000 == 0) { printf ("%d entries processed...\n", count); } reinitializeString (&source); reinitializeString (&type); } //Display the stats printf ("%d entries process. All stats Parsed.\n\t###MAKER Matches###\nMAKER Consensus Genes:\t%d\nAugustus Matches:\t%d\nsnap Matches:\t\t%d\nGenemark Matches:\t%d\nBLASTn Matches\t\t%d\nBLASTx Matches\t\t%d\nest2genome Matches:\t%d\nprotein2genome Matches:\t%d\nRepeatMasker Matches:\t%d\nRepeatrunner Matches:\t%d\n\t###Other Annotations###\nLTRharvest Matches:\t%d\nLTRfinder Matches:\t%d\nTRF Matches:\t\t%d\ntRNAscan Matches:\t%d\n\t###Generic Matches###\nGenes:\t\t\t%d\nTransposable Elements:\t%d\n", count, maker_count, augustus_count, snap_count, genemark_count, blastn_count, blastx_count, est2genome_count, protein2genome_count, repeatmasker_count, repeatrunner_count, LTRharvest_count, LTRfinder_count, TRF_count, tRNAscan_count, gene_count, TE_count); //Close everything and free memory free (source.str); free (type.str); fclose (inFile); return 0; }
void exportUser(PatientT * patient) { if(patient == NULL) { //Lol you boi return; } char * uuid = patient->uuid; char fileName[45]; initializeString(fileName, 45); strncat(fileName, "records/", 8); strncat(fileName, uuid, 32); FILE * userRecords = fopen(fileName, "w+"); int err; err = fprintf(userRecords, "%s,%s,%d,%s,%s,%d,%s,%s\n", patient->firstName, patient->lastName, patient->smokes, patient->race, patient->gender, patient->age, patient->ssn, patient->dateOfBirth ); if(err < 0) { //Error } err = fprintf(userRecords, "%s,%s\n", patient->insurance->name, patient->insurance->policyNumber ); if(err < 0) { //Error } ImmunizationListT * currentImmuList = patient->immunizations; int numRecords = 1; int i = 0; while(currentImmuList->next != NULL) { currentImmuList = currentImmuList->next; numRecords++; } err = fprintf(userRecords, "IMMUNIZATIONS,%d\n", numRecords); if(err < 0) { //Error } currentImmuList = patient->immunizations; for(i = 0; i < numRecords; i++) { err = fprintf(userRecords, "%s,%s,%s\n", currentImmuList->item->name, currentImmuList->item->datePerformed, currentImmuList->item->performingPerson ); if(err < 0) { //Error } currentImmuList = currentImmuList->next; } MedicationListT * currentMedList = patient->medications; while(currentMedList->next != NULL) { currentMedList = currentMedList->next; numRecords++; } err = fprintf(userRecords, "MEDICATIONS,%d\n", numRecords); if(err < 0) { //Error } currentMedList = patient->medications; for(i = 0; i < numRecords; i++) { err = fprintf(userRecords, "%s,%d,%s\n", currentMedList->item->name, currentMedList->item->dosage, currentMedList->item->prescribingPerson ); if(err < 0) { //Error } currentMedList = currentMedList->next; } VisitListT * currentVisitList = patient->visits; while(currentVisitList->next != NULL) { currentVisitList = currentVisitList->next; numRecords++; } err = fprintf(userRecords, "VISITS,%d\n", numRecords); if(err < 0) { //Error } currentVisitList = patient->visits; for(i = 0; i < numRecords; i++) { err = fprintf(userRecords, "%d,%d,%s,%s\n", currentVisitList->item->heartRate, currentVisitList->item->bloodPressure, currentVisitList->item->visitDateTime, currentVisitList->item->personSeen ); if(err < 0) { //Error } currentVisitList = currentVisitList->next; } TestResultListT * currentTestList = patient->testResults; while(currentTestList->next != NULL) { currentTestList = currentTestList->next; numRecords++; } err = fprintf(userRecords, "TESTRESULT,%d\n", numRecords); if(err < 0) { //Error } currentTestList = patient->testResults; for(i = 0; i < numRecords; i++) { err = fprintf(userRecords, "%s,%s\n", currentTestList->item->testName, currentTestList->item->testResults ); if(err < 0) { //Error } currentTestList = currentTestList->next; } fclose(userRecords); }
void editPatient(char* uuid){ //TODO check if uuid is part of DOC's patients PatientT * patient = fetchPatient(uuid); fprintf(stderr, "found patient\n"); int choice=0; char temp[2]; initializeString(temp,2); //display edit menu while(choice!=9){ displayPatient(uuid); printf("\n****Edit Patient\n"); printf("[1] Insurance\n"); printf("[2] Add Immunization\n"); printf("[3] Add Medication\n"); printf("[4] Add Vitals\n"); printf("[5] Add Test Results\n"); printf("[6] Demographics\n"); printf("[9] EXIT\n"); //get input if(fgets(temp,2,stdin)); choice = temp[0]-48; //process choice switch(choice){ case 1: ; while(getchar()!='\n');//clean buffer //edit insurance char name[40]; char policyNumber[30]; initializeString(name,40); initializeString(policyNumber,40); while(getchar()!='\n');//clean buffer printf("INSURANCE NAME: "); if(fgets(name,40,stdin)); while(getchar()!='\n');//clean buffer printf("\nPOLICY NO: "); if(fgets(policyNumber,30,stdin)); printf("\n"); sanitizeInput(name,40); sanitizeInput(policyNumber,30); strncpy(patient->insurance->name,name,40); strncpy(patient->insurance->policyNumber,policyNumber,30); exportUser(patient); printf("\nUPDATED!\n"); break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: ; while(getchar()!='\n');//clean buffer char firstName[30]; initializeString(firstName,30); char lastName[30]; initializeString(lastName,30); bool smokes=3; char race[30]; initializeString(race,30); char gender[30]; initializeString(gender,30); int age=-1; char tempAge[10]; initializeString(tempAge,10); char ssn[10]; initializeString(ssn,10); char dateOfBirth[11]; initializeString(dateOfBirth,11); while(getchar()!='\n');//clean buffer printf("FIRSTNAME: "); if(fgets(firstName,30,stdin)); while(getchar()!='\n');//clean buffer printf("\nLASTNAME: "); if(fgets(lastName,30,stdin)); while(getchar()!='\n');//clean buffer while(smokes!=0&&smokes!=1){ printf("\nSmoker?{1=YES,0=NO}"); if(fgets(temp,2,stdin)); sanitizeInt(temp,2); smokes=temp[0]-48; while(getchar()!='\n');//clean buffer } while(getchar()!='\n');//clean buffer printf("\nGENDER: "); if(fgets(gender,30,stdin)); while(getchar()!='\n');//clean buffer printf("\nRACE: "); if(fgets(race,30,stdin)); while(getchar()!='\n');//clean buffer while(age<=0||age>=999){ printf("\nAGE {000}"); if(fgets(tempAge,3,stdin)); //sanitizeInt(tempAge,4); //age+=((tempAge[0]+48)*1); //age+=((tempAge[1]+48)*10); //age+=((tempAge[2]+48)*100); age= (int) strtol(tempAge,NULL,10); while(getchar()!='\n');//clean buffer } while(getchar()!='\n');//clean buffer printf("\nSSN: "); if(fgets(ssn,10,stdin)); while(getchar()!='\n');//clean buffer printf("\nDOB{MM/DD/YYYY}"); if(fgets(dateOfBirth,11,stdin)); sanitizeInput(firstName,30); sanitizeInput(lastName,30); sanitizeInput(race,30); sanitizeInput(gender,30); sanitizeInput(ssn,10); sanitizeInput(dateOfBirth,11); strncpy(patient->firstName,firstName,30); strncpy(patient->lastName,lastName,30); strncpy(patient->race,race,30); strncpy(patient->gender,gender,30); strncpy(patient->ssn,ssn,10); strncpy(patient->dateOfBirth,dateOfBirth,11); patient->smokes=smokes; patient->age=age; exportUser(patient); printf("\nUPDATED!\n"); break; case 9: break; default: break; } } }
//Sets minimum values to a node void initializeNode (node *newNode) { initializeString (&newNode->entry); initializeString (&newNode->scaffold); newNode->next = NULL; return; }
void initializeCommon( ) { initializeString(); initializeX11(); }
//Constructor-Start listen on uart WiFlyRNXV::WiFlyRNXV(byte pinReceive, byte pinSend) : uart (pinReceive, pinSend),irSystem(IR_RECEIVEPIN){ initializeString(responseBuffer,LONG_STRING); initializeString(ipValue,SHORT_STRING); inCommandMode=false; wifiStatus=false; }
PatientT * fetchPatient(char * uuid) { fprintf(stderr,"Fetching Patient INFO\n"); if(patientCache == NULL) { patientCache = malloc(sizeof(PatientCacheT)); if(patientCache == NULL) { //malloc error } else { patientCache->item = NULL; patientCache->next = NULL; } } //First we need to search the cache for a proper user PatientCacheT * currentRecord = patientCache; while(true) { if(currentRecord->item == NULL) { //There is no record, ayyyyy break; } //Match found if(strncmp(currentRecord->item->uuid, uuid, 33)) { return currentRecord->item; } else { currentRecord = currentRecord->next; } } //No record :c fprintf(stderr,"NO RECORD SEARCHING FILE\n"); char fileName[45]; initializeString(fileName, 45); strncat(fileName, "records/", 8); strncat(fileName, uuid, 32); FILE * userRecords = fopen(fileName, "r"); char line[500]; initializeString(line, 500); //First thing we wanna read in is the basic information about the user fprintf(stderr,"Reading Basic info\n"); if(fgets(line, 500, userRecords) == NULL) { //Error during reading } PatientT * patient = malloc(sizeof(PatientT)); if(patient == NULL) { //Error during malloc } initializePatient(patient); if(feof(userRecords) && (line[0] == '\0' || line[0] == ' ' || line[1] == '\0')) { fclose(userRecords); return patient; } char csvData[10][50]; parseCSV(line, csvData); strncpy(patient->uuid, uuid, 33); strncpy(patient->firstName, csvData[0], 29); strncpy(patient->lastName, csvData[1], 29); patient->smokes = (strncmp(csvData[2], "1", 1) == 0) ? true : false; strncpy(patient->race, csvData[3], 29); strncpy(patient->gender, csvData[4], 29); int age = (int) strtol(csvData[5], NULL, 10); if(age == 0) { //Errored out during conversion printf("System errored during age import. Setting age to -1\n"); age = -1; } patient->age = age; strncpy(patient->ssn, csvData[6], 10); strncpy(patient->dateOfBirth, csvData[7], 10); fprintf(stderr,"Read basic info\n"); fprintf(stderr,"Reading insuracne info"); if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); InsuranceT * insurance = malloc(sizeof(InsuranceT)); if(insurance == NULL) { //Malloc error } strncpy(insurance->name, csvData[0], 40); strncpy(insurance->policyNumber, csvData[1], 30); patient->insurance = insurance; //-------------------------------------------------------------------------------- //Immunization data fprintf(stderr,"Read Immunization"); if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); int numberOfRecords = (int) strtol(csvData[1], NULL, 10); if(numberOfRecords == 0) { printf("System errored during Immunization import. Ignoring."); numberOfRecords = 0; } int i = 0; ImmunizationListT * lastRecordImmu = malloc(sizeof(ImmunizationListT)); if(lastRecordImmu == NULL) { //Malloc error } ImmunizationListT * firstRecordImmu = lastRecordImmu; for(i = 0; i < numberOfRecords; i++) { if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); ImmunizationT * record = malloc(sizeof(ImmunizationT)); if(record == NULL) { //Malloc error } initializeString(record->name, 40); initializeString(record->datePerformed, 20); initializeString(record->performingPerson, 33); strncpy(record->name, csvData[0], 40); strncpy(record->datePerformed, csvData[1], 20); strncpy(record->performingPerson, csvData[2], 33); lastRecordImmu->item = record; if(i + 1 >= numberOfRecords) { lastRecordImmu->next = NULL; break; } lastRecordImmu->next = malloc(sizeof(ImmunizationListT)); if(lastRecordImmu->next == NULL) { //Malloc error } lastRecordImmu = lastRecordImmu->next; lastRecordImmu->next = NULL; } patient->immunizations = firstRecordImmu; //-------------------------------------------------------------------------------- //Medication data if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); numberOfRecords = (int) strtol(csvData[1], NULL, 10); if(numberOfRecords == 0) { printf("System errored during Medication import. Ignoring."); numberOfRecords = 0; } MedicationListT * lastRecordMedi = malloc(sizeof(MedicationListT)); if(lastRecordMedi == NULL) { //Malloc error } MedicationListT * firstRecordMedi = lastRecordMedi; for(i = 0; i < numberOfRecords; i++) { if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); MedicationT * record = malloc(sizeof(MedicationT)); if(record == NULL) { //Malloc error } initializeString(record->prescribingPerson, 33); strncpy(record->name, csvData[0], 40); const int dosage = (int) strtol(csvData[1], NULL, 10); if(dosage == 0) { printf("System error during Medication import."); record->dosage = -1; } else { record->dosage = dosage; } strncpy(record->prescribingPerson, csvData[2], 33); lastRecordMedi->item = record; if(i + 1 >= numberOfRecords) { lastRecordMedi->next = NULL; break; } lastRecordMedi->next = malloc(sizeof(MedicationListT)); if(lastRecordMedi->next == NULL) { //Malloc error } lastRecordMedi = lastRecordMedi->next; lastRecordMedi->next = NULL; } patient->medications = firstRecordMedi; //--------------------------------------------------------------------------------- //Visits data if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); numberOfRecords = (int) strtol(csvData[1], NULL, 10); if(numberOfRecords == 0) { printf("System error during Visits import. Ignoring."); numberOfRecords = 0; } VisitListT * lastVisitRecord = malloc(sizeof(VisitListT)); if(lastVisitRecord == NULL) { //Malloc error } VisitListT * firstVisitRecord = lastVisitRecord; for(i = 0; i < numberOfRecords; i++) { if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); VisitT * record = malloc(sizeof(VisitT)); if(record == NULL) { //Malloc error } initializeString(record->visitDateTime, 19); initializeString(record->personSeen, 33); const int heartRate = (int) strtol(csvData[0], NULL, 10); if(heartRate == 0) { printf("System error during Visit import"); record->heartRate = -1; } else { record->heartRate = heartRate; } const int bloodPressure = (int) strtol(csvData[1], NULL, 10); if(bloodPressure == 0) { printf("System error during Visit import"); record->bloodPressure = -1; } else { record->bloodPressure = bloodPressure; } strncpy(record->visitDateTime, csvData[2], 19); strncpy(record->personSeen, csvData[3], 33); lastVisitRecord->item = record; if(i + 1 >= numberOfRecords) { lastVisitRecord->next = NULL; break; } lastVisitRecord->next = malloc(sizeof(VisitT)); if(lastVisitRecord->next == NULL) { //Malloc error } lastVisitRecord = lastVisitRecord->next; lastVisitRecord->next = NULL; } patient->visits = firstVisitRecord; //--------------------------------------------------------------------------------- //Test Result data if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); numberOfRecords = (int) strtol(csvData[1], NULL, 10); if(numberOfRecords == 0) { printf("System error during Test Results import. Ignoring."); numberOfRecords = 0; } TestResultListT * lastTestRecord = malloc(sizeof(TestResultListT)); if(lastTestRecord == NULL) { //Malloc error; } TestResultListT * firstTestRecord = lastTestRecord; for(i = 0; i < numberOfRecords; i++) { if(fgets(line, 500, userRecords) == NULL) { //Error during reading } parseCSV(line, csvData); TestResultT * record = malloc(sizeof(TestResultT)); if(record == NULL) { //Malloc error } initializeString(record->testName, 30); initializeString(record->testResults, 120); strncpy(record->testName, csvData[0], 30); strncpy(record->testResults, csvData[1], 120); lastTestRecord->item = record; if(i + 1 >= numberOfRecords) { lastTestRecord->next = NULL; break; } lastTestRecord->next = malloc(sizeof(TestResultT)); if(lastTestRecord->next == NULL) { //Malloc error; } lastTestRecord = lastTestRecord->next; lastTestRecord->next = NULL; } patient->testResults = firstTestRecord; //I think we're done here. patientCache->item = patient; patientCache->next = malloc(sizeof(PatientCacheT)); if(patientCache->next == NULL) { //Error; } fclose(userRecords); return patient; }
boolean WiFlyRNXV::getDataType(String& fillBuff,int action){ initializeString(fillBuff,SHORT_STRING); if(!inCommandMode) EnterCommandMode(); String delimit; if(action==GET_IP){ delimit="IP="; uart.println("get ip"); }else if(action==GET_DEVID){ delimit="d="; uart.println("show deviceid"); } boolean bufRead = true; //Finish Reading boolean ipReadMode = false; //Ready to write in IP boolean ipReadOver = false; //Finished writing IP int bufpos = 0; //Buffer position char chResponse = 'A'; //Initial character response boolean compareSuccess=false; //Compare Success int timeout=5000; //Timeout value fixed //Fill the buffer unsigned long startTime = millis(); while(bufRead){ //Start getting values if(uart.available()){ chResponse = uart.read(); //Serial.print(chResponse); //Stop at character : if(chResponse==':'){ ipReadOver=true; break; } if(ipReadMode==false){ responseBuffer[bufpos]=chResponse; }else{ fillBuff[bufpos]=chResponse; } bufpos++; } //Check for existence of the comparison string, or if timeout stop if(checkForString(delimit,responseBuffer) && ipReadMode==false){ ipReadMode=true; bufpos=0; }else if((millis()-startTime)>timeout){ compareSuccess=false; bufRead=false; } } if(ipReadOver==true){ //ipValue.trim(); ipValue.replace(" ",""); Serial.print("IPVAL:"); Serial.println(fillBuff); compareSuccess=true; delay(200); ExitCommandMode(); } uart.flush(); return compareSuccess; }