COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
bbFctns.cpp File Reference
#include "support/configCosmos.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include "device/general/cssl_lib.h"
#include "device/general/bbFctns.h"
Include dependency graph for bbFctns.cpp:

Functions

void FindBbPort (int *BbPortNum)
 
bool OpenBb (cssl_t **SerialBb, int BbPortNum)
 
void runBbUnit1 (float DesiredTemperature, cssl_t *SerialBb)
 

Variables

cssl_tSerialBb
 

Function Documentation

void FindBbPort ( int *  BbPortNum)
49 {
50  int i, nBytes = 255;
51  char strPort[32];
52  char comString[256];
53  cssl_t *SerialCheck;
54 
55  // Find Temperature Controller
56  for(i=0 ; i<16 ; i++) {
57  sprintf(strPort, "/dev/ttyUSB%d", i);
58  SerialCheck=cssl_open(strPort, 2400,8,0,1);
59 
60  COSMOS_USLEEP(10000);
61  if(SerialCheck) {
62  cssl_settimeout(SerialCheck, 0, 1); // 1 second timeout!
63 
64  // Is this a Temperature (BB) Controller
65  strcpy(comString, "#00R00\r\n");
66  cssl_putstring(SerialCheck,comString);
67  COSMOS_USLEEP(50000);
68  memset(comString, 0, 255);
69  cssl_getdata(SerialCheck, (uint8_t*)comString, nBytes);
70 
71 
72  // Takes a second time to get a reply if we did Slide first.
73  strcpy(comString, "#00R00\r\n");
74  cssl_putstring(SerialCheck,comString);
75  COSMOS_USLEEP(50000);
76  memset(comString, 0, 255);
77  cssl_getdata(SerialCheck, (uint8_t*)comString, nBytes);
78 
79 
80  if(strstr(comString, "#00R00=") != NULL) {
81  // It is!
82  *BbPortNum = i;
83  cssl_drain(SerialCheck);
84  cssl_close(SerialCheck);
85  break;
86  }
87  cssl_drain(SerialCheck);
88  cssl_close(SerialCheck);
89  }
90  }
91 }
int i
Definition: rw_test.cpp:37
int32_t cssl_close(cssl_t *serial)
Definition: cssl_lib.cpp:197
int32_t cssl_putstring(cssl_t *serial, char *str)
Definition: cssl_lib.cpp:535
cssl_t * cssl_open(const char *fname, int baud, int bits, int parity, int stop)
Definition: cssl_lib.cpp:108
int32_t cssl_getdata(cssl_t *serial, uint8_t *buffer, int size)
Definition: cssl_lib.cpp:738
int32_t cssl_drain(cssl_t *serial)
Definition: cssl_lib.cpp:685
int32_t cssl_settimeout(cssl_t *serial, int, double timeout)
Set read timeout.
Definition: cssl_lib.cpp:469
Definition: cssl_lib.h:34
bool OpenBb ( cssl_t **  SerialBb,
int  BbPortNum 
)
95 {
96  int nBytes = 255;
97  char comString[256];
98  char strPort[32];
99 
100  // ***Open BB
101  sprintf(strPort, "/dev/ttyUSB%d", BbPortNum);
102  *SerialBb=cssl_open(strPort, 2400,8,0,1);
103  if (!*SerialBb) {
104  printf("%s\n",cssl_geterrormsg());
105  return(false);
106  } else {
107 
108  cssl_settimeout(*SerialBb, 0, 0.5); // .05 second timeout.
109  // Start by requesting the Black Body temperature (so it will be ready later).
110  sprintf (comString, "#00R00\r\n");
111  cssl_putstring(*SerialBb,comString);
112 
113  // Throw away response
114  COSMOS_USLEEP(40000);
115  cssl_getdata(*SerialBb, (uint8_t*)comString, nBytes);
116 
117  return(true);
118  }
119 }
const char * cssl_geterrormsg()
Definition: cssl_lib.cpp:56
int32_t cssl_putstring(cssl_t *serial, char *str)
Definition: cssl_lib.cpp:535
cssl_t * cssl_open(const char *fname, int baud, int bits, int parity, int stop)
Definition: cssl_lib.cpp:108
int32_t cssl_getdata(cssl_t *serial, uint8_t *buffer, int size)
Definition: cssl_lib.cpp:738
int32_t cssl_settimeout(cssl_t *serial, int, double timeout)
Set read timeout.
Definition: cssl_lib.cpp:469
void runBbUnit1 ( float  DesiredTemperature,
cssl_t SerialBb 
)
126 {
127  char comStringIn[256];
128  char comStringOut[256];
129  int nBytes=255;
130 
131 
132  // ***** Set the temperature.
133  if(DesiredTemperature < 0) {
134  sprintf (comStringOut, "#00M01-%.1lfC\r\n", fabs(DesiredTemperature) );
135  }
136  else {
137  sprintf (comStringOut, "#00M01+%.1lfC\r\n", DesiredTemperature);
138  }
139 
140  // ***** Send the command.
141  cssl_putstring(SerialBb,comStringOut);
142  COSMOS_USLEEP(100000);
143 
144 
145  // ***** Get Athena's reply.
146  memset (comStringIn, 0, 40);
147  cssl_getdata(SerialBb, (uint8_t*)comStringIn, nBytes);
148  if ((strstr (comStringIn, "M")) == NULL) {
149 
150  //Try again if Athena didn't respond.
151  cssl_putstring(SerialBb,comStringOut);
152  COSMOS_USLEEP(100000);
153 
154  //Read Athena's reply.
155  memset (comStringIn, 0, 40);
156  cssl_getdata(SerialBb, (uint8_t*)comStringIn, nBytes);
157  if ((strstr (comStringIn, "M")) == NULL) {
158 
159  //Try a third time if Athena didn't respond.
160  cssl_putstring(SerialBb,comStringOut);
161  COSMOS_USLEEP(100000);
162 
163  //Read Athena's reply.
164  memset (comStringIn, 0, 40);
165  cssl_getdata(SerialBb, (uint8_t*)comStringIn, nBytes);
166  if ((strstr (comStringIn, "M")) == NULL) {
167  printf("Black Body not responding");
168  } else {
169  printf("\nTemperature set to %3.1fC" , DesiredTemperature);
170  }
171  } else {
172  printf("\nTemperature set to %3.1fC" , DesiredTemperature);
173  }
174  } else {
175  printf("\nTemperature set to %3.1fC" , DesiredTemperature);
176  }
177 
178 
179 
180  // ***** Send command to get temperature (So it will be ready for next request.)
181  strcpy(comStringOut, "#00R00\r\n");
182  cssl_putstring(SerialBb,comStringOut);
183  COSMOS_USLEEP(200000);
184 
185  return;
186 }
int32_t cssl_putstring(cssl_t *serial, char *str)
Definition: cssl_lib.cpp:535
int32_t cssl_getdata(cssl_t *serial, uint8_t *buffer, int size)
Definition: cssl_lib.cpp:738

Variable Documentation

cssl_t* SerialBb