예제 #1
0
uint8_t slave_null_read_data(uint8_t slave_addr, uint8_t* buf, uint8_t max_len)
{
			/* limit number of registers to the max. available */
			if(max_len > sizeof(modbus_null_input_register_list))
			{
				max_len = sizeof(modbus_null_input_register_list);
			}
		
#if MODBUS_NULL_SLAVE_SIMULATION == 0				
			/* Detecta equipamentos de medição e faz a leitura dos dados */			
			NULL_IRList.Reg.Pressure_Valve = sensors_read(PRESSURE_VALVE);
			NULL_IRList.Reg.Oil_Level =  sensors_read(SENSOR_LEVEL);
			FATFS   *fs;	 /* Pointer to file system object */
			uint32_t p1;
			if (f_getfree(".", (DWORD*)&p1, &fs) == FR_OK)
			{
				NULL_IRList.Reg.SD_bytes_available = (uint32_t)(p1 * fs->csize * 512);
			}			
			NULL_IRList.Reg.Local_time = (uint32_t)simon_clock_get();
#else	
			uint8_t nregs = 0;
			/* return random data */	
			for(nregs = NULL_REGLIST_OFFSET_NREGS; nregs < (NULL_REGLIST_INPUT_NREGS+NULL_REGLIST_OFFSET_NREGS);nregs++)
			{				
				NULL_IRList.Regs16[nregs] = random_get();
			}
#endif
		
			/* get and set timestamp of reading and device id */
			SetModbusHeader(slave_addr, NULL_IRList.Regs8);	
			memcpy(buf,NULL_IRList.Regs8,max_len);						
			return (max_len);			
}
예제 #2
0
int 
main (int argc, char **argv)
{
	int ch;
	/*char uptimeInfo[15], lightInfo[15], timebuf[15];*/
	/*int lightlevel;*/
	int ocontrast = 40; /* Contrast defaults to 40 */
	screen_t *sc;
	sensor_t  sensors;
	led_t	  displed;
	extern char *optarg;
	extern int optind;/*, opterr, optopt;*/


	while ((ch = getopt(argc, argv, "lDvc:")) != -1) {
		switch (ch) {
			case 'l':
				led_on_darkness=1;
				break;
			case 'D':
				dodaemon=1;
				break;
			case 'v':
				verbose_mode=1;
				break;
			case 'c':
				ocontrast = atoi(optarg);
				break;
			default:
				usage();
		}
	}
	argc -= optind;
	argv += optind;
	if (dodaemon) {
		daemon(1, 0);
	}
	openlog("pcd8544", LOG_PID|LOG_PERROR, LOG_LOCAL0);
	/* print infos */
	syslog(LOG_LOCAL0|LOG_INFO, "pilab");

  


	if ((sc = screen_init(DIN_PIN, SCLK_PIN, DC_PIN, RST_PIN, CS_PIN, ocontrast)) == NULL) {
		syslog(LOG_LOCAL0|LOG_INFO, "failed to init screen");
		err(3, "failed to init screen");
	}

	/* check wiringPi setup */
	delay(2000);
 	if (verbose_mode)
		syslog(LOG_LOCAL0|LOG_DEBUG, "initialisation of screen led");
        led_init(&displed, DISP_LED_GPIO);
 	if (verbose_mode)
		syslog(LOG_LOCAL0|LOG_DEBUG, "initialisation of screen led - bringing up");
	led_setstate(&displed, LED_UP);
  
	for (;;) {
		/* clear lcd */
		LCDclear();
	  
		if (sensors_read(&sensors) < 0)
			syslog(LOG_LOCAL0|LOG_INFO, "failed to read data from sensors");
		if (led_on_darkness) {
			if (sensors.sens_light < 50 && displed.l_state != LED_UP) {
				if (verbose_mode)
					syslog(LOG_LOCAL0|LOG_DEBUG, "bringing screen led up");
				led_setstate(&displed, LED_UP);
			} else if (sensors.sens_light > 50 && displed.l_state == LED_UP)
				led_setstate(&displed, LED_DOWN);
		}

		if (statistics_update(sc, &sensors) < 0)
			syslog(LOG_LOCAL0|LOG_INFO, "failed to update statistics");
		if (screen_include(sc) < 0)
			syslog(LOG_LOCAL0|LOG_INFO, "failed to include file line");
		/* build screen */
		screen_update(sc);
	  
		sleep(5);
	}
  return 0;
}