Termbank
  1. A
    1. Abstraction
    2. Alias
    3. Argument
    4. Array
  2. B
    1. Binary code file
    2. Binary number
    3. Bit
    4. Bitwise negation
    5. Bitwise operation
    6. Byte
  3. C
    1. C library
    2. C-function
    3. C-variable
    4. Character
    5. Code block
    6. Comment
    7. Compiler
    8. Complement
    9. Conditional statement
    10. Conditional structure
    11. Control structure
  4. D
    1. Data structure
    2. Duck typing
  5. E
    1. Error message
    2. Exception
  6. F
    1. Flag
    2. Float
  7. H
    1. Header file
    2. Headers
    3. Hexadecimal
  8. I
    1. Immutable
    2. Initialization
    3. Instruction
    4. Integer
    5. Interpreter
    6. Introduction
    7. Iteroitava
  9. K
    1. Keyword
  10. L
    1. Library
    2. Logical operation
  11. M
    1. Machine language
    2. Macro
    3. Main function
    4. Memory
    5. Method
  12. O
    1. Object
    2. Optimization
  13. P
    1. Parameter
    2. Placeholder
    3. Pointer
    4. Precompiler
    5. Precompiler directive
    6. Prototype
    7. Python console
    8. Python format
    9. Python function
    10. Python import
    11. Python list
    12. Python main program
    13. Python variable
    14. Python-for
    15. Pääfunktio
    16. printf
  14. R
    1. Resource
    2. Return value
  15. S
    1. Statement
    2. Static typing
    3. String
    4. Syntax
  16. T
    1. Terminal
    2. Type
    3. Typecast
  17. U
    1. Unsigned
  18. V
    1. Value
  19. W
    1. Warning
    2. while
Completed: / exercises

Final project 2024. Secret Messages.

Note: This material will be updated during the course with clarifications and additions to the content. During the course, we will also add hints to help with common problems and other information. So, check this page from time to time!
Last updated: 1.10.2024. Initial version.

Introduction

Students are working for a goverment's intelligence agency. Your task is to develop a communication device that allows sending message to other agent using hidden interactions with the device. In this the Sensor Tag is going to be our communication tool.

Learning goals

In the project, the students will learn to use the peripheral devices of the SensorTag-board with TI-RTOS real-time operating system. In the basic completion level, the students are able to recognize certain movements with the MPU-sensor of the device, and transmit a character based on different movements to an external device via UART. UART is also used to receive messages from an external source, which are handled in the device in some way, by for example using the buzzer of the device to play out sounds with different lengths to represent certain characters.

Project specifications

Secret messages

In the project work you and your team need to implement a messaging program based on Morse-code. Morse alphabet is a part of a messaging system developed by |Samuel Morse in 1838, that was used to deliver messages via telegraph. Nowadays Morse alphabet and telegraphy are only used rarely, but for example the reconnaissance officers with radio training (also called "sissiradistit|Sissiradisti" in Finnish) of the Finnish Defense Forces learn and use them. Radio amateurs are also sometimes required to learn these skills to have permissions to broadcast at certain frequencies.
The program to be implemented as a project work will recognize the dots, dashes and spaces needed to form the Morse-coded messages by using movements captured from the sensor data of the device, or for example from button presses. Messages produced in this manner will then be transferred to a program running on a workstation computer, where they will be translated back to text. The program created for the device of the course should also be able to interpret a received message that consists of Morse-coded characters (dots, dashes and space) and present it to its user.

Message protocol

The communication happening between the device and the workstation abides to the international Morse code alphabet with some exceptions and application-specific clarifications. These exceptions are listed below.

Example

To make the rules defined above more concrete, we have an example of the usage of our protocol below.
    Word to send: aasi
    Encoding the word to a sequence of Morse-encoded characters, inserting one space in between of every character: 
    
    aasi => .- .- ... ..
    
    We send the character through UART to the workstation:
    .\r\n
    -\r\n
     \r\n
    .\r\n
    -\r\n
     \r\n
    .\r\n
    .\r\n
    .\r\n
     \r\n
    .\r\n
    .\r\n
     \r\n
     \r\n
     \r\n

Workstation program

The course's virtual machine already has a program installed that sends and receives messages in Morse code via UART. You can start it using the "Serial Client" shortcut on the desktop. If this doesn't work, you can use the virtual machine's terminal and first navigate to the program's folder with the command cd serial-client, then start the program with the command npm start.
When it starts, the program reads the config.json-file located in the same folder, which contains the necessary configurations for using different development boards. Currently, the configuration file already has settings for the devices used in this course (SensorTag and Pico W), but it is also possible to include other devices. If the settings are read successfully, the program will print Config loaded with 2 known devices to the screen, after which it will wait for a known device to be connected.
When you connect a known device to the workstation, it switches to messaging mode, where messages typed into the terminal (except for program commands) are sent to the connected device via UART in Morse code. Data received from the device in Morse code is printed to the terminal, and when the three spaces indicating the end of a message are detected, the message itself is converted to text and printed to the window. This way, you can see the sent message as well as the characters that make up the message, which can help with debugging the program.

Commands

As mentioned before, all messages containing only allowed characters are sent to the device via UART in Morse-encoded format, with the exception being the program commands. These commands you can use to control the program.

Requirements

  1. The program should have a minimal user interface. Implementation with for example buttons, LEDs and sounds.
  2. Control commands (dots, dashes and spaces) have to be captured initially from the data collected from accelerometer and gyroscope (MPU9250)
    • At least two different positions or movements need to be recognized
      • Position is letting the device static in certain position and orientation.
      • In a movement the device has an original position and end position: moving the device up, letting it drop ... The movements can be also implemented in 3-dimensional way to many directions
    • You can also attach button presses to the movements, along with other state information, enabling the implementation of more complex commands.
  3. The program has to send a message to the workstation when a command has been recognized
  4. The program has to inform the user about a recognized command with a sound cue or a LED
  5. The program has to receive messages from the workstation and react to those using either LEDs or buzzer (Morse code must be shown to the user)
  6. The implementation of the program has to be based on task-based implementation with the real-time operating system of the course, and a state machine
  7. You can use additional sensor recognition, for instance to send specific messages (e.g HOT if temperature > threshold)

Towards a better grade

The score for the project can be increased by implementing additional functionalities. Below are some examples, and the list will be updated further:
Each implemented functionality is counted only once. The scoring of functionalities will be based on common sense and the teaching staff's experience in embedded systems programming.

Sensor data in final project

Here are the instructions on how to implement command interpretation in a program based on sensor data collection and interpretation.
There are two options to detect data using the MPU:
Implementation of control commands as movements of the device, while holding it in hand, is freely decided by the group. Possible alternative implementations include at least the following:
General guidelines for interpreting control commands:

Interpreting a command

1. It is advisable to start the work by collecting your own dataset with the MPU9250 sensor as a time series while manually moving the device. The collection should be done so that only one movement is made at a time and saved in its own file.
When the data is collected in a table, the result is a 7-dimensional table. The data in the table might look something like this:
aika,   acc_x,      acc_y, acc_z,   gyro_x,  gyro_y,   gyro_z
0,      0.0029,  -0.0063,  -1.0115, 1.1215,  -0.4578,  0.3204
11,     0.0133,  0.0291,   -0.9753, 0.0229,  -0.0458,  -0.2060
19,     0.0028,  0.0964,   -1.0406, 5.2948,  -14.09,   19.0735
30,     -0.085,  0.2474,   -1.8069, -1.833,  0.0992,   15.4953
41,     -0.20,   0.3864,   -2.2000, -6.180,  29.9924,  70.5643
Note that the figures are normalized with the gravity. Hence, 1 means 9.8 m/s2
2. The collected data can be visualized in relation to different axes to see what happened in the data during each movement/command execution, and thus understand how to implement recognition programmatically.
By visualizing, it is easy to see what the sensor data looks like at different stages of the command when the device moves:
3. After collecting and visualizing the dataset, the control command can be recognized from the data quite simply:
  1. The duration of the movement in relation to different axes
  2. Exceeding/falling below a chosen threshold value in relation to an axis
  3. Various features can be calculated for the time series, such as the average, variance, standard deviation, etc., which can be used to distinguish commands from each other (and optionally fine-tune command recognition).
    • This can also be useful if you want to chain commands or implement more complex commands (for those extra points?)
  4. Since sensor data is obtained on three axes (x, y, and z), it can also be treated as a 2- or 3-dimensional vector, which has, for example, direction and length.
  5. Anything you can find in a math book / online / taught in an AI course.
    • Remember to mention sources in the code.

Ready-made test data

The staff has pre-collected a small test dataset of various movements of the device held in hand, which can be used for preliminary command recognition in the work. The methods mentioned here for moving the device are not necessarily the only, easiest, or best way to implement commands with the device.
The test data was collected using the SensorTag's MPU9250 accelerometer. In the files, the data format is [timestamp, acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z]. The data was measured so that the device was stationary at the beginning of the measurement and then moved up in two different ways. The images visualize the data for the x, y, and z axes (in different colors) over time for both the accelerometer (g) and the gyroscope (angular velocity).
1. Sensor data when the device is stationary:
jtkj-paik-csv
jtkj-paik-h
2. Sensor data when the device is jerked fast from the table surface to the direction up two times:
jtkj-nyka-csv
jtkj-nyka-h
3. Sensor data, when the device is lifted up from the table surface and moved to the direction up:
jtkj-nosto-csv
jtkj-nosto-h

Own test data

Collecting test data independently is easiest by first implementing a separate data collection task in the device as a separate program or task that simply collects movement sensor data into a table at selected intervals. Finally, the program prints the table row by row to the development environment, from where it can be easily copied and pasted into an editor and/or file. The data can be visualized using a Python library (hint hint, matplotlib) or a program like gnuplot or MS Excel.
When collecting your own test data, it is important to perform the movement always in the same way, i.e., the user and the sensor in the same position, etc., and absolutely only one movement at a time. This is so that the visualization clearly shows what happened in the data. Additionally, the data collected in different measurements is then comparable between different measurements. It is also noted that different people's hand movements are usually so different that, for example, the above test data does not directly apply to your own command recognition. The sensor is so precise that even small differences can be detected.

Tips for the project work

Not so surprisingly, many things are already told and many questions answered in the lecture materials. So, it is beneficial to study the materials very carefully..
The implementation of the project work should be designed with the help of Modular and procedural programming extra material. This way, even a big problem can be divided into parts that are easily manageable.

Project-related tips

We will update this section with additional tips when the implementation of the project work progresses and we know more..

Implementation order

Below is a suggested (staff-approved) implementation order for the project. First, implement the required functionality and then aim for a higher grade by adding additional features.
  1. Project plan, which doesn't have to be final, but helps the group understand what they are doing. (The plan can change, see below)
  2. Collecting and analyzing sensor data on the device for command interpretation.
  3. Implementing the recognition algorithm in C on a workstation based on collected data.
  4. Transferring the working algorithm to the device and testing functionalities in real life.
  5. Fine-tuning the user interface, sending/receiving messages via serial communication.
  6. Additional features.

Deliverables

Project plan

As part of the course, a short project plan must be created for the project. These plans are not shown publicly to others; the purpose is to help yourselves in completing the final project. Creating a plan might seem unnecessary, but based on previous student feedback, it really helps to get your thoughts organized and to think about what actually needs to be done in the project! It also helps in scheduling the work.
The plan does not need to go into great detail; a high level of abstraction is sufficient. You can use bullet points to describe the items briefly. The plan should be a maximum of one A4 page. The plan is not binding, meaning it will likely evolve as the project progresses. An example plan is provided below.
jtkj-plan
Contents:
  1. A brief description of the functionalities in the program.
  2. Outline of the peripherals to be used (buttons, sensors, etc.) and their purpose in the program.
  3. Define the number of tasks and the role of each one
  4. State machine that implements the project. It is easiest to present this as a diagram.
    • The state machine should cover the main tasks of the program; lower levels of abstraction are not necessary.
  5. Identify data structures, constants and global variable that you are using.
  6. Sketch a set of target movements to be used in the application
  7. Collection of sensor data: number of samples to collect, time interval, etc.
  8. Considered additional features.
  9. Preliminary schedule, including milestones and distribution of work.
The plan must be submitted by Friday 25.10 at 23.59. The plan is a mandatory part of the project. It is sufficient for one student from the project group to submit the plan to Lovelace. However, if you have questions, it is best to ask the assistants directly during the exercises.

PROJECT PLAN

ASSESSMENT CRITERIA NOT YET UPDATED.
Upload the design document into this exercise. Use a well-known file format, i.e. JPG/PNG/PDF/Word document.
Remember to add the names of all students in your group into the document.
Note! Do not send large files (i.e. size of several megabytes), but try to reduce the image size.
Palautettavan tiedoston maksimikoko on 2,5 MB!
Warning: You have not logged in. You cannot answer.
Note! You are allowed to start the implementation of the project work before presenting a plan!
Note! The plans might be used as a reference material in academic research at a later time, in which case they will be anonymised. If you want to, you can decline the usage of your plan as research material by stating that in your plan.

Project code

The deadline for submissions is 2024-11-17 23:59
The code must be returned to the return box below before the deadline. This will be the code that is evaluated.

Course project code

ASSESMENT CRITERIA NOT YET UPDATED
Upload here your code before the deadline expires. Return here all your C-files that you have written, including code and header files. If you have multiple files, please zip them.
Please do not zip and upload the whole project directory, as there are lots of unnecessary extra stuff including large debug files, etc!
Make sure to include your names into the code as comments.
Include also the code and the files you have generated after collecting data from the sensors (csv, graphs...)
Warning: You have not logged in. You cannot answer.

Personal diary

Students need to keep a personal diary and return it at the end of the course. Each member of the team, need to return a text file or pdf file. Diary can be kept online, but it should move to a file before delivering. The diary is a personal task, not a team task.
The diary should contain at least one weekly entry with the following information:
1. Tasks that you have performed during the week and time taken for each task. Be specific: e.g. Implemented function [getActivity], collected up and down movement data for sensor
2. Which has been the main challenges?
3. What have you learnt this week?
4. What are your tasks for next week.
If you are aiming for a 1 (see [|[below]]), indicate it also at the beginning of the dairy
Warning: You have not logged in. You cannot answer.

Quizz

This quizz is similar to the one completed for the C part:

Warning: You have not logged in. You cannot answer.

Project evaluation

The project evaluation will be conducted in groups during the review session after the deadline. The session will be held in the workstation classroom.

Grading

The maximum score for the project is 30 points, which constitutes 50% of the course grade.
Project grading:
1. Plan: 2 points -> Same grade for all members of the team
2. Project: 20 points -> Same grade for all members of the team
3. Personal diary: 1.5 points
4. Questions during the project evaluation: 2.5 points
5. Contribution to the project: 6 points to be distributed among group members. Decision agreed with students during final meeting.
6. Quizz about theoretical/practical aspects of the implementation 2 points
Detailed evaluation criteria can be found in the submission box for the plan, the program code and the diary. Check the evaluation criteria in the corresponding submission box.
Final Grade
The other 50% of the course grade comes from previous C language exercises (max 30 points), so the maximum total score is 60 points.
Requirements to pass

Special requirements fo those aiming for 1 in the course

If you want a 1, you should mention clearly at the beginning of your diary. If you opt for this option, you wont get points but get just PASS / FAIL if following criteria is met:

FAQ

  1. Can the work be done individually?
    • If there are valid reasons for working alone, please contact the teacher.
  2. Can the work be done in a larger group than a pair?
    • The work can be done in a group of 2-3 people. In previous years, groups of three had to do additional tasks, but this practice is not in effect in autumn 2024. Groups of four are not allowed.
  3. The code worked at home, but not during the project evaluation. Can I try it on my own computer? Can I show it remotely from home?
    • No. Make sure the code works in the development environment installed on the course virtual machines before submitting.
  4. Can I discuss the work with a friend?
    • Of course, you can discuss it during exercises, social gatherings, etc., but if two groups submit the same code, you may be guilty of plagiarism. For this reason, groups that have collaborated should be mentioned in the code comments or similar.
    • The line is that you can discuss the task, but you must write the code yourself!
  5. Can the work be submitted late?
    • No.
  6. Can I use someone else's (or code found online)?
    • You cannot use the code of those participating in the same course, even if you cite the source. In other words, you cannot copy code from someone else's project into your own.
    • Otherwise, you can, as long as you indicate where the code was obtained from (website, etc.), so you do not commit plagiarism.
  7. Can I use AI?
    • Yes, as long as you specify in your code what AI you used, what prompts you used, and how you modified the code based on the AI's response. If during the meeting we suspect that you have used AI and you do not have reported it your project might be rejected.
  8. What about plagiarism?

Temporary code sharing space

Use this return box to share code with your team members. DO NOT USE THIS RETURN BOX TO UPLOAD THE FINAL VERSION OF YOUR CODE. CODE IN THIS RETURN BOX WILL NOT BE EVALUATED

Temporary Code sharing and storage

Please, use this return box to upload temporary code that you would like to share with other member of the team. This code does not count for final evaluation.
Still the preferred option to share code is using Git (see instructions in Session 1)
Important note Use this return box ONLY TO SHARE CODE RELATED TO THIS COURSE. Any code that is not related to the course content will be removed.
Warning: You have not logged in. You cannot answer.
?
Abstraction is a process through which raw machine language instructions are "hidden" underneath the statements of a higher level programming language. Abstraction level determines how extensive the hiding is - the higher the abstraction level, the more difficult it is to exactly say how a complex statement will be turned into machine language instructions. For instance, the abstraction level of Python is much higher than that of C (in fact, Python has been made with C).
Alias is a directive for the precompiler that substitus a string with another string whenever encountered. In it's basic form it's comparable to the replace operation in a text editor. Aliases are define with the #define directeve, e.g. #define PI 3.1416
Argument is the name for values that are given to functions when they are called. Arguments are stored into parameters when inside the function, although in C both sides are often called just arguments. For example in printf("%c", character); there are two arguments: "%c" format template and the contents of the character variable.
Array is a common structure in programming languages that contains multiple values of (usually) the same type. Arrays in C are static - their size must be defined when they are introduced and it cannot change. C arrays can only contain values of one type (also defined when introduced).
Binary code file is a file that contains machine language instructions in binary format. They are meant to be read only by machines. Typically if you attempt to open a binary file in a text editor, you'll see just a mess of random characters as the editor is attempting to decode the bits into characters. Most editors will also warn that the file is binary.
Binary number is a number made of bits, i.e. digits 0 and 1. This makes it a base 2 number system.
A bit is the smallest unit of information. It can have exactly two values: 0 and 1. Inside the computer everything happens with bits. Typically the memory contains bitstrings that are made of multiple bits.
Bitwise negation is an operation where each bit of a binary number is negated so that zeros become ones and vice versa. The operator is ~.
Bitwise operations are a class of operations with the common feature that they manipulate individual bits. For example bitwise negation reverses each bit. Some operations take place between two binary values so that bits in the same position affect each other. These operations include and (&), or (|) and xor (^). There's also shift operations (<< and >>) where the bits of one binary number are shifted to the left or right N steps.
Byte is the size of one memory slot - typically 8 bits. It is the smallest unit of information that can be addressed from the computer's memory. The sizes of variable types are defined as bytes.
External code in C is placed in libraries from which they can be taken to use with the #include directive. C has its own standard libraries, and other libraries can also be included. However any non-standard libraries must be declared to the compiler. Typically a library is made of its source code file (.c) and header file (.h) which includes function prototypes etc.
Functions in C are more static than their Python counterparts. A function in C can only have ne return value and its type must be predefined. Likewise the types of all parameers must be defined. When a function is called, the values of arguments are copied into memory reserved for the function parameters. Therefore functions always handle values that are separate from the values handled by the coe that called them.
C variables are statically typed, which means their type is defined as the variable is introduced. In addition, C variables are tied to their memory area. The type of a variable cannot be changed.
Character is a single character, referred in C as char. It can be interpreted as an ASCII character but can also be used as an integer as it is the smallest integer that can be stored in memory. It's exactly 1 byte. A character is marked with single quotes, e.g. 'c'.
Code block is a group of code lines that are in the same context. For instance, in a conditional structure each condtion contains its own code block. Likewise the contents of a function are in their own code block. Code blocks can contain other code blocks. Python uses indentation to separate code blocks from each other. C uses curly braces to mark the beginning and end of a code block.
Comments are text in code files that are not part of the program. Each language has its own way of marking comments. Python uses the # character, C the more standard //. In C it's also possible to mark multiple lines as comments by placing them between /* and */.
A compiler is a program that transforms C source code into a binary file containing machine language instructions that can be executed by the computer's processor. The compiler also examines the source code and informs the user about any errors or potential issues in the code (warnings). The compiler's behavior can be altered with numerous flags.
Complement is a way to represent negative numbers, used typically in computers. The sign of a number is changed by flipping all its bits. In two's complement which is used in this course, 1 is added to the result after flipping.
Conditional statement is (usually) a line of code that defined a single condition, followed by a code block delimited by curly braces that is entered if the condition evaluates as true. Conditional statements are if statements that can also be present with the else keyword as else if. A set of conditional statements linked together by else keywords are called conditional structures.
Conditional structure is a control structure consisting of one or more conditional statements. Most contrl structures contain at least two branches: if and else. Between these two there can also be any number of else if statements. It is however also possible to have just a single if statement. Each branch in a conditional structure cotains executable code enclosed within a block. Only one branch of the structure is ever entered - with overlapping conditions the first one that matches is selected.
Control structures are code structures that somehow alter the program's control flow. Conditional structures and loops belong to this category. Exception handling can also be considered as a form of control structure.
Data structure is a comman name for collection that contain multiple values. In Python these include lists, tuples and dictionaries. In C the most common data structures are arrays and structs.
Python's way of treating variable values is called dynamic typing aka duck typing. The latter comes from the saying "if it swims like a duck, walks like a duck and quacks like a duck, it is a duck". In other words, the validity of a value is determined by its properties in a case-by-case fashion rather than its type.
An error message is given by the computer when something goes wrong while running or compiling a program. Typically it contains information about the problem that was encountered and its location in the source code.
An exception is what happens when a program encounters an error. Exceptions have type (e.g. TypeError) that can be used in exception handling within the program, and also as information when debugging. Typically exceptions also include textual description of the problem.
Flags are used when executing programs from the command line interface. Flags are options that define how the program behaves. Usually a flag is a single character prefixed with a single dash (e.g. -o) or a word (or multiple words connected with dashes) prefixed with two dashes (e.g. --system. Some flags are Boolean flags which means they are either on (if present) or off (if not present). Other flags take a parameter which is typically put after the flag separated either by a space or = character (e.g. -o hemulen.exe.
Floating point numbers are an approximation of decimal numbers that are used by computers. Due to their archicture computers aren't able to process real decimal numbers, so they use floats instead. Sometimes the imprecision of floats can cause rounding errors - this is good to keep in mind. In C there are two kinds of floating point numbers: float and double, where the latter has twice the number of bits.
Header files use the .h extension, and they contain the headers (function prototypes, type definitions etc.) for a .c file with the same name.
Headers in C are used to indicate what is in the code file. This includes things like function prototypes. Other typical content for headers are definition of types (structs etc.) and constants. Headers can be at the beginning of the code file, but more often - especially for libraries - they are in placed in a separate header (.h) file.
Hexadecimal numbers are base 16 numbers that are used particularly to represent memory addresses and the binary contents of memory. A hexadecimal number is typically prefixed with 0x. They use the letters A-F to represent digits 10 to 15. Hexadecimals are used because each digit represents exactly 4 bits which makes transformation to binary and back easy.
In Python objects were categorized into mutable and immutable values. An immutable value cannot have its contents changed - any operations that seemingly alter the object actually create an altered copy in a new memory location. For instance strings are immutable in Python. In C this categorization is not needed because the relationship of variables and memory is tighter - the same variable addresses the same area of memory for the duration of its existence.
When a variable is given its initial value in code, the process is called initialization. A typical example is the initialization of a number to zero. Initialization can be done alongside with introduction: int counter = 0; or separately. If a variable has not been initialized, its content is whatever was left there by the previous owner of the memory area.
Instruction set defines what instructions the processor is capable of. These instructions form the machine language of the processor architecture.
Integers themselves are probably familiar at this point. However in C there's many kinds of integers. Integer types are distinguished by their size in bits and whether they are signed or not. As a given number of bits can represent up to (2 ^ n) different integers, the maximum value for a signed integer is (2 * (n - 1))
Python interpreter is a program that transforms Python code into machine language instructions at runtime.
The moment a variable's existence is announed for the first is called introduction. When introduced, a variable's type and name must be defined, e.g. int number;. When a variable is introduced, memory is reserved for it even though nothing is written there yet - whatever was in the memory previously is still there. For this reason it's often a good idea to initialize variables when introducing them.
Iteroitava objekti on sellainen, jonka voi antaa silmukalle läpikäytäväksi (Pythonissa for-silmukalle). Tähän joukkoon kuuluvat yleisimpinä listat, merkkijonot ja generaattorit. C:ssä ei ole silmukkaa, joka vastaisi Pythonin for-silmukan toimintaa, joten taulukoiden yms. läpikäynti tehdään indeksiä kasvattavilla silmukoilla.
Keywords are words in programming languages that have been reserved. Good text editors generally use a different formatting for keywords (e.g. bold). Usually keywords are protected and their names cannot be used for variables. Typical keywords include if and else that are used in control structures. In a way keywords are part of the programming language's grammar.
A library is typically a toolbox of functions around a single purpose. Libraries are taken to use with the include directive. If a library is not part of the C standard library, its use must also be told to the compiler.
Logical operation refers to Boole's algebra, dealing with truth values. Typical logical operations are not, and, or which are often used in conditional statements. C also uses bitwise logical operations that work in the same way but affect each bit separately.
Machine language is made of instructions understood by the processor. Machine language is often called Assembly and it is the lowest level where it's reasonable for humans to give instructions to computers. Machine language is used at the latter part of this course - students taking the introduction part do not need to learn it.
Macro is an alias that defines a certain keyword to be replaced by a piece of code. When used well, macros can create more readable code. However, often the opposite is true. Using macros is not recommended in this course, you should just be able to recognize one when you see it.
In C the main function is the starting point when the program is run. The command line arguments of the program are passed on to the main function (although they do not have to be received), and its return value type is int. At its shortest a main function can defined as int main().
When programs are run, all their data is stored in the computer's memory. The memory consists of memory slots with an address and contents. All slots are of equal size - if an instance of data is larger, a continuous area of multiple memory slots is reserved.
Method is a function that belongs to an object, often used by the object to manipulate itself. When calling a method, the object is put before the method: values.sort().
Object is common terminology in Python. Everything in Python is treated as objects - this means that everything can be referenced by a variable (e.g. you can use a variable to refer to a function). Objects are typically used in object-oriented languages. C is not one.
Optimization means improving the performance of code, typically by reducing the time it takes to run the code or its memory usage. The most important thing to understand about opimization is that it should not be done unless it's needed. Optimization should only be considered once the code is running too slowly or doesn't fit into memory. Optimization should also not be done blindly. It's important to profile the code and only optimize the parts that are most wasteful.
A parameter is a variable defined alongside with a function. Parameters receive the values of the function's arguments when it's called. This differentation between parameters and arguments is not always used, sometimes both ends of the value transfer are called arguments.
Placeholders are used in string formatting to mark a place where a value from e.g. a variable will be placed. In Python we used curly braces to mark formatting placeholders. In C the % character is used which is followed by definitions, where the type of the value is mandatory. For instance "%c" can only receive a char type variable.
Pointers in C are special variables. A pointer contains a memory address of the memory location where the actual data value is located. In a sense they work like Python variables. A variable can be defined as a pointer by postfixing its type with * when it's being introduced, e.g. int* value_ptr; creates a pointer to an integer. The contents of the memory address can be fetched by prefixing the variable name with * (e.g. *value_ptr. On the other hand, the address of a memory adress can be fetched by prefixing a variable name with &, (e.g. &value.
The C precompiler is an apparatus that goes through all the precompiler directives in the code before the program is actually compiled. These directives include statements which add the source code of the included libraries into the program, and define directives that can define constant values (aliases) and macros.
Directives are instructions that are addressed at the precompiler. They are executed and removed from the code before the actual compilation. Directives start with the # character. The most common one is include which takes a library into use. Another common one is define, which is used e.g. to create constant values.
Prototype defines a function's signature - the type of its return value, its name and all the arguments. A prototype is separate from the actual function definition. It's just a promise that the function that matches the prototype will be found in the code file. Prototypes are introduced at the beginning of the file or in a separate header file. In common cases the prototype definition is the same as the line that actually starts the function introduction.
Interactive interpreter or Python console is a program where users can write Python code lines. It's called interactive because each code line is executed after its been fully written, and the interpreter shows the return value (if any).
The format method of string in Python is a powerful way to include variable values into printable text. The string can use placeholders to indicate where the format method's arguments are placed.
Python functions can have optional parameters that have a given default value. In Python the values of arguments in a function call are transferred to function parameters through reference, which means that the values are the same even though they may have different names. Python functions can have multiple return values.
In Python the import statement is used for bringing in modules/libraries - either built-in ones, thrid party modules or other parts of the same application. In Python the names from the imported module's namespace are accessible through the module name (e.g. math.sin). In C libraries are taken to use with include, and unlike Python import it brings the library's namespace into the program's global namespace.
Python lists were discovered to be extremely effective tools in Elementary Programming. A Python list is an ordered collection of values. Its size is dynamic (i.e. can be changed during execution) and it can include any values - even mixed types. Lists can also include other lists etc.
In Python main program is the part of code that is executed when the program is started. Usually the main program is at the end of the code file and most of the time under if __name__ == "__main__": if statement. In C there is no main program as such, code execution starts with the main function instead.
In Python a variable is a reference to a value, a connection between the variable's name in code and the actual data in memory. In Python variables have no type but their values do. The validity of a value is tested case by case when code is executed. In these ways they are different from C variables, and in truth Python variables are closer to C pointers.
Pythonin for-silmukka vastaa toiminnaltaan useimmissa kielissä olevaa foreach-silmukkaa. Se käy läpi sekvenssin -esim. listan - jäsen kerrallaan, ottaen kulloinkin käsittelyssä olevan jäsenen talteen silmukkamuuttujaan. Silmukka loppuu, kun iteroitava sekvenssi päättyy.
Pääfunktio on C:ssä ohjelman aloituspiste ja se korvaa Pythonista tutun pääohjelman. Oletuksena pääfunktion nimi on main ja se määritellään yksinkertaisimmillaan int main().
Resource referes to the processing power, memory, peripheral devices etc. that are availlable in the device. It includes all the limitations within which programs can be executed and therefore defines what is possible with program code. On a desktop PC resources are - for a programmer student - almost limitless, but on embedded devices resources are much more scarce.
Return value is what a function returns when its execution ends. In C functions can only have one return value, while in Python there can be multiple. When reading code, return value can be understood as something that replaces the function call after the function has been executed.
A statement is a generic name for a single executable set of instructions - usually one line of code.
C uses static typing This means that the type of variables is defined as they are created, and values of different types cannot be assigned to them. The validity of a value is determined by its type (usually done by the compiler). Python on the other hand uses dynamic typing aka.duck typing.
In Python all text is handled as strings and it has no type for single characters. However in C there are no strings at all - there's only character arrays. A character array can be defined like a string however, e.g. char animal[7] = "donkey"; where the number is the size of the array + 1. The +1 is neede because the string must have space for the null terminator '\0' which is automatically added to the end of the "string".
Syntax is the grammar of a programming language. If a text file does not follow the syntax of code, it cannot be executed as code, or in the case of C, it cannot be compiled.
Terminal, command line interface, command line prompt etc. are different names to the text-based interface of the operating system. In Windows you can start the command line prompt by typing md to the Run... window (Win+R). Command line is used to give text-based commands to the operating system.
The data in a computer's memory is just bits, but variables have type. Type defines how the bits in memory should be interpreted. It also defines how many bits are required to store a value of the type. Types are for instance int, float and char.
Typecast is an operation where a variable is transformed to another type. In the elementary course this was primarily done with int and float functions. In C typecast is marked a bit differently: floating = (float) integer}. It's also noteworthy that the result must be stored in a variable that is the proper type. it is not possible to change the type of an existing variable.
Unsigned integer is a an integer type where all values are interpreted as positive. Since sign bit is not needed, unsigned integers can represent twice as large numbers as signed integers of the same size. An integer can be introduced as unsigned by using the unsigend keyword, e.g. unsigned int counter;.
In the elementary programming course we used the term value to refer to all kinds of values handled by programs be it variables, statement results or anything. In short, a value is data in the computer's memory that can be referenced by variables. In C the relationship between a variable and its value is tighter as variables are strictly tied to the memory area where its value is stored.
A warning is a notification that while executing or - in this course particularly - compiling it, something suspicious was encountered. The program may still work, but parts of it may exhibit incorrect behavior. In general all warnings should be fixed to make the program stable.
One way to print stuff in C is the printf function, which closely resembles Python's print function. It is given a printable string along with values that will be formatted into the string if placeholders are used. Unlike Python, C's printf doesn't automatically add a newline at the end. Therefore adding \n at the end is usually needed.
Out of loops, while is based on repetition through checking a condition - the code block inside the loop is repeated until the loop's condition is false. The condition is defined similarly to conditional statements, e.g. while (sum < 21).