This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:spring2019:unix:projects:spf1 [2019/04/16 15:47] – [Getting a readout of the GPIO pins] 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 128: | Line 116: | ||
You will want to perform similar actions on the other LED-wired pins to create the desired situations as required by this project. | You will want to perform similar actions on the other LED-wired pins to create the desired situations as required by this project. | ||
=====Process===== | =====Process===== | ||
- | 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 the calculations... no skimping on this), and the other will use that produced data to search through the digits of PI in order to find occurrences of patterns. Further details follow: | + | It is your task to write 4 scripts, |
- | ====script1: | + | ====script1: |
- | You are to write a script, called | + | A useful bit of logic, appropriately setting the pin modes to OUTPUT |
- | By default, if you run the script | + | Therefore, you will start by writing |
- | < | + | This script should make use of a loop to perform its task (setting OUTPUT mode and WRITING a 0 state to the pin). |
- | 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 that many digits of PI, saving it in a file **pi.#.out**, where # is the number of digits requested. | + | ====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. | ||
- | You also need to verify | + | So, it is your task for this script to write a visual " |
- | Additionally: | + | You will want to create your visual output in standard observed form for binary numbers (ie the left side denotes the MOST SIGNIFICANT BIT, and the right-most side denotes the LEAST SIGNIFICANT BIT). |
- | * Your script | + | For example, if displaying the number 13 with this script, our binary value being output should |
- | * 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): | + | 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. |
- | < | + | Also, the script should accept the following optional arguments: |
- | lab46:~/ | + | |
- | ERROR: must specify PATTERN | + | |
- | lab46: | + | |
- | </ | + | |
- | It will have online usage information, | + | * $1 - step value (the rate of incrementation; |
+ | | ||
+ | | ||
- | < | + | 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 the LEDs in an OFF state. |
- | lab46: | + | |
- | | + | 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 |
- | must be part of pipeline (send PI digits in via STDIN) | + | |
- | | + | If ONLY a step and starting value is given, proceed from that point to the final bound (being an incrementer if step is positive, or decrementer if step is negative). |
- | note: if MAX variable is set, cap processing at that value | + | ====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. |
- | atend - calculations are based on last digit of match | + | ====script4: |
- | byline - output one value per line (default is space-separated) | + | The purpose |
- | drop3 - do not include leading 3 of pi (*3*14) in processing | + | |
- | | + | |
- | help - display | + | |
- | lab46: | ||
- | </ | ||
- | |||
- | Your script should also take the following arguments (in this order): | ||
- | |||
- | * 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 it does not alter default processing | ||
- | * **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> | ||
- | lab46: | ||
- | 26 26 | ||
- | lab46: | ||
- | </ | ||
- | |||
- | ====one result per line==== | ||
- | Using the **byline** option, instead of displaying results horizonally, | ||
- | |||
- | <cli> | ||
- | lab46: | ||
- | 26 | ||
- | 26 | ||
- | lab46: | ||
- | </ | ||
- | |||
- | ====compute offsets from start of digits==== | ||
- | The **offset** argument will, instead of displaying the numeric matches (which, aside from counting are of dubious value) will display how many digits away from the start of the PI digits the pattern resides. | ||
- | |||
- | <cli> | ||
- | lab46: | ||
- | 7 22 | ||
- | lab46: | ||
- | </ | ||
- | |||
- | With an example like this, we should easily be able to verify its correctness: | ||
- | |||
- | <cli> | ||
- | lab46: | ||
- | 314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664 | ||
- | lab46: | ||
- | 2626 | ||
- | lab46: | ||
- | </ | ||
- | |||
- | ====mixing options (offset, byline)==== | ||
- | And we can mix options (in any order): | ||
- | |||
- | <cli> | ||
- | lab46: | ||
- | 7 | ||
- | 22 | ||
- | lab46: | ||
- | </ | ||
- | |||
- | ====Using atend with offset==== | ||
- | The **atend** option, issued by itself, has no impact on operations: | ||
- | |||
- | <cli> | ||
- | lab46: | ||
- | 26 26 | ||
- | lab46: | ||
- | </ | ||
- | |||
- | So we need to combine it with the **offset** option to make an impact: | ||
- | |||
- | <cli> | ||
- | lab46: | ||
- | 8 23 | ||
- | lab46: | ||
- | </ | ||
- | |||
- | ====dropping the leading 3==== | ||
- | With the **drop3** option, we merely exclude the leading 3 of pi from our calculations. This should result in everything being "off by one" from previous outputs (with any combination of arguments): | ||
- | |||
- | <cli> | ||
- | lab46: | ||
- | 7 22 | ||
- | lab46: | ||
- | </ | ||
- | |||
- | ====Using MAX to limit processing==== | ||
- | Sometimes, a pattern may produce an untenable quantity of results. We may wish to restrict it, and can do so with the aid of setting the **MAX** variable. | ||
- | |||
- | Take this request, which produces numerous results: | ||
- | |||
- | <cli> | ||
- | 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): | ||
- | |||
- | <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 375: | 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 396: | 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 |
</ | </ | ||