//-------------------------------------------------------------------------- // Prints the mission data optionaly to a file or standard out // void PrintResults(ThermoStateType *ThermoState, FILE *fp, int ConvertToF) { // aslink only can handle 64k, so we use the second 64k bank char *str=(xdata char*)0x190000; // check if need to use standard out if (fp == NULL) fp = stdout; #if 0 // get big block to use as a buffer str = malloc(80000); if (str == NULL) { printf("Insufficient memory available to print!\n"); return; } #endif // mission status MissionStatusToString(&ThermoState->MissStat, ConvertToF, &str[0]); fprintf(fp,"\n%s\n",str); // alarm events AlarmsToString(&ThermoState->AlarmData, &str[0]); fprintf(fp,"%s\n",str); // histogram HistogramToString(&ThermoState->HistData, ConvertToF, &str[0]); fprintf(fp,"%s\n",str); // log data LogToString(&ThermoState->LogData, ConvertToF, &str[0]); fprintf(fp,"%s\n",str); // debug raw data DebugToString(&ThermoState->MissStat, &ThermoState->AlarmData, &ThermoState->HistData, &ThermoState->LogData, &str[0]); fprintf(fp,"%s\n",str); #if 0 // free the memory block used free(str); #endif }
//---------------------------------------------------------------------- // This is the Main routine for thermoms. // int main(int argc, char **argv) { int Fahrenheit=FALSE,num,i,j; char str[800]; ThermoStateType ThermoState; uchar ThermoSN[MAXDEVICES][8]; //the serial numbers for the devices int portnum=0; // check arguments to see if request instruction with '?' or too many if ((argc < 2) || (argc > 3) || ((argc > 1) && (argv[1][0] == '?' || argv[1][1] == '?'))) ExitProg("\nusage: thermoms 1wire_net_name </Fahrenheit>\n" " - Thermochron configuration on the 1-Wire Net port\n" " - 1wire_net_port required port name\n" " example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" \n" " (Linux DS2480),\"{1,5}\" (Win32 TMEX)\n" " - </Fahrenheit> optional Fahrenheit mode (default Celsius)\n" " - version 2.00\n",1); // attempt to acquire the 1-Wire Net if((portnum = owAcquireEx(argv[1])) < 0) { OWERROR_DUMP(stdout); exit(1); } // success printf("Port opened: %s\n",argv[1]); //---------------------------------------- // Introduction printf("\n/---------------------------------------------\n"); printf(" Find and mission DS1921 Thermochron iButton(s)\n" " Version 2.00\n\n"); // check arguments Fahrenheit = FALSE; if (argc >= 3) { if ((argv[2][0] == '/') && ((argv[2][1] == 'F') || (argv[2][1] == 'f'))) Fahrenheit = TRUE; } // get list of Thermochron's num = FindDevices(portnum, &ThermoSN[0],THERMO_FAM, MAXDEVICES); // check if not present or more then 1 present if (num == 0) ExitProg("Thermochron not present on 1-Wire\n",1); // loop to mission each Thermochron for (i = 0; i < num; i++) { // set the serial number portion in the thermo state printf("\nRead status of Thermochron: "); for (j = 7; j >= 0; j--) { ThermoState.MissStat.serial_num[j] = ThermoSN[i][j]; printf("%02X",ThermoSN[i][j]); } printf("\n"); // read Thermochron state if (ReadThermoStatus(portnum,&ThermoSN[i][0],&ThermoState,stdout)) { // display mission status InterpretStatus(&ThermoState.MissStat); MissionStatusToString(&ThermoState.MissStat, Fahrenheit, &str[0]); printf("\n%s\n",str); // ask user mission questions if (!InputMissionType(&ThermoState,Fahrenheit)) { printf("Input abort\n"); continue; } GAMEOVER(); // run the script to display the thermochron if (MissionThermo(portnum,&ThermoSN[i][0],&ThermoState,stdout)) { // read Thermochron state if (ReadThermoStatus(portnum,&ThermoSN[i][0],&ThermoState,stdout)) { // display the new mission status InterpretStatus(&ThermoState.MissStat); MissionStatusToString(&ThermoState.MissStat, Fahrenheit, &str[0]); printf("\n%s\n",str); } else printf("ERROR reading Thermochon state\n"); } else printf("ERROR, Thermochon missioning not complete\n"); } else printf("ERROR reading Thermochon state\n"); } // release the 1-Wire Net owRelease(portnum); printf("\nClosing port %s.\n", argv[1]); printf("End program normally\n"); exit(0); return 0; }