Skip to content
This repository has been archived by the owner on Dec 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #8 from vanti-public/master
Browse files Browse the repository at this point in the history
Merge of Vanti additions
  • Loading branch information
Kim Burgess committed Nov 11, 2015
2 parents f750b27 + 3fb54d7 commit 8d34efd
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 21 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -15,6 +15,8 @@ Currently the project provides a math library, string manipulation library, time

[Motaz Abuthiab](mailto:[email protected])

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

# Contributing

Want to help out? Awesome.
Expand Down
96 changes: 89 additions & 7 deletions debug.axi
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}


Expand Down Expand Up @@ -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 {
Expand All @@ -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
14 changes: 14 additions & 0 deletions math.axi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ define_function long math_raw_be_to_long(char x[4])
return x[1] << 24 + x[2] << 16 + x[3] << 8 + 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.
*
Expand Down
18 changes: 9 additions & 9 deletions netlinx-common-libraries.axi
Original file line number Diff line number Diff line change
@@ -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'
44 changes: 43 additions & 1 deletion string.axi
Original file line number Diff line number Diff line change
Expand Up @@ -804,4 +804,46 @@ define_function char string_ends_with(char a[], char search[])
return right_string(a, length_string(search)) == search;
}

#end_if

/**
* 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
6 changes: 3 additions & 3 deletions unixtime.axi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 8d34efd

Please sign in to comment.