-
Notifications
You must be signed in to change notification settings - Fork 4
/
one_wire_api_settings.c
129 lines (106 loc) · 4.25 KB
/
one_wire_api_settings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
Licensed under the EUPL V.1.1, Lizenziert unter EUPL V.1.1
*/
/*
* one_wire_api_settings.c
*
* Created on: May 3, 2010
* Author: zumbruch
*/
#include <avr/pgmspace.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include "api_define.h"
#include "api_global.h"
#include "api_debug.h"#include "mem-check.h"
#include "one_wire_temperature.h"
#include "one_wire_adc.h"
#include "one_wire_api_settings.h"
static const char filename[] PROGMEM = __FILE__;
/* max length defined by MAX_LENGTH_PARAMETER */
static const char owiApiCommandKeyword00[] PROGMEM = "common_temp_convert";
static const char owiApiCommandKeyword01[] PROGMEM = "common_adc_convert";
//const showCommand_t showCommands[] PROGMEM =
//{
// { (int8_t(*)(struct uartStruct)) showFreeMemNow, owiApiCommandKeyword00 },
// { (int8_t(*)(struct uartStruct)) showUnusedMemNow, owiApiCommandKeyword01 },
// { (int8_t(*)(struct uartStruct)) showUnusedMemStart, owiApiCommandKeyword02 }
//};
const char* const owiApiCommandKeywords[] PROGMEM = {
owiApiCommandKeyword00,
owiApiCommandKeyword01};
int8_t owiApi(struct uartStruct *ptr_uartStruct)
{
uint8_t index;
//int8_t (*func)(struct uartStruct);
//struct showCommand_t
printDebug_p(debugLevelEventDebug, debugSystemOWIApiSettings, __LINE__, filename, PSTR("begin"));
switch(ptr_uartStruct->number_of_arguments)
{
case 0:
for (index = 0; index < owiApiCommandKeyNumber_MAXIMUM_NUMBER; index++)
{
printDebug_p(debugLevelEventDebug, debugSystemOWIApiSettings, __LINE__, filename, PSTR("all begin %i"), index);
ptr_uartStruct->number_of_arguments = 1;
clearString(setParameter[1], MAX_LENGTH_PARAMETER);
snprintf_P(setParameter[1],MAX_LENGTH_PARAMETER -1, (PGM_P) (pgm_read_word( &(owiApiCommandKeywords[index]))));
printDebug_p(debugLevelEventDebug, debugSystemOWIApiSettings, __LINE__, filename, PSTR("recursive call of %s with parameter \"%s\" (%p)"), __func__, &setParameter[1][0], &setParameter[1][0]);
owiApi(ptr_uartStruct);
printDebug_p(debugLevelEventDebug, debugSystemOWIApiSettings, __LINE__, filename, PSTR("all end %i"), index);
ptr_uartStruct->number_of_arguments = 0;
}
break;
default: /* index > 0 */
index = apiFindCommandKeywordIndex(setParameter[1], owiApiCommandKeywords, owiApiCommandKeyNumber_MAXIMUM_NUMBER);
switch (index)
{
case owiApiCommandKeyNumber_COMMON_ADC_CONVERSION:
case owiApiCommandKeyNumber_COMMON_TEMPERATURE_CONVERSION:
owiApiFlag(ptr_uartStruct, index);
break;
default:
CommunicationError_p(ERRA, dynamicMessage_ErrorIndex, FALSE, PSTR("owiApi:invalid argument"));
return 1;
break;
}
break;
}
printDebug_p(debugLevelEventDebug, debugSystemOWIApiSettings, __LINE__, filename, PSTR("end"));
return 0;
}
int8_t owiApiFlag(struct uartStruct * ptr_uartStruct, uint8_t index)
{
uint8_t flag = 0;
if (1 < ptr_uartStruct->number_of_arguments) /*set value*/
{
flag = ( 0 != strtoul(setParameter[2], &ptr_setParameter[2], 16));
}
switch (index)
{
case owiApiCommandKeyNumber_COMMON_ADC_CONVERSION:
if (1 < ptr_uartStruct->number_of_arguments) /*set value*/
{
owiUseCommonAdcConversion_flag = flag;
}
flag = owiUseCommonAdcConversion_flag;
break;
case owiApiCommandKeyNumber_COMMON_TEMPERATURE_CONVERSION:
if (1 < ptr_uartStruct->number_of_arguments) /*set value*/
{
owiUseCommonTemperatureConversion_flag = flag;
}
flag = owiUseCommonTemperatureConversion_flag;
break;
default:
CommunicationError_p(ERRA, dynamicMessage_ErrorIndex, FALSE, PSTR("owiApiFlag:invalid argument"));
return 1;
break;
}
createExtendedSubCommandReceiveResponseHeader(ptr_uartStruct, commandKeyNumber_OWSA, index, owiApiCommandKeywords);
snprintf_P(uart_message_string,BUFFER_SIZE -1, PSTR("%s%i"), uart_message_string, flag);
strncat_P(uart_message_string,((flag)?PSTR(" (TRUE)"):PSTR(" (FALSE)")),BUFFER_SIZE -1);
UART0_Send_Message_String_p(NULL,0);
return 0;
}