This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
haas:spring2019:unix:projects:spf1 [2019/04/16 15:36] – created wedge | haas:spring2019:unix:projects:spf1 [2019/04/18 18:41] (current) – [Objective] wedge | ||
---|---|---|---|
Line 10: | Line 10: | ||
* any bugfixes or project updates will be posted here | * any bugfixes or project updates will be posted here | ||
- | =====Toolbox===== | ||
- | In addition to the tools you're already familiar with, it is recommended you check out the following tools for possible application in this project (you may not need to use them in your solution, but they definitely offer up functionality that some solutions can make use of): | ||
- | |||
- | * **basename(1)** | ||
- | * **bc(1)** | ||
- | * **cut(1)** | ||
- | * **diff(1)** | ||
- | * **grep(1)** | ||
- | * **mktemp(1)** | ||
- | * **sed(1)** | ||
- | * **tr(1)** | ||
- | * **wc(1)** | ||
=====Objective===== | =====Objective===== | ||
Line 30: | Line 18: | ||
* an initialization script | * an initialization script | ||
* an incrementing 8-bit binary counter (0-255) | * an incrementing 8-bit binary counter (0-255) | ||
- | * a decreminting | + | * a decrementing |
* a strobing light sequence (back and forth) | * a strobing light sequence (back and forth) | ||
Line 56: | Line 44: | ||
<cli> | <cli> | ||
- | lab46:~$ ssh pi@pi1b_0# | + | lab46:~$ ssh pi@pi1b_0X |
</ | </ | ||
Line 87: | Line 75: | ||
</ | </ | ||
- | =====Process===== | + | When using the **gpio** tool, we are specifically interested in the " |
- | It is your task to write 2 scripts; one will be responsible for generating a file containing calculated digits of PI (and you must perform | + | |
- | ====script1: pigen==== | + | ====Assembly of LED circuits==== |
- | You are to write a script, called and submitted by the name **pigen** | + | The eight LED circuits established on each pi are hooked into a unique GPIO (wiring pi numbers 0-7). |
- | By default, if you run the script by itself, it should calculate and produce (in a file in the current directory), a file by the name of **pi.100.out**, | + | When the pin is active (3.3V applied, the ' |
- | < | + | When the pin is inactive (0V applied, the ' |
- | lab46: | + | |
- | lab46: | + | |
- | pi.100.out | + | |
- | lab46: | + | |
- | 3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067 | + | |
- | lab46: | + | |
- | </ | + | |
- | If you provide a command-line argument, it must be a valid numeric value between 1 and 2000, and will calculate | + | ====Configuring GPIO pins for use with our LEDs==== |
+ | If you look in the table for wiringPi pins 0-7, you'll see under the " | ||
- | You also need to verify your results against | + | To utilize the LEDs, we need to instead OUTPUT from the pins. |
- | Additionally: | + | A mode change is needed, which can be accomplished with the **gpio** command, **mode** parameter. It requires the wiringPi pin number (0-7), and the desire mode to set it to (in, out). |
- | * Your script is to only produce a **pi.# | + | To set wiringPi GPIO pin 0 for output mode, for instance, we'll want to do this: |
- | * ANY temporary files need to be created in (and subsequently removed from) the **/tmp** directory, of a relatively unique name autogenerated by the **mktemp(1)** tool. | + | |
- | + | ||
- | ====script2: | + | |
- | Your second script will be called **pigrep** (no extension, although it is to be a bash script, with proper shabang, comments, and solution), and will perform searches on a **pigen**-generated **pi.# | + | |
- | + | ||
- | By default, if you run the script by itself, it should generate the following error (and exit with a non-zero value): | + | |
<cli> | <cli> | ||
- | lab46:~/ | + | pi@pi1b_0#:~ $ gpio mode 0 out |
- | ERROR: must specify PATTERN | + | |
- | lab46: | + | |
</ | </ | ||
- | It will have online usage information, | + | You may want to repeat (or loop) this for the remaining pins. |
- | <cli> | + | ====Writing to the GPIO pin==== |
- | lab46: | + | To modify the state of the pin (it can be in a ' |
- | | + | To write a 1 to wiringPi GPIO pin 0, we'll want to do this: |
- | must be part of pipeline (send PI digits in via STDIN) | + | |
- | | + | <cli> |
- | + | pi@pi1b_0#:~ $ gpio write 0 1 | |
- | note: if MAX variable is set, cap processing at that value | + | |
- | + | ||
- | | + | |
- | + | ||
- | atend - calculations are based on last digit of match | + | |
- | | + | |
- | drop3 - do not include leading 3 of pi (*3*14) in processing | + | |
- | | + | |
- | help - display this help and exit | + | |
- | + | ||
- | lab46:~/ | + | |
</ | </ | ||
- | Your script should also take the following arguments (in this order): | + | Similarly, to turn it back off again, we'll want to write a zero there: |
- | + | ||
- | * required argument: | + | |
- | * **PATTERN**: | + | |
- | * for example: ' | + | |
- | * optional arguments: | + | |
- | * **atend**: by default, offset calculations are based on the first (left-most) digit of the pattern; with this option, compute the offset based on the last (right-most) digit of the pattern | + | |
- | * **atend** is meant to be used in conjunction with **offset**, by itself | + | |
- | * **byline**: by default, matches are space-separated. With this option, display one match per line | + | |
- | * **drop3**: do not include the leading 3 of PI in processing | + | |
- | * **offset**: determine offsets of matches from start of digits | + | |
- | * **help**: display usage information | + | |
- | + | ||
- | You are also to check for the existence of a MAX variable, and if set to a valid, positive non-zero decimal (base 10) number, will cap the amount of results it processes / outputs. | + | |
- | + | ||
- | Numerical arguments are to be given as valid, positive non-zero decimal (base 10) values. | + | |
- | + | ||
- | With any of these arguments validly provided, they should adjust the script' | + | |
- | + | ||
- | Also to keep in mind: | + | |
- | + | ||
- | * Your script is not to produce any files as a result of operating. | + | |
- | * If your solution calls for ANY temporary files, they need to be created in (and subsequently removed from) the **/tmp** directory, and be of a relatively unique name autogenerated by the **mktemp(1)** tool. | + | |
- | + | ||
- | Some sample outputs follow: | + | |
- | + | ||
- | + | ||
- | + | ||
- | ====Only specifying numeric pattern==== | + | |
- | In the event only a pattern is provided, search through the PI data for the provided pattern, displaying each match to STDOUT. | + | |
- | + | ||
- | For example: | + | |
<cli> | <cli> | ||
- | lab46: | + | pi@pi1b_0#:~ $ gpio write 0 0 |
- | 26 26 | + | |
- | lab46:~/ | + | |
</ | </ | ||
- | ====one result per line==== | + | You will want to perform similar actions on the other LED-wired pins to create the desired situations as required by this project. |
- | Using the **byline** option, instead of displaying results horizonally, | + | =====Process===== |
+ | It is your task to write 4 scripts, specifications laid out as follows: | ||
- | <cli> | + | ====script1: |
- | lab46: | + | A useful bit of logic, appropriately setting the pin modes to OUTPUT and turning the pins to an OFF state is likely something your other scripts will want to call upon before they perform their intended tasks. |
- | 26 | + | |
- | 26 | + | |
- | lab46: | + | |
- | </ | + | |
- | ====compute offsets from start of digits==== | + | Therefore, you will start by writing a script you can run that establishes a sane operating environment for your LED manipulations. |
- | The **offset** argument will, instead of displaying the numeric matches (which, aside from counting are of dubious value) | + | |
- | < | + | This script should make use of a loop to perform its task (setting OUTPUT mode and WRITING a 0 state to the pin). |
- | lab46: | + | |
- | 7 22 | + | |
- | lab46: | + | |
- | </ | + | |
- | With an example like this, we should easily be able to verify its correctness: | + | ====script2: |
+ | It is not by accident the LEDs were build next to each other, wired up in sequential fashion as they are. The intention was to create an 8-bit quantity that you could manipulate. | ||
- | < | + | So, it is your task for this script to write a visual " |
- | lab46: | + | |
- | 314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664 | + | |
- | lab46: | + | |
- | 2626 | + | |
- | lab46: | + | |
- | </ | + | |
- | ====mixing options | + | You will want to create your visual output in standard observed form for binary numbers |
- | And we can mix options (in any order): | + | |
- | < | + | For example, if displaying the number 13 with this script, our binary value being output should be: |
- | lab46:~/ | + | |
- | 7 | + | |
- | 22 | + | |
- | lab46: | + | |
- | </ | + | |
- | ====Using atend with offset==== | + | < |
- | The **atend** option, issued by itself, has no impact on operations: | + | |
- | < | + | Where 2^7=0, 2^6=0, 2^5=0, 2^4=0, 2^3=1, 2^2=1, 2^1=0, and 2^0=1. |
- | lab46: | + | |
- | 26 26 | + | |
- | lab46: | + | |
- | </ | + | |
- | So we need to combine it with the **offset** option to make an impact: | + | Also, the script should accept the following optional arguments: |
- | <cli> | + | * $1 - step value (the rate of incrementation; |
- | lab46: | + | |
- | 8 23 | + | |
- | lab46: | + | |
- | </ | + | |
- | ====dropping | + | Unless you merge in the decrementing script logic into this script, you should do error checking to ensure that the starting point is LOWER than the ending point, otherwise display an error message and exit, leaving |
- | With the **drop3** option, we merely exclude | + | |
- | < | + | If you DO choose to incorporate decrement logic into this same script, a starting point being HIGHER than the ending point indicates the script should decrement instead of increment. |
- | lab46: | + | |
- | 7 22 | + | |
- | lab46: | + | |
- | </ | + | |
- | ====Using MAX to limit processing==== | + | If ONLY a step and starting value is given, proceed from that point to the final bound (being |
- | Sometimes, a pattern may produce | + | |
- | Take this request, which produces numerous results: | + | ====script3: decrementing 8-bit binary counter==== |
+ | Like the script above, only its default behavior is to decrement instead of increment. | ||
- | < | + | NOTE that you CAN combine script2 and script3 into ONE script, with the appropriate supporting logic to handle both modes. |
- | lab46: | + | |
- | 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 | + | |
- | lab46: | + | |
- | </ | + | |
- | We can cut that down to a smaller quantity by setting MAX accordingly (let's say, limit to 4 matches): | + | ====script4: |
+ | The purpose of this script is to create | ||
- | <cli> | ||
- | lab46: | ||
- | 2 2 2 2 | ||
- | lab46: | ||
- | </ | ||
- | |||
- | You could also **export** MAX, mitigating the need to manually specify it for each run. | ||
=====Specifications===== | =====Specifications===== | ||
- | Evaluation will be based on correctness of values as well as on formatting/ | + | Evaluation will be based on correctness of values as well as on commenting/formatting/ |
- | + | ||
- | You'll notice that everything lines up and is positioned similarly: | + | |
* groupwork! This project is specifically designed to be performed in groups. | * groupwork! This project is specifically designed to be performed in groups. | ||
* I want to see groups ranging from a minimum of 2 people, to a maximum of 4 people. Any less and any more are not allowed. | * I want to see groups ranging from a minimum of 2 people, to a maximum of 4 people. Any less and any more are not allowed. | ||
+ | * There are 4 pi's, 1 per table. There are 11 total people in the class, and on average 9 people regularly showing up; this could mean three groups of three (for example). | ||
* EVERY group member needs to be identified in your scripts (in a comment listing everyone). | * EVERY group member needs to be identified in your scripts (in a comment listing everyone). | ||
+ | * ONE GROUP PER TABLE (no group should share a pi with another). | ||
* EVERY group member needs to be familiar with the end products | * EVERY group member needs to be familiar with the end products | ||
* EVERY group member needs to submit a copy of the scripts (they should all be identical- I will check) | * EVERY group member needs to submit a copy of the scripts (they should all be identical- I will check) | ||
* in the event you feel other group members have not lived up to their obligations, | * in the event you feel other group members have not lived up to their obligations, | ||
* EVERY group member needs to do an approximately equal portion of the work. Slackers should be called out (I'll be keeping an eye out as well) and they will lose credit. | * EVERY group member needs to do an approximately equal portion of the work. Slackers should be called out (I'll be keeping an eye out as well) and they will lose credit. | ||
+ | * EACH group member is responsible for prolifically commenting and demonstrating functionality of ONE of the scripts. The commenter should be identified at the top of the particular script. No one person should be commenting all the scripts. | ||
* This project is designed to be done DURING class time. It may offer up some useful insights into other projects (that you're doing on your own). | * This project is designed to be done DURING class time. It may offer up some useful insights into other projects (that you're doing on your own). | ||
- | * You need to check your arguments to ensure they are present and valid. | + | * You need to check your arguments to ensure |
- | * all mentioned arguments implementing their indicated functionality | + | * all mentioned arguments implementing their indicated functionality |
- | * help takes priority over other options | + | * any invalid arguments |
- | * **atend** has no appreciable impact unless **offset** is also specified | + | |
- | * any invalid arguments should | + | |
* your script needs to commence with a proper **shabang** to run using bash; your script needs to end with an " | * your script needs to commence with a proper **shabang** to run using bash; your script needs to end with an " | ||
* comments and indentation are required and necessary | * comments and indentation are required and necessary | ||
* comments should explain how or why you are doing something | * comments should explain how or why you are doing something | ||
* indentation should be consistent throughout the script (no mixing of different indentation units; no mixing of tabs and spaces) | * indentation should be consistent throughout the script (no mixing of different indentation units; no mixing of tabs and spaces) | ||
- | * indentation is to be no less than 3 on-screen spaces (I recommend tabstops of 4). | + | * indentation is to be no less than 3 on-screen spaces (I recommend tabstops/ |
* continuing with our shell scripting, your scripts will need to employ in a core/ | * continuing with our shell scripting, your scripts will need to employ in a core/ | ||
* variables | * variables | ||
* command-line argument parsing and usage | * command-line argument parsing and usage | ||
- | * command-line pipelines | ||
- | * command expansions | ||
- | * regular expressions | ||
* conditional/ | * conditional/ | ||
* loops | * loops | ||
+ | * if appropriate: | ||
+ | * command-line pipelines | ||
+ | * command expansions | ||
+ | * regular expressions | ||
* your logic needs to: | * your logic needs to: | ||
* flow (one thing leads into the next, as best as possible) | * flow (one thing leads into the next, as best as possible) | ||
Line 335: | Line 222: | ||
This can be in the form of comments in your script, or even a separate file submitted at time of submission (if a file, be sure to make mention of it in your script so I can be sure to look for it). | This can be in the form of comments in your script, or even a separate file submitted at time of submission (if a file, be sure to make mention of it in your script so I can be sure to look for it). | ||
- | |||
=====Submission===== | =====Submission===== | ||
- | By successfully performing this project, you should have a fully functioning set of scripts by the names **pigen** and **pigrep**, which are all you need to submit for project completion (no steps file, as your " | + | By successfully performing this project, you should have a fully functioning set of scripts by the names **script1** through |
To submit this project to me using the **submit** tool, run the following command at your lab46 prompt: | To submit this project to me using the **submit** tool, run the following command at your lab46 prompt: | ||
<cli> | <cli> | ||
- | $ submit unix spf0 pigen pigrep | + | $ submit unix spf1 script1 script2 script3 script4 |
- | Submitting unix project "spf0": | + | Submitting unix project "spf1": |
- | -> pigen(OK) | + | -> script1(OK) |
- | -> pigrep(OK) | + | -> script2(OK) |
+ | -> script3(OK) | ||
+ | -> script4(OK) | ||
SUCCESSFULLY SUBMITTED | SUCCESSFULLY SUBMITTED | ||
Line 356: | Line 244: | ||
< | < | ||
- | 26:spf0:final tally of results (26/26) | + | 52:spf1:final tally of results (52/52) |
- | *:spf0: | + | *:spf1: |
- | *:spf0:scripts effectively utilize command-line arguments | + | *:spf1:initialization script logic present and functions |
- | *:spf0:scripts effectively utilize command expansions | + | *:spf1:initialization logic uses loop to automate task [4/4] |
- | *:spf0:scripts effectively utilize regular expressions | + | *:spf1:incrementation script logic present and functions |
- | *:spf0:scripts effectively utilize selection structures | + | *:spf1:counter script logic is centrally based on loop [4/4] |
- | *:spf0:scripts effectively utilize looping structures | + | *:spf1:counter script logic does adequate error checking |
- | *:spf0:scripts are proper bash scripts with shabang | + | *:spf1:decrementation script logic present |
- | *:spf0:pigrep displays values in proper orientation | + | *:spf1:flashy script logic present and functions |
- | *:spf0:pigrep accurately displays values as requested | + | *:spf1:scripts appropriately call the initialization logic [4/4] |
- | *:spf0: | + | *:spf1: |
- | *:spf0:pigen operates according to specifications | + | *:spf1:scripts effectively utilize selection structures |
- | *:spf0:pigrep operates according to specifications | + | *:spf1:scripts effectively utilize looping structures |
- | *:spf0:script logic is organized | + | *:spf1:scripts are proper bash scripts with shabang |
</ | </ | ||