esp_idf  1.1.1
esp_idf
com_espressif_esp_idf_nvs.c
Go to the documentation of this file.
1 /*
2  * C
3  *
4  * Copyright 2020 MicroEJ Corp. All rights reserved.
5  * This library is provided in source code for use, modification and test, subject to license terms.
6  * Any modification of the source code will break MicroEJ Corp. warranties on the whole library.
7  */
8 
18 #include "nvs.h"
19 
20 void Java_com_espressif_esp_1idf_nvs_nvs_1close(jint handle) {
21  nvs_close(handle);
22 }
23 
24 void Java_com_espressif_esp_1idf_nvs_nvs_1commit(jint handle) {
25  int err = nvs_commit(handle);
26  if (err != ESP_OK) {
27  SNI_throwNativeIOException(err, NULL);
28  }
29 }
30 
31 void Java_com_espressif_esp_1idf_nvs_nvs_1erase_1all(jint handle) {
32  int err = nvs_erase_all(handle);
33  if (err != ESP_OK) {
34  SNI_throwNativeIOException(err, NULL);
35  }
36 }
37 
38 void Java_com_espressif_esp_1idf_nvs_nvs_1erase_1key(jint handle, jbyte* key) {
39  int err = nvs_erase_key(handle, (char*) key);
40  if (err != ESP_OK) {
41  SNI_throwNativeIOException(err, NULL);
42  }
43 }
44 
45 jint Java_com_espressif_esp_1idf_nvs_nvs_1get_1blob(jint handle, jbyte* key, jbyte* blob, jint length) {
46  int err;
47  err = nvs_get_blob(handle, (char*) key, (char*) blob, (size_t*) &length);
48  if (err != ESP_OK){
49  SNI_throwNativeIOException(err, NULL);
50  }
51  return length;
52 }
53 
54 jshort Java_com_espressif_esp_1idf_nvs_nvs_1get_1i16(jint handle, jbyte* key) {
55  jshort value;
56  int err = nvs_get_i16(handle, (char*) key, &value);
57  if (err != ESP_OK) {
58  SNI_throwNativeIOException(err, NULL);
59  }
60  return value;
61 }
62 
63 jint Java_com_espressif_esp_1idf_nvs_nvs_1get_1i32(jint handle, jbyte* key) {
64  jint value;
65  int err = nvs_get_i32(handle, (char*) key, &value);
66  if (err != ESP_OK) {
67  SNI_throwNativeIOException(err, NULL);
68  }
69  return value;
70 }
71 
72 jlong Java_com_espressif_esp_1idf_nvs_nvs_1get_1i64(jint handle, jbyte* key) {
73  jlong value;
74  int err = nvs_get_i64(handle, (char*) key, &value);
75  if (err != ESP_OK) {
76  SNI_throwNativeIOException(err, NULL);
77  }
78  return value;
79 }
80 
81 jbyte Java_com_espressif_esp_1idf_nvs_nvs_1get_1i8(jint handle, jbyte* key) {
82  jbyte value;
83  int err = nvs_get_i8(handle, (char*) key, &value);
84  if (err != ESP_OK) {
85  SNI_throwNativeIOException(err, NULL);
86  }
87  return value;
88 }
89 
90 jint Java_com_espressif_esp_1idf_nvs_nvs_1get_1str(jint handle, jbyte* key, jbyte* str, jint length) {
91  int err;
92  err = nvs_get_str(handle, (char*) key, (char*) str, (size_t*) &length);
93  if (err != ESP_OK) {
94  SNI_throwNativeIOException(err, NULL);
95  }
96  return length;
97 }
98 
99 jshort Java_com_espressif_esp_1idf_nvs_nvs_1get_1u16(jint handle, jbyte* key) {
100  jshort value;
101  int err = nvs_get_u16(handle, (char*) key, (uint16_t *) &value);
102  if (err != ESP_OK) {
103  SNI_throwNativeIOException(err, NULL);
104  }
105  return value;
106 }
107 
108 jint Java_com_espressif_esp_1idf_nvs_nvs_1get_1u32(jint handle, jbyte* key) {
109  jint value;
110  int err = nvs_get_u32(handle, (char*) key, (uint32_t *) &value);
111  if (err != ESP_OK) {
112  SNI_throwNativeIOException(err, NULL);
113  }
114  return value;
115 }
116 
117 jlong Java_com_espressif_esp_1idf_nvs_nvs_1get_1u64(jint handle, jbyte* key) {
118  jlong value;
119  int err = nvs_get_u64(handle, (char*) key, (uint64_t *) &value);
120  if (err != ESP_OK) {
121  SNI_throwNativeIOException(err, NULL);
122  }
123  return value;
124 }
125 
126 jbyte Java_com_espressif_esp_1idf_nvs_nvs_1get_1u8(jint handle, jbyte* key) {
127  jbyte value;
128  int err = nvs_get_u8(handle, (char*) key, (uint8_t *) &value);
129  if (err != ESP_OK) {
130  SNI_throwNativeIOException(err, NULL);
131  }
132  return value;
133 }
134 
135 jlong Java_com_espressif_esp_1idf_nvs_nvs_1get_1used_1entry_1count(jint handle) {
136  size_t used_entries;
137  int err = nvs_get_used_entry_count(handle, &used_entries);
138  if (err != ESP_OK) {
139  SNI_throwNativeIOException(err, NULL);
140  }
141  return used_entries;
142 }
143 
144 jint Java_com_espressif_esp_1idf_nvs_nvs_1open(jbyte* name, jint open_mode) {
145  nvs_handle_t handle;
146  int err = nvs_open((char*) name, open_mode, &handle);
147  if (err != ESP_OK) {
148  SNI_throwNativeIOException(err, NULL);
149  }
150  return handle;
151 }
152 
153 jint Java_com_espressif_esp_1idf_nvs_nvs_1open_1from_1partition(jbyte* part_name, jbyte* name, jint open_mode) {
154  nvs_handle_t handle;
155  int err = nvs_open_from_partition((char*) part_name, (char*) name, open_mode, &handle);
156  if (err != ESP_OK) {
157  SNI_throwNativeIOException(err, NULL);
158  }
159  return handle;
160 }
161 
162 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1blob(jint handle, jbyte* key, jbyte* blob, jint length) {
163  int err = nvs_set_blob(handle, (char*) key, (char*) blob, (size_t) length);
164  if (err != ESP_OK) {
165  SNI_throwNativeIOException(err, NULL);
166  }
167 }
168 
169 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1i16(jint handle, jbyte* key, jshort value) {
170  int err = nvs_set_i16(handle, (char*) key, value);
171  if (err != ESP_OK) {
172  SNI_throwNativeIOException(err, NULL);
173  }
174 }
175 
176 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1i32(jint handle, jbyte* key, jint value) {
177  int err = nvs_set_i32(handle, (char*) key, value);
178  if (err != ESP_OK) {
179  SNI_throwNativeIOException(err, NULL);
180  }
181 }
182 
183 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1i64(jint handle, jbyte* key, jlong value) {
184  int err = nvs_set_i64(handle, (char*) key, value);
185  if (err != ESP_OK) {
186  SNI_throwNativeIOException(err, NULL);
187  }
188 }
189 
190 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1i8(jint handle, jbyte* key, jbyte value) {
191  int err = nvs_set_i8(handle, (char*) key, value);
192  if (err != ESP_OK) {
193  SNI_throwNativeIOException(err, NULL);
194  }
195 }
196 
197 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1str(jint handle, jbyte* key, jbyte* value) {
198  int err = nvs_set_str(handle, (char*) key, (char*) value);
199  if (err != ESP_OK) {
200  SNI_throwNativeIOException(err, NULL);
201  }
202 }
203 
204 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1u16(jint handle, jbyte* key, jshort value) {
205  int err = nvs_set_u16(handle, (char*) key, value);
206  if (err != ESP_OK) {
207  SNI_throwNativeIOException(err, NULL);
208  }
209 }
210 
211 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1u32(jint handle, jbyte* key, jint value) {
212  int err = nvs_set_u32(handle, (char*) key, value);
213  if (err != ESP_OK) {
214  SNI_throwNativeIOException(err, NULL);
215  }
216 }
217 
218 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1u64(jint handle, jbyte* key, jlong value) {
219  int err = nvs_set_u64(handle, (char*) key, value);
220  if (err != ESP_OK) {
221  SNI_throwNativeIOException(err, NULL);
222  }
223 }
224 
225 void Java_com_espressif_esp_1idf_nvs_nvs_1set_1u8(jint handle, jbyte* key, jbyte value) {
226  int err = nvs_set_u8(handle, (char*) key, value);
227  if (err != ESP_OK) {
228  SNI_throwNativeIOException(err, NULL);
229  }
230 }
esp-idf low level API