Andrew Sowers's fall2012 Opus
Who is John Galt?
Since personal introductions are out of the way I'll introduce my intention of requesting an independent study for the Fall 2012 semester. It isn't out of arrogance or pride, I genuinely desire to grasp the fundamentals of C, C++ and maybe even touch objective c if time permits?(pun totally intended) So I'll begin researching concepts immediately and await your instruction. Haas, I'm very excited for what's ahead. Also data communication sounds like there's the opportunity for a lot fun. The proprietary LAIR alert system sounds feasible and practical! Can't wait to get going with it.
Today I began reading on good old wikipedia about the different compilers I could choose from, I found the following options.
Impressions of Freeswitch
From what I've read about FreeSWITCH is that it's relatively new (as of 2006) and is a softswitch communicator that interfaces with both physical and digital phones. It's built on open source technologies like SQLight and Apache. FreeSWITCH accepts an array of protocols such as VOIP, SIP, Google Talk and many more to interface with and supports a wide array of audio codecs.
Here are some of the more important configuration file fore FreeSWITCH:
On our datacom server, FreeSWITCH is located in '/usr/local/freeswitch' and includes the following directories in its base:
[root@dhcp-171 freeswitch]# ls bin conf db grammar htdocs include lib log mod recordings run scripts sounds storage [root@dhcp-171 freeswitch]#
Bin holds the various executables that are the core of freeswitch, conf holds configuration files that some genius wrote in xml to sort in some ridiculous hierarchical model.
There are other meta items like FreeSWITCH's library and scripts.
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
Identification of chosen keyword.
All programs contain at least a main() function. The main()function typically is executed when the program starts. functions contain parameters or instructions to be used during the programs computation. Here is an example of a function parameter:
long sum( int array[], int number ) // Identifiers { //body of function int i; long result = 0; for( i = 0; i < number; ++i ) result += (long)array[i]; return result; }
Functions can also have declarations before the body where you can call datatypes.
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
Identification of chosen keyword.
Structs, not your mama's sneaker shoes.
#include <stdio.h> #include <stdlib.h> struct mystruct { // int test; // Declaration of initial struct. }; // typedef struct mystruct * newstruct; // newstruct function is a pointer to my struct. newstruct getnewstruct() { newstruct temp = (newstruct)malloc(sizeof(newstruct*)) ; return temp; } int main() { newstruct tester = getnewstruct() ; // tester -> test = 8; // Mathematical manipulation and printing of structure. tester -> test++; // printf ("The value is %i\n",tester -> test) ; // free(tester) ; return 0; }
Demonstration of the indicated keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
andrew ~ $ gcc malloc.c -o malloc andrew ~ $ ./malloc First value: 10 Pi is: 3.140000
Identification of chosen keyword.
Definition (in your own words) of the chosen keyword.
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
asterisk
A programming language to communicate and execute the basic functions of telephony services.
'extensions.conf' located in '/etc/asterisk/extensions.conf' maintains a bulk of the configurations options for the asterisk service including your dial plan and how inbound/outbound calls are routed. Example of an extension:
exten => 602,1,Dial(SIP/Andrew,20) exten => 602,n,VoiceMail(602@vm,u)
'sip.conf' located in '/etc/asterisk/sip.conf' maintains the users locations and affiliation to the asterisk server. Example of a sip.conf user entry:
[Andrew] type=friend secret=123456 host=dynamic context=users deny=0.0.0.0/0 permit=10.80.2.0/255.255.255.0 mailbox=778@vm
Can you include the main() of a program in a header file?
I suspect that you can include any function within a header file and call it. Including main().
Then call it like so:
main();
I'm going to take the main portion of the encipher program from project two and place it into main.h
int main(int argc, char **argv) { printf("Greetings, Agent Haas.\n"); FILE *in, *out; int cipher; int key; in = fopen("plain.txt", "r"); out = fopen("enciphered.txt", "w"); if(argv[1] == NULL) { printf("\nNo argument provided, execute with key argument.\nexample: ./encipher 1\n"); exit(1); } char *plain; plain = (char*) malloc (sizeof(char) * 127); int count = 0; if(in == NULL) { printf("\nFile empty, enter some text to encipher\n"); fgets(plain, 127, stdin); while(plain[count] != '\0') { count = count+1; } int cipher = atoi(argv[1]); count = 0; while(plain[count] != '\0') { key = 1; if(plain[count] >= 65 && plain[count] <= 90) { key = plain[count] + cipher; while(key > 90) { key = key - 26; } } if(plain[count] >= 97 && plain[count] <= 122) { key = plain[count] + cipher; while(key > 122) { key = key - 26; } } if(key == 1) { key = 32; } fprintf(out, "%c", key); count = count+1; } printf("\nEnciphered text is loated in enciphered.txt\n"); printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC); } else { fgets(plain, 127, in); printf("\nText before cipherication: "); while(plain[count] != '\0') { printf("%c", plain[count]); count = count+1; } int cipher = atoi(argv[1]); count = 0; printf("\nCiphered text output: "); while(plain[count] != '\0') { key = 1; if(plain[count] >= 65 && plain[count] <= 90) { key = plain[count] + cipher; while(key > 90) { key = key - 26; } } if(plain[count] >= 97 && plain[count] <= 122) { key = plain[count] + cipher; while(key > 122) { key = key - 26; } } if(key == 1) { key = 32; } printf("%c", key); fprintf(out, "%c", key); count = count+1; } fclose(in); fclose(out); return (0); } }
Here's main.h:
#ifndef _MAIN_H #define _MAIN_H int main(int argc, char **argv) { int t; t = clock(); printf("Greetings, Agent Haas.\n"); FILE *in, *out; int cipher; int key; in = fopen("plain.txt", "r"); out = fopen("enciphered.txt", "w"); if(argv[1] == NULL) { printf("\nNo argument provided, execute with key argument.\nexample: ./encipher 1\n"); exit(1); } char *plain; plain = (char*) malloc (sizeof(char) * 127); int count = 0; if(in == NULL) { printf("\nFile empty, enter some text to encipher\n"); fgets(plain, 127, stdin); while(plain[count] != '\0') { count = count+1; } int cipher = atoi(argv[1]); count = 0; while(plain[count] != '\0') { key = 1; if(plain[count] >= 65 && plain[count] <= 90) { key = plain[count] + cipher; while(key > 90) { key = key - 26; } } if(plain[count] >= 97 && plain[count] <= 122) { key = plain[count] + cipher; while(key > 122) { key = key - 26; } } if(key == 1) { key = 32; } fprintf(out, "%c", key); count = count+1; } printf("\nEnciphered text is loated in enciphered.txt\n"); printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC); } else { fgets(plain, 127, in); printf("\nText before cipherication: "); while(plain[count] != '\0') { printf("%c", plain[count]); count = count+1; } int cipher = atoi(argv[1]); count = 0; printf("\nCiphered text output: "); while(plain[count] != '\0') { key = 1; if(plain[count] >= 65 && plain[count] <= 90) { key = plain[count] + cipher; while(key > 90) { key = key - 26; } } if(plain[count] >= 97 && plain[count] <= 122) { key = plain[count] + cipher; while(key > 122) { key = key - 26; } } if(key == 1) { key = 32; } printf("%c", key); fprintf(out, "%c", key); count = count+1; } printf("\nEnciphered text is located in enciphered.txt\n\n"); printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC); fclose(in); fclose(out); return (0); } } #endif
Here's the modified program:
#include <stdio.h> #include <math.h> #include <stdlib.h> #include "main.h" main();
And the gcc output:
lab46:~/src/cprog/cipher$ gcc encipher.c -o encipher encipher.c:20: warning: data definition has no type or storage class lab46:~/src/cprog/cipher$
Got a warning, but it worked.
Based on the data collected:
Header files are a brilliant way to break up ANY function in a program to allow more readable code and FAR better organization.
Today we figured out how to call system tasks using nothing but the asterisk extensions.conf file.
To add an extension executes a script you simply need to add “System(pathtoscript.sh)”
In practice this would look like this:
exten => 607,1,Answer exten => 607,2,Wait(1) exten => 607,3,System(path/to/script.sh) ;make sure to place in writable path for asterisk user exten => 607,4,Hangup()
This opens a plethora of new possibilities that we'll explore in the coming weeks!
Today I've decided to start researching the implications of installing PBX and Asterisk on my Raspberry Pi. My ultimate goal would be initiating a house appliance by literally calling it through asterisk. Smart appliances here I come! =D I'm starting my research here:
UPDATE! FreePBX is loaded and I've setup some extensions. Now I'll be looking into some ip appliances for automation.
Finding direction in Data Com
With everyone moving into their individual projects I'm at as loss with what to do. Hoping we can establish a tangible direction some time soon.
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
Identification of chosen keyword.
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
Identification of chosen keyword.
Arrays are buckets or memory locations that group similar integers or character strings.
Arrays can be manipulated to hold different values of any datatype as long as that datatype is consistant across the entire array. You can even copy the contents of one array to another!
Example:
#include<stdio.h> int main() { int array [5]; int i; short onethroughfive [5]; array[0] = 45; array[1] = 56; array[2] = 34; array[3] = 42; array[4] = 32; for(i=0; i<5; i++){ *(onethroughfive+i)=*(array+i); } for (i=0; i<5; i++){ printf("%d\n", *(onethroughfive+i)); } return (0); }
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
Identification of chosen keyword.
The Raspberry Pi hosts a General Purpose Input Output board for interfacing with low level peripherals. Dragon.net was nice enough to write a detailed C library for the GPIO to make electronics programming super easy! Here's an example of a program that turns on and off an LED:
/* * blink.c: * Simple test program to blink an LED on pin 7 */ #include <wiringPi.h> #include <stdio.h> int main (void) { int pin = 7; printf("Raspberry Pi wiringPi blink test\n"); if (wiringPiSetup() == -1) exit (1); pinMode(pin, OUTPUT); for (;;){ printf("LED On\n"); digitalWrite(pin, 1); delay(250); printf("LED Off\n"); digitalWrite(pin, 0); delay(250); } return 0; }
by way of this reference I hope to setup a simple c application using a solid state relay for my future automated “Dial a Coffee” via Asterisk and Pi ingenuity:http://elinux.org/RPi_Low-level_peripherals#GPIO_Driving_Example_.28C.29
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
Identification of chosen keyword.
A simple program that operates a relay switch that supplies electricity for delicious caffeinated beverages.
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
/* Lair_Brew ~ Caffeine ~ Version 0.2 */ #include <wiringPi.h> #include <stdio.h> void loopback(void) { char ch; ch = getchar(); while( ch != '\n' ) ch = getchar(); } int main (void) { int pin = 7; char ch; int exit_flag = 0; printf("welcome to Lair Brew\n"); if (wiringPiSetup() == -1) return(1); pinMode(pin, OUTPUT); printf("Brew on\n"); digitalWrite(pin, 1); while( exit_flag == 0 ) { printf("Wish to exit? (Y)\n"); scanf(" %c", &ch ); ch = toupper( ch ); if((ch == 'Y')){ printf("\nBrew Off\n"); digitalWrite(pin, 0); delay(250); printf("\nEnjoy Your Coffee, Sir!\n"); } else { printf("\nType (y) to exit.\n"); loopback(); } if( ch == 'Y' ) exit_flag = 1; } return 0; }
The program is loaded into /etc/asterisk/extensions.conf like so:
exten => 607,1,Answer exten => 607,2,Wait(1) exten => 607,3,System(/tmp/Lair_brew_auto) exten => 607,4,Hangup()
Can you include the main() of a program in a header file?
Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.
Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.
State your rationale.
How are you going to test your hypothesis? What is the structure of your experiment?
Perform your experiment, and collect/document the results here.
Based on the data collected:
What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.
At this point I'm nearly done with bignum, all that is needed is the multiplication function along with some minor tweaking. I hope to complete it before the end of break.
Today I've looked into some extensive research:(http://math.berkeley.edu/~jakub/pdf/kominiarczuk2004.pdf) regarding tin-can phones. In order to receive higher quality connection I propose we build a box apparatus around our speaker and microphone setups. Also, the fishing line will most likely produce the greatest result with identical plastic cups rather than cans due to their membranes ability to vibrate easily. Finally the tension. Section D discuses frequency of waves in relation to tension. Essentially, to tight is just as bad as too loose. (that's what he said.)
I hope we can put this information to use on Tuesday Dec 4.
today for data comm, I've started research on network programming with a a focus in C to be reinvent to my independent study. I plan on spending a better part of this day going over this page: http://shoe.bocks.com/net/
My hope is to build network status LED via the GPIO on my Raspberry Pi
Out with my girlfriend Dana and some friends at Ithaca College. We were paying a game called “Power Hour”(Google is your friend) I decided that instead of keeping track of the time, why not write a simple program to do this for us? I came up with the following:
#include <time.h> #include <stdio.h> int main() { printf("\a"); for (;;) { printf("begin minute\n"); sleep(60); printf("BEEP\a\n"); } }
Having lots of funnnn
UPDATE: After looking over what I had done last night I realized there was huge room for improvement. Here's the update:
#include <stdio.h> #include <time.h> int main() { printf("Begin power hour!\n\a"); int i; for(i = 0; i <= 60; ++i) { printf("Minute Number: %d\n",i); sleep(60); printf("Drink!\n\a"); } return 0; }
Identification of chosen keyword.
Malloc uses blocks of memory and pointers to perform operations. In the following program we declare the struct RECORD, fill it with datatypes, and point to it. malloc lets us output the individual blocks of RECORD we defined to stdout.
#include<stdio.h> typedef struct rec { int i; float PI; char A; }RECORD; int main() { RECORD *point; point = (RECORD *) malloc (sizeof(RECORD)); point->i = 10; point->PI = 3.14; point->A = 'a'; printf("First value: %d\n", point->i); printf("Pi is: %f\n", point->PI); printf("Third value: %c\n", point->A); free(point); return 0; }
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
Identification of chosen keyword.
Malloc uses blocks of memory and pointers to perform operations. In the following program we declare the struct RECORD, fill it with datatypes, and point to it. malloc lets us output the individual blocks of RECORD we defined to stdout.
#include<stdio.h> typedef struct rec { int i; float PI; char A; }RECORD; int main() { RECORD *point; point = (RECORD *) malloc (sizeof(RECORD)); point->i = 10; point->PI = 3.14; point->A = 'a'; printf("First value: %d\n", point->i); printf("Pi is: %f\n", point->PI); printf("Third value: %c\n", point->A); free(point); return 0; }
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
Demonstration of the indicated keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
#include<stdio.h> typedef struct rec { int i; float PI; char A; }RECORD; int main() { RECORD *point; point = (RECORD *) malloc (sizeof(RECORD)); point->i = 10; point->PI = 3.14; point->A = 'a'; printf("First value: %d\n", point->i); printf("Pi is: %f\n", point->PI); printf("Third value: %c\n", point->A); free(point); return 0; }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
andrew ~ $ nano -c malloc.c andrew ~ $ gcc malloc.c -o malloc andrew ~ $ ./malloc First value: 10 Pi is: 3.140000 Third value: a andrew ~ $
Identification of chosen keyword.
Minimodem is a linux command line utility that generates modem tones. It works over different modem protocols. to use minimoddem you want to set it to transmit or receive and set the bit rate. Example:
andrew ~/ls |minimodem -t "200"
minimodem will pass the result of the ls to transmit via minimodem at a bit rate of 200. the receiveing end would simply change -t to -r and pass it into a file.
The audio output of minimodem can travel over any acceptable medium. Even cup and string! (if implemented properly)
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
Identification of chosen keyword.
Definition (in your own words) of the chosen keyword.
List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).
Demonstration of the indicated keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Can I declare all my datatypes in a struct and alias them in main?
I believe that it will be possible to declare all my datatypes in a simple structure and call them in main.
I've built a simple program that calls three integers and one character array that I will use as a base for my experiment.
#include <stdio.h> #include <string.h> int main() { int a = 1; int b = 2; int c = 3; char abc[] = "abc"; printf("Now I know my %s's, they are easy as %d, %d, %d\n", abc, a, b, c); return 0; }
Program modified with struct:
#include <stdio.h> #include <string.h> typedef struct { int a; int b; int c; char abc[]; }node; int main() { node n; n.a = 1; n.b = 2; n.c = 3; strcpy(n.abc, "abc"); printf("Now I know my %s's, they are easy as %d, %d, %d\n", n.abc, n.a, n.b, n.c); return 0; }
By declaring variables with their assigned datatype in the typedef struct, you can call the variable with an alias to that struct without setting the datatype in that function.
Based on the data collected:
What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.