Example #1
0
// revoke access to GPIO and PWM
bool GPIO_teardown() {
	for (size_t i = 0; i < SIZE_OF_ARRAY(gpio_map); ++i) {
		delete_map(gpio_map[i]);
	}

	for (size_t i = 0; i < SIZE_OF_ARRAY(pwm); ++i) {
		if (NULL != pwm[i].name) {
			close(pwm[i].fd);
			free(pwm[i].name);
		}
	}

	if (NULL != slots) {
		// should unload the loaded firmware here,
		// but any attempt to do this crashes the process
		// probably a kernel bug, which may cause system instablility
		free(slots);
	}

	if (NULL != ocp) {
		free(ocp);
	}

	// clear all pointers so calling setup again will work
	memset(gpio_map, 0, sizeof(gpio_map));
	memset(pwm, 0, sizeof(pwm));
	slots = NULL;
	ocp = NULL;

	return true;
}
Example #2
0
/********************************************************************
 * @创建人 :揭成
 * @功能 :USB主窗口
 * @输入 :NONE
 * @输出  :NONE
********************************************************************/
void app_USBmod_window_creat( void )
{
	Bsize_t hoffset = 0;
	Bsize_t voffset = 0;
	hwin_t*hp;
	GUI_window_hwin_req(GET_GUIWIN);
	GUI_set_Bgcolor( USBmod_BG_COLOR );
	GUI_clean_screen();
	GUI_set_Bgcolor( USBmod_WIN_BG_COLOR );
	GUI_set_Fgcolor( USBmod_FG_COLOR );
	GUI_SetFront(&GUI_HZK16_EXTASCII);
	m_USB_win = Gui_3D_window_creat((LCD_WIDE-540)/2,(LCD_HIGH-450)/2,540,450,( char* )m_usb_title[g_language], WIN_3D | WIN_FILL, GET_GUIWIN );

	GUI_window_hwin_req( m_USB_win );
	GUI_SetFront(&GUI_HZK16_EXTASCII);
	while ( voffset < ( SIZE_OF_ARRAY(m_usb_option) / 2 + 1 ) )
	{
		if ( hoffset < SIZE_OF_ARRAY(m_usb_option))
		{
			hp = Gui_button_creat(80, 20 + (voffset)*(85),150,35, app_global_Ntokey( hoffset ) | BUTTON_PAINT, m_USB_win);
			GUI_button_title_display( hp, (char* )m_usb_option[hoffset][g_language] );
			hoffset++;
		}
		if ( hoffset < SIZE_OF_ARRAY(m_usb_option))
		{
			hp = Gui_button_creat(310,20 + (voffset)*(85),150,35,app_global_Ntokey( hoffset ) | BUTTON_PAINT, m_USB_win);
			GUI_button_title_display( hp, ( char* )m_usb_option[hoffset][g_language] );
			hoffset++;
		}
		voffset++;
	}
	GUI_window_hwin_release( m_USB_win );
	GUI_window_hwin_release(GET_GUIWIN);
	return;
}
Example #3
0
/// revoke access to GPIO and PWM
bool GPIO_teardown() {
	for (size_t i = 0; i < SIZE_OF_ARRAY(gpio_info); ++i) {
		if (NULL == gpio_info[i].name) {
			continue;
		}
		if (gpio_info[i].fd >= 0) {
			close(gpio_info[i].fd);
			gpio_info[i].fd = -1;
		}
		if (NULL != gpio_info[i].state) {
			free(gpio_info[i].state);
			gpio_info[i].state = NULL;
		}
		if (NULL != gpio_info[i].number) {
			unexport(gpio_info[i].number);
			free(gpio_info[i].number);
			gpio_info[i].number = NULL;
		}
		if (NULL != gpio_info[i].direction) {
			free(gpio_info[i].direction);
			gpio_info[i].direction = NULL;
		}
		if (NULL != gpio_info[i].active_low) {
			free(gpio_info[i].active_low);
			gpio_info[i].active_low = NULL;
		}
		if (NULL != gpio_info[i].value) {
			free(gpio_info[i].value);
			gpio_info[i].value = NULL;
		}
	}

	for (size_t i = 0; i < SIZE_OF_ARRAY(pwm); ++i) {
		if (NULL != pwm[i].name) {
			close(pwm[i].fd);
			pwm[i].fd = -1;
			free(pwm[i].name);
			pwm[i].name = NULL;
		}
	}

	if (NULL != slots) {
		// should unload the loaded firmware here,
		// but any attempt to do this crashes the process
		// probably a kernel bug, which may cause system instablility
		free(slots);
		slots = NULL;
	}

	if (NULL != ocp) {
		free(ocp);
		ocp = NULL;
	}

	// all data cleared so calling setup again will work

	return true;
}
Test(snmptrapd_parser, test_v2_with_symbolic_names_and_various_types)
{
  const gchar *input =
    "2017-05-13 12:17:32 localhost [UDP: [127.0.0.1]:52407->[127.0.0.1]:162]:  \n "
    "mib-2.1.3.0 = Timeticks: (875496867) 101 days, 7:56:08.67 \t"
    "snmpModules.1.1.4.1.0 = OID: netSnmpExampleHeartbeatNotification "
    "netSnmpExampleHeartbeatRate = INTEGER: 60\t"
    "netSnmpExampleString = STRING: \"string innerkey='innervalue'\"\t"
    "org.2.2 = Gauge32: 22\t"
    "org.1.1 = Counter32: 11123123   "
    "org.5.3 = Hex-STRING: A0 BB CC DD EF \t"
    "org.8.8 = NULL\t"
    "dod.7 = IpAddress: 192.168.1.0\t  "
    "org.5.9 = STRING: \"@\"";

  TestNameValue expected[] =
  {
    { ".snmp.hostname", "localhost" },
    { ".snmp.transport_info", "UDP: [127.0.0.1]:52407->[127.0.0.1]:162" },
    { ".snmp.snmpModules.1.1.4.1.0", "netSnmpExampleHeartbeatNotification" },
    { ".snmp.netSnmpExampleHeartbeatRate", "60" },
    { ".snmp.netSnmpExampleString", "string innerkey='innervalue'" },
    { ".snmp.org.2.2", "22" },
    { ".snmp.org.1.1", "11123123" },
    { ".snmp.org.5.3", "A0 BB CC DD EF" },
    { ".snmp.org.8.8", "NULL" },
    { ".snmp.dod.7", "192.168.1.0" },
    { ".snmp.org.5.9", "@" }
  };

  assert_log_message_name_values(input, expected, SIZE_OF_ARRAY(expected));
}
Example #5
0
tag_reader* reader_wma( DWORD handle )
{
	if (HIWORD(BASS_GetVersion())<0x204)
		return new reader( handle );

	return new preproc_reader( 
		BASS_ChannelGetTags( handle, BASS_TAG_WMA ),
		"WMA: bad tag format", remap, SIZE_OF_ARRAY(remap), '=', 0 );
}
Example #6
0
File: gpio.c Project: RavenB/gratis
/// revoke access to GPIO and PWM
bool GPIO_teardown() {

	// finalise SPI multiplexor
	for (int i = 0; i < SIZE_OF_ARRAY(spi_state_file); ++i) {
		write_file(spi_state_file[i], MUX_default "\n", CONST_STRLEN(MUX_default "\n"));
	}

	for (size_t pin = 0; pin < SIZE_OF_ARRAY(gpio_info); ++pin) {
		if (Mode_NONE == gpio_info[pin].active) {
			continue;
		}
		if (gpio_info[pin].fd >= 0) {
			close(gpio_info[pin].fd);
			gpio_info[pin].fd = -1;
		}

		switch(gpio_info[pin].active) {
		case Mode_NONE:
			break;

		case Mode_GPIO:
			unexport(pin);
			break;

		case Mode_PWM:
		{
			int chip = gpio_info[pin].pwm_chip;
			int channel = gpio_info[pin].pwm_channel;

			write_pwm_file(PWM_DUTY_CYCLE, chip, channel, "0\n", 2);
			write_pwm_file(PWM_ENABLE, chip, channel, "0\n", 2);

			unexport_pwm(chip, channel);
			write_file(pwm_state_file[gpio_info[pin].pwm_state], MUX_default "\n", CONST_STRLEN(MUX_default "\n"));
			//unexport(pin);
			break;
		}
		}

		gpio_info[pin].active = Mode_NONE;
	}

	return true;
}
Example #7
0
Host::Host( NvPlatformContext* platform ) : NvOwnApp( platform, "Application Name" )
{
	horizon::core::sysInit();

	horizon::core::jobInit( &sSandboxJobList[0], SIZE_OF_ARRAY( sSandboxJobList ) );
	horizon::core::jobChange( "Initialize" );

	mpInputReceiver = NULL;
	mSingleKeyDown = 0;
}
Example #8
0
int main(int argc, char const *argv[])
{
    char array[10];
    printf("array: %d\n", array);                   // arrayはarray[0]のアドレスと一致する!.
    for (int i = 0; i < SIZE_OF_ARRAY(array); ++i)
    {
        printf("&array[%d]: %d\n", i, &array[i]);
    }
    return 0;
}
Example #9
0
const char *EntryList_entryTypeToString(EntryTypes entryType, const char *defaultValue)
{
  uint       z;
  const char *name;

  z = 0;
  while (   (z < SIZE_OF_ARRAY(ENTRY_TYPES))
         && (ENTRY_TYPES[z].entryType != entryType)
        )
  {
    z++;
  }
  if (z < SIZE_OF_ARRAY(ENTRY_TYPES))
  {
    name = ENTRY_TYPES[z].name;
  }
  else
  {
    name = defaultValue;
  }

  return name;
}
Example #10
0
int main( void )
{
	time_t t;
	srand((unsigned) time(&t));
	unsigned int frequency[ 10 ] = { 0 }; // init array frequency of size 10 with all values 0.
	unsigned int response[ SIZE ];
	for ( int i = 0; i < SIZE; i++) // generate an array of random numbers
	{
		response[i] = (rand() % 9) + 1;
	}
	mean( response );
	median( response, SIZE_OF_ARRAY(response)); // I could just compare based on SIZE but i wanted to learn how get the number of elements from an array.
	mode( frequency, response );
}
Example #11
0
bool EntryList_parseEntryType(const char *name, EntryTypes *entryType)
{
  uint z;

  assert(name != NULL);
  assert(entryType != NULL);

  z = 0;
  while (   (z < SIZE_OF_ARRAY(ENTRY_TYPES))
         && !stringEqualsIgnoreCase(ENTRY_TYPES[z].name,name)
        )
  {
    z++;
  }
  if (z < SIZE_OF_ARRAY(ENTRY_TYPES))
  {
    (*entryType) = ENTRY_TYPES[z].entryType;
    return TRUE;
  }
  else
  {
    return FALSE;
  }
}
Example #12
0
void GPIO_mode(GPIO_pin_type pin, GPIO_mode_type mode) {

	// ignore unimplemented pins
	if (pin < 0 || pin >= SIZE_OF_ARRAY(gpio_info) || NULL == gpio_info[pin].name) {
		return;
	}

	switch (mode) {
	default:
	case GPIO_INPUT:
		if (gpio_info[pin].fd < 0 && !GPIO_enable(pin)) {
			return;
		}
		write_file(gpio_info[pin].direction, DIRECTION_in "\n", CONST_STRLEN(DIRECTION_in "\n"));
		write_file(gpio_info[pin].active_low, "0\n", 2);
		write_file(gpio_info[pin].state, STATE_rxEnable_pullNone "\n", CONST_STRLEN(STATE_rxEnable_pullNone "\n"));
		break;

	case GPIO_OUTPUT:
		if (gpio_info[pin].fd < 0 && !GPIO_enable(pin)) {
			return;
		}
		write_file(gpio_info[pin].direction, DIRECTION_out "\n", CONST_STRLEN(DIRECTION_out "\n"));
		write_file(gpio_info[pin].active_low, "0\n", 2);
		write_file(gpio_info[pin].state, STATE_rxDisable_pullNone "\n", CONST_STRLEN(STATE_rxDisable_pullNone "\n"));
		break;

	case GPIO_PWM:  // only certain pins allowed
		switch (pin) {
		case GPIO_P9_14:    // EHRPWM1A
			PWM_enable(0, "P9_14");
			break;
		case GPIO_P9_16:    // EHRPWM1B
			PWM_enable(1, "P9_16");
			break;
		case GPIO_P8_19:    // EHRPWM2A
			PWM_enable(2, "P8_19");
			break;
		case GPIO_P8_13:    // EHRPWM2B
			PWM_enable(3, "P8_13");
			break;
		default:
			break;
		}
		break;
	}
}
Example #13
0
File: gpio.c Project: RavenB/gratis
void GPIO_write(GPIO_pin_type pin, int value) {
	// ignore unimplemented or inactive pins
	if (pin < 0 || pin >= SIZE_OF_ARRAY(gpio_info) || NULL == gpio_info[pin].name || gpio_info[pin].fd < 0) {
		return;
	}

	int fd = gpio_info[pin].fd;

	lseek(fd, 0, SEEK_SET);

	if (0 == value) {
		write(fd, "0\n", 2);
	} else {
		write(fd, "1\n", 2);
	}
	fsync(fd);
}
Example #14
0
LOCAL void printUsage(const char *programName)
 {
  assert(programName != NULL);

  printf("Usage: %s [<options>] [--] <input file> [<command>...]\n",programName);
  printf("\n");
  printf("Commands:\n");
  printf("  m:<position>:<value>  - modify byte at <position> into <value>\n");
  printf("  r:<position>:<length> - randomize <length> byte from <position>\n");
  printf("  d:<position>:<length> - delete <length> bytes from <position>\n");
  printf("  i:<position>:<value>  - insert at <position> byte <value>\n");
  printf("\n");
  CmdOption_printHelp(stdout,
                      COMMAND_LINE_OPTIONS,SIZE_OF_ARRAY(COMMAND_LINE_OPTIONS),
                      0
                     );
 }
Example #15
0
int32_t AR0330_GetContrast(int32_t option) {
	CyU3PDebugPrint(4, "AR0330_GetContrast\r\n");

	switch (option) {
	default:
		return 0;
	case 1:  // current value
		return current_contrast;
	case 2:  // minimum value
		return 0;
	case 3:  // maximum value
		return SIZE_OF_ARRAY(analog_gain) - 1;
	case 4:  // resolution
		return 1;
	case 7:  // default
		return 0;
	}
}
Example #16
0
File: gpio.c Project: RavenB/gratis
int GPIO_read(int pin) {
	// ignore unimplemented or inactive pins
	if (pin < 0 || pin >= SIZE_OF_ARRAY(gpio_info) || NULL == gpio_info[pin].name || gpio_info[pin].fd < 0) {
		return 0;
	}

	int fd = gpio_info[pin].fd;
	char buffer[2];
	buffer[0] = 0;

	lseek(fd, 0, SEEK_SET);
	read(fd, buffer, sizeof(buffer));

	if ('1' == buffer[0]) {
		return 1;
	} else {
		return 0;
	}
}
Example #17
0
File: gpio.c Project: RavenB/gratis
static bool load_firmware(const char *pin_name) {

	int fd = open(CAPE_MANAGER_SLOTS, O_RDWR);
	if (fd < 0) {
		return false;  // failed
	}

	char buffer[8192];  // only 4096 is indicated in sysfs, can it be larger?

	memset(buffer, 0, sizeof(buffer));
	read(fd, buffer, sizeof(buffer) - 1);  // allow one nul at end

#if defined(CAPE_IIO)
	// IO multiplexing
	LOAD_CAPE_FIRMWARE_FILE(CAPE_IIO)
#endif

#if defined(CAPE_UNIVERSAL)
	// try universal before other I/Os
	LOAD_CAPE_FIRMWARE_FILE(CAPE_UNIVERSAL)
#endif

#if defined(CAPE_PWM)
	// PWM
	LOAD_CAPE_FIRMWARE_FILE(CAPE_PWM)
#endif

#if defined(CAPE_SPI)
	// also set up SPI0 -> /dev/spidevX.Y
	LOAD_CAPE_FIRMWARE_FILE(CAPE_SPI)
#endif

	// finished with the cape manager
	close(fd);

	// initialise SPI multiplexor
	for (int i = 0; i < SIZE_OF_ARRAY(spi_state_file); ++i) {
		write_file(spi_state_file[i], MUX_spi "\n", CONST_STRLEN(MUX_spi "\n"));
	}

	return true;
}
Example #18
0
void AR0330_Debug(void)
{
#if DEBUG_ENABLE
	uint16_t tempaddr = 0x3000;
	int i;
	for (i = 0; i < 256; i += 4) {
		CyU3PDebugPrint(4, "DEBUG: 0x%x:  ", tempaddr);
		int j;
		for (j = 0; j < 4; ++j, tempaddr += 2) {
			uint16_t d;
			sensor_read(tempaddr, &d);
			CyU3PDebugPrint(4, "0x%x%x%x%x ",
					 (d >> 12) & 0x0f,
					 (d >>  8) & 0x0f,
					 (d >>  4) & 0x0f,
					 (d >>  0) & 0x0f);
		}
		CyU3PDebugPrint(4, "\r\n");
	}

	static const uint16_t addresses[] = {
		0x3780,
		0x301A  // reset status
//		0x3ED0,  0x3ED2,  0x3ED4,  0x3ED6,
//		0x3ED8,  0x3EDA,  0x3EDC,  0x3EDE,
//		0x3EE0,                    0x3EE6,
//		0x3EE8,  0x3EEA,
//		0x3F06,
	};

	for (i = 0; i < SIZE_OF_ARRAY(addresses); ++i) {
		tempaddr = addresses[i];
		uint16_t tempdata;
		sensor_read(tempaddr, &tempdata);
		CyU3PDebugPrint(4, "DEBUG: read address = 0x%x data = 0x%x\r\n", tempaddr, tempdata);
	}

	// report if MIPI is active
	CyU3PDebugPrint(4, "DEBUG: MIPI active = %d\r\n", CyU3PMipicsiCheckBlockActive());
#endif
}
Example #19
0
Test(snmptrapd_parser, test_v1_with_symbolic_names)
{
  const gchar *input =
    "2017-05-13 12:18:30  localhost  [UDP: [127.0.0.1]:58143->[127.0.0.1]:162] : netSnmpExampleNotification \n"
    "\t Warm Start Trap (1) Uptime:  27 days, 2:39:02.34\n "
    "netSnmpExampleInteger = INTEGER: 123456 \t netSnmpExampleString = STRING: random string";

  TestNameValue expected[] =
  {
    { ".snmp.hostname", "localhost" },
    { ".snmp.transport_info", "UDP: [127.0.0.1]:58143->[127.0.0.1]:162" },
    { ".snmp.enterprise_oid", "netSnmpExampleNotification" },
    { ".snmp.type", "Warm Start Trap" },
    { ".snmp.subtype", "1" },
    { ".snmp.uptime", "27 days, 2:39:02.34" },
    { ".snmp.netSnmpExampleInteger", "123456" },
    { ".snmp.netSnmpExampleString", "random string" }
  };

  assert_log_message_name_values(input, expected, SIZE_OF_ARRAY(expected));
}
Example #20
0
/*******************************************************************
*
*       _DrawIt
*/
static void _DrawIt(void * pData) {
  tDrawItContext * pDrawItContext = (tDrawItContext *)pData;
  GUI_Clear();
  GUI_SetFont(&GUI_Font8x8);
  GUI_SetTextMode(GUI_TM_TRANS);
  /* draw background */
  GUI_SetColor(GUI_GREEN);
  GUI_FillRect(pDrawItContext->XPos_Text, 
               pDrawItContext->YPos_Text - 25,
               pDrawItContext->XPos_Text + 100,
               pDrawItContext->YPos_Text - 5);
  /* draw polygon */
  GUI_SetColor(GUI_BLUE);
  GUI_FillPolygon(pDrawItContext->aPointsDest, SIZE_OF_ARRAY(aPoints), 160, 120);
  /* draw foreground */
  GUI_SetColor(GUI_RED);
  GUI_FillRect(220 - pDrawItContext->XPos_Text, 
               pDrawItContext->YPos_Text + 5,
               220 - pDrawItContext->XPos_Text + 100,
               pDrawItContext->YPos_Text + 25);
}
Example #21
0
Test(snmptrapd_parser, test_general_v1_message_with_oids)
{
  const gchar *input =
    "2017-11-10 13:23:16 localhost [UDP: [127.0.0.1]:53831->[127.0.0.1]:162]: iso.3.6.1.4.1.8072.2.3.1\n"
    "\t Enterprise Specific Trap (.17) Uptime: 18:41:07.83\n"
    "iso.3.6.1.4.1.8072.2.1.1 = INTEGER: 123456";

  TestNameValue expected[] =
  {
    { ".snmp.hostname", "localhost" },
    { ".snmp.transport_info", "UDP: [127.0.0.1]:53831->[127.0.0.1]:162" },
    { ".snmp.enterprise_oid", "iso.3.6.1.4.1.8072.2.3.1" },
    { ".snmp.type", "Enterprise Specific Trap" },
    { ".snmp.subtype", ".17" },
    { ".snmp.uptime", "18:41:07.83" },
    { ".snmp.iso.3.6.1.4.1.8072.2.1.1", "123456" },
    { "DATE", "Nov 10 13:23:16" }
  };

  assert_log_message_name_values(input, expected, SIZE_OF_ARRAY(expected));
}
Example #22
0
Test(snmptrapd_parser, test_general_v2_message_with_oids)
{
  const gchar *input =
    "2017-05-10 12:46:14 web2-kukorica.syslog_ng.balabit [UDP: [127.0.0.1]:34257->[127.0.0.1]:162]:\n"
    "iso.3.6.1.2.1.1.3.0 = Timeticks: (875496867) 101 days, 7:56:08.67\t"
    "iso.3.6.1.6.3.1.1.4.1.0 = OID: iso.3.6.1.4.1.8072.2.3.0.1       "
    "iso.3.6.1.4.1.8072.2.3.2.1 = INTEGER: 60        \t "
    "iso.3.6.1.4.1.8072.2.1.3 = \"\"";

  TestNameValue expected[] =
  {
    { ".snmp.hostname", "web2-kukorica.syslog_ng.balabit" },
    { ".snmp.transport_info", "UDP: [127.0.0.1]:34257->[127.0.0.1]:162" },
    { ".snmp.iso.3.6.1.2.1.1.3.0", "(875496867) 101 days, 7:56:08.67" },
    { ".snmp.iso.3.6.1.6.3.1.1.4.1.0", "iso.3.6.1.4.1.8072.2.3.0.1" },
    { ".snmp.iso.3.6.1.4.1.8072.2.3.2.1", "60" },
    { ".snmp.iso.3.6.1.4.1.8072.2.1.3", "" },
    { "DATE", "May 10 12:46:14" },
  };

  assert_log_message_name_values(input, expected, SIZE_OF_ARRAY(expected));
}
Example #23
0
/*******************************************************************
*
*       _DemoBandingMemdev
*/
static void _DemoBandingMemdev(void) {
  tDrawItContext DrawItContext;
  int i, swap=0;
  GUI_SetBkColor(GUI_BLACK);
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);
  GUI_SetFont(&GUI_Font24_ASCII);
  GUI_DispStringHCenterAt("MEMDEV_Banding - Sample", 160, 5);
  GUI_SetFont(&GUI_Font8x9);
  GUI_DispStringHCenterAt("Banding memory device\nwithout flickering", 160, 40);
  DrawItContext.XPos_Poly = 160;
  DrawItContext.YPos_Poly = 120;
  DrawItContext.YPos_Text = 116;
  while (1) {
    swap = ~swap;
    for (i = 0; i < 220; i++) {
      float angle = i * 3.1415926 / 55;
      DrawItContext.XPos_Text = (swap) ? i : 220 - i;
      /* Rotate the polygon */
      GUI_RotatePolygon(DrawItContext.aPointsDest, aPoints, 
                        SIZE_OF_ARRAY(aPoints), angle);
      #if USE_BANDING_MEMDEV
      {
        GUI_RECT Rect = {0, 70, 320,170};
        /* Use banding memory device for drawing */
        GUI_MEMDEV_Draw(&Rect, &_DrawIt, &DrawItContext, 0, 0);
      }
      #else
        /* Simple drawing without using memory devices */
        _DrawIt((void *)&DrawItContext);
      #endif
      #ifdef WIN32
        GUI_Delay(20); /* Use a short delay only in the simulation */
      #endif
    }
  }
}
Example #24
0
File: gpio.c Project: RavenB/gratis
void GPIO_mode(GPIO_pin_type pin, GPIO_mode_type mode) {

	// ignore unimplemented pins
	if (pin < 0 || pin >= SIZE_OF_ARRAY(gpio_info) || NULL == gpio_info[pin].name) {
		return;
	}

	switch (mode) {
	default:
	case GPIO_INPUT:
		if (gpio_info[pin].fd < 0 && !GPIO_enable(pin)) {
			return;
		}
		write_pin_file(GPIO_DIRECTION, pin, GPIO_DIRECTION_in "\n", CONST_STRLEN(GPIO_DIRECTION_in "\n"));
		write_pin_file(GPIO_ACTIVE_LOW, pin, "0\n", 2);
		write_pin_file(GPIO_EDGE, pin, GPIO_EDGE_none "\n", CONST_STRLEN(GPIO_EDGE_none "\n"));
		//write_pin_file(GPIO_STATE, pin, STATE_rxEnable_pullNone "\n", CONST_STRLEN(STATE_rxEnable_pullNone "\n"));
		break;

	case GPIO_OUTPUT:
		if (gpio_info[pin].fd < 0 && !GPIO_enable(pin)) {
			return;
		}
		write_pin_file(GPIO_DIRECTION, pin, GPIO_DIRECTION_out "\n", CONST_STRLEN(GPIO_DIRECTION_out "\n"));
		write_pin_file(GPIO_ACTIVE_LOW, pin, "0\n", 2);
		write_pin_file(GPIO_EDGE, pin, GPIO_EDGE_none "\n", CONST_STRLEN(GPIO_EDGE_none "\n"));
		//write_pin_file(GPIO_STATE, pin, STATE_rxDisable_pullNone "\n", CONST_STRLEN(STATE_rxDisable_pullNone "\n"));
		break;

	case GPIO_PWM:  // only certain pins allowed
		if (gpio_info[pin].fd < 0 && !PWM_enable(pin)) {
			return;
		}
		break;
	}
}
Example #25
0
    "2017-05-17 13:26:04 localhost [UDP: [127.0.0.1]:34257->[127.0.0.1]:162]:\n"
    "iso.3.6.1.4.1.18372.3.2.1.1.1.6 = STRING: \"test\"";

  TestNameValue expected[] =
  {
    { ".snmp.hostname", "localhost" },
    { ".snmp.transport_info", "UDP: [127.0.0.1]:34257->[127.0.0.1]:162" },
    { ".snmp.iso.3.6.1.4.1.18372.3.2.1.1.1.6", "test" },

    {
      "MESSAGE", "hostname='localhost', transport_info='UDP: [127.0.0.1]:34257->[127.0.0.1]:162', "
      "iso.3.6.1.4.1.18372.3.2.1.1.1.6='test'"
    }
  };

  assert_log_message_name_values_with_options(&options, input, expected, SIZE_OF_ARRAY(expected));
}

Test(snmptrapd_parser, test_v2_with_generated_message_escaped)
{
  TestParserOptions options =
  {
    .set_message_macro = TRUE
  };

  const gchar *input =
    "2017-05-17 13:26:04 localhost [UDP: [127.0.0.1]:34257->[127.0.0.1]:162]:\n"
    "iso.3.6.1.4.1.18372.3.2.1.1.1.6 = STRING: \"test 'escaped'\"";

  TestNameValue expected[] =
  {
Example #26
0
// the main test program
int main(int argc, char *argv[]) {

	int rc = 0;
	EPD_size display_size = EPD_1_44;
	const uint8_t *const *images = images_1_44;
	int image_count = SIZE_OF_ARRAY(images_1_44);

	if (argc < 2) {
		usage(argv[0], "missing argument(s)");
	} else if (argc > 3) {
		usage(argv[0], "extraneous extra argument(s)");
	}

	if (0 == strcmp("1.44", argv[1]) || 0 == strcmp("1_44", argv[1])) {
		display_size = EPD_1_44;
		images = images_1_44;
		image_count = SIZE_OF_ARRAY(images_1_44);
#if EPD_1_9_SUPPORT
	} else if (0 == strcmp("1.9", argv[1]) || 0 == strcmp("1_9", argv[1])) {
		display_size = EPD_1_9;
		images = images_1_9;
		image_count = SIZE_OF_ARRAY(images_1_9);
#endif
	} else if (0 == strcmp("2.0", argv[1]) || 0 == strcmp("2_0", argv[1])) {
		display_size = EPD_2_0;
		images = images_2_0;
		image_count = SIZE_OF_ARRAY(images_2_0);
#if EPD_2_6_SUPPORT
	} else if (0 == strcmp("2.6", argv[1]) || 0 == strcmp("2_6", argv[1])) {
		display_size = EPD_2_6;
		images = images_2_6;
		image_count = SIZE_OF_ARRAY(images_2_6);
#endif
	} else if (0 == strcmp("2.7", argv[1]) || 0 == strcmp("2_7", argv[1])) {
		display_size = EPD_2_7;
		images = images_2_7;
		image_count = SIZE_OF_ARRAY(images_2_7);
	} else {
		usage(argv[0], "unknown display size: %s", argv[1]);
	}

	if (argc > 2) {
		int n = atoi(argv[2]);
		if (n < 0) {
			usage(argv[0], "image-count cannot be negative");
		} else if (n > image_count) {
			usage(argv[0], "image-count: %d, cannot be greater than: %d", n, image_count);
		}
		image_count = n;
	}

	if (!GPIO_setup()) {
		rc = 1;
		warn("GPIO_setup failed");
		goto done;
	}

	SPI_type *spi = SPI_create(SPI_DEVICE, SPI_BPS);
	if (NULL == spi) {
		rc = 1;
		warn("SPI_setup failed");
		goto done_gpio;
	}

	GPIO_mode(panel_on_pin, GPIO_OUTPUT);
	GPIO_mode(border_pin, GPIO_OUTPUT);
	GPIO_mode(discharge_pin, GPIO_OUTPUT);
#if EPD_PWM_REQUIRED
	GPIO_mode(pwm_pin, GPIO_PWM);
#endif
	GPIO_mode(reset_pin, GPIO_OUTPUT);
	GPIO_mode(busy_pin, GPIO_INPUT);

	EPD_type *epd = EPD_create(display_size,
				   panel_on_pin,
				   border_pin,
				   discharge_pin,
#if EPD_PWM_REQUIRED
				   pwm_pin,
#endif
				   reset_pin,
				   busy_pin,
				   spi);

	if (NULL == epd) {
		rc = 1;
		warn("EPD_setup failed");
		goto done_spi;
	}

	// EPD display
	printf("clear display\n");
	EPD_begin(epd);
	EPD_clear(epd);
	EPD_end(epd);

	if (image_count > 0) {
		printf("images start\n");
		for (int i = 0; i < image_count; ++i) {
			printf("image = %d\n", i);
			EPD_begin(epd);
#if EPD_IMAGE_TWO_ARG
			if (0 == i) {
				EPD_image_0(epd, images[i]);
			} else {
				EPD_image(epd, images[i - 1], images[i]);
			}
#elif EPD_IMAGE_ONE_ARG
			EPD_image(epd, images[i]);
#else
#error "unsupported EPD_image() function"
#endif
			EPD_end(epd);
			if (i < image_count - 1) {
				sleep(5);
			}
		}
	}

	// release resources
//done_epd:
	EPD_destroy(epd);
done_spi:
	SPI_destroy(spi);
done_gpio:
	GPIO_teardown();
done:
	return rc;
}
Example #27
0
tag_reader* reader_ogg( DWORD handle )
{
	return new preproc_reader( 
		BASS_ChannelGetTags( handle, BASS_TAG_OGG ),
		"OGG: bad tag format", remap, SIZE_OF_ARRAY(remap), '=', 0 );
}
Example #28
0
uint64 Misc_parseDateTime(const char *string)
{
  const char *DATE_TIME_FORMATS[] =
  {
    "%Y-%m-%dT%H:%i:%s%Q",       // 2011-03-11T14:46:23-06:00

    "%A, %d %b %y %H:%M:%S %z",  // Fri, 11 Mar 11 14:46:23 -0500
    "%a, %d %b %y %H:%M:%S %z",  // Friday, 11 Mar 11 14:46:23 -0500
    "%A, %d %B %y %H:%M:%S %z",  // Fri, 11 Mar 11 14:46:23 -0500
    "%a, %d %B %y %H:%M:%S %z",  // Friday, 11 Mar 11 14:46:23 -0500
    "%A, %d %b %Y %H:%M:%S %z",  // Fri, 11 Mar 2011 14:46:23 -0500
    "%a, %d %b %Y %H:%M:%S %z",  // Friday, 11 Mar 2011 14:46:23 -0500
    "%A, %d %B %Y %H:%M:%S %z",  // Fri, 11 Mar 2011 14:46:23 -0500
    "%a, %d %B %Y %H:%M:%S %z",  // Friday, 11 Mar 2011 14:46:23 -0500

    "%A, %d-%b-%y %H:%M:%S UTC", // Fri, 11-Mar-11 14:46:23 UTC
    "%a, %d-%b-%y %H:%M:%S UTC", // Friday, 11-Mar-11 14:46:23 UTC
    "%A, %d-%B-%y %H:%M:%S UTC", // Fri, 11-March-11 14:46:23 UTC
    "%a, %d-%B-%y %H:%M:%S UTC", // Friday, 11-March-11 14:46:23 UTC
    "%A, %d-%b-%Y %H:%M:%S UTC", // Fri, 11-Mar-2011 14:46:23 UTC
    "%a, %d-%b-%Y %H:%M:%S UTC", // Friday, 11-Mar-2-11 14:46:23 UTC
    "%A, %d-%B-%Y %H:%M:%S UTC", // Fri, 11-March-2011 14:46:23 UTC
    "%a, %d-%B-%Y %H:%M:%S UTC", // Friday, 11-March-2011 14:46:23 UTC

    "%A, %d %b %y %H:%M:%S GMT",  // Fri, 11 Mar 11 14:46:23 GMT
    "%a, %d %b %y %H:%M:%S GMT",  // Friday, 11 Mar 11 14:46:23 GMT
    "%A, %d %B %y %H:%M:%S GMT",  // Fri, 11 March 11 14:46:23 GMT
    "%a, %d %B %y %H:%M:%S GMT",  // Friday, 11 March 11 14:46:23 GMT
    "%A, %d %b %Y %H:%M:%S GMT",  // Fri, 11 Mar 2011 14:46:23 GMT
    "%a, %d %b %Y %H:%M:%S GMT",  // Friday, 11 Mar 2011 14:46:23 GMT
    "%A, %d %B %Y %H:%M:%S GMT",  // Fri, 11 March 2011 14:46:23 GMT
    "%a, %d %B %Y %H:%M:%S GMT",  // Friday, 11 March 2011 14:46:23 GMT

     DATE_TIME_FORMAT_DEFAULT
  };

  #ifdef HAVE_GETDATE_R
    struct tm tmBuffer;
  #endif /* HAVE_GETDATE_R */
  struct tm  *tm;
  uint       z;
  const char *s;
  uint64     dateTime;

  assert(string != NULL);

  #ifdef HAVE_GETDATE_R
    tm = (getdate_r(string,&tmBuffer) == 0) ? &tmBuffer : NULL;
  #else /* not HAVE_GETDATE_R */
    tm = getdate(string);
  #endif /* HAVE_GETDATE_R */

  if (tm == NULL)
  {
    z = 0;
    while ((z < SIZE_OF_ARRAY(DATE_TIME_FORMATS)) && (tm == NULL))
    {
      s = strptime(string,DATE_TIME_FORMATS[z],&tmBuffer);
      if ((s != NULL) && ((*s) == '\0'))
      {
        tm = &tmBuffer;
      }
      z++;
    }
  }

  if (tm != NULL)
  {
    dateTime = (uint64)mktime(tm);
  }
  else
  {
    dateTime = 0LL;
  }

  return dateTime;
}
static const DWORD g_registryPermissionFlags[] =
{
  KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY, 
  KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, KEY_CREATE_LINK, 
  DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, SYNCHRONIZE,
  KEY_READ, KEY_WRITE, KEY_EXECUTE, KEY_ALL_ACCESS
};

static const SchemeType g_fileScheme[] =
{
  _T("file"), SE_FILE_OBJECT,
  OBJECT_INHERIT_ACE,
  g_filePermissionNames, 
  g_filePermissionFlags,
  SIZE_OF_ARRAY(g_filePermissionFlags)
};

static const SchemeType g_directoryScheme[] =
{
  _T("directory"), SE_FILE_OBJECT,
  OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE,
  g_directoryPermissionNames, 
  g_directoryPermissionFlags,
  SIZE_OF_ARRAY(g_directoryPermissionFlags)
};

static const SchemeType g_registryScheme[] =
{ 
  _T("registry"), SE_REGISTRY_KEY,
  CONTAINER_INHERIT_ACE,
Example #30
0
ENCODE_RANGE g_InternalRange[] = {
    { g_DummyStart, g_DummyEnd, ES_FLAGS_ENCODE_1 },
    { EncodeDummyStart, EncodeDummyEnd, ES_FLAGS_ENCODE_1 },
};

ENCODE_STUB g_InternalStub = {
    TYPE_ENCODE_INTERNAL,
    sizeof( ENCODE_STUB ),
    0,
    0,
    DEFAULT_ENCODE_KEY,
    DEFAULT_ENCODE_KEY_LENGTH,
    { 0 },
    0,
    { 0 },
    SIZE_OF_ARRAY( g_InternalRange ),
    g_InternalRange
};
PENCODE_STUB g_InternalStubPtr = &g_InternalStub;

/*
///////////////////////////////////////////////////////////////////////////////
// F U N C T I O N S  P R O T O T Y P E
///////////////////////////////////////////////////////////////////////////////
*/
/* Standard DES encode/decode */
static void DES( UCHAR Out[8], const UCHAR In[8], const PDES_SUBKEY SubKey, ULONG Type );
static void SetKey( PDES_SUBKEY SubKey, ULONG *Is3DES, const UCHAR *Key, ULONG Length );
static void SetSubKey( PDES_SUBKEY SubKey, const UCHAR Key[8] );
static void F_Func( UCHAR In[32], const UCHAR Ki[48] );
static void S_Func( UCHAR Out[32], const UCHAR In[48] );