|  |  |  | @ -1955,6 +1955,46 @@ exports.writeMotorStatus = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | exports.writeMotorStatus = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |   try { | 
			
		
	
		
			
				
					|  |  |  |  |     const motor_id = req.body.motor_id; | 
			
		
	
		
			
				
					|  |  |  |  |     const status = req.body.status; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Find the tank that contains the specified motor_id in its inputConnections
 | 
			
		
	
		
			
				
					|  |  |  |  |     const tank = await Tank.findOne({ "connections.inputConnections.motor_id": motor_id }); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     if (!tank) { | 
			
		
	
		
			
				
					|  |  |  |  |       return reply.status(404).send({ | 
			
		
	
		
			
				
					|  |  |  |  |         status_code: 404, | 
			
		
	
		
			
				
					|  |  |  |  |         message: 'Motor not found for the specified motor_id' | 
			
		
	
		
			
				
					|  |  |  |  |       }); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Find the inputConnection with the specified motor_id
 | 
			
		
	
		
			
				
					|  |  |  |  |     const inputConnection = tank.connections.inputConnections.find(conn => conn.motor_id === motor_id); | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     // Update the motor_status of the inputConnection
 | 
			
		
	
		
			
				
					|  |  |  |  |     inputConnection.motor_status = status; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Update real_motor_status based on the conditions
 | 
			
		
	
		
			
				
					|  |  |  |  |     if (status === "1" && inputConnection.real_motor_status === "4") { | 
			
		
	
		
			
				
					|  |  |  |  |       inputConnection.real_motor_status = 1; | 
			
		
	
		
			
				
					|  |  |  |  |     } else if (status === "2" && inputConnection.real_motor_status === "3") { | 
			
		
	
		
			
				
					|  |  |  |  |       inputConnection.real_motor_status = 2; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Save the updated tank
 | 
			
		
	
		
			
				
					|  |  |  |  |     await tank.save(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // Send the response with the updated motor_status
 | 
			
		
	
		
			
				
					|  |  |  |  |     reply.send({ | 
			
		
	
		
			
				
					|  |  |  |  |       status_code: 200, | 
			
		
	
		
			
				
					|  |  |  |  |       motor_status: status | 
			
		
	
		
			
				
					|  |  |  |  |     }); | 
			
		
	
		
			
				
					|  |  |  |  |   } catch (err) { | 
			
		
	
		
			
				
					|  |  |  |  |     throw boom.boomify(err); | 
			
		
	
		
			
				
					|  |  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |