From ca7459d64d3f7ef1579e5d0e1b899499ae24d9ec Mon Sep 17 00:00:00 2001
From: Carl Philipp Klemm <philipp@uvos.xyz>
Date: Thu, 22 Feb 2024 17:04:14 +0100
Subject: [PATCH] test: dont requrie a parameter on the get command, dont print
 time

---
 test.cpp | 52 +++++++++++++++++++++++-----------------------------
 1 file changed, 23 insertions(+), 29 deletions(-)

diff --git a/test.cpp b/test.cpp
index a38ace5..7e67331 100644
--- a/test.cpp
+++ b/test.cpp
@@ -28,46 +28,46 @@ void heaterfailed(int heater, int device)
 bool preparePsu(Vcpps* psu, float voltage, float current)
 {
 	Vcpps::Status status;
-	Log(Log::INFO)<<"Setting psu voltage to "<<voltage;
+	Log(Log::INFO, true, false)<<"Setting psu voltage to "<<voltage;
 	bool ret = psu->setVoltage(voltage);
 	if(!ret)
 	{
-		Log(Log::ERROR)<<"Unable to set psu voltage";
+		Log(Log::ERROR, true, false)<<"Unable to set psu voltage";
 		return false;
 	}
-	Log(Log::INFO)<<"Setting psu current to "<<current;
+	Log(Log::INFO, true, false)<<"Setting psu current to "<<current;
 	ret = psu->setCurrent(current);
 	if(!ret)
 	{
-		Log(Log::ERROR)<<"Unable to set psu current";
+		Log(Log::ERROR, true, false)<<"Unable to set psu current";
 		return false;
 	}
 	ret = psu->setEnabled(true);
 	if(!ret)
 	{
-		Log(Log::ERROR)<<"Unable to enable psu output";
+		Log(Log::ERROR, true, false)<<"Unable to enable psu output";
 		return false;
 	}
 
-	Log(Log::INFO)<<"Waiting for psu to stablize";
+	Log(Log::INFO, true, false)<<"Waiting for psu to stablize";
 	std::this_thread::sleep_for(std::chrono::seconds(2));
 
 	ret = psu->getStatus(status);
 	if(!ret || status.curent_limited)
 	{
-		Log(Log::ERROR)<<"Psu is overcurrent, abort";
+		Log(Log::ERROR, true, false)<<"Psu is overcurrent, abort";
 		psu->setEnabled(false);
 		return false;
 	}
 
-	Log(Log::INFO)<<"PSU voltage: "<<status.voltage<<" current: "<<status.current
+	Log(Log::INFO, true, false)<<"PSU voltage: "<<status.voltage<<" current: "<<status.current
 	<<" is currently "<<(status.curent_limited ? "" : "not")<<" current limited";
 	return true;
 }
 
 void print_cmd_help(const std::string& line)
 {
-	Log(Log::INFO)<<line<<" is not a valid command. Valid commands: connect (c), disconnect (d), set (s), get (g), clear."<<
+	Log(Log::INFO, true, false)<<line<<" is not a valid command. Valid commands: connect (c), disconnect (d), set (s), get (g), clear."<<
 		"all commands except clear require a number containing the id of the coincell after the command";
 }
 
@@ -82,11 +82,11 @@ int main(int argc, char** argv)
 
 	try
 	{
-		Log(Log::INFO)<<"Geting PSU";
+		Log(Log::INFO, true, false)<<"Geting PSU";
 		Vcpps psu(config.psuPort);
 		psu.setEnabled(false);
 
-		Log(Log::INFO)<<"Aquireing heaters and multiplexers";
+		Log(Log::INFO, true, false)<<"Aquireing heaters and multiplexers";
 		Heaters heaters(config.heaterSerials,
 						[&psu](int device, uint16_t serial, int code){devicefailed(psu, device, serial, code);},
 						&heaterfailed);
@@ -108,17 +108,11 @@ int main(int argc, char** argv)
 			std::vector<std::string> tokens = tokenize(line, ' ');
 
 			int coincellId = 0;
-
-			if(tokens.size() < 2 && tokens[0] != "clear")
-			{
-				print_cmd_help(line);
-				continue;
-			}
-			else if(tokens[0] != "clear" && tokens[0] != "get" && tokens.size() >= 2)
+			if(tokens[0] != "clear" && tokens[0] != "get" && tokens.size() >= 2)
 			{
 				coincellId = std::stol(tokens[1]);
 				if(coincellId < 0 || coincellId > coinCells.size())
-					Log(Log::ERROR)<<"Invalid coin cell id: "<<tokens[1];
+					Log(Log::ERROR, true, false)<<"Invalid coin cell id: "<<tokens[1];
 			}
 			else if(tokens.size() < 2 && tokens[0] != "clear" && tokens[0] != "get")
 			{
@@ -129,30 +123,30 @@ int main(int argc, char** argv)
 			{
 				bool ret = coinCells[coincellId]->setConnected(true);
 				if(!ret)
-					Log(Log::ERROR)<<"unable to connect coin cell "<<coincellId;
+					Log(Log::ERROR, true, false)<<"unable to connect coin cell "<<coincellId;
 				else
-					Log(Log::ERROR)<<"connected coin cell "<<coincellId;
+					Log(Log::ERROR, true, false)<<"connected coin cell "<<coincellId;
 			}
 			else if(tokens[0] == "disconnect" || tokens[0] == "d")
 			{
 				bool ret = coinCells[coincellId]->setConnected(false);
 				if(!ret)
-					Log(Log::ERROR)<<"unable to disconnect coin cell "<<coincellId;
+					Log(Log::ERROR, true, false)<<"unable to disconnect coin cell "<<coincellId;
 				else
-					Log(Log::ERROR)<<"disconnected coin cell "<<coincellId;
+					Log(Log::ERROR, true, false)<<"disconnected coin cell "<<coincellId;
 			}
 			else if(tokens[0] == "set" || tokens[0] == "s")
 			{
 				if(tokens.size() < 3)
 				{
-					Log(Log::ERROR)<<"This command requires a temperature";
+					Log(Log::ERROR, true, false)<<"This command requires a temperature";
 					continue;
 				}
 
 				float temperature = std::stod(tokens[2]);
 				if(temperature < 10 || temperature > 100)
 				{
-					Log(Log::ERROR)<<"Temperature "<<tokens[2]<<" is invalid";
+					Log(Log::ERROR, true, false)<<"Temperature "<<tokens[2]<<" is invalid";
 					continue;
 				}
 				coinCells[coincellId]->setEnabled(true);
@@ -168,14 +162,14 @@ int main(int argc, char** argv)
 					bool ret = cell->getTemperature(temperature);
 
 					if(!ret)
-						Log(Log::ERROR)<<"Cell "<<i<<" UNABLE TO READ";
+						Log(Log::ERROR, true, false)<<"Cell "<<i<<" UNABLE TO READ";
 					else
-						Log(Log::INFO)<<"Cell "<<i<<" temperature "<<temperature;
+						Log(Log::INFO, true, false)<<"Cell "<<i<<" temperature "<<temperature;
 				}
 
 				auto connected = multiplexers.getConnected();
 				for(size_t i = 0; i < connected.size(); ++i)
-					Log(Log::INFO)<<"multiplexer channel "<<i<<' '<<(connected[i] ? "connected" : "disconnected");
+					Log(Log::INFO, true, false)<<"multiplexer channel "<<i<<' '<<(connected[i] ? "connected" : "disconnected");
 			}
 			else if(tokens[0] == "clear")
 			{
@@ -188,7 +182,7 @@ int main(int argc, char** argv)
 	}
 	catch(const startup_failure& err)
 	{
-		Log(Log::ERROR)<<err.what();
+		Log(Log::ERROR, true, false)<<err.what();
 		return 1;
 	}
 
-- 
GitLab