Example #1
0
static void sync_serial(void) {
	char buffer[10];

	ser_send(upsfd, "\r");
	ser_get_line(upsfd, buffer, sizeof(buffer), '\r', "\012", 3, 0);
	ser_get_line(upsfd, buffer, sizeof(buffer), ENDCHAR, IGNCHARS, 3, 0);

	while (ser_get_line(upsfd, buffer, sizeof(buffer), '>', "\012", 3, 0) <= 0) {
		ser_send(upsfd, "\r");
	}
}
Example #2
0
static int execute(const char *cmd, char *result, int resultsize) 
{
  int ret;
  char buf[256];
  
  ser_send(upsfd, "%s", cmd);
  ser_get_line(upsfd, buf, sizeof(buf), '\012', "", 3, 0);
  ret = ser_get_line(upsfd, result, resultsize, '\015', "\012", 3, 0);
  ser_get_line(upsfd, buf, sizeof(buf), '>', "", 3, 0);
  return ret;

}
Example #3
0
int sec_upsrecv (char *buf)
{

 char lenbuf[4];
 int  ret;
	

        ser_get_line(upsfd, buf, 140, ENDCHAR, IGNCHARS,SER_WAIT_SEC, SER_WAIT_USEC);
	if (buf[0] ==  SEC_MSG_STARTCHAR){
		switch (buf[1]){
		case  SEC_NAK:
		return(-1);
		case  SEC_ACK:
		return(0);
		case SEC_DATAMSG:
		strncpy(lenbuf,buf+2,3);
		ret = atoi(lenbuf);
		if (ret > 0){
		strcpy(buf,buf+5);
		return(ret);}
		else return (-2);
		default:
		return(-2);
		}
	}	
	else 
         { return (-2); }
}
Example #4
0
File: oneac.c Project: sbutler/nut
int OneacGetResponse (char* chBuff, const int BuffSize, int ExpectedCount)
{
	int Retries = 10;		/* x/2 seconds max with 500000 USEC */
	int return_val;

	do
	{
		return_val = ser_get_line(upsfd, chBuff, BuffSize, ENDCHAR, IGNCHARS, 
																	SECS, USEC);

		if (return_val == ExpectedCount)
			break;

		upsdebugx (3,"!OneacGetResponse retry (%d, %d)...", return_val,Retries);
		
	} while (--Retries > 0);

	upsdebugx (4,"OneacGetResponse buffer: %s",chBuff);

	if (Retries == 0)
	{
		upsdebugx (2,"!!OneacGetResponse timeout...");
		return_val = 1;					/* Comms error */
	}
	else
	{
		if (Retries < 10)
			upsdebugx (2,"OneacGetResponse recovered (%d)...", Retries);
			
		return_val = 0;					/* Good comms */
	}
	
    return return_val;
}
Example #5
0
File: oneac.c Project: sbutler/nut
int SetOutputAllow(const char* lowval, const char* highval)
{
	char buffer[32];

	snprintf(buffer, 4, "%.3s", lowval);

	/*the UPS wants this value to always be three characters long*/
	/*so put a zero in front of the string, if needed....      */

	if (strlen(buffer) < 3)
	{
		buffer[3] = '\0';
		buffer[2] = buffer[1];
		buffer[1] = buffer[0];
		buffer[0] = '0';
	}
	
	upsdebugx (2,"SetOutputAllow sending %s%.3s,%.3s...", 
											SETX_OUT_ALLOW, buffer, highval);
					
	ser_send(upsfd,"%s%.3s,%.3s%s", SETX_OUT_ALLOW, buffer, highval, 
																COMMAND_END);
	ser_get_line(upsfd,buffer,sizeof(buffer), ENDCHAR, IGNCHARS,SECS,USEC);
	
	if(buffer[0] == DONT_UNDERSTAND)
	{
		upsdebugx (2,"SetOutputAllow got asterisk back...");

		return 1;					/* Invalid command */
	}
	
	return 0;						/* Valid command */
}