~kb/ncl

8d34efd097418253e2840b13cc776c7ca567fb71 — Kim Burgess 8 years ago f750b27 + 3fb54d7 main
Merge pull request #8 from vanti-public/master

Merge of Vanti additions
6 files changed, 161 insertions(+), 21 deletions(-)

M README.md
M debug.axi
M math.axi
M netlinx-common-libraries.axi
M string.axi
M unixtime.axi
M README.md => README.md +3 -1
@@ 1,4 1,4 @@
´╗┐This project contains globally useful, portable includes for augmenting the base functionality of the proprietary AMX NetLinx language used for programming [AMX NetLinx integrated controllers](http://www.amx.com/products/categoryCentralControllers.asp).
This project contains globally useful, portable includes for augmenting the base functionality of the proprietary AMX NetLinx language used for programming [AMX NetLinx integrated controllers](http://www.amx.com/products/categoryCentralControllers.asp).

Currently the project provides a math library, string manipulation library, time and date library, array utils, a managed debug messaging library and an associated console output library.



@@ 15,6 15,8 @@ Currently the project provides a math library, string manipulation library, time

[Motaz Abuthiab](mailto:moty66@gmail.com)

[Vanti](https://www.vanti.co.uk)

# Contributing

Want to help out? Awesome.

M debug.axi => debug.axi +89 -7
@@ 11,12 11,16 @@ char DEBUG_OFF		= 0				// Available debug verbosity levels
char DEBUG_ERROR 	= 1
char DEBUG_WARN 	= 2
char DEBUG_INFO 	= 3
char DEBUG_DEBUG    = 4

char DEBUG_LEVEL_STRINGS[4][16] = {
char DEBUG_MAX_LEVEL = 4

char DEBUG_LEVEL_STRINGS[5][16] = {
    'Off',
    'Error',
    'Warn',
    'Info'
    'Info',
    'Debug'
}




@@ 70,7 74,7 @@ define_function char debug_get_level_from_string(char x[]) {
 */
define_function debug_set_level(char x)
{
	if (x >= DEBUG_OFF && x <= DEBUG_INFO) {
	if (x >= DEBUG_OFF && x <= DEBUG_MAX_LEVEL) {
		println("'Debug level set to ', debug_get_level_string(x)")
		debug_level = x
	} else {


@@ 92,13 96,91 @@ define_function debug_set_level(char x)
 */
define_function debug_msg(char msg_level, char msg[])
{
	if (msg_level < DEBUG_ERROR || msg_level > DEBUG_INFO) {
	stack_var long i,l;
	stack_var char c;
	stack_var char out[255];
	stack_var char in[255];

	if (msg_level < DEBUG_ERROR || msg_level > DEBUG_MAX_LEVEL) {
		debug_msg(DEBUG_ERROR, "'invalid debug level specified - ', msg")
		return
	}
    if (msg_level <= debug_level) {
		println("upper_string(debug_get_level_string(msg_level)),': ', msg")
    }
	if (msg_level <= debug_level) {
		if (FIND_STRING(msg, "$00", 1) > 0){
			in = msg
			out = ""
			l = LENGTH_STRING(in)
			for (i = 0; i < l; i++){
				c = GET_BUFFER_CHAR(in)
				if(c == "$00"){
					out = "out,'$00'"
				}else{
					out = "out,c"
				}
			}
			println("upper_string(debug_get_level_string(msg_level)),': ', out")
		}else{
			println("upper_string(debug_get_level_string(msg_level)),': ', msg")
		}
	}
}

/**
 * Prints a debug message forced to hex - this avoids situations where a hex 
 * value is a valid ascii character
 *
 * @param	msg_level	a char specifying the debug level of the message
 * @param	msg			a string containing the debug message to be printed as hex
 */
define_function debug_hex(char msg_level, char msg[])
{
	stack_var long i,l;
	stack_var char c;
	stack_var char out[255];
	stack_var char in[255];
	
	if (msg_level < DEBUG_ERROR || msg_level > DEBUG_MAX_LEVEL) {
		debug_msg(DEBUG_ERROR, "'invalid debug level specified - ', msg")
		return
	}
	if (msg_level <= debug_level) {
		in = msg
		out = ""
		l = LENGTH_STRING(in)
		for (i = 0; i < l; i++){
			c = GET_BUFFER_CHAR(in)
			out = "out, '$', itohex(c),','"
		}
		println("upper_string(debug_get_level_string(msg_level)),': ',out")
	}
}

/**
 * Prints a debug message forced to decimal
 *
 * @param	msg_level	a char specifying the debug level of the message
 * @param	msg			a string containing the debug message to be printed as decimal
 */
define_function debug_dec(char msg_level, char msg[])
{
	stack_var long i,l;
	stack_var char c;
	stack_var char in[255];
	
	if (msg_level < DEBUG_ERROR || msg_level > DEBUG_MAX_LEVEL) {
		debug_msg(DEBUG_ERROR, "'invalid debug level specified - ', msg")
		return
	}
	if (msg_level <= debug_level) {
		in = msg
		l = LENGTH_STRING(in)
		println("'message length: ',itoa(l)")
		for (i = 1; i <= l; i++){
			c = GET_BUFFER_CHAR(in)
			println("'[',itoa(i),'] ',itoa(c)")
		}
	}
}


#end_if
\ No newline at end of file

M math.axi => math.axi +14 -0
@@ 35,6 35,20 @@ define_function long math_raw_be_to_long(char x[4])
}

/**
 * Load 4 bytes of little endian data contained in a character array into a long.
 *
 * Note: Array position 4 should contain MSB / position 1 should contain LSB
 *
 * @param	x		a 4 byte character array containg the data to load
 * @return			a long filled with the passed data
 */
define_function long math_raw_le_to_long(char x[4])
{
    return x[4] << 24 + x[3] << 16 + x[2] << 8 + x[1]
}


/**
 * Load a float value's IEEE 754 bit pattern into a long.
 *
 * @param	x		the float to load

M netlinx-common-libraries.axi => netlinx-common-libraries.axi +9 -9
@@ 1,9 1,9 @@
program_name='ncl'

include 'io'
include 'debug'
include 'array'
include 'string'
include 'math'
include 'unixtime'
include 'graph'
program_name='netlinx-common-libraries'

include 'io'
include 'debug'
include 'array'
include 'string'
include 'math'
include 'unixtime'
include 'graph'

M string.axi => string.axi +43 -1
@@ 804,4 804,46 @@ define_function char string_ends_with(char a[], char search[])
	return right_string(a, length_string(search)) == search;
}

#end_if
\ No newline at end of file

/**
 * Remove characters from the end of the string.
 *
 * @param	a			the input string
 * @param	count		the number of characters to remove
 * @return				the contents of 'a' with the characters removed
 */
define_function char[STRING_RETURN_SIZE_LIMIT] strip_chars_right(char a[],
		integer count)
{
	return left_string(a, length_string(a) - count)
}

/**
 * Wrapper method for mid_string to bring inline with other programming
 * languages.
 *
 * @param	a			the input string
 * @param	start		the start location of the substring
 * @param	count		the number of characters to extract
 */
define_function char[STRING_RETURN_SIZE_LIMIT] substr(char a[], integer start,
		integer count)
{
	return mid_string(a, start, count);
}

/**
 * Alternative to substr which allows an end location to be specified instead of
 * a count
 *
 * @param	a			the input string
 * @param	start		the start location of the substring
 * @param	end			the end location of the substring
 */
define_function char[STRING_RETURN_SIZE_LIMIT] substring(char a[],
		integer start, integer end)
{
	return substr(a, start, end-start+1);
}

#end_if

M unixtime.axi => unixtime.axi +3 -3
@@ 517,7 517,7 @@ define_function char[STRING_RETURN_SIZE_LIMIT] fmt_date(char fmt[1024], slong u)
 * @param	yr		year
 * @param	days	amount of days since the beginning of the year
 */
define_function unixtime_to_raw_values(slong u, integer hr, integer min, integer sec,
define_function unixtime_to_raw_values(slong u, integer hr, integer minute, integer sec,
				integer month, integer dy, integer yr, integer days)
{
	stack_var integer	i


@@ 589,10 589,10 @@ define_function unixtime_to_raw_values(slong u, integer hr, integer min, integer
		w = w - w2
	}

	min = 0
	minute = 0
	w2 = UNIXTIME_SECONDS_PER_MINUTE
	while (w >= UNIXTIME_SECONDS_PER_MINUTE) {
		min++
		minute++
		w = w - w2
	}