summaryrefslogtreecommitdiff
path: root/common/mock/battery_mock.c
blob: 63e94c660bdd5090bd4af8dd5572ee5cc6feab5d (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* Copyright 2021 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "battery.h"
#include "string.h"

/*****************************************************************************
 * Battery functions needed to enable CONFIG_BATTERY
 */
static int battery_soc_value = 100;
int board_get_battery_soc(void)
{
	return battery_soc_value;
}
void set_battery_soc(int new_value)
{
	battery_soc_value = new_value;
}

static int battery_status_value;
int battery_status(int *status)
{
	*status = battery_status_value;
	return EC_SUCCESS;
}
void set_battery_status(int new_value)
{
	battery_status_value = new_value;
}

static int battery_serial_number_value;
int battery_serial_number(int *serial)
{
	*serial = battery_serial_number_value;
	return EC_SUCCESS;
}
void set_battery_serial_number(int new_value)
{
	battery_serial_number_value = new_value;
}

static int battery_design_voltage_value = 5000;
int battery_design_voltage(int *voltage)
{
	*voltage = battery_design_voltage_value;
	return EC_SUCCESS;
}
void set_battery_design_voltage(int new_value)
{
	battery_design_voltage_value = new_value;
}

static int battery_mode_value;
int battery_get_mode(int *mode)
{
	*mode = battery_mode_value;
	return EC_SUCCESS;
}
void set_battery_mode(int new_value)
{
	battery_mode_value = new_value;
}

static int battery_soc_abs_value = 100;
int battery_state_of_charge_abs(int *percent)
{
	*percent = battery_soc_abs_value;
	return EC_SUCCESS;
}
void set_battery_soc_abs(int new_value)
{
	battery_soc_abs_value = new_value;
}

static int battery_remaining_capacity_value = 100;
int battery_remaining_capacity(int *capacity)
{
	*capacity = battery_remaining_capacity_value;
	return EC_SUCCESS;
}
void set_battery_remaining_capacity(int new_value)
{
	battery_remaining_capacity_value = new_value;
}

static int battery_full_charge_capacity_value = 100;
int battery_full_charge_capacity(int *capacity)
{
	*capacity = battery_full_charge_capacity_value;
	return EC_SUCCESS;
}
void set_battery_full_charge_capacity(int new_value)
{
	battery_full_charge_capacity_value = new_value;
}

static int battery_design_capacity_value = 100;
int battery_design_capacity(int *capacity)
{
	*capacity = battery_design_capacity_value;
	return EC_SUCCESS;
}
void set_battery_design_capacity(int new_value)
{
	battery_design_capacity_value = new_value;
}

static int battery_time_to_empty_value = 60;
int battery_time_to_empty(int *minutes)
{
	*minutes = battery_time_to_empty_value;
	return EC_SUCCESS;
}
void set_battery_time_to_empty(int new_value)
{
	battery_time_to_empty_value = new_value;
}

static int battery_run_time_to_empty_value = 60;
int battery_run_time_to_empty(int *minutes)
{
	*minutes = battery_run_time_to_empty_value;
	return EC_SUCCESS;
}
void set_battery_run_time_to_empty(int new_value)
{
	battery_run_time_to_empty_value = new_value;
}

static int battery_time_to_full_value;
int battery_time_to_full(int *minutes)
{
	*minutes = battery_time_to_full_value;
	return EC_SUCCESS;
}
void set_battery_time_to_full(int new_value)
{
	battery_time_to_full_value = new_value;
}

#define MAX_DEVICE_NAME_LENGTH 40
static char battery_device_name_value[MAX_DEVICE_NAME_LENGTH+1] = "?";
int battery_device_name(char *dest, int size)
{
	int i;

	for (i = 0; i < size && i < MAX_DEVICE_NAME_LENGTH; ++i)
		dest[i] = battery_device_name_value[i];
	for (; i < size; ++i)
		dest[i] = '\0';
	return EC_SUCCESS;
}
void set_battery_device_name(char *new_value)
{
	int i;
	int size = strlen(new_value);

	for (i = 0; i < size && i < MAX_DEVICE_NAME_LENGTH; ++i)
		battery_device_name_value[i] = new_value[i];
	for (; i < MAX_DEVICE_NAME_LENGTH+1; ++i)
		battery_device_name_value[i] = '\0';
}

#define MAX_DEVICE_CHEMISTRY_LENGTH 40
static char battery_device_chemistry_value[MAX_DEVICE_CHEMISTRY_LENGTH+1] = "?";
int battery_device_chemistry(char *dest, int size)
{
	int i;

	for (i = 0; i < size && i < MAX_DEVICE_CHEMISTRY_LENGTH; ++i)
		dest[i] = battery_device_chemistry_value[i];
	for (; i < size; ++i)
		dest[i] = '\0';
	return EC_SUCCESS;
}
void set_battery_device_chemistry(char *new_value)
{
	int i;
	int size = strlen(new_value);

	for (i = 0; i < size && i < MAX_DEVICE_CHEMISTRY_LENGTH; ++i)
		battery_device_chemistry_value[i] = new_value[i];
	for (; i < MAX_DEVICE_CHEMISTRY_LENGTH+1; ++i)
		battery_device_chemistry_value[i] = '\0';
}

static int battery_current_value = 3000;
static int battery_desired_current_value = 3000;
static int battery_desired_voltage_value = 5000;
static int battery_is_present_value = BP_YES;
static int battery_temperature_value = 20;
static int battery_voltage_value = 5000;
void battery_get_params(struct batt_params *batt)
{
	struct batt_params batt_new = {0};

	batt_new.temperature = battery_temperature_value;
	batt_new.state_of_charge = battery_soc_value;
	batt_new.voltage = battery_voltage_value;
	batt_new.current = battery_current_value;
	batt_new.desired_voltage = battery_desired_voltage_value;
	batt_new.desired_current = battery_desired_current_value;
	batt_new.remaining_capacity = battery_remaining_capacity_value;
	batt_new.full_capacity = battery_full_charge_capacity_value;
	batt_new.status = battery_status_value;
	batt_new.is_present = battery_is_present_value;

	memcpy(batt, &batt_new, sizeof(*batt));
}