Skip to content

Commit

Permalink
Fix formatting in the C code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
JZimnol committed Jul 25, 2023
1 parent 2a97566 commit dd56c29
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 86 deletions.
28 changes: 14 additions & 14 deletions docs/academy/exercise2b.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ Next, open the **CMakeLists.txt**, change the file names and add the required in
cmake_minimum_required(VERSION 3.13)
add_executable(psk-mode
main.c
)
main.c
)
target_link_libraries(psk-mode
pico_stdlib
anjay-pico
FreeRTOS
)
pico_stdlib
anjay-pico
FreeRTOS
)
target_include_directories(psk-mode PRIVATE
${COMMON_DIR}/config
)
${COMMON_DIR}/config
)
target_compile_definitions(psk-mode PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
ENDPOINT_NAME=\"${ENDPOINT_NAME}\"
PSK_IDENTITY=\"${PSK_IDENTITY}\"
PSK_KEY=\"${PSK_KEY}\"
)
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
ENDPOINT_NAME=\"${ENDPOINT_NAME}\"
PSK_IDENTITY=\"${PSK_IDENTITY}\"
PSK_KEY=\"${PSK_KEY}\"
)
pico_enable_stdio_usb(psk-mode 1)
pico_enable_stdio_uart(psk-mode 0)
Expand Down
69 changes: 33 additions & 36 deletions docs/academy/exercise3a.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ typedef struct time_instance_struct {
anjay_iid_t iid;
char application_type[64];
char application_type_backup[64];
} time_instance_t;
} time_instance_t;
typedef struct time_object_struct {
const anjay_dm_object_def_t *def;
AVS_LIST(time_instance_t) instances;
} time_object_t;
} time_object_t;
```


Expand Down Expand Up @@ -171,18 +171,17 @@ static int resource_read(anjay_t *anjay,
assert(inst);
switch (rid) {
case RID_CURRENT_TIME: {
assert(riid == ANJAY_ID_INVALID);
int64_t timestamp;
if (avs_time_real_to_scalar(&timestamp, AVS_TIME_S,
avs_time_real_now())) {
return -1;
}
return anjay_ret_i64(ctx, timestamp);
}
case RID_CURRENT_TIME:
assert(riid == ANJAY_ID_INVALID);
int64_t timestamp;
if (avs_time_real_to_scalar(&timestamp, AVS_TIME_S,
avs_time_real_now())) {
return -1;
}
return anjay_ret_i64(ctx, timestamp);
case RID_APPLICATION_TYPE:
assert(riid == ANJAY_ID_INVALID);
return anjay_ret_string(ctx, inst->application_type);
assert(riid == ANJAY_ID_INVALID);
return anjay_ret_string(ctx, inst->application_type);
default:
return ANJAY_ERR_METHOD_NOT_ALLOWED;
}
Expand All @@ -208,9 +207,9 @@ static int resource_write(anjay_t *anjay,
switch (rid) {
case RID_APPLICATION_TYPE:
assert(riid == ANJAY_ID_INVALID);
return anjay_get_string(ctx, inst->application_type,
sizeof(inst->application_type));
assert(riid == ANJAY_ID_INVALID);
return anjay_get_string(ctx, inst->application_type,
sizeof(inst->application_type));
default:
return ANJAY_ERR_METHOD_NOT_ALLOWED;
}
Expand Down Expand Up @@ -308,28 +307,28 @@ Include the `time_object.h` file on the top of the *main.c* file.
cmake_minimum_required(VERSION 3.13)
add_executable(time_object
main.c
time_object.c
time_object.h
)
main.c
time_object.c
time_object.h
)
target_link_libraries(time_object
pico_stdlib
anjay-pico
FreeRTOS
)
pico_stdlib
anjay-pico
FreeRTOS
)
target_include_directories(time_object PRIVATE
${COMMON_DIR}/config
)
${COMMON_DIR}/config
)
target_compile_definitions(time_object PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
ENDPOINT_NAME=\"${ENDPOINT_NAME}\"
PSK_IDENTITY=\"${PSK_IDENTITY}\"
PSK_KEY=\"${PSK_KEY}\"
)
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
ENDPOINT_NAME=\"${ENDPOINT_NAME}\"
PSK_IDENTITY=\"${PSK_IDENTITY}\"
PSK_KEY=\"${PSK_KEY}\"
)
pico_enable_stdio_usb(time_object 1)
pico_enable_stdio_uart(time_object 0)
Expand Down Expand Up @@ -357,8 +356,7 @@ Go back to the *time_object.c* file and update the file using the following code
<p style="text-align: center;">time_object.c</p>
```
static int transaction_begin(anjay_t *anjay,
const anjay_dm_object_def_t *const *obj_ptr) {
const anjay_dm_object_def_t *const *obj_ptr) {
(void) anjay;
time_object_t *obj = get_obj(obj_ptr);
time_instance_t *element;
Expand All @@ -369,8 +367,7 @@ const anjay_dm_object_def_t *const *obj_ptr) {
}
static int transaction_rollback(anjay_t *anjay,
const anjay_dm_object_def_t *const *obj_ptr) {
const anjay_dm_object_def_t *const *obj_ptr) {
(void) anjay;
time_object_t *obj = get_obj(obj_ptr);
time_instance_t *element;
Expand Down
38 changes: 19 additions & 19 deletions docs/academy/exercise3b.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ void anjay_task(__unused void *params) {
}
temperature_sensor_install(g_anjay);
xTaskCreateStatic(temperature_sensor_update_task,
"TemperatureUpdateTask",TEMP_UPDATE_TASK_SIZE, NULL,
TEMP_UPDATE_TASK_PRIORITY,temp_update_stack, &temp_update_task_buffer);
"TemperatureUpdateTask", TEMP_UPDATE_TASK_SIZE, NULL,
TEMP_UPDATE_TASK_PRIORITY, temp_update_stack, &temp_update_task_buffer);
main_loop();
Expand Down Expand Up @@ -307,29 +307,29 @@ static StaticTask_t temp_update_task_buffer;
cmake_minimum_required(VERSION 3.13)
add_executable(temperature_object_lm35
main.c
temperature_sensor.c
lm35.c
)
main.c
temperature_sensor.c
lm35.c
)
target_link_libraries(temperature_object_lm35
pico_stdlib
hardware_adc
anjay-pico
FreeRTOS
)
pico_stdlib
hardware_adc
anjay-pico
FreeRTOS
)
target_include_directories(temperature_object_lm35 PRIVATE
${COMMON_DIR}/config
)
${COMMON_DIR}/config
)
target_compile_definitions(temperature_object_lm35 PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
ENDPOINT_NAME=\"${ENDPOINT_NAME}\"
PSK_IDENTITY=\"${PSK_IDENTITY}\"
PSK_KEY=\"${PSK_KEY}\"
)
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
ENDPOINT_NAME=\"${ENDPOINT_NAME}\"
PSK_IDENTITY=\"${PSK_IDENTITY}\"
PSK_KEY=\"${PSK_KEY}\"
)
pico_enable_stdio_usb(temperature_object_lm35 1)
pico_enable_stdio_uart(temperature_object_lm35 0)
Expand Down
32 changes: 15 additions & 17 deletions docs/academy/exercise4b.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Let’s start with the *temperature_sensor.c* file where we define the Temperatu
#include "temperature_sensor.h"
#define NUM_INSTANCES 1
/**
* Min Measured Value: R, Single, Optional
* type: float, range: N/A, unit: N/A
Expand Down Expand Up @@ -79,10 +78,10 @@ Next, at the end of the *temperature_sensor.c* file, add a handler which is call
<p style="text-align: center;">temperature_sensor.c</p>
```
static void send_finished_handler(anjay_t *anjay,
anjay_ssid_t ssid,
const anjay_send_batch_t *batch,
int result,
void *data) {
anjay_ssid_t ssid,
const anjay_send_batch_t *batch,
int result,
void *data) {
(void) anjay;
(void) ssid;
(void) batch;
Expand Down Expand Up @@ -120,17 +119,17 @@ void temperature_object_lm35_send(anjay_t *anjay) {
for (int it = 0; it < NUM_INSTANCES; it++) {
// Add current values of resources from Temperature Object.
if (anjay_send_batch_data_add_current(builder, anjay, 3303, it,
RID_MIN_MEASURED_VALUE)
RID_MIN_MEASURED_VALUE)
|| anjay_send_batch_data_add_current(builder, anjay, 3303, it,
RID_MAX_MEASURED_VALUE)
RID_MAX_MEASURED_VALUE)
|| anjay_send_batch_data_add_current(builder, anjay, 3303, it,
RID_MIN_RANGE_VALUE)
RID_MIN_RANGE_VALUE)
|| anjay_send_batch_data_add_current(builder, anjay, 3303, it,
RID_MAX_RANGE_VALUE)
RID_MAX_RANGE_VALUE)
|| anjay_send_batch_data_add_current(builder, anjay, 3303, it,
RID_SENSOR_VALUE)
RID_SENSOR_VALUE)
|| anjay_send_batch_data_add_current(builder, anjay, 3303, it,
RID_SENSOR_UNITS)) {
RID_SENSOR_UNITS)) {
anjay_send_batch_builder_cleanup(&builder);
avs_log(temperature_sensor, ERROR,
"Failed to add batch data, result: %d", res);
Expand Down Expand Up @@ -220,8 +219,8 @@ static void send_job(avs_sched_t *sched, const void *args_ptr) {
// Schedule run of the same function after 10 seconds
AVS_SCHED_DELAYED(sched, NULL,
avs_time_duration_from_scalar(10, AVS_TIME_S), send_job,
args, sizeof(*args));
avs_time_duration_from_scalar(10, AVS_TIME_S), send_job,
args, sizeof(*args));
}
```

Expand Down Expand Up @@ -250,8 +249,8 @@ void anjay_task(__unused void *params) {
}
temperature_sensor_install(g_anjay);
xTaskCreateStatic(temperature_sensor_update_task, "TemperatureUpdateTask",
TEMP_UPDATE_TASK_SIZE, NULL, TEMP_UPDATE_TASK_PRIORITY,
temp_update_stack, &temp_update_task_buffer);
TEMP_UPDATE_TASK_SIZE, NULL, TEMP_UPDATE_TASK_PRIORITY,
temp_update_stack, &temp_update_task_buffer);
send_job(anjay_get_scheduler(g_anjay), &(const temperature_object_lm35_job_args_t) {
.anjay = g_anjay,
Expand All @@ -270,8 +269,7 @@ Save the created code, recompile the application and flash the board.
After flashing the board, open up your serial communication program and wait for the event ** “Send Operation successful” **. This event shows that the Client performs regular Send Operations containing Temperature data.

```
INFO [temperature_sensor]
[/temperature_object_lm35_send/temperature_sensor.c:135]: Send successful
INFO [temperature_sensor][/temperature_object_lm35_send/temperature_sensor.c:135]: Send successful
```

Now, open {{ coiote_long_name }} and validate if the Resources are updated after each configured time interval.
Expand Down

0 comments on commit dd56c29

Please sign in to comment.