CPS: Read contact data from codeplug

replace/78c49ab947a3986b1912b5995628be98fbef8239
Federico Amedeo Izzo 2021-01-23 11:28:12 +01:00
rodzic 739d1a2429
commit 0608176342
4 zmienionych plików z 87 dodań i 6 usunięć

Wyświetl plik

@ -22,6 +22,7 @@
#define CPS_H
#include <stdint.h>
#include <stdbool.h>
#include <interfaces/rtx.h>
#include <datatypes.h>
@ -108,7 +109,18 @@ typedef struct
typedef struct
{
char name[16]; /**< Zone name */
uint16_t member[64]; /**< Channels 1...64, 0=empty zone */
uint16_t member[64]; /**< Channel indexes */
} zone_t;
/**
* Data structure containing all the information of a contact.
*/
typedef struct
{
char name[16]; /**< Contact name */
uint32_t id; /**< DMR ID: 24bit number, 1...16777215 */
uint8_t type; /**< Call Type: Group Call, Private Call or All Call */
bool receive_tone; /**< Call Receive Tone: No or yes */
} contact_t;
#endif

Wyświetl plik

@ -64,4 +64,13 @@ int nvm_readChannelData(channel_t *channel, uint16_t pos);
*/
int nvm_readZoneData(zone_t *zone, uint16_t pos);
/**
* Read one contact from table stored in nonvolatile memory.
*
* @param contact: pointer to the contact_t data structure to be populated.
* @param pos: position, inside the zone table, from which read data.
* @return 0 on success, -1 on failure
*/
int nvm_readContactData(contact_t *contact, uint16_t pos);
#endif /* NVMEM_H */

Wyświetl plik

@ -114,8 +114,7 @@ typedef struct
// Bytes 32-63
uint16_t name[16];
}
mduv3x0Channel_t;
} mduv3x0Channel_t;
typedef struct {
// Bytes 0-31
@ -133,11 +132,26 @@ typedef struct {
uint16_t member_b[64]; // Member B: channels 1...64
} mduv3x0ZoneExt_t;
const uint32_t chDataBaseAddr = 0x110000; /**< Base address of channel data */
typedef struct {
// Bytes 0-2
uint8_t id[3]; // Call ID: 1...16777215
// Byte 3
uint8_t type : 5, // Call Type: Group Call, Private Call or All Call
receive_tone : 1, // Call Receive Tone: No or yes
_unused2 : 2; // 0b11
// Bytes 4-35
uint16_t name[16]; // Contact Name (Unicode)
} mduv3x0Contact_t;
const uint32_t zoneBaseAddr = 0x149e0; /**< Base address of zones */
const uint32_t zoneExtBaseAddr = 0x31000; /**< Base address of zone extensions */
const uint32_t chDataBaseAddr = 0x110000; /**< Base address of channel data */
const uint32_t contactBaseAddr = 0x140000; /**< Base address of contacts */
const uint32_t maxNumChannels = 3000; /**< Maximum number of channels in memory */
const uint32_t maxNumZones = 250; /**< Maximum number of zones and zone extensions in memory */
const uint32_t maxNumContacts = 10000; /**< Maximum number of contacts in memory */
/**
* \internal Utility function to convert 4 byte BCD values into a 32-bit
@ -234,7 +248,7 @@ void nvm_readCalibData(void *buf)
int nvm_readChannelData(channel_t *channel, uint16_t pos)
{
if(pos > maxNumChannels) return -1;
if(pos >= maxNumChannels) return -1;
W25Qx_wakeup();
delayUs(5);
@ -327,7 +341,7 @@ int nvm_readChannelData(channel_t *channel, uint16_t pos)
int nvm_readZoneData(zone_t *zone, uint16_t pos)
{
if(pos > maxNumZones) return -1;
if(pos >= maxNumZones) return -1;
W25Qx_wakeup();
delayUs(5);
@ -363,3 +377,34 @@ int nvm_readZoneData(zone_t *zone, uint16_t pos)
return 0;
}
int nvm_readContactData(contact_t *contact, uint16_t pos)
{
if(pos >= maxNumContacts) return -1;
W25Qx_wakeup();
delayUs(5);
mduv3x0Contact_t contactData;
uint32_t contactAddr = contactBaseAddr + pos * sizeof(mduv3x0Contact_t);
W25Qx_readData(contactAddr, ((uint8_t *) &contactData), sizeof(mduv3x0Contact_t));
W25Qx_sleep();
// Check if contact is empty
if(wcslen((wchar_t *) contactData.name) == 0) return -1;
/*
* Brutally convert channel name from unicode to char by truncating the most
* significant byte
*/
for(uint16_t i = 0; i < 16; i++)
{
contact->name[i] = ((char) (contactData.name[i] & 0x00FF));
}
// Copy contact DMR ID
contact->id = (contactData.id[0] | contactData.id[1] << 8 | contactData.id[2] << 16);
// Copy contact details
contact->type = contactData.type;
contact->receive_tone = contactData.receive_tone ? true : false;
return 0;
}

Wyświetl plik

@ -67,5 +67,20 @@ int main()
}
puts("\r");
}
printf("Contacts:\r\n");
for(int pos=0,result=0; result != -1; pos++)
{
contact_t contact;
result = nvm_readContactData(&contact, pos);
if(result != -1)
{
printf("Contact n.%d:\r\n", pos+1);
printf(" %s\r\n", contact.name);
printf(" - DMR ID:%lu\r\n", contact.id);
printf(" - Type:%d\r\n", contact.type);
printf(" - Receive Tone:%s\r\n", contact.receive_tone ? "True" : "False");
}
puts("\r");
}
return 0;
}